/* ═══════════════════════════════════════════════════════════════════════
   Fleet Payment Middleware — Admin Console
   Design system: restrained, enterprise-fintech
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* ── surfaces ── */
  --bg:              #0b0d10;
  --bg-surface:      #12151a;
  --bg-elevated:     #171b21;
  --bg-input:        #1a1e24;
  --bg-hover:        #1f242c;
  --bg-active:       #232932;

  /* ── borders ── */
  --border:          #23272e;
  --border-subtle:   #1a1e24;
  --border-strong:   #2f353e;

  /* ── text ── */
  --text:            #e4e7eb;
  --text-secondary:  #9aa0a8;
  --text-muted:      #808896;   /* AA contrast on --bg for small text */
  --text-disabled:   #4b525c;

  /* ── accents (restrained; one primary) ── */
  --accent:          #4285f4;
  --accent-hover:    #5b95f6;
  --accent-active:   #3272d6;
  --accent-bg:       rgba(66,133,244,.10);
  --accent-border:   rgba(66,133,244,.30);

  /* ── semantic (muted, not neon) ── */
  --ok:              #34d17b;
  --ok-bg:           rgba(52,209,123,.10);
  --warn:            #e0a92a;
  --warn-bg:         rgba(224,169,42,.10);
  --err:             #ef5b5b;
  --err-bg:          rgba(239,91,91,.10);
  --info:            #4285f4;
  --info-bg:         rgba(66,133,244,.10);
  --neutral:         #7a8291;
  --neutral-bg:      rgba(122,130,145,.10);
  --violet:          #a78bfa;
  --violet-bg:       rgba(167,139,250,.10);

  /* ── radii ── */
  --r-1:             3px;
  --r-2:             4px;
  --r-3:             6px;
  --r-4:             8px;

  /* ── shadows (used sparingly) ── */
  --sh-1:            0 1px 2px rgba(0,0,0,.30);
  --sh-2:            0 6px 20px rgba(0,0,0,.35);
  --sh-3:            0 16px 40px rgba(0,0,0,.45);

  /* ── typography ── */
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, Consolas, "Roboto Mono", monospace;

  --fs-xs:    11px;
  --fs-sm:    12px;
  --fs-md:    13px;   /* body */
  --fs-lg:    14px;
  --fs-xl:    16px;
  --fs-2xl:   19px;
  --fs-3xl:   24px;

  --lh-tight:  1.30;
  --lh-body:   1.50;
  --lh-loose:  1.65;

  /* ── spacing (4px grid) ── */
  --s-1:  4px;
  --s-2:  8px;
  --s-3:  12px;
  --s-4:  16px;
  --s-5:  20px;
  --s-6:  24px;
  --s-7:  32px;
  --s-8:  48px;
  --s-9:  64px;

  /* ── layout ── */
  --sidebar-w:  228px;
  --topbar-h:   52px;
  --content-max: 1400px;
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11", "tnum";
  height: 100%;
  overflow-x: hidden;
}

/* ═════════════ utility ═════════════ */
.hidden       { display: none !important; }
.muted        { color: var(--text-secondary); }
.dim          { color: var(--text-muted); }
.small        { font-size: var(--fs-sm); }
.xsmall       { font-size: var(--fs-xs); }
.mono         { font-family: var(--mono); font-size: var(--fs-sm); letter-spacing: -.01em; }
.error        { color: var(--err); }
.strong       { font-weight: 600; }
.nowrap       { white-space: nowrap; }
.right        { text-align: right; }
.grow         { flex: 1; }
.tabnum       { font-variant-numeric: tabular-nums; }

/* ═════════════ links ═════════════ */
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ═════════════ headings ═════════════ */
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
h1 { font-size: var(--fs-3xl); line-height: var(--lh-tight); }
h2 { font-size: var(--fs-xl); line-height: var(--lh-tight); }
h3 { font-size: var(--fs-lg); line-height: var(--lh-tight); }
h4 { font-size: var(--fs-md); line-height: var(--lh-tight); }

