:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #141a24;
  --muted: #687385;
  --line: #e3e7ee;
  --accent: #1a73c9;
  --accent-ink: #ffffff;
  --accent-soft: #e8f2fc;
  --danger: #c73a3a;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 4px 16px rgb(16 24 40 / .05);
  --radius: 12px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23687385' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.4; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); margin: 0; }

svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- controls ---------- */

button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.wide { width: 100%; justify-content: center; height: 42px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; height: 38px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 400; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 90px; padding: 8px 10px; }
select { appearance: none; padding-right: 30px; background: var(--surface) var(--chevron) no-repeat right 10px center; text-overflow: ellipsis; }
select:disabled { background-color: var(--surface-2); color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- login ---------- */

.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent 60%), var(--bg);
}
.login-card {
  width: min(380px, 100%); display: grid; gap: 14px; padding: 32px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; margin-top: 6px; }
.login-card .muted { margin-top: -8px; margin-bottom: 6px; }
.error { color: var(--danger); margin: 0; min-height: 1.2em; white-space: pre-line; }

.logo { height: 30px; width: auto; display: block; }
.logo.big { height: 46px; justify-self: start; }

/* ---------- layout ---------- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { padding-right: 12px; border-right: 1px solid var(--line); box-sizing: content-box; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text span { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.tabs button { border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 12px;
}
.user-name { color: var(--muted); }

main { padding: 24px; max-width: 1400px; margin: 0 auto; display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.tab { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters { display: grid; gap: 14px; padding: 18px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 17px; }
.card-head .muted { font-size: 13px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 0; padding: 10px 18px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.hint svg { width: 13px; height: 13px; }
.hint:empty { display: none; }

/* ---------- table ---------- */

.table-wrap { overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 10px 18px; text-align: left; border-bottom: 1px solid var(--line); }
.grid th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: var(--accent-soft); }
.grid .num { width: 1%; white-space: nowrap; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.grid td.actions-cell { width: 1%; white-space: nowrap; text-align: right; padding-top: 4px; padding-bottom: 4px; }
#s-rows tr { cursor: pointer; }
.login-pill {
  display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px;
}
.grid .empty { text-align: center; color: var(--muted); padding: 48px 18px; }
.grid .empty svg { display: block; width: 34px; height: 34px; margin: 0 auto 10px; opacity: .5; }

.search-bar { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.search-bar > svg { color: var(--muted); width: 18px; height: 18px; }
.search-bar input { max-width: 480px; }

/* ---------- dialog / toast ---------- */

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / .25);
}
dialog::backdrop { background: rgb(10 15 25 / .45); backdrop-filter: blur(2px); }
.dlg { padding: 22px; display: grid; gap: 16px; }
.dlg h2 { font-size: 17px; }
#dlg-body { display: grid; gap: 12px; max-height: 65vh; overflow: auto; }
#dlg-body .grid th, #dlg-body .grid td { padding: 7px 10px; }
.dlg-buttons { display: flex; flex-direction: row-reverse; gap: 8px; }
.note { color: var(--muted); font-size: 12px; margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 20;
  max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 10px;
  background: var(--ink); color: var(--bg); box-shadow: 0 10px 30px rgb(0 0 0 / .2);
}
.toast.err { background: var(--danger); color: #fff; }

@media (max-width: 900px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 12px; }
  .brand-text span, .user-name { display: none; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; }
  .card-head .actions { width: 100%; }
  .card-head .btn { flex: 1 1 auto; justify-content: center; }
  main { padding: 16px; }
  .filters { grid-template-columns: 1fr; padding: 16px; }
  .grid th, .grid td { padding: 9px 12px; }
}
