:root {
  --bg: #f4f6f9; --card: #fff; --text: #1d2433; --muted: #6b7385; --line: #e2e6ee;
  --brand: #1f6feb; --brand-ink: #fff; --danger: #c93636; --ok: #1a7f37; --row-hover: #f0f5ff;
  --sel: #dbe8ff; --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --card: #1a1f29; --text: #e6e9ef; --muted: #98a0b3; --line: #2b3240;
    --brand: #4c8dff; --row-hover: #222a38; --sel: #263a5c; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card);
         border-radius: 8px; padding: 7px 14px; }
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { width: 100%; padding: 7px 10px; border: 1px solid var(--line);
         border-radius: 8px; background: var(--bg); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }

/* top bar */
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px;
         background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header h1 { font-size: 16px; margin: 0 8px 0 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.tabs button { border-radius: 999px; padding: 5px 14px; }
.tabs button.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.user { display: flex; gap: 8px; align-items: center; color: var(--muted); }

/* layout */
main { display: grid; grid-template-columns: 380px 1fr; gap: 16px; padding: 16px; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; padding: 12px; } }
.panel { padding: 16px; min-width: 0; }
.panel h2 { font-size: 15px; margin: 0 0 12px; display: flex; justify-content: space-between; }
.panel h2 small { color: var(--muted); font-weight: normal; }

form.entry label { display: block; margin-bottom: 10px; }
form.entry label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
form.entry .req::after { content: " *"; color: var(--danger); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions .spacer { flex: 1; }

.listbar { display: flex; gap: 8px; margin-bottom: 10px; }
.listbar input { flex: 1; }
.tablewrap { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid var(--line); border-radius: 8px; }
@media (max-width: 900px) { .tablewrap { max-height: 70vh; } }
table { border-collapse: collapse; width: 100%; white-space: nowrap; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { position: sticky; top: 0; background: var(--card); cursor: pointer; user-select: none; z-index: 1; }
th.sorted::after { content: " ▲"; font-size: 10px; }
th.sorted.desc::after { content: " ▼"; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--row-hover); }
tbody tr.selected { background: var(--sel); }
td.empty { text-align: center; color: var(--muted); padding: 30px; cursor: default; }

/* toast + dialog */
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); padding: 10px 18px;
         border-radius: 8px; background: var(--text); color: var(--bg); opacity: 0;
         transition: opacity .2s; pointer-events: none; max-width: calc(100vw - 32px); z-index: 10; }
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
         color: var(--text); padding: 20px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 10px; font-size: 15px; }
dialog section { margin-bottom: 20px; }
.rows > div { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.rows > div > span { flex: 1; }
.inline { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.inline input, .inline select { flex: 1; min-width: 120px; width: auto; }
.muted { color: var(--muted); }

/* login */
.login { max-width: 360px; margin: 12vh auto 0; padding: 28px; }
.login h1 { font-size: 18px; margin: 0 0 18px; }
.login label { display: block; margin-bottom: 12px; }
.login label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.login button { width: 100%; margin-top: 6px; }
.login .err { color: var(--danger); min-height: 20px; margin-top: 10px; }
@media (max-width: 420px) { .login { margin: 8vh 16px 0; } }
