:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --navy: #0f172a;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --good: #059669;
  --good-bg: #ecfdf5;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.2);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

code {
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.85em;
}

.topbar {
  background: var(--navy);
  color: #ffffff;
  padding: 14px 20px;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dot {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.topbar-brand h1 { margin: 0; font-size: 1.08rem; }
.topbar-sub { font-size: 0.78rem; color: #94a3b8; }

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

.db-badge {
  font-size: 0.76rem;
  font-weight: 700;
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.3);
  padding: 5px 10px;
  border-radius: 999px;
}

.week-select {
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 9px;
  padding: 8px 10px;
}

.week-select option {
  color: var(--text);
  background: #ffffff;
}

.tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.tabs-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 13px 15px;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-count {
  font-size: 0.74rem;
  background: #f1f5f9;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 999px;
}

.tab-btn.active .tab-count {
  background: #dbeafe;
  color: var(--primary);
}

.admin-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 20px 36px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

/* Generator Card */
.generator-card {
  padding: 16px 18px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 100%);
  border-color: #bfdbfe;
}

.generator-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.gen-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.gen-field label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--navy);
}

.generator-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.link-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.link-open {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.link-open:hover {
  text-decoration: underline;
}

.link-exp-text {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.pill-role-ft {
  background: #ede9fe;
  color: #5b21b6;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.kpi-label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); }
.kpi-value { font-size: 1.55rem; font-weight: 800; }
.kpi-good .kpi-value { color: var(--good); }
.kpi-bad .kpi-value { color: var(--bad); }
.kpi-blue .kpi-value { color: var(--primary); }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.input {
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
}

.search-input { min-width: 230px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm { padding: 5px 9px; font-size: 0.78rem; }
.btn-full { width: 100%; }
.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--good); color: #ffffff; }
.btn-success:hover { background: #047857; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-outline-light { background: transparent; color: #ffffff; border-color: rgba(255, 255, 255, 0.32); }
.btn-outline-light:hover { background: rgba(255, 255, 255, 0.12); }
.btn-danger-outline { background: var(--surface); color: var(--bad); border-color: #fecaca; }
.btn-danger-outline:hover { background: var(--bad-bg); }

.icon-btn {
  border: none;
  background: #f1f5f9;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap { width: 100%; overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.data-table th {
  text-align: left;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr.is-muted { opacity: 0.55; background: #fafafa; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.pill-sent { background: var(--good-bg); color: #065f46; }
.pill-pending { background: var(--bad-bg); color: #991b1b; }
.pill-role { background: #eff6ff; color: var(--primary); }
.pill-cat { background: #f1f5f9; color: #475569; border-radius: 6px; }

.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  font-weight: 800;
  background: #f1f5f9;
  border: 1px solid var(--border-strong);
  color: var(--navy);
  padding: 3px 8px;
  border-radius: 7px;
  letter-spacing: 0.04em;
}

.code-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  font-weight: 800;
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
  color: var(--primary);
  padding: 9px 12px;
  border-radius: 9px;
  text-align: center;
  letter-spacing: 0.06em;
}

.row-actions { display: flex; justify-content: flex-end; gap: 6px; }

.switch-input {
  appearance: none;
  width: 38px;
  height: 22px;
  background: #cbd5e1;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
}

.switch-input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.switch-input:checked { background: var(--good); }
.switch-input:checked::after { transform: translateX(16px); }

.settings-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.65fr;
  gap: 16px;
  align-items: start;
}

.settings-card { padding: 20px; }
.settings-card h3 { margin: 0 0 14px; font-size: 1.02rem; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-group label { font-size: 0.82rem; font-weight: 700; }
.hint { font-weight: 500; color: var(--text-muted); }

.db-info-box {
  margin-top: 18px;
  padding: 13px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  font-size: 0.82rem;
  color: #166534;
}

.db-info-box p { margin: 5px 0 0; }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { margin: 0; font-size: 1.02rem; }
.modal-sub { font-size: 0.78rem; color: var(--text-muted); }

.modal-body { padding: 16px 18px; overflow-y: auto; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.import-preview {
  padding: 9px 12px;
  background: var(--good-bg);
  border: 1px solid #6ee7b7;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #065f46;
}

.sub-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
}

.sub-detail-row:last-child { border-bottom: none; }

/* PIN Overlay */
.pin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.pin-overlay[hidden] { display: none; }

.pin-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 26px 22px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pin-icon { font-size: 1.9rem; }
.pin-card h2 { margin: 0; font-size: 1.1rem; }
.pin-card p { margin: 0; font-size: 0.84rem; color: var(--text-muted); }
.pin-error { color: var(--bad) !important; font-weight: 700; }
.pin-back { font-size: 0.8rem; color: var(--text-muted); text-decoration: none; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--navy);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 150;
}

.toast.error { background: var(--bad); }

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
