:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --line: #d8ded8;
  --line-strong: #b9c5bb;
  --text: #17211b;
  --muted: #607067;
  --accent: #1f7a5c;
  --accent-strong: #156248;
  --blue: #2468b2;
  --red: #c83f3f;
  --amber: #9a661a;
  --shadow: 0 8px 28px rgba(25, 45, 34, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; }

button, .download-link {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  min-height: 36px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover, .download-link:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:disabled { cursor: not-allowed; opacity: .55; }
.ghost-btn { background: transparent; color: var(--text); border-color: var(--line-strong); }
.ghost-btn:hover { background: var(--surface-2); border-color: var(--line-strong); }

input, select, textarea {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 92, .14);
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.app-shell { min-height: 100vh; }

.topbar {
  min-height: 72px;
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.runtime-info { min-height: 19px; margin-top: 5px; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; }

.stats-row {
  padding: 14px 22px;
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  background: #f1f5f2;
  border-bottom: 1px solid var(--line);
}
.stat {
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255,255,255,.72);
}
.stat strong { display: block; font-size: 22px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12px; }

.token-band, .import-band, .toolbar, .table-band {
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
}
.token-card {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(260px, 420px);
  gap: 12px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.token-card input {
  height: 38px;
  padding: 0 10px;
}
.token-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.token-status {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #f9fbfa;
  overflow-wrap: anywhere;
}
.token-live {
  color: var(--accent);
  border-color: rgba(31,122,92,.35);
  background: #f2fbf6;
}
.token-dead {
  color: var(--red);
  border-color: rgba(200,63,63,.35);
  background: #fff5f5;
}
.import-controls { display: grid; grid-template-columns: minmax(280px, 1fr) 180px; gap: 12px; }
textarea#importText { width: 100%; min-height: 112px; padding: 11px 12px; resize: vertical; line-height: 1.45; }
.import-side { display: grid; gap: 10px; align-content: start; }
.import-side select, .toolbar select, .toolbar input { height: 36px; padding: 0 10px; }
.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 150px 160px auto auto auto;
  gap: 10px;
  align-items: center;
  background: var(--surface);
}
.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
table { width: 100%; min-width: 1100px; border-collapse: collapse; table-layout: fixed; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 10px; vertical-align: middle; text-align: left; }
th { position: sticky; top: 0; z-index: 5; background: #eaf0ec; color: #25342b; font-size: 12px; font-weight: 700; }
th:first-child, td:first-child { width: 42px; text-align: center; }
th:nth-child(2), td:nth-child(2) { width: 230px; }
th:nth-child(3), td:nth-child(3) { width: 114px; }
th:nth-child(4), td:nth-child(4) { width: 260px; }
th:nth-child(5), td:nth-child(5) { width: 220px; }
th:nth-child(6), td:nth-child(6) { width: 132px; }
th:nth-child(7), td:nth-child(7) { width: 145px; }
th:nth-child(8), td:nth-child(8) { width: 200px; }
th:nth-child(9), td:nth-child(9) { width: 154px; }
tbody tr:hover { background: #f7fbf8; }
tbody tr.status-changed { background: #fff7e8; }
tbody tr.status-error { background: #fff1f1; }
.uid-cell { display: grid; gap: 4px; }
.uid-cell a { color: var(--blue); text-decoration: none; overflow-wrap: anywhere; }
.uid-cell code { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.name-input, .note-input, .type-select { width: 100%; min-height: 32px; padding: 0 8px; }
.name-input, .note-input { border-color: transparent; background: transparent; }
.name-input:hover, .note-input:hover, .name-input:focus, .note-input:focus { border-color: var(--line-strong); background: #fff; }
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  background: #fff;
}
.status-ok { color: var(--accent); border-color: rgba(31,122,92,.35); }
.status-changed-pill { color: var(--amber); border-color: rgba(154,102,26,.35); }
.status-error-pill { color: var(--red); border-color: rgba(200,63,63,.35); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions button { min-height: 30px; padding: 0 9px; }
.danger-btn { background: #fff; border-color: rgba(200,63,63,.45); color: var(--red); }
.danger-btn:hover { background: #fff0f0; border-color: var(--red); color: var(--red); }
.empty-state { display: none; padding: 28px; text-align: center; color: var(--muted); }
.empty-state.visible { display: block; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 6px;
  background: #19231d;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(120deg, rgba(31,122,92,.10), rgba(36,104,178,.10)), var(--bg);
}
.login-shell, .install-shell { width: min(760px, calc(100vw - 32px)); }
.login-box, .dialog-form, .install-box {
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-shell { width: min(390px, calc(100vw - 32px)); }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}
.login-box h1, .dialog-form h2, .install-box h1 { margin: 0; font-size: 22px; }
.login-box input, .dialog-form input, .install-box input { height: 40px; padding: 0 10px; }
.login-box button { min-height: 42px; }
.form-error { min-height: 19px; margin: 0; color: var(--red); }
dialog { border: 0; padding: 0; border-radius: 8px; background: transparent; }
dialog::backdrop { background: rgba(8,15,11,.42); }
.dialog-form { width: min(380px, calc(100vw - 32px)); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.error-text { color: var(--red); font-size: 12px; margin-top: 4px; overflow-wrap: anywhere; }
.install-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.install-note { margin: 0; color: var(--muted); }
.config-output { min-height: 180px; padding: 10px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

@media (max-width: 980px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .stats-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .token-card, .import-controls, .toolbar, .install-grid { grid-template-columns: 1fr; }
  .topbar-actions, .row-actions { width: 100%; }
  .topbar-actions button, .toolbar button, .token-actions button, .download-link, .import-side button { width: 100%; }
  .token-actions { width: 100%; }
}
@media (max-width: 560px) {
  .topbar, .stats-row, .token-band, .import-band, .toolbar, .table-band { padding-left: 12px; padding-right: 12px; }
  .stats-row { grid-template-columns: 1fr; }
}
