:root {
  --bg: #0f1216;
  --panel: #181d24;
  --panel-2: #212832;
  --text: #e6e9ee;
  --muted: #93a0b0;
  --border: #2a323d;
  --accent: #3ea06b;
  --accent-hover: #47b87a;
  --danger: #d9534f;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); display: inline-flex; align-items: center; gap: 9px; letter-spacing: .02em; }
.logo { width: 24px; height: 24px; display: block; }
.logo-lg { width: 40px; height: 40px; vertical-align: middle; margin-right: 4px; }
.topbar nav a {
  margin-left: 18px; color: var(--muted); padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.topbar nav a:hover { color: var(--text); text-decoration: none; }
.topbar nav a.active { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 900px; margin: 0 auto; padding: 24px 20px 60px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 22px; margin-bottom: 22px;
}
.card h1, .card h2 { margin-top: 0; }
.muted { color: var(--muted); }

.grid { display: grid; gap: 14px; }
.grid label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 14px; }
.row label { flex: 1; }

input[type=text], input[type=password], input[type=number], input[type=search] {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font-size: 14px;
}
input:focus { outline: none; border-color: var(--accent); }

fieldset.stores {
  border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
}
fieldset.stores legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
/* Override the generic `.grid label { display:grid }` so checkbox + label sit
   on one row, left-aligned. */
.grid fieldset.stores label.checkbox {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  color: var(--text); font-size: 14px; margin: 0;
}
.checkbox input[type=checkbox] { width: auto; margin: 0; flex: none; }

/* English -> Japanese keyword suggestions */
.translit { margin: 2px 0 0; font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 0; }
.translit:empty { margin: 0; }
.translit-label { color: var(--muted); }
.chip {
  background: var(--panel-2); color: var(--accent-hover); border: 1px solid var(--border);
  padding: 4px 11px; border-radius: 16px; font-size: 13px; cursor: pointer; font-weight: 500;
}
.chip:hover { border-color: var(--accent); background: rgba(62,160,107,.12); }

button {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--accent-hover); }
/* Small secondary button with a leading icon */
.btn-sm {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 11px; font-size: 13px; font-weight: 500; cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { background: var(--panel-2); color: var(--text); border-color: var(--muted); }
.btn-sm.danger:hover {
  color: #f0938f; border-color: var(--danger); background: rgba(217,83,79,.12);
}
.btn-sm svg { width: 14px; height: 14px; flex: none; }
a.btn-sm { text-decoration: none; }
a.btn-sm:hover { text-decoration: none; }
.actions { margin-top: 4px; }
.form-actions { display: flex; align-items: center; gap: 12px; }

/* Explanatory note under a field */
.hint { font-size: 13px; margin: -4px 0 0; line-height: 1.5; }
input:disabled {
  opacity: .6; cursor: not-allowed; background: var(--bg);
}

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.list td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr.inactive { opacity: .5; }
.kw { font-weight: 600; }
.rowactions { display: flex; gap: 4px; }
.rowactions form { margin: 0; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 20px; }
.badge.on { background: rgba(62,160,107,.18); color: var(--accent-hover); }
.badge.off { background: var(--panel-2); color: var(--muted); }
.badge.err { background: rgba(217,83,79,.18); color: #f0938f; }
.badge.pending { background: var(--panel-2); color: var(--muted); }

/* Search bar (overrides) */
.searchbar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; position: relative; }
.searchbar input {
  flex: 1; padding-left: 34px; -webkit-appearance: none; appearance: none;
}
.searchbar .search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); display: flex; pointer-events: none;
}
.searchbar .search-icon svg { width: 15px; height: 15px; }
.searchbar .clear { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* Overrides editor */
.override-add { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.override-add input { flex: 1; min-width: 180px; }
.override-add .arrow { color: var(--muted); }
.override-add button { flex: none; }
table.overrides td { padding: 8px 10px; }
.count { margin-top: 12px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 18px; }
.pagination a { color: var(--accent-hover); }
.pagination .disabled { color: var(--border); }

/* DeepL quota meter */
.meter {
  height: 7px; background: var(--panel-2); border-radius: 5px;
  overflow: hidden; margin-top: 9px;
}
.meter-fill {
  height: 100%; background: var(--accent); border-radius: 5px;
  transition: width .4s ease;
}
.meter-fill.warn { background: #d8a13d; }
.meter-fill.danger { background: var(--danger); }

/* Test notification */
.test-notify {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border);
  font-size: 13px;
}

/* Notification toggles */
.notif-list { display: grid; gap: 4px; }
.notif {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px 0; border-top: 1px solid var(--border);
}
.notif .detail { margin-top: 4px; line-height: 1.5; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; margin-top: 2px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer; border-radius: 22px;
  background: var(--panel-2); border: 1px solid var(--border); transition: .2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 2px; top: 2px;
  background: var(--muted); border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: rgba(62,160,107,.35); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--accent-hover); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

.detail-cell { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

/* In-progress spinner for async buttons */
.spinner {
  display: inline-block; width: 12px; height: 12px; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent-hover);
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
button:disabled { opacity: .65; cursor: progress; }
.ok-text { color: var(--accent-hover); }

/* Health */
.health-head { display: flex; align-items: center; justify-content: space-between; }
.refresh { font-size: 13px; }
.health-item { padding: 14px 0; border-top: 1px solid var(--border); }
.health-row { display: flex; align-items: center; gap: 10px; }
.health-row .latency { margin-left: auto; }
.detail { font-size: 13px; margin-top: 5px; }
.err-text { color: #f0938f; }

.history .item { display: flex; align-items: center; gap: 10px; max-width: 340px; }
.history .item img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: none; }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash.ok { background: rgba(62,160,107,.15); border: 1px solid var(--accent); }
.flash.error { background: rgba(217,83,79,.15); border: 1px solid var(--danger); }

.login-card { max-width: 360px; margin: 8vh auto 0; text-align: center; }
.login-card form { display: grid; gap: 12px; margin-top: 18px; }

/* --------------------------------------------------------------------------
   Mobile
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  main { padding: 16px 12px 48px; }
  .card { padding: 16px 14px; border-radius: 10px; margin-bottom: 16px; }
  .card h2 { font-size: 19px; }

  /* Nav wraps onto its own line instead of overflowing */
  .topbar { padding: 12px 14px; flex-wrap: wrap; gap: 10px; }
  .topbar nav { width: 100%; display: flex; flex-wrap: wrap; gap: 6px 16px; }
  .topbar nav a { margin-left: 0; font-size: 14px; padding: 2px 0; }

  /* 16px inputs stop iOS from zooming in on focus */
  input[type=text], input[type=password], input[type=number], input[type=search] {
    font-size: 16px; padding: 11px;
  }
  .searchbar input { padding-left: 36px; }
  button { padding: 11px 16px; }
  .btn-sm { padding: 8px 12px; }
  .row { flex-direction: column; gap: 14px; }
  .override-add { flex-direction: column; align-items: stretch; }
  .override-add .arrow { display: none; }

  /* Tables become stacked cards, labelled from each cell's data-label */
  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr {
    border: 1px solid var(--border); border-radius: 10px;
    padding: 4px 12px; margin-bottom: 12px;
  }
  table.list td {
    border-bottom: none; padding: 9px 0; display: flex; align-items: center;
    justify-content: space-between; gap: 14px; text-align: right;
  }
  table.list td + td { border-top: 1px solid var(--border); }
  table.list td::before {
    content: attr(data-label); flex: none; text-align: left;
    color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  }
  table.list td[data-label=""]::before { content: none; }
  .rowactions { justify-content: flex-end; }
  .history .item { max-width: none; justify-content: flex-end; }
  .history .item a { overflow-wrap: anywhere; }

  .pagination { gap: 14px; font-size: 14px; flex-wrap: wrap; }
  .health-row { flex-wrap: wrap; }
  .health-row .latency { margin-left: 0; }
  .login-card { margin-top: 5vh; }
}
