:root {
  color-scheme: light;
  --ink: #172133;
  --muted: #637083;
  --line: #dde4ed;
  --page: #eef3f6;
  --surface: #ffffff;
  --navy: #12304a;
  --navy-soft: #dbe8f2;
  --coral: #f06449;
  --coral-dark: #ca3e2a;
  --gold: #f3b331;
  --green: #12805c;
  --green-soft: #dff5ec;
  --red: #d72f2f;
  --amber-soft: #fff3d2;
  --shadow: 0 22px 55px rgba(18, 48, 74, 0.18);
  --shadow-soft: 0 10px 28px rgba(18, 48, 74, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ---------- Dark mode: variable overrides only ---------- */

body.dark-mode {
  color-scheme: dark;
  --ink: #e8edf4;
  --muted: #9aa7b8;
  --line: #2a3648;
  --page: #0f1620;
  --surface: #17222f;
  --navy: #0d2739;
  --navy-soft: #1c3348;
  --green-soft: #123527;
  --amber-soft: #3a2c0d;
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.5);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.4);
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  background: #1c2836;
  color: var(--ink);
  border-color: var(--line);
}

body.dark-mode .secondary-action,
body.dark-mode .ghost-action {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

body.dark-mode .data-table thead {
  background: #101a26;
}

body.dark-mode .data-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

body.dark-mode .kpi-card,
body.dark-mode .panel-head-row,
body.dark-mode .table-scroll {
  background: var(--surface);
}

/* ---------- Base elements ---------- */

input,
select,
textarea {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #c4cedb;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(18, 48, 74, 0.15);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  padding: 0 16px;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible {
  outline: 3px solid rgba(18, 48, 74, 0.35);
  outline-offset: 2px;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

.is-hidden {
  display: none !important;
}

.eyebrow {
  margin: 0;
  color: var(--coral-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.primary-action {
  background: var(--coral);
  color: #fff;
}

.primary-action:hover:not(:disabled) {
  background: #e5573d;
}

.primary-action:active:not(:disabled) {
  background: var(--coral-dark);
}

.secondary-action {
  background: #e7edf3;
  color: var(--ink);
}

.secondary-action:hover:not(:disabled) {
  background: #dbe3ec;
}

.danger-action {
  background: var(--red);
  color: #fff;
}

.danger-action:hover:not(:disabled) {
  background: #b82424;
}

.row-delete-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12.5px;
  background: #fff2f1;
  color: var(--red);
  border: 1px solid #f3c8c4;
}

.row-delete-button:hover:not(:disabled) {
  background: var(--red);
  color: #fff;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 33, 0.55);
  z-index: 100;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  padding: 24px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.modal-card h2 {
  margin: 6px 0 10px;
  font-size: 19px;
  line-height: 1.35;
}

.modal-copy {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.modal-confirm-label {
  display: grid;
  gap: 6px;
  margin-bottom: 18px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ghost-action {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.ghost-action:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- Sign-in ---------- */

.auth-shell {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  overflow-y: auto;
  padding: max(32px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
  background:
    radial-gradient(1100px 620px at 12% -12%, rgba(240, 100, 73, 0.10), transparent 60%),
    radial-gradient(900px 700px at 112% 12%, rgba(18, 48, 74, 0.10), transparent 55%),
    var(--page);
}

.auth-shell.is-hidden {
  display: none;
}

.auth-card {
  width: min(100%, 440px);
  height: fit-content;
  margin: auto;
  display: grid;
  gap: 16px;
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0;
  color: var(--navy);
  font-size: 26px;
  line-height: 1.12;
}

.auth-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-message {
  min-height: 22px;
  margin: 0;
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.4;
}

.auth-message.is-error {
  color: var(--red);
}

/* ---------- Dashboard shell ---------- */

.dashboard-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
}

.dashboard-shell.is-hidden {
  display: none;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background: var(--navy);
  color: #fff;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--coral);
  color: #fff;
  font-weight: 900;
  font-size: 17px;
}

.brand-copy {
  display: grid;
  gap: 1px;
  line-height: 1.2;
}

.brand-copy strong {
  font-size: 14px;
  color: #fff;
}

.brand-copy em {
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
}

.side-nav {
  display: grid;
  gap: 4px;
  flex: 1;
}

.side-nav-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
}

.side-nav-button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.side-nav-button.is-active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.nav-badge {
  display: inline-flex;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.sidebar-foot {
  display: grid;
  gap: 10px;
}

.sidebar-foot .ghost-action {
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
  background: transparent;
}

.sidebar-foot .ghost-action:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.admin-id-card {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.admin-id-card strong {
  font-size: 13px;
  color: #fff;
}

.admin-id-card span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.6);
}

.sidebar-foot .secondary-action {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-foot .secondary-action:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- Main area ---------- */

.main-area {
  min-width: 0;
  padding: 24px 28px 64px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
  background: var(--page);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 22px;
  color: var(--navy);
}

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

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 30;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

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

.toast.is-success {
  background: var(--green);
}

.panel-hint {
  margin: 18px 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.panel-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-head-row input[type="search"] {
  min-width: 220px;
  flex: 1;
  max-width: 320px;
}

.panel-head-row select {
  min-width: 170px;
  width: auto;
}

.panel-head-row .muted {
  margin-left: auto;
}

/* ---------- KPI grid ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}

.kpi-card {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 26px;
  color: var(--navy);
  letter-spacing: -0.01em;
}

.kpi-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

body.dark-mode .kpi-value {
  color: var(--ink);
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.insight-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.insight-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.insight-value {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  color: var(--navy);
  letter-spacing: -0.01em;
}

body.dark-mode .insight-value {
  color: var(--ink);
}

.insight-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.insight-metrics div {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--page);
}

.insight-metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.insight-metrics strong {
  color: var(--navy);
  font-size: 18px;
}

body.dark-mode .insight-metrics strong {
  color: var(--ink);
}

.insight-foot {
  margin: 0;
  line-height: 1.45;
}

/* ---------- Data tables ---------- */

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

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

.data-table thead {
  background: var(--page);
}

.data-table th {
  text-align: left;
  padding: 11px 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--ink);
}

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

.data-table tbody tr:nth-child(even) {
  background: rgba(18, 48, 74, 0.02);
}

.cell-detail {
  max-width: 240px;
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 12.5px;
}

.empty-state {
  margin: 16px 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.online-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--line);
  margin-right: 6px;
}

.online-dot.is-online {
  background: var(--green);
}

.location-cell {
  display: inline-block;
  line-height: 1.5;
  font-size: 12px;
}

.location-cell a {
  color: var(--navy);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--line);
}

.location-cell small {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- Row action controls (built by JS inside table cells) ---------- */

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.row-status-select {
  min-height: 36px;
  padding: 6px 8px;
  font-size: 12.5px;
  width: auto;
  min-width: 140px;
}

.row-note-input {
  min-height: 36px;
  padding: 6px 8px;
  font-size: 12.5px;
  width: 150px;
}

.row-apply-button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12.5px;
  background: var(--navy);
  color: #fff;
}

.row-apply-button:hover:not(:disabled) {
  background: #0d2739;
}

.row-dispute-actions {
  display: flex;
  gap: 6px;
}

.row-dispute-actions button {
  min-height: 36px;
  padding: 0 10px;
  font-size: 12.5px;
}

.button-overturn {
  background: var(--amber-soft);
  color: #765100;
}

.button-overturn:hover:not(:disabled) {
  background: #ffe9ab;
}

.button-uphold {
  background: var(--navy-soft);
  color: var(--navy);
}

.button-uphold:hover:not(:disabled) {
  background: #c9dcec;
}

.status-chip {
  display: inline-flex;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--navy-soft);
  color: var(--navy);
  white-space: nowrap;
}

.status-chip.is-good {
  background: var(--green-soft);
  color: var(--green);
}

.status-chip.is-bad {
  background: #ffd8d3;
  color: #842316;
}

.status-chip.is-warning {
  background: var(--amber-soft);
  color: #765100;
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .side-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1 1 100%;
    order: 3;
  }

  .side-nav-button {
    flex: 1 1 auto;
  }

  .sidebar-foot {
    flex-direction: row;
    order: 2;
    margin-left: auto;
    align-items: center;
  }

  .admin-id-card {
    display: none;
  }

  .main-area {
    padding: 18px 16px 48px;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .panel-head-row .muted {
    margin-left: 0;
  }

  .insight-metrics {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.001ms !important;
  }
}

.panel {
  animation: panel-fade 0.15s ease;
}

@keyframes panel-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
