/* ============================================================
   Autofrp WebUI — flat / minimal
   ============================================================ */
:root {
  --bg: #0b1220;
  --surface: #101a2a;
  --surface-2: #16223a;
  --surface-3: #1c2a43;
  --border: #24344d;
  --border-strong: #34476a;

  --text: #e9eff8;
  --text-soft: #c8d4e6;
  --muted: #94a3b8;
  --faint: #6b7c94;

  --brand: #38bdf8;
  --brand-bg: rgba(56, 189, 248, 0.12);
  --cta: #16a34a;
  --cta-hover: #15803d;
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --purple: #a855f7;

  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 220px;
  --font-sans: "Fira Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "Fira Code", ui-monospace, SFMono-Regular, "JetBrains Mono",
    Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f2f5f9;
  --surface-3: #e8edf4;
  --border: #dfe5ee;
  --border-strong: #c6d1e0;

  --text: #0f172a;
  --text-soft: #334155;
  --muted: #5b6b82;
  --faint: #8494a8;

  --brand: #0284c7;
  --brand-bg: rgba(2, 132, 199, 0.1);
  --cta: #16a34a;
  --cta-hover: #15803d;
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.09);
  --warning: #b45309;
  --purple: #7c3aed;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.mono { font-family: var(--font-mono); font-size: 0.92em; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================================================ shell */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 6px 18px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--brand);
  color: #04121f;
  font-weight: 700;
  font-size: 17px;
}

.brand-name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-tag { font-size: 11.5px; color: var(--faint); }

.nav-label {
  padding: 10px 8px 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-soft);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background-color 120ms linear, color 120ms linear;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item .i { flex: none; color: var(--muted); }
.nav-item[aria-current="page"] {
  background: var(--brand-bg);
  border-color: rgba(56, 189, 248, 0.28);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--brand);
}
.nav-item[aria-current="page"] .i { color: var(--brand); }

.nav-count {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}
.nav-item[aria-current="page"] .nav-count { background: var(--brand-bg); color: var(--brand); }

.sidebar-foot {
  margin-top: auto;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 2px;
  font-size: 11.5px;
  color: var(--faint);
  min-width: 0;
}
.sidebar-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================ main */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 22px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.page-title { font-size: 16px; font-weight: 600; }
.page-sub { font-size: 12.5px; color: var(--muted); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.content {
  padding: 18px 22px 56px;
  display: grid;
  gap: 16px;
  max-width: 1280px;
  width: 100%;
}

.section { display: none; gap: 16px; }
.section.active { display: grid; }

.section-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.section-head > div:first-child { min-width: 0; }
.section-title { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.section-desc { margin-top: 2px; font-size: 12.5px; color: var(--muted); max-width: 80ch; }
.section-actions { margin-left: auto; display: flex; gap: 7px; flex-wrap: wrap; }

/* ============================================================ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card.tight { padding: 12px 14px; }
.card.flush { padding: 0; overflow: hidden; }

.card-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 12px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text-soft); display: flex; align-items: center; gap: 7px; }
.card-title .i { color: var(--brand); }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.grid-overview { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 12px; align-items: start; }

/* ============================================================ status cards */
.stat { display: flex; flex-direction: column; gap: 10px; }
.stat-top { display: flex; align-items: center; gap: 9px; }

.stat-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--brand-bg);
  color: var(--brand);
  flex: none;
}
.stat-name { font-size: 13.5px; font-weight: 600; }
.stat-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.stat-actions { display: flex; gap: 5px; flex-wrap: wrap; margin-top: auto; }

