/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f4f6f9;
  --surface:   #ffffff;
  --border:    #dde1e8;
  --text:      #1a1d23;
  --text-dim:  #6b7280;
  --primary:   #3b6ef0;
  --primary-h: #2958d4;
  --success:   #22c55e;
  --warning:   #f59e0b;
  --danger:    #ef4444;
  --sidebar-w: 220px;
  --radius:    6px;
  --shadow:    0 1px 4px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: #1a1d23;
  color: #c9cdd6;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid #2d3139;
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo { font-size: 22px; }
.logo-text { font-weight: 700; font-size: 15px; color: #fff; }

.nav-list {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-list li { margin: 0; }

.nav-link {
  display: block;
  padding: 9px 16px;
  color: #c9cdd6;
  transition: background .15s, color .15s;
}
.nav-link:hover, .nav-link.active {
  background: #252930;
  color: #fff;
  text-decoration: none;
}
.nav-link.active { border-left: 3px solid var(--primary); }

.sidebar-footer {
  padding: 12px 0;
  border-top: 1px solid #2d3139;
}

/* ── Main content ─────────────────────────────────────────────────────────── */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1200px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  font-weight: 500;
}
.flash-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* ── Stat grid ────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 32px; font-weight: 700; margin-top: 4px; }
.stat-sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

/* ── Two-column grid ──────────────────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* ── Panel ────────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th {
  background: #f8f9fb;
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8f9fb; }
.data-table-clickable tr:hover td { background: #eef2ff; cursor: pointer; }

.truncate { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nt-checkboxes { display:flex; flex-wrap:wrap; gap:.4rem .75rem; margin-bottom:.35rem; }
.nt-cb-label { display:flex; align-items:center; gap:.3rem; cursor:pointer; font-size:.85rem; }
.nt-cb-value { font-family:monospace; font-size:.8rem; color:#374151; }
.nt-cb-alias { font-size:.75rem; color:#6b7280; }

/* Dashboard filter pills */
.dash-filter-grid { display:flex; flex-direction:column; gap:.6rem; }
.dash-filter-row { display:flex; align-items:flex-start; gap:1rem; }
.dash-filter-label { flex-shrink:0; width:72px; font-size:.78rem; font-weight:600; color:#6b7280; text-transform:uppercase; letter-spacing:.04em; padding-top:.3rem; }
.dash-tags { display:flex; flex-wrap:wrap; gap:.35rem; }
.dash-tag { display:inline-flex; align-items:center; padding:.2rem .65rem; border-radius:20px; border:1.5px solid #d1d5db; font-size:.78rem; font-family:monospace; color:#374151; cursor:pointer; user-select:none; transition:background .12s,border-color .12s,color .12s; }
.dash-tag:hover { border-color:#a5b4fc; }
.dash-tag input[type=checkbox] { display:none; }
.dash-tag:has(input:checked) { background:#6366f1; border-color:#6366f1; color:#fff; }
.truncate-desc { max-width: 360px; }
.empty { color: var(--text-dim); text-align: center; padding: 24px; }
.error-cell { color: var(--danger); font-size: 12px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge-test {
  background: #fef3c7;
  color: #92400e;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
}
.badge-status { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge-enabled  { background: #dcfce7; color: #15803d; }
.badge-disabled { background: #fee2e2; color: #b91c1c; }
.status-badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
  text-align: center;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); color: #fff; text-decoration: none; }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; color: var(--text); text-decoration: none; }
.btn-success   { background: #22c55e; color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm        { padding: 4px 10px; font-size: 12px; }
.btn-full      { width: 100%; display: block; }
.action-cell   { white-space: nowrap; }
.action-cell form { display: inline; }

/* ── Filter form ──────────────────────────────────────────────────────────── */
.filter-form { margin-bottom: 20px; }
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.filter-row .form-group { min-width: 120px; }
.filter-row .form-group-btn { display: flex; gap: 6px; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--text-dim); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.input-disabled { background: #f3f4f6; color: var(--text-dim); }
.input-error { border-color: var(--danger) !important; }
.field-error { color: var(--danger); font-size: 12px; }
.code-textarea { font-family: "JetBrains Mono", "Fira Code", monospace; font-size: 12px; }
.hint { font-size: 11px; color: var(--text-dim); margin-left: 4px; }

.settings-form { max-width: 680px; }
.settings-section { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.section-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.subsection-title { font-size: 13px; font-weight: 600; margin-bottom: 8px; color: var(--text-dim); }
.section-hint { color: var(--text-dim); font-size: 12px; margin-bottom: 12px; }

.row-hidden td { opacity: .45; }
.row-hidden code { text-decoration: line-through; }

.checkbox-group { display: flex; flex-direction: column; gap: 10px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.checkbox-label input[type="checkbox"] { width: 15px; height: 15px; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 40px;
  width: 360px;
  box-shadow: var(--shadow);
}
.login-title { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 4px; }
.login-subtitle { color: var(--text-dim); text-align: center; margin-bottom: 24px; font-size: 13px; }
.login-form .form-group { margin-bottom: 16px; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.page-link {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
}
.page-link:hover { background: #f3f4f6; text-decoration: none; }
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-ellipsis { padding: 5px 6px; color: var(--text-dim); font-size: 13px; }

/* ── Subtotal bar ─────────────────────────────────────────────────────────── */
.subtotal-bar {
  display: flex;
  gap: 24px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-dim);
}
.subtotal-bar strong { color: var(--text); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 720px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-dim);
}
.modal-close:hover { color: var(--text); }
.raw-pre {
  background: #1a1d23;
  color: #c9cdd6;
  padding: 16px;
  border-radius: var(--radius);
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 12px;
  overflow-x: auto;
  margin-top: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Breadcrumb ───────────────────────────────────────────────────────────── */
.breadcrumb { margin-bottom: 16px; color: var(--text-dim); font-size: 13px; }
.breadcrumb a { color: var(--primary); }

/* ── Info / help blocks ───────────────────────────────────────────────────── */
.info-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 12px;
  color: #1e40af;
  margin-bottom: 16px;
  line-height: 1.6;
}
.info-box p { margin: 0 0 6px; }
.info-box p:last-child { margin-bottom: 0; }
.info-box code {
  background: #dbeafe;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: "JetBrains Mono","Fira Code",monospace;
  font-size: 11px;
}
.info-box ul { margin: 4px 0 4px 18px; }
.info-box li { margin-bottom: 2px; }

details.help-details { margin-bottom: 14px; }
details.help-details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--primary);
  user-select: none;
  margin-bottom: 6px;
}
details.help-details summary:hover { text-decoration: underline; }
details.help-details .info-box { margin-top: 8px; margin-bottom: 0; }