/* ═════════════ page structure ═════════════ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  padding-bottom: var(--s-5);
  margin-bottom: var(--s-5);
  border-bottom: 1px solid var(--border-subtle);
}
.page-header-text  { min-width: 0; }
.page-title        { font-size: var(--fs-2xl); font-weight: 600; margin: 0 0 var(--s-1); }
.page-sub          { color: var(--text-secondary); font-size: var(--fs-md); margin: 0; }
.page-header-right { display: flex; align-items: center; gap: var(--s-2); flex-shrink: 0; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: var(--s-6) 0 var(--s-3);
}
.section-title { font-size: var(--fs-lg); font-weight: 600; color: var(--text); margin: 0; }

/* ═════════════ buttons ═════════════ */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1;
  height: 32px;
  padding: 0 var(--s-3);
  border-radius: var(--r-3);
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
  white-space: nowrap;
  user-select: none;
}
button:hover, .btn:hover      { background: var(--accent-hover); }
button:active, .btn:active    { background: var(--accent-active); }
button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.secondary, .btn.secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-strong);
}
button.secondary:hover, .btn.secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

button.ghost, .btn.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
button.ghost:hover, .btn.ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

button.danger, .btn.danger {
  background: var(--err);
  color: #fff;
}
button.danger:hover, .btn.danger:hover { background: #d94a4a; }

button.link, .btn.link {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  height: auto;
  padding: 0;
}
button.link:hover, .btn.link:hover { text-decoration: underline; background: transparent; }

button.sm { height: 26px; padding: 0 var(--s-2); font-size: var(--fs-sm); }
button.lg { height: 40px; padding: 0 var(--s-4); font-size: var(--fs-lg); }

/* ═════════════ inputs ═════════════ */
input, select, textarea {
  font: inherit;
  font-size: var(--fs-md);
  height: 34px;
  padding: 0 var(--s-3);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
  width: 100%;
}
textarea { height: auto; padding: var(--s-2) var(--s-3); resize: vertical; min-height: 80px; }
input[readonly] { background: var(--bg-surface); color: var(--text-secondary); cursor: default; }

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}
input:disabled, select:disabled, textarea:disabled {
  opacity: .5; cursor: not-allowed;
}

label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0 0 var(--s-1);
}

.field       { margin-bottom: var(--s-3); }
.field-row   { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); margin-bottom: var(--s-3); }
.field-help  { font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--s-1); }
.field-err   { font-size: var(--fs-sm); color: var(--err); margin-top: var(--s-1); }

/* ═════════════ AUTH SCREENS ═════════════ */
.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--s-6);
  background: radial-gradient(ellipse at top, #14181e 0%, var(--bg) 60%);
}
.login-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  padding: var(--s-7) var(--s-6);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--sh-2);
}
.login-card h1 { font-size: var(--fs-2xl); margin: 0 0 var(--s-1); }
.login-card > p:first-of-type { margin: 0 0 var(--s-6); color: var(--text-secondary); font-size: var(--fs-md); }
.login-card label { margin-top: var(--s-3); }
.login-card button[type=submit] { width: 100%; height: 38px; margin-top: var(--s-4); }
.login-card p.small { margin: var(--s-4) 0 0; color: var(--text-muted); font-size: var(--fs-sm); }

/* ═════════════ APP SHELL ═════════════ */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── sidebar ── */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: var(--s-4) 0 var(--s-3);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  padding: 0 var(--s-4) var(--s-4);
  margin-bottom: var(--s-3);
  border-bottom: 1px solid var(--border-subtle);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: var(--r-3);
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .04em;
  flex-shrink: 0;
}
.brand-title    { font-weight: 600; font-size: var(--fs-md); line-height: 1.2; }
.brand-subtitle { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; letter-spacing: .02em; text-transform: uppercase; }

.sidebar nav {
  display: flex; flex-direction: column;
  flex: 1;
  padding: 0 var(--s-3);
  gap: 1px;
}
.nav-section-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: var(--s-3) var(--s-3) var(--s-1);
  margin-top: var(--s-2);
}
.nav-section-label:first-child { margin-top: 0; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px var(--s-3);
  border-radius: var(--r-2);
  color: var(--text-secondary);
  font-size: var(--fs-md);
  font-weight: 400;
  transition: background .1s, color .1s;
  text-decoration: none;
}
.sidebar nav a:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--accent-bg);
  color: var(--text);
  font-weight: 500;
}

/* sidebar foot: user menu */
.sidebar-foot {
  padding: var(--s-3);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--s-2);
  position: relative;
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  padding: var(--s-2);
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--r-3);
  cursor: pointer;
  text-align: left;
  height: auto;
  font-weight: 400;
}
.user-menu-btn:hover { background: var(--bg-hover); border-color: var(--border); }
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  display: grid; place-items: center;
  font-weight: 600;
  font-size: var(--fs-sm);
  flex-shrink: 0;
  border: 1px solid var(--accent-border);
}
.user-name { font-size: var(--fs-md); line-height: 1.2; }
.user-email { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.2; margin-top: 2px; }
.user-menu-btn > div:nth-child(2) { flex: 1; min-width: 0; }
.user-menu-btn > div:nth-child(2) > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.user-caret {
  color: var(--text-muted);
  font-size: 10px;
}

