:root {
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.08), 0 1px 1px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.18);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --t-fast: 120ms ease;
  --t-med: 220ms cubic-bezier(.2,.7,.2,1);
  --danger: #ef4444;
  --warn: #f59e0b;
  --ok: #10b981;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f17;
  --bg-elev: #11161f;
  --bg-elev-2: #161c27;
  --bg-input: #0e131c;
  --border: #232b3a;
  --border-strong: #2f3a4d;
  --text: #e6eaf2;
  --text-dim: #97a2b6;
  --text-faint: #6b7589;
  --accent: #7c5cff;
  --accent-hover: #8c6fff;
  --accent-soft: rgba(124,92,255,.16);
  --danger-bg: rgba(239,68,68,.12);
  --ok-bg: rgba(16,185,129,.12);
  --warn-bg: rgba(245,158,11,.14);
  --focus: 0 0 0 3px rgba(124,92,255,.35);
  --topbar-bg: rgba(11,15,23,.7);
  --backdrop: rgba(0,0,0,.55);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6fa;
  --bg-elev: #ffffff;
  --bg-elev-2: #fbfbfd;
  --bg-input: #ffffff;
  --border: #e3e6ee;
  --border-strong: #cdd2dd;
  --text: #1a1f2c;
  --text-dim: #5a6373;
  --text-faint: #8a93a3;
  --accent: #5b3df5;
  --accent-hover: #4c2eea;
  --accent-soft: rgba(91,61,245,.12);
  --danger-bg: rgba(239,68,68,.10);
  --ok-bg: rgba(16,185,129,.10);
  --warn-bg: rgba(245,158,11,.14);
  --focus: 0 0 0 3px rgba(91,61,245,.22);
  --topbar-bg: rgba(255,255,255,.7);
  --backdrop: rgba(15,20,30,.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--accent-soft), transparent 60%),
    var(--bg);
}

#app { min-height: 100vh; display: block; }

.view { display: block; }
.view.is-hidden, .view[hidden] { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.muted { color: var(--text-dim); }
.text-dim { color: var(--text-dim); }

code, pre, .mono { font-family: var(--mono); }

/* ============== Buttons ============== */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
  user-select: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-elev-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn[disabled], .btn.is-loading {
  opacity: .6;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 20px -10px var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.05); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { background: var(--bg-elev-2); color: var(--text); }

.btn-icon { padding: 8px; }

.btn .ic-sun, .btn .ic-moon { display: none; }
html[data-theme="dark"] .btn .ic-sun { display: inline-block; }
html[data-theme="light"] .btn .ic-moon { display: inline-block; }

/* ============== Inputs ============== */
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
input::placeholder { color: var(--text-faint); }
input:hover { border-color: var(--border-strong); }
input:focus { border-color: var(--accent); box-shadow: var(--focus); }

label {
  display: block;
  margin-bottom: 14px;
  font-size: 14px;
}
label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: .01em;
}
label small { display: block; margin-top: 6px; font-size: 12px; }
label code { background: var(--bg-elev-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

.input-with-action {
  position: relative;
  display: flex;
  gap: 6px;
}
.input-with-action input { flex: 1; }
.input-with-action .btn {
  padding: 0 10px;
  border: 1px solid var(--border);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 6px 0 0;
  min-height: 1em;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 10px 0 10px;
  width: 240px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.search:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.search svg { color: var(--text-faint); flex: 0 0 auto; }
.search input {
  border: 0;
  background: transparent;
  padding: 9px 6px;
  width: 100%;
  box-shadow: none !important;
}
.search input:focus { box-shadow: none !important; }

/* ============== Auth views ============== */
#view-login, #view-setup {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
  animation: pop .25s var(--t-med);
}

.auth-card .brand {
  text-align: center;
  margin-bottom: 22px;
}
.auth-card .brand svg {
  color: var(--accent);
  margin-bottom: 8px;
}
.auth-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.auth-card p.muted { margin: 0; font-size: 14px; }

.auth-card form { display: block; }
.auth-card .btn-primary { width: 100%; justify-content: center; padding: 11px 14px; }

#btn-theme-login {
  position: absolute;
  top: 14px;
  right: 14px;
}

@keyframes pop {
  from { transform: translateY(6px) scale(.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ============== Top bar ============== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--topbar-bg);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 22px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; letter-spacing: -.01em;
  color: var(--text);
  flex: 0 0 auto;
}
.logo svg { color: var(--accent); }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font: inherit;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
}
.tab:hover { color: var(--text); background: var(--bg-elev-2); }
.tab.active {
  color: var(--text);
  background: var(--accent-soft);
}
.tab:focus-visible { outline: none; box-shadow: var(--focus); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}
.chip::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-bg);
}

/* ============== Layout ============== */
.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.tab-panel { display: none; animation: fade .2s ease; }
.tab-panel.active { display: block; }
@keyframes fade {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: none; }
}

.panel-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.panel-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.panel-header p { margin: 0; font-size: 14px; }
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============== Cards / Forms ============== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card h3 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 600;
}
.card p { margin-top: 0; }

.form { max-width: 520px; }
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

/* ============== Table ============== */
.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--bg-elev-2);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr {
  transition: background var(--t-fast);
}
.table tbody tr:hover { background: var(--bg-elev-2); }
.table .col-num { width: 56px; color: var(--text-faint); }
.table .col-actions { width: 130px; text-align: right; }
.table .row-actions { display: inline-flex; gap: 4px; justify-content: flex-end; }
.table .host-cell {
  font-family: var(--mono);
  font-size: 13px;
}

.empty {
  background: var(--bg-elev);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
  color: var(--text-dim);
}

.backup-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 13px;
}
.backup-list li {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}
.backup-list li:nth-child(odd) { background: var(--bg-elev-2); }

/* ============== Output ============== */
.output {
  margin-top: 14px;
  padding: 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 360px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* ============== Modal ============== */
.modal {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: var(--radius-lg);
  padding: 0;
  width: min(460px, 92vw);
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.modal[open] { animation: pop .18s var(--t-med); }
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 18px; }
.modal footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-small { width: min(380px, 92vw); }

/* ============== Toasts ============== */
#toast-host {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 240px;
  max-width: 360px;
  font-size: 14px;
  animation: slidein .2s var(--t-med);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.leaving { animation: slideout .2s var(--t-med) forwards; }
@keyframes slidein {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes slideout {
  to { transform: translateX(20px); opacity: 0; }
}

/* ============== Responsive ============== */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .topbar-left { width: 100%; flex-wrap: wrap; }
  .tabs { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .tab { white-space: nowrap; }
  .topbar-right { width: 100%; justify-content: flex-end; }
  .panel-actions .search { width: 100%; }
  .panel-header { align-items: flex-start; }
  .table .col-num { display: none; }
  .table th:first-child, .table td:first-child { display: none; }
}

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