/* ============================================================ badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.65;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

.badge-ok { color: #4ade80; background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.28); }
.badge-off { color: #f87171; background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.26); }
.badge-warn { color: #fbbf24; background: rgba(245, 158, 11, 0.12); border-color: rgba(245, 158, 11, 0.26); }
.badge-info { color: var(--brand); background: var(--brand-bg); border-color: rgba(56, 189, 248, 0.26); }
.badge-purple { color: #c084fc; background: rgba(168, 85, 247, 0.12); border-color: rgba(168, 85, 247, 0.26); }
.badge-neutral { color: var(--text-soft); background: var(--surface-2); border-color: var(--border); }

html[data-theme="light"] .badge-ok { color: #15803d; background: rgba(22, 163, 74, 0.1); border-color: rgba(22, 163, 74, 0.26); }
html[data-theme="light"] .badge-off { color: #b91c1c; background: rgba(220, 38, 38, 0.08); border-color: rgba(220, 38, 38, 0.22); }
html[data-theme="light"] .badge-warn { color: #a16207; background: rgba(234, 179, 8, 0.12); border-color: rgba(202, 138, 4, 0.28); }
html[data-theme="light"] .badge-purple { color: #6d28d9; background: rgba(124, 58, 237, 0.08); border-color: rgba(124, 58, 237, 0.22); }

/* ============================================================ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms linear, border-color 120ms linear;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--cta);
  border-color: var(--cta);
  color: #ffffff;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--cta-hover); border-color: var(--cta-hover); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-soft); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger-bg); border-color: rgba(239, 68, 68, 0.35); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.2); }

.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12.5px; gap: 4px; }
.btn-icon { width: 32px; height: 32px; min-height: 32px; padding: 0; }
.btn-block { width: 100%; }
.btn .i { flex: none; }

.btn.loading { position: relative; color: transparent !important; }
.btn.loading .i { visibility: hidden; }
.btn.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-color: #fff transparent #fff transparent;
  animation: spin 700ms linear infinite;
}
.btn:not(.btn-primary).loading::after { border-color: var(--text) transparent var(--text) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================ segmented */
.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.segmented button {
  min-height: 30px;
  padding: 5px 11px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--brand-bg);
  color: var(--brand);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.3);
}

/* ============================================================ forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.field { display: grid; gap: 5px; align-content: start; }
.field > label { font-size: 12.5px; font-weight: 500; color: var(--text-soft); }
.field .hint, .hint { font-size: 11.5px; color: var(--faint); line-height: 1.45; }

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }
select { cursor: pointer; }
textarea { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; resize: vertical; }

.input-row { display: flex; gap: 6px; }
.input-row > input { flex: 1; min-width: 0; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text-soft); cursor: pointer; min-height: 22px; }
.check input[type="checkbox"] { width: 16px; height: 16px; min-height: 16px; margin: 2px 0 0; accent-color: var(--cta); cursor: pointer; flex: none; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }

/* ============================================================ tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 740px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

.cell-main { font-weight: 600; color: var(--text); }
.cell-sub { margin-top: 2px; font-size: 11.5px; color: var(--faint); }
.cell-actions { display: flex; gap: 5px; flex-wrap: wrap; }

/* ============================================================ empty */
.empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
  display: grid;
  justify-items: center;
  gap: 9px;
}
.empty .empty-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--faint);
}
.empty p { font-size: 13px; max-width: 46ch; }