/* dropdown appearing above the user menu */
.user-menu-dropdown {
  position: absolute;
  bottom: 100%;
  left: var(--s-3);
  right: var(--s-3);
  margin-bottom: var(--s-1);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-3);
  padding: var(--s-1);
  box-shadow: var(--sh-2);
  z-index: 20;
}
.user-menu-dropdown a, .user-menu-dropdown button {
  display: block;
  width: 100%;
  padding: 8px var(--s-3);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 400;
  border: none;
  border-radius: var(--r-2);
  text-align: left;
  cursor: pointer;
  height: auto;
  text-decoration: none;
}
.user-menu-dropdown a:hover, .user-menu-dropdown button:hover {
  background: var(--bg-hover);
  text-decoration: none;
}
.user-menu-dropdown .divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--s-1) 0;
}

/* ── main / topbar ── */
main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s-6);
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(11,13,16,.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: sticky; top: 0;
  z-index: 5;
}
.topbar-left  { display: flex; align-items: center; gap: var(--s-3); }
.topbar-right { display: flex; align-items: center; gap: var(--s-3); }

/* status badge (top of topbar) */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 4px var(--s-2);
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
}
.status-badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-badge.ok::before   { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.status-badge.warn::before { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.status-badge.err::before  { background: var(--err); box-shadow: 0 0 0 3px var(--err-bg); }

/* view container */
#view {
  padding: var(--s-6) var(--s-6) var(--s-8);
  max-width: var(--content-max);
  width: 100%;
  flex: 1;
}

/* ═════════════ STATUS PILLS (badges) ═════════════ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px var(--s-2);
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: .01em;
  border: 1px solid transparent;
  white-space: nowrap;
  background: var(--neutral-bg);
  color: var(--neutral);
}
.pill::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.pill.no-dot::before { display: none; }
.pill-ok      { background: var(--ok-bg);      color: var(--ok); }
.pill-warn    { background: var(--warn-bg);    color: var(--warn); }
.pill-err     { background: var(--err-bg);     color: var(--err); }
.pill-info    { background: var(--info-bg);    color: var(--info); }
.pill-neutral { background: var(--neutral-bg); color: var(--neutral); }
.pill-violet  { background: var(--violet-bg);  color: var(--violet); }

/* ═════════════ CARDS ═════════════ */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  padding: var(--s-4) var(--s-5);
}

/* stat card */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-6);
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}
.stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.stat-value {
  font-size: var(--fs-3xl);
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.stat-sub { font-size: var(--fs-sm); color: var(--text-secondary); }

/* ═════════════ TABLES ═════════════ */
.data-table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-md);
}
th, td {
  text-align: left;
  padding: 10px var(--s-4);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
thead th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  height: 36px;
  padding-top: 0; padding-bottom: 0;
}
tbody tr {
  transition: background .08s;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg-hover); }
tbody tr.norow:hover { background: transparent; cursor: default; }
td.num, td.right, th.right { text-align: right; font-variant-numeric: tabular-nums; }
td.mono, .mono-cell { font-family: var(--mono); font-size: var(--fs-sm); }

/* action buttons in a row - inline set */
.row-actions { display: flex; gap: var(--s-1); }

/* ═════════════ TOOLBAR / FILTERS ═════════════ */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-bottom: var(--s-3);
}
.toolbar select, .toolbar input {
  height: 32px;
  min-width: 160px;
  width: auto;
}
.filter-active-indicator {
  padding: 2px var(--s-2);
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 500;
}

/* ═════════════ PAGINATION ═════════════ */
.pagination {
  display: flex;
  gap: var(--s-2);
  margin-top: var(--s-3);
  align-items: center;
  justify-content: flex-end;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* ═════════════ DETAIL VIEWS ═════════════ */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-bottom: var(--s-3);
}
.back-link:hover { color: var(--text); text-decoration: none; }

.detail-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: var(--s-2) var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-4);
}
.detail-grid .k {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  padding-top: 2px;
}
.detail-grid .v {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--text);
  word-break: break-word;
  padding-bottom: 2px;
}
.detail-grid .v.plain { font-family: var(--sans); font-size: var(--fs-md); }

