/* Headscale Panel — dark theme */
:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2230;
  --border: #2a3140;
  --border-strong: #3a4253;
  --text: #e6edf3;
  --text-dim: #9aa5b1;
  --text-muted: #6b7785;
  --accent: #2f81f7;
  --accent-hover: #4f98ff;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --orange: #db6d28;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
  --radius: 6px;
  --radius-lg: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-width: 200px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
}

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

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}

input, select, textarea {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

button {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--bg-elev); border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

button.danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}
button.danger:hover:not(:disabled) { background: rgba(248,81,73,0.12); }

button.sm { padding: 4px 10px; font-size: 12px; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */

.admin-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */

.admin-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand-text { font-size: 14px; font-weight: 600; color: var(--text); }
.sidebar-brand-sub { font-size: 11px; color: var(--text-muted); }

.sidebar-nav { padding: 10px 0; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-dim);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  font-size: 13px;
  font-weight: 500;
  user-select: none;
}
.nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-item.active { color: var(--accent); border-left-color: var(--accent); background: rgba(47,129,247,0.08); }
.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.sidebar-footer button { width: 100%; font-size: 12px; color: var(--text-dim); }

/* ── Main content ─────────────────────────────────────────────────────────────── */

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.panel-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.panel-actions { display: flex; gap: 8px; align-items: center; }

/* ── Stat grid ─────────────────────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 14px;
}
.stat-box-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.stat-box-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-box-value.green { color: var(--green); }
.stat-box-value.red { color: var(--red); }
.stat-box-value.yellow { color: var(--yellow); }
.stat-box-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ─────────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }

table.adm {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.adm thead tr {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
table.adm th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
table.adm td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.adm tbody tr:last-child td { border-bottom: none; }
table.adm tbody tr:hover { background: rgba(255,255,255,0.02); }

.cell-actions { display: flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.cell-mono { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }

/* ── Filter bar ─────────────────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filter-bar input, .filter-bar select { flex: 1; min-width: 160px; max-width: 280px; }

/* ── Pills ─────────────────────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.pill-pass  { background: rgba(63,185,80,0.15);  color: var(--green); }
.pill-warn  { background: rgba(210,153,34,0.15); color: var(--yellow); }
.pill-fail  { background: rgba(248,81,73,0.15);  color: var(--red); }
.pill-ok    { background: rgba(63,185,80,0.15);  color: var(--green); }
.pill-grey  { background: rgba(155,165,177,0.15); color: var(--text-dim); }
.pill-blue  { background: rgba(47,129,247,0.15); color: var(--accent); }

/* ── Tag chips ─────────────────────────────────────────────────────────────── */

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(47,129,247,0.12);
  border: 1px solid rgba(47,129,247,0.3);
  color: var(--accent);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
}
.tag-chip .rm {
  cursor: pointer;
  opacity: 0.7;
  margin-left: 2px;
  font-size: 13px;
  line-height: 1;
}
.tag-chip .rm:hover { opacity: 1; }
.tags-cell { display: flex; flex-wrap: wrap; gap: 4px; }

/* ── Online dot ─────────────────────────────────────────────────────────────── */

.online-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  vertical-align: middle;
  margin-right: 4px;
  flex-shrink: 0;
}
.online-dot.online { background: var(--green); box-shadow: 0 0 4px var(--green); }
.online-dot.offline { background: var(--text-muted); }

/* ── Expiry coloring ─────────────────────────────────────────────────────────── */

.expiry-warn { color: var(--yellow); font-weight: 600; }
.expiry-crit { color: var(--red); font-weight: 600; }
.expiry-ok   { color: var(--text-dim); }
.expiry-none { color: var(--text-muted); font-style: italic; }

/* ── Key box ─────────────────────────────────────────────────────────────────── */

.key-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  max-width: 280px;
  overflow: hidden;
}
.key-box span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.key-box button { padding: 2px 6px; font-size: 11px; flex-shrink: 0; }

/* ── Log area ─────────────────────────────────────────────────────────────────── */

