:root {
  color-scheme: light;
  --nav-bg: #111827;
  --nav-deep: #0b1220;
  --nav-active: #1f2a44;
  --nav-accent: #2563eb;
  --nav-text: #d6deea;
  --nav-muted: #8fa3bf;
  --page-bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #e2e8f0;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
.is-hidden { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text);
}
.login-screen { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px; background: var(--nav-bg); }
.login-card { width: min(420px, 100%); display: grid; gap: 16px; padding: 24px; border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: 0 28px 70px rgba(0,0,0,.35); }
.login-card h1 { font-size: 28px; }
.login-card p { color: var(--muted); }
.login-brand { margin: -24px -24px 4px; }
.login-error { min-height: 20px; color: #b91c1c; font-size: 13px; font-weight: 800; }
.current-user { color: var(--muted); font-size: 13px; font-weight: 800; }
button, input, select { font: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.admin-shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--nav-bg); color: var(--nav-text); }
.brand-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) 32px; align-items: center; gap: 8px; min-height: 56px; padding: 0 18px; background: var(--nav-deep); }
.brand-row strong { color: #fff; font-size: 14px; white-space: nowrap; }
.brand-mark { position: relative; width: 26px; height: 26px; }
.brand-mark span { position: absolute; inset: 2px; border: 2px solid #fff; border-radius: 8px 11px 11px 8px; transform: skewY(-18deg); }
.brand-mark span:nth-child(2) { inset: 5px 1px 2px 5px; opacity: .82; }
.brand-mark span:nth-child(3) { inset: 8px 0 2px 8px; opacity: .62; }

.collapse-button, .nav-button, .submenu-button, .icon-button, .primary-action, .secondary-action, .segmented-control button, .modal-close { border: 0; }
.collapse-button { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; background: transparent; color: #fff; }
.nav-list { padding: 18px 0; }
.nav-button, .submenu-button {
  width: 100%;
  min-height: 44px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: transparent;
  color: var(--nav-text);
  text-align: left;
}
.submenu-button { grid-template-columns: 26px minmax(0, 1fr); min-height: 40px; font-size: 13px; }
.nav-button svg, .submenu-button svg { color: var(--nav-muted); }
.nav-button span, .submenu-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-button:hover, .submenu-button:hover { background: rgba(37, 99, 235, .12); color: #fff; }
.nav-button.active { background: var(--nav-active); color: #fff; font-weight: 700; }
.nav-button.active svg { color: var(--nav-accent); }
.submenu { display: none; background: #162033; }
.nav-group.open > .submenu { display: block; }
.submenu-button.active { background: var(--nav-accent); color: #fff; font-weight: 700; }
.submenu-button.active svg { color: #fff; }

.workspace { min-width: 0; padding: 28px; }
.workspace-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 22px; margin-bottom: 22px; }
h1, h2, p { margin: 0; }
h1 { font-size: 30px; line-height: 1.15; }
.workspace-header p, .panel-heading p, .stat-card small { color: var(--muted); }
.workspace-header p { margin-top: 8px; font-size: 14px; overflow-wrap: anywhere; }
.workspace-header > div:first-child { min-width: 0; max-width: 100%; }
.header-actions, .user-management-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.search-field { display: flex; align-items: center; gap: 8px; min-width: 300px; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.icon-button, .primary-action, .secondary-action { height: 42px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.icon-button { width: 42px; background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.primary-action { gap: 8px; padding: 0 14px; background: var(--blue); color: #fff; }
.secondary-action { padding: 0 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.sheet-link { display: inline-flex; align-items: center; height: 34px; padding: 0 12px; border-radius: 8px; background: #eef2ff; color: var(--blue-dark); font-size: 13px; font-weight: 800; text-decoration: none; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-card, .panel { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.stat-card { display: grid; gap: 8px; min-height: 126px; padding: 18px; }
.stat-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat-card strong { font-size: 25px; line-height: 1.1; }
.stat-card.accent { background: #1d4ed8; color: #fff; }
.stat-card.accent span, .stat-card.accent small { color: rgba(255,255,255,.84); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(360px, .95fr); gap: 16px; margin-bottom: 16px; }
.panel { overflow: hidden; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 18px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { font-size: 18px; }
.panel-heading p { margin-top: 6px; font-size: 13px; }
.bar-chart { display: grid; grid-template-columns: repeat(5, minmax(72px, 1fr)); align-items: end; gap: 16px; height: 280px; padding: 22px 18px 18px; }
.bar-item { display: grid; align-items: end; gap: 8px; min-width: 0; height: 100%; }
.bar-track { display: flex; align-items: flex-end; height: 205px; border-radius: 8px; background: #eaf1ff; overflow: hidden; }
.bar-fill { width: 100%; min-height: 10px; border-radius: 8px 8px 0 0; background: #2563eb; }
.bar-item.is-empty .bar-fill { background: #cbd5e1; }
.bar-item.is-empty .bar-track { background: #f1f5f9; }
.bar-label { display: grid; gap: 3px; text-align: center; }
.bar-label strong { font-size: 12px; }
.bar-label span { color: var(--muted); font-size: 11px; }

.category-list { display: grid; gap: 12px; padding: 18px; }
.category-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; }
.category-row strong { font-size: 14px; }
.category-row span { color: var(--muted); font-size: 12px; }
.category-row small { color: var(--blue-dark); font-size: 12px; font-weight: 800; }
.category-row .status-live { color: #047857; }
.category-row .status-pending { color: #9a3412; }
.gmpay-data-panel { margin-bottom: 16px; }
.gmpay-summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding: 16px 18px; background: var(--surface-soft); border-bottom: 1px solid var(--line); }
.mini-stat { display: grid; gap: 6px; min-height: 82px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.mini-stat span { color: var(--muted); font-size: 12px; font-weight: 800; }
.mini-stat strong { font-size: 18px; line-height: 1.1; }
.mini-stat.negative strong, .negative-cell { color: #b91c1c; font-weight: 800; }
.segmented-control { display: inline-flex; padding: 3px; border-radius: 8px; background: #eaf1ff; }
.segmented-control button { height: 30px; padding: 0 12px; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.segmented-control button.active { background: var(--surface); color: var(--blue-dark); box-shadow: 0 5px 14px rgba(52,82,232,.14); }
.gmpay-project-tabs button.active { background: var(--blue); color: #fff; }

.table-wrap { overflow: auto; }
table { width: 100%; min-width: 980px; border-collapse: collapse; }
.compact-table { min-width: 1080px; }
th, td { min-height: 54px; padding: 14px 18px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); background: var(--surface-soft); font-size: 12px; text-transform: uppercase; }
td { font-size: 14px; }
.report-total-row td { background: var(--surface-soft); font-weight: 800; }
.user-cell { display: grid; gap: 4px; }
.user-cell strong { font-size: 14px; }
.user-cell span { color: var(--muted); font-size: 12px; }
.permission-list { display: flex; flex-wrap: wrap; gap: 6px; }
.permission-chip, .status-pill { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; font-size: 12px; font-weight: 800; }
.permission-chip { height: 24px; padding: 0 9px; background: #eaf1ff; color: var(--blue-dark); }
.status-pill { min-width: 78px; height: 26px; }
.status-pill.active { background: #dcfce7; color: #047857; }
.status-pill.disabled { background: #fee2e2; color: #b91c1c; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { min-height: 28px; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); color: var(--text); font-size: 12px; font-weight: 800; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 22px; background: rgba(10,16,31,.54); }
.modal-backdrop[hidden] { display: none; }
.modal-card { width: min(720px, 100%); max-height: calc(100vh - 44px); overflow: auto; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); box-shadow: 0 28px 70px rgba(8,14,28,.28); }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px; border-bottom: 1px solid var(--line); }
.modal-heading p { margin-top: 6px; color: var(--muted); font-size: 13px; }
.modal-close { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border-radius: 8px; background: var(--surface-soft); color: var(--muted); }
.user-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px; }
.form-field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 800; }
.form-field input, .form-field select { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 8px; padding: 0 11px; background: var(--surface-soft); color: var(--text); }
.choice-group { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; }
.choice-group legend { padding: 0 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
.choice-group label { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; color: var(--text); font-size: 13px; font-weight: 700; }
.choice-group input { width: 16px; height: 16px; accent-color: var(--blue); }
.modal-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

@media (max-width: 1120px) {
  .admin-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .brand-row { grid-template-columns: 1fr; justify-items: center; padding: 12px; }
  .brand-row strong, .collapse-button, .nav-button span, .nav-button svg:last-child, .submenu-button span { display: none; }
  .nav-button, .submenu-button { grid-template-columns: 1fr; justify-items: center; padding: 0; }
}

@media (max-width: 900px) {
  .workspace { padding: 18px; }
  .workspace-header, .panel-heading { flex-direction: column; }
  .workspace-header p { max-width: min(100%, 340px); }
  .header-actions, .user-management-actions, .search-field, .icon-button, .primary-action, .secondary-action { width: 100%; }
  .stats-grid, .dashboard-grid, .user-form, .choice-group { grid-template-columns: 1fr; }
  .gmpay-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal-actions { flex-direction: column-reverse; }
}

@media (max-width: 620px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .brand-row { grid-template-columns: 28px minmax(0, 1fr); justify-items: start; }
  .brand-row strong { display: block; }
  .nav-list { display: flex; width: 100vw; max-width: 100vw; overflow-x: auto; padding: 8px; }
  .nav-group, .submenu { display: contents; }
  .nav-group:not(.open) > .submenu { display: none; }
  .nav-group.open > .submenu { display: contents; }
  .nav-button, .submenu-button { width: 58px; flex: 0 0 auto; border-radius: 8px; }
  .workspace { padding: 14px; }
  .bar-chart { grid-template-columns: repeat(2, minmax(52px, 1fr)); height: auto; }
}