pre.code-block {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-3);
  padding: var(--s-3);
  overflow: auto;
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 260px;
  margin: 0;
}

/* ═════════════ EMPTY STATE ═════════════ */
.empty-state {
  text-align: center;
  padding: var(--s-8) var(--s-6);
  color: var(--text-secondary);
}
.empty-state-icon {
  width: 44px; height: 44px;
  margin: 0 auto var(--s-3);
  border-radius: 50%;
  background: var(--bg-hover);
  color: var(--text-muted);
  display: grid; place-items: center;
  font-size: 20px;
}
.empty-state-title {
  color: var(--text);
  font-weight: 500;
  font-size: var(--fs-lg);
  margin: 0 0 var(--s-1);
}
.empty-state-sub {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin: 0 0 var(--s-4);
  max-width: 380px;
  margin-left: auto; margin-right: auto;
  line-height: var(--lh-loose);
}
.empty-state button { margin-top: var(--s-2); }

/* ═════════════ SKELETON LOADER ═════════════ */
.skel {
  background: linear-gradient(90deg,
    var(--bg-hover) 0%, var(--bg-active) 50%, var(--bg-hover) 100%);
  background-size: 200% 100%;
  animation: skel-pulse 1.4s ease-in-out infinite;
  border-radius: var(--r-2);
}
.skel-row {
  height: 40px;
  border-bottom: 1px solid var(--border-subtle);
  padding: 10px var(--s-4);
  display: flex;
  align-items: center;
  gap: var(--s-4);
}
.skel-cell { height: 12px; border-radius: 3px;
  background: linear-gradient(90deg,
    var(--bg-hover) 0%, var(--bg-active) 50%, var(--bg-hover) 100%);
  background-size: 200% 100%;
  animation: skel-pulse 1.4s ease-in-out infinite;
}
@keyframes skel-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ═════════════ MODAL ═════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
  z-index: 50;
  animation: fade-in .12s;
}
.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-4);
  padding: var(--s-5) var(--s-6);
  box-shadow: var(--sh-3);
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow: auto;
  animation: scale-in .14s;
}
.modal h2 { margin: 0 0 var(--s-2); font-size: var(--fs-xl); }
.modal p { margin: 0 0 var(--s-3); color: var(--text-secondary); }
.modal .modal-actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  margin-top: var(--s-5);
}
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }
@keyframes scale-in { from { opacity: 0; transform: translate(-50%, -48%) scale(.98) } to { opacity: 1; transform: translate(-50%, -50%) scale(1) } }

/* invite-link reveal (unchanged position, updated styling) */
.invite-link-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: var(--s-3);
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--accent);
  word-break: break-all;
  margin: var(--s-3) 0;
  line-height: var(--lh-loose);
}

/* ═════════════ TOAST ═════════════ */
#toast {
  position: fixed;
  bottom: var(--s-5);
  right: var(--s-5);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-3);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--sh-2);
  max-width: 380px;
  font-size: var(--fs-md);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  transform: translateY(20px);
  opacity: 0;
  transition: all .18s;
  z-index: 80;
  pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; pointer-events: auto; }
#toast.ok::before  { content: "✓"; color: var(--ok);  font-size: 16px; font-weight: 700; }
#toast.err::before { content: "!"; color: var(--err); font-size: 16px; font-weight: 700; }

/* ═════════════ COPY BUTTON ═════════════ */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px 1px 4px;
  margin-left: 6px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--r-2);
  cursor: pointer;
  font: inherit;
  font-size: var(--fs-xs);
  height: 20px;
  opacity: 0;
  transition: opacity .12s, background .12s, color .12s, border-color .12s;
  flex-shrink: 0;
  vertical-align: middle;
}
.copy-btn::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 1px solid currentColor;
  border-radius: 2px;
  box-shadow: -2px 2px 0 -1px transparent, -3px 3px 0 -2px currentColor;
  display: inline-block;
  transform: translateY(-1px);
}
.copy-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}
.copy-btn.copied {
  color: var(--ok);
  border-color: transparent;
  opacity: 1;
}
.copy-btn.copied::before {
  content: "";
  width: 10px; height: 6px;
  border: none;
  border-left: 1.5px solid var(--ok);
  border-bottom: 1.5px solid var(--ok);
  transform: rotate(-45deg) translate(1px, -2px);
  box-shadow: none;
  border-radius: 0;
}
.copyable, .copyable-parent {
  display: inline-flex;
  align-items: center;
}
.copyable:hover .copy-btn,
.copyable-parent:hover .copy-btn,
.copy-btn:focus-visible {
  opacity: 1;
}