.log-area {
  width: 100%;
  height: 340px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  padding: 12px;
  resize: vertical;
  tab-size: 2;
}

/* ── Raw ACL editor ─────────────────────────────────────────────────────────── */

.raw-acl-area {
  width: 100%;
  height: 440px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  padding: 12px;
  resize: vertical;
}

/* ── Doctor accordion ─────────────────────────────────────────────────────────── */

.doctor-section {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.doctor-section-title {
  background: var(--bg-elev);
  padding: 10px 14px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.doctor-section-title .arrow { transition: transform 0.2s; }
.doctor-section-title.open .arrow { transform: rotate(90deg); }
.doctor-items { padding: 0; }
.doctor-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.doctor-item-name { flex: 1; font-weight: 500; color: var(--text); }
.doctor-item-detail { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ── Sub-panels (ACL tabs) ─────────────────────────────────────────────────── */

.sub-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.sub-panel h3 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.sub-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.sub-tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.sub-tab-panel { display: none; }
.sub-tab-panel.active { display: block; }

/* ── Form rows ─────────────────────────────────────────────────────────────── */

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  align-items: flex-end;
}
.form-row > * { flex: 1; min-width: 140px; }
.form-row label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.form-row input, .form-row select { width: 100%; }

/* ── Wizard ─────────────────────────────────────────────────────────────────── */

.wiz-steps {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.wiz-step {
  padding: 10px 18px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: default;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.wiz-step .wiz-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
}
.wiz-step.active { color: var(--accent); border-bottom-color: var(--accent); }
.wiz-step.active .wiz-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.wiz-step.done { color: var(--green); }
.wiz-step.done .wiz-num { background: var(--green); border-color: var(--green); color: #fff; }

.wiz-body { min-height: 160px; }
.wiz-page { display: none; }
.wiz-page.active { display: block; }

.wiz-label { font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }

.picker-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 80px;
  max-height: 200px;
  overflow-y: auto;
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.picker-item:hover { background: var(--bg-elev-2); }
.picker-item input[type="checkbox"] { margin: 0; }

.wiz-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Toast notifications ─────────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  pointer-events: auto;
  max-width: 360px;
  animation: toast-in 0.25s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.warn    { border-left: 3px solid var(--yellow); }
.toast.info    { border-left: 3px solid var(--accent); }
.toast-icon { flex-shrink: 0; font-size: 16px; }
.toast-msg { flex: 1; }
.toast-close { flex-shrink: 0; cursor: pointer; opacity: 0.6; font-size: 16px; line-height: 1; background: none; border: none; color: var(--text); padding: 0; }
.toast-close:hover { opacity: 1; }
.toast-fade { animation: toast-out 0.3s ease forwards; }

@keyframes toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(8px); } }

/* ── Modals / Dialogs ─────────────────────────────────────────────────────────── */

dialog {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text);
  padding: 0;
  max-width: 560px;
  width: 94vw;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
dialog::backdrop {
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(2px);
}
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  z-index: 1;
}
.dialog-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.dialog-close { background: none; border: none; color: var(--text-dim); font-size: 20px; cursor: pointer; padding: 0; line-height: 1; }
.dialog-close:hover { color: var(--text); background: none; border: none; }
.dialog-body { padding: 20px; }
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--bg-elev);
}

/* ── Empty state ─────────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }
.empty-state-text { font-size: 14px; }

/* ── Loading spinner ─────────────────────────────────────────────────────────── */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-muted);
  gap: 10px;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Card ─────────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text); margin: 0 0 12px; }

/* ── Mobile responsive ─────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  :root { --sidebar-width: 56px; }

  .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 12px; gap: 0; }
  .sidebar-brand-text, .sidebar-brand-sub { display: none; }
  .sidebar-brand { justify-content: center; }
  .sidebar-footer button { font-size: 0; padding: 8px; }

  .admin-content { padding: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-header { flex-direction: column; align-items: flex-start; }
  .filter-bar { flex-direction: column; }
  .filter-bar input, .filter-bar select { max-width: 100%; }
  dialog { max-width: 98vw; }
}