/* ============================================================ banner */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(245, 158, 11, 0.3);
  background: rgba(245, 158, 11, 0.08);
  font-size: 13px;
}
.banner .i { color: var(--warning); flex: none; }
.banner-info { border-color: rgba(56, 189, 248, 0.3); background: var(--brand-bg); }
.banner-info .i { color: var(--brand); }
.banner-ok { border-color: rgba(34, 197, 94, 0.3); background: rgba(34, 197, 94, 0.08); }
.banner-ok .i { color: #4ade80; }
.banner-actions { margin-left: auto; display: flex; gap: 6px; }

/* ============================================================ checklist */
.checklist { display: grid; gap: 1px; }
.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.checklist-item:hover { background: var(--surface-2); }
.checklist-item.done { color: var(--faint); }
.checklist-item.done .step-mark { background: rgba(34, 197, 94, 0.12); color: #4ade80; border-color: rgba(34, 197, 94, 0.35); }
.step-mark {
  width: 22px; height: 22px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.checklist-item .go { margin-left: auto; color: var(--faint); }
.checklist-item:hover .go { color: var(--brand); }

/* ============================================================ kv */
.kv { display: grid; gap: 1px; }
.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 12.8px;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: 0; }
.kv-row > span:first-child { color: var(--muted); flex: none; }
.kv-value { display: flex; align-items: center; gap: 6px; min-width: 0; }
.kv-value .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.copy-btn {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  padding: 3px;
  border-radius: 4px;
  display: inline-grid;
  place-items: center;
  min-height: 24px;
  min-width: 24px;
}
.copy-btn:hover { color: var(--brand); background: var(--brand-bg); }

/* ============================================================ code */
.code {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow: auto;
}
.code.tall { max-height: 56vh; }

/* ============================================================ modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 8, 18, 0.62);
}
html[data-theme="light"] .modal-backdrop { background: rgba(15, 23, 42, 0.38); }
.modal-backdrop[hidden] { display: none; }

.modal {
  width: min(100%, 620px);
  max-height: min(88dvh, 880px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
}
.modal.wide { width: min(100%, 760px); }
.modal.narrow { width: min(100%, 420px); }

.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-sub { margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.modal-head .close { margin-left: auto; }

.modal-body { padding: 16px 18px; overflow-y: auto; display: grid; gap: 12px; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
  flex-wrap: wrap;
}

/* ============================================================ toast */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2000;
  display: grid;
  gap: 8px;
  width: min(340px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--brand);
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  font-size: 13px;
}
.toast.ok { border-left-color: var(--cta); }
.toast.err { border-left-color: var(--danger); }
.toast .i { flex: none; margin-top: 1px; }
.toast.ok .i { color: #4ade80; }
.toast.err .i { color: var(--danger); }
.toast.info .i { color: var(--brand); }

/* ============================================================ wizard */
.steps { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.step { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--faint); }
.step-num {
  width: 21px; height: 21px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  font-size: 11px;
  font-weight: 600;
}
.step.active { color: var(--text); }
.step.active .step-num { border-color: var(--brand); color: var(--brand); background: var(--brand-bg); }
.step.done .step-num { border-color: rgba(34, 197, 94, 0.4); color: #4ade80; background: rgba(34, 197, 94, 0.12); }
.step-line { flex: 1; height: 1px; background: var(--border); min-width: 10px; }

.choice-grid { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}
.choice:hover { border-color: var(--brand); }
.choice input { margin: 3px 0 0; accent-color: var(--brand); flex: none; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-bg); }
.choice-title { font-size: 13px; font-weight: 600; }
.choice-desc { font-size: 12px; color: var(--muted); margin-top: 1px; }

.progress-list { display: grid; gap: 7px; }
.progress-item { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-soft); }
.progress-item .state { margin-left: auto; font-size: 12px; color: var(--muted); }

/* ============================================================ logs */
.log-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.log-filter { flex: 1 1 200px; min-width: 140px; max-width: 320px; }
.log-follow { font-size: 12.5px; white-space: nowrap; }
.log-status { margin-left: auto; font-size: 12px; color: var(--faint); white-space: nowrap; }

.log-view {
  height: min(52vh, 520px);
  min-height: 240px;
  overflow: auto;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-soft);
}
.log-line {
  white-space: pre-wrap;
  word-break: break-word;
  content-visibility: auto;
  contain-intrinsic-size: auto 20px;
}
.log-line:hover { background: var(--surface-3); }
.log-err { color: #f87171; }
.log-warn { color: #fbbf24; }
html[data-theme="light"] .log-err { color: #b91c1c; }
html[data-theme="light"] .log-warn { color: #a16207; }
.log-empty { color: var(--faint); padding: 8px 2px; }

/* ============================================================ misc */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 11.5px;
}
.divider { height: 1px; background: var(--border); border: 0; margin: 4px 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ============================================================ responsive */
@media (max-width: 1180px) {
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-overview { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1023px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0 8px 0 0; flex: none; }
  .brand-tag, .nav-label, .sidebar-foot { display: none; }
  .nav { flex-direction: row; gap: 4px; overflow: visible; }
  .nav-item { white-space: nowrap; min-height: 34px; padding: 6px 10px; font-size: 13px; }
  .topbar { padding: 10px 14px; }
  .content { padding: 14px 14px 48px; }
}

@media (max-width: 820px) {
  .grid-stats, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .section-actions { margin-left: 0; width: 100%; }
  .section-actions .btn { flex: 1 1 auto; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  table { min-width: 0; }
  thead { display: none; }
  tbody tr { display: grid; gap: 5px; padding: 11px 12px; border-bottom: 1px solid var(--border); }
  tbody tr:last-child { border-bottom: 0; }
  tbody td { display: flex; align-items: center; gap: 8px; padding: 1px 0; border: 0; }
  tbody td::before { content: attr(data-label); flex: none; width: 88px; color: var(--faint); font-size: 11.5px; }
  .cell-actions { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }
  .log-status { margin-left: 0; }
}

@media (max-width: 520px) {
  body { font-size: 14px; }
  .topbar-actions { width: 100%; justify-content: space-between; flex-wrap: nowrap; }
  .segmented { width: auto; flex: 1; min-width: 0; }
  .segmented button { flex: 1; padding: 5px 7px; font-size: 12px; }
  .brand-name { font-size: 15px; }
  .card { padding: 13px; }
  .toasts { right: 10px; left: 10px; bottom: 10px; width: auto; }
}

@media (pointer: coarse) {
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .nav-item { min-height: 42px; }
  .copy-btn { min-height: 34px; min-width: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