/* ═════════════ COLLAPSIBLE JSON ═════════════ */
details.json-detail {
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-2);
  background: var(--bg-surface);
  overflow: hidden;
}
details.json-detail > summary {
  cursor: pointer;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  list-style: none;
  user-select: none;
  transition: background .1s;
}
details.json-detail > summary::-webkit-details-marker { display: none; }
details.json-detail > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 10px;
  transition: transform .1s;
}
details.json-detail[open] > summary::before { transform: rotate(90deg); }
details.json-detail > summary:hover { background: var(--bg-hover); }
details.json-detail[open] > summary {
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text);
}
details.json-detail > pre {
  margin: 0;
  padding: var(--s-3);
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
  background: var(--bg-elevated);
}
details.json-detail > pre .k { color: var(--accent); }
details.json-detail > pre .s { color: var(--ok); }
details.json-detail > pre .n { color: var(--warn); }
details.json-detail > pre .b { color: var(--violet); }

/* ═════════════ SORTABLE TABLES ═════════════ */
th.sortable {
  cursor: pointer;
  user-select: none;
  padding-right: 22px;
  position: relative;
  transition: color .1s;
}
th.sortable:hover { color: var(--text); }
th.sortable::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 1px solid var(--text-muted);
  border-bottom: 1px solid var(--text-muted);
  transform: translateY(-70%) rotate(45deg);
  opacity: .3;
  transition: opacity .1s, transform .1s;
}
th.sortable.sort-asc::after {
  transform: translateY(-30%) rotate(-135deg);
  opacity: 1;
  border-color: var(--accent);
}
th.sortable.sort-desc::after {
  transform: translateY(-70%) rotate(45deg);
  opacity: 1;
  border-color: var(--accent);
}

/* ═════════════ SEARCH INPUT (with prefix icon) ═════════════ */
.search-input-wrap {
  position: relative;
  display: inline-block;
  min-width: 220px;
}
.search-input-wrap input {
  padding-left: 30px;
}
.search-input-wrap::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--text-muted);
  border-radius: 50%;
  transform: translateY(-60%);
  pointer-events: none;
}
.search-input-wrap::after {
  content: "";
  position: absolute;
  left: 20px;
  top: 50%;
  width: 5px;
  height: 1.5px;
  background: var(--text-muted);
  transform: translateY(3px) rotate(45deg);
  transform-origin: 0 0;
  pointer-events: none;
}

/* ═════════════ AUDIT TIMELINE ═════════════ */
.timeline {
  position: relative;
  padding: var(--s-3) 0 var(--s-3) var(--s-6);
}
.timeline::before {
  content: "";
  position: absolute;
  left: 12px;
  top: var(--s-3);
  bottom: var(--s-3);
  width: 1px;
  background: var(--border-strong);
}
.timeline-item {
  position: relative;
  padding-bottom: var(--s-4);
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: "";
  position: absolute;
  left: -19px;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border-strong);
}
.timeline-item.ok::before  { background: var(--ok);  box-shadow: 0 0 0 1px var(--ok); }
.timeline-item.err::before { background: var(--err); box-shadow: 0 0 0 1px var(--err); }
.timeline-item.warn::before { background: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.timeline-header {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.timeline-action {
  font-family: var(--mono);
  font-size: var(--fs-md);
  color: var(--text);
  font-weight: 500;
}
.timeline-actor {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.timeline-time {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-left: auto;
}

/* ═════════════ POS specifics ═════════════ */
.pos-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  padding: var(--s-5);
  max-width: 560px;
}
/* Touch-optimised inputs inside .pos-card — bigger targets + ≥16px
   font-size (iOS Safari zooms in on inputs < 16px on focus). */
.pos-card input, .pos-card select {
  font-size: 15px;
  height: 42px;
  padding: 0 14px;
}
.pos-card label {
  font-size: var(--fs-md);
  margin-bottom: 6px;
}
.pos-card button {
  height: 42px;
  font-size: var(--fs-lg);
  padding: 0 var(--s-4);
}
.pos-card .field-help { font-size: var(--fs-md); }
.pos-amount-input {
  font-variant-numeric: tabular-nums;
  font-size: 22px !important;
  height: 52px !important;
  font-weight: 500;
  letter-spacing: -.01em;
}
.pos-step-label {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 0 0 var(--s-2);
}
.pos-step-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: 11px;
  font-weight: 600;
}

/* ═════════════ SKIP-TO-CONTENT (a11y) ═════════════ */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--s-3);
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-2);
  font-weight: 500;
  transition: top .12s;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: var(--s-3);
  outline: 2px solid var(--text);
  outline-offset: 2px;
  text-decoration: none;
}

