:root {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --text-primary: #0f172a;
  --text-muted: #475569;
  --border-col: #e2e8f0;
  --brand-dark: #14532d;
  --brand: #185c37;
  --brand-hover: #166534;
  --brand-soft: rgba(24, 92, 55, 0.1);
  --amber-text: #92400e;
  --amber-bg: #fef3c7;
  --amber-border: #f59e0b;
  --red-text: #991b1b;
  --red-bg: #fee2e2;
  --red-border: #ef4444;
  --emerald-text: #065f46;
  --emerald-bg: #d1fae5;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.22);
}

body.theme-dark {
  --bg-page: #0b1120;
  --bg-card: #111827;
  --bg-subtle: #1e293b;
  --text-primary: #f1f5f9;
  --text-muted: #94a3b8;
  --border-col: #263248;
  --brand: #22c55e;
  --brand-hover: #16a34a;
  --brand-soft: rgba(34, 197, 94, 0.14);
  --amber-text: #fde68a;
  --amber-bg: rgba(245, 158, 11, 0.18);
  --amber-border: rgba(245, 158, 11, 0.5);
  --red-text: #fecaca;
  --red-bg: rgba(239, 68, 68, 0.18);
  --red-border: rgba(239, 68, 68, 0.5);
  --emerald-text: #a7f3d0;
  --emerald-bg: rgba(16, 185, 129, 0.18);
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  margin: 4px 0 0;
  font-size: 13px;
}

/* Top Bar */
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: #185c37;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
}

.admin-topbar-left,
.admin-topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.admin-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
}

.admin-logo-mark {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #ffffff;
  color: #185c37;
  font-weight: 800;
  font-size: 14px;
}

.admin-brand-text small {
  font-weight: 500;
  opacity: 0.85;
  margin-left: 3px;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.mode-badge.mode-test {
  background: #fef3c7;
  color: #92400e;
}

.mode-badge.mode-live {
  background: #dcfce7;
  color: #14532d;
}

.period-group {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  padding: 2px;
}

.period-btn {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.86);
  padding: 5px 10px;
  border-radius: 5px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.period-btn.active {
  background: #ffffff;
  color: #185c37;
}

.top-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  text-decoration: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.top-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* Main Container */
.admin-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

.state-card {
  max-width: 440px;
  margin: 56px auto;
  padding: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.auth-card {
  text-align: left;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
}

.denied-icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid var(--border-col);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.auth-form label {
  font-weight: 600;
  font-size: 13px;
}

.auth-form input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-col);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font: inherit;
}

.form-error {
  color: var(--red-text);
  font-size: 13px;
  margin: 4px 0 0;
}

.form-error:empty {
  display: none;
}

.btn-emerald {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: 8px;
  border: 1px solid #167447;
  background: #167447;
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-emerald:hover {
  background: #14532d;
}

.btn-emerald:disabled,
.btn-outline:disabled,
.btn-sm:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-col);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-sm {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-col);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm:hover:not(:disabled) {
  border-color: var(--brand);
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.pagination-bar .inline-actions {
  margin-top: 0;
}

/* Dashboard Content */
.dashboard-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.error-banner {
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red-text);
  font-weight: 500;
}

.dashboard-meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.dashboard-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.admin-actor-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  font-size: 12.5px;
  color: var(--text-muted);
}

.admin-actor-pill strong {
  color: var(--text-primary);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.kpi-card {
  padding: 16px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-card.kpi-warn {
  border-color: var(--amber-border);
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-currency,
.kpi-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.tag-emerald {
  background: var(--emerald-bg);
  color: var(--emerald-text);
}

.tag-amber {
  background: var(--amber-bg);
  color: var(--amber-text);
}

.tag-red {
  background: var(--red-bg);
  color: var(--red-text);
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* Panels & Tables */
.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

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

.panel-header h2 {
  margin: 0;
  font-size: 17px;
}

.search-box input {
  width: min(320px, 80vw);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-col);
  background: var(--bg-subtle);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.pill {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-col);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.pill.active {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.data-table th {
  padding: 10px 12px;
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border-col);
  white-space: nowrap;
}

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

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr.clickable-row {
  cursor: pointer;
}

.data-table tbody tr.clickable-row:hover {
  background: var(--bg-subtle);
}

.empty-cell {
  text-align: center;
  padding: 28px !important;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-pro {
  background: var(--emerald-bg);
  color: var(--emerald-text);
}

.badge-warn {
  background: var(--amber-bg);
  color: var(--amber-text);
}

.badge-danger {
  background: var(--red-bg);
  color: var(--red-text);
}

.badge-neutral {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-col);
}

.ext-link {
  color: var(--brand);
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

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

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

/* Ops Health Grid */
.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 14px;
}

.ops-card h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.ops-list {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  font-size: 13px;
}

.ops-list dt {
  color: var(--text-muted);
}

.ops-list dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.disk-meter {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-col);
  overflow: hidden;
  margin-bottom: 12px;
}

.disk-meter-fill {
  height: 100%;
  background: #16a34a;
  transition: width 0.25s ease;
}

.disk-meter-fill.warn {
  background: #d97706;
}

.disk-meter-fill.crit {
  background: #dc2626;
}

/* Slide-Over Customer Drawer */
.customer-drawer {
  margin: 0 0 0 auto;
  padding: 0;
  width: min(580px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  border: 0;
  border-left: 1px solid var(--border-col);
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
}

.customer-drawer::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.drawer-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-col);
}

.drawer-header h2 {
  margin: 2px 0 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.close-btn {
  border: 1px solid var(--border-col);
  background: var(--bg-subtle);
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
}

.drawer-body {
  padding: 18px 22px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.drawer-section {
  border: 1px solid var(--border-col);
  border-radius: 10px;
  padding: 14px;
  background: var(--bg-subtle);
}

.drawer-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.drawer-kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 6px 10px;
  font-size: 13px;
}

.drawer-kv span {
  color: var(--text-muted);
}

.mini-item {
  padding: 9px 0;
  border-top: 1px solid var(--border-col);
  font-size: 12.5px;
}

.mini-item:first-child {
  border-top: 0;
  padding-top: 0;
}

@media (max-width: 720px) {
  .admin-container {
    padding: 16px 12px 40px;
  }
  .search-box input {
    width: 100%;
  }
  .drawer-kv {
    grid-template-columns: 1fr;
  }
}