/* ═════════════ SR-ONLY (a11y) ═════════════ */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ═════════════ FOCUS RINGS (keyboard-only) ═════════════ */
/* base focus outline goes to focus-visible only, so mouse clicks don't ring */
a:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline-offset: -1px;
}
.sidebar nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
tbody tr.clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
th.sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ═════════════ TABLE HORIZONTAL SCROLL wrapper ═════════════ */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ═════════════ RESPONSIVE ═════════════ */

/* --- tablet + small desktop (≤900px): off-canvas sidebar, tighter padding --- */
@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 260px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: var(--sh-3);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar-mobile-menu { display: inline-flex !important; }
  #view { padding: var(--s-4); }
  .page-header { flex-direction: column; align-items: flex-start; }
  .detail-grid { grid-template-columns: 1fr; gap: var(--s-1); }
  .detail-grid .k { padding-top: var(--s-2); }
  .field-row { grid-template-columns: 1fr; }
}
.topbar-mobile-menu { display: none; }

/* mobile-menu backdrop when sidebar is open */
@media (max-width: 900px) {
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 39;
    animation: fade-in .12s;
  }
}

/* --- mobile (≤640px): tables collapse to card rows, modal full-height --- */
@media (max-width: 640px) {
  #view { padding: var(--s-3); }
  .page-title { font-size: var(--fs-xl); }
  .toolbar { gap: var(--s-2); }
  .toolbar select, .toolbar input, .search-input-wrap { width: 100%; min-width: 0; }
  .search-input-wrap { display: block; }

  /* Tables → each row becomes a stacked list of label / value pairs */
  .data-table-wrap table { display: block; }
  .data-table-wrap thead { display: none; }
  .data-table-wrap tbody { display: block; }
  .data-table-wrap tbody tr {
    display: block;
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border-subtle);
  }
  .data-table-wrap tbody tr:last-child { border-bottom: none; }
  .data-table-wrap tbody tr.clickable { cursor: pointer; }
  .data-table-wrap tbody tr td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--s-3);
    padding: 3px 0;
    border: none;
    text-align: left !important;
    min-height: 22px;
  }
  .data-table-wrap tbody tr td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    flex-shrink: 0;
  }
  .data-table-wrap tbody tr td.num,
  .data-table-wrap tbody tr td.right { text-align: right !important; }
  .data-table-wrap tbody tr td .muted.small { display: inline; margin-left: 4px; }

  /* modal → bottom-sheet */
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--r-4) var(--r-4) 0 0;
    top: auto; left: 0; right: 0; bottom: 0;
    transform: none;
    padding: var(--s-4);
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; height: 44px; }
  @keyframes scale-in {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  /* login card → fills viewport */
  .login-screen { padding: var(--s-3); }
  .login-card { padding: var(--s-5) var(--s-4); box-shadow: none; border: 1px solid var(--border-subtle); }
  .login-card h1 { font-size: var(--fs-xl); }

  /* topbar: hide the clock, keep only badge + refresh */
  #now-tick { display: none; }
  .topbar { padding: 0 var(--s-3); }
  #refresh .lg-only { display: none; }

  /* POS: single-column and taller buttons */
  .pos-card { padding: var(--s-4); }
  .field-row { grid-template-columns: 1fr; gap: var(--s-2); }
  .pos-card button { width: 100%; }

  /* timeline: reduce indent */
  .timeline { padding-left: var(--s-5); }
  .timeline::before { left: 8px; }
  .timeline-item::before { left: -17px; }

  /* toast: full width at the bottom */
  #toast { left: var(--s-3); right: var(--s-3); bottom: var(--s-3); max-width: none; }
}

/* --- prefers-reduced-motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .skel, .skel-cell { animation: none; background: var(--bg-hover); }
}

/* --- high-contrast fallback: force borders visible if OS says so --- */
@media (prefers-contrast: more) {
  :root {
    --border:        #4a5260;
    --border-subtle: #3a414c;
    --border-strong: #5a6272;
    --text-muted:    #b0b6c0;
  }
  .pill { border-color: currentColor; }
}

/* selection */
::selection { background: var(--accent-bg); color: var(--text); }

/* scrollbars (webkit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
