/* ==========================================================================
   Track Flow — admin panel theme
   Dark by default (matching the product screenshots), with a light theme
   available via data-theme="light" on <html>.
   ========================================================================== */

/* ------------------------------------------------------------------ tokens */
:root {
  /* surfaces */
  --bg:            #0B0E14;
  --bg-2:          #0F131B;
  --sidebar-bg:    #101622;
  --surface:       #151B25;
  --surface-2:     #1A212D;
  --surface-3:     #212A38;
  --overlay:       rgba(6, 9, 14, .68);

  /* lines */
  --border:        #222B39;
  --border-2:      #2E3A4C;

  /* text */
  --text:          #E9EEF6;
  --text-2:        #B3BECD;
  --muted:         #7C8AA0;
  --faint:         #5A6779;

  /* brand + state */
  --primary:       #5B4CF5;
  --primary-2:     #7A6DFF;
  --primary-ink:   #FFFFFF;
  --primary-soft:  rgba(91, 76, 245, .16);
  --primary-line:  rgba(122, 109, 255, .38);

  --success:       #22C79B;
  --success-soft:  rgba(34, 199, 155, .14);
  --warning:       #F5A524;
  --warning-soft:  rgba(245, 165, 36, .14);
  --danger:        #F2506E;
  --danger-soft:   rgba(242, 80, 110, .14);
  --info:          #3BA9F5;
  --info-soft:     rgba(59, 169, 245, .14);

  /* shape */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;
  --r-xl: 18px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow:    0 4px 16px -6px rgba(0, 0, 0, .55);
  --shadow-lg: 0 18px 46px -18px rgba(0, 0, 0, .78);

  /* metrics */
  --sidebar-w:   260px;
  --sidebar-cw:  76px;
  --topbar-h:    64px;

  --sans: system-ui, "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "SF Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(.4, 0, .2, 1);
}

html[data-theme="light"] {
  --bg:            #F1F4F9;
  --bg-2:          #E9EEF5;
  --sidebar-bg:    #FFFFFF;
  --surface:       #FFFFFF;
  --surface-2:     #F7F9FC;
  --surface-3:     #EDF1F7;
  --overlay:       rgba(15, 23, 42, .42);

  --border:        #E2E8F1;
  --border-2:      #CBD6E4;

  --text:          #0F172A;
  --text-2:        #3E4C63;
  --muted:         #64748B;
  --faint:         #94A3B8;

  --primary:       #4F3FE8;
  --primary-2:     #6355F0;
  --primary-soft:  rgba(79, 63, 232, .09);
  --primary-line:  rgba(79, 63, 232, .28);

  --success:       #0F9C7A;
  --success-soft:  rgba(15, 156, 122, .10);
  --warning:       #B87514;
  --warning-soft:  rgba(184, 117, 20, .11);
  --danger:        #D93A5B;
  --danger-soft:   rgba(217, 58, 91, .10);
  --info:          #1B7FCB;
  --info-soft:     rgba(27, 127, 203, .10);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow:    0 4px 14px -6px rgba(15, 23, 42, .16);
  --shadow-lg: 0 18px 42px -16px rgba(15, 23, 42, .22);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 650; letter-spacing: -.011em; color: var(--text); }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

a { color: var(--primary-2); text-decoration: none; }
a:hover { color: var(--primary-2); text-decoration: underline; }

img { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

::selection { background: var(--primary-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--primary-2);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }

/* ==========================================================================
   Shell
   ========================================================================== */
.app { min-height: 100vh; }

.app-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .22s var(--ease);
}
body.sidebar-collapsed .app-main { margin-left: var(--sidebar-cw); }

.content {
  flex: 1;
  padding: 22px 26px 56px;
  width: 100%;
  max-width: 1560px;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: width .22s var(--ease), transform .24s var(--ease);
}
body.sidebar-collapsed .sidebar { width: var(--sidebar-cw); }

/* brand ------------------------------------------------------------------ */
.brand {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--primary-2), var(--primary));
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 3px 12px -3px rgba(91, 76, 245, .7);
}
.brand-text { min-width: 0; }
.brand-name {
  font-size: 15px; font-weight: 700; color: var(--text);
  letter-spacing: -.02em; white-space: nowrap;
}
.brand-sub {
  font-size: 10.5px; color: var(--muted);
  letter-spacing: .07em; text-transform: uppercase; white-space: nowrap;
}
body.sidebar-collapsed .brand { padding: 0; justify-content: center; }
body.sidebar-collapsed .brand-text { display: none; }

/* nav -------------------------------------------------------------------- */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 20px;
}

.nav-group { margin-bottom: 4px; }
.nav-group + .nav-group { margin-top: 14px; }

.nav-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 6px 12px;
  white-space: nowrap;
}
body.sidebar-collapsed .nav-label {
  text-align: center;
  padding: 10px 0 4px;
  font-size: 0;
}
body.sidebar-collapsed .nav-label::after {
  content: "";
  display: block;
  height: 1px;
  background: var(--border);
  margin: 0 16px;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  margin: 2px 0;
  border-radius: var(--r);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link svg { flex: 0 0 20px; color: var(--muted); transition: color .14s var(--ease); }
.nav-link:hover svg { color: var(--text-2); }

.nav-link.is-active {
  background: var(--primary-soft);
  color: var(--text);
  font-weight: 600;
}
.nav-link.is-active svg { color: var(--primary-2); }
.nav-link.is-active::before {
  content: "";
  position: absolute;
  left: -12px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--primary-2);
}

.nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.nav-count {
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-2);
}
.nav-count.is-alert { background: var(--danger-soft); color: var(--danger); }

body.sidebar-collapsed .nav-link { justify-content: center; padding: 10px 0; }
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .nav-count { display: none; }
body.sidebar-collapsed .nav-link.is-active::before { left: -8px; }

/* collapsed tooltip */
body.sidebar-collapsed .nav-link::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) scale(.94);
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-2);
  padding: 5px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s var(--ease), transform .12s var(--ease);
  z-index: 5;
}
body.sidebar-collapsed .nav-link:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }

/* footer ----------------------------------------------------------------- */
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}
.sidebar-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }
.sidebar-toggle svg { transition: transform .22s var(--ease); }
body.sidebar-collapsed .sidebar-toggle { justify-content: center; }
body.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
body.sidebar-collapsed .sidebar-toggle span { display: none; }

/* ==========================================================================
   Topbar
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 26px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title { min-width: 0; }
.topbar-title h1 {
  font-size: 17px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title .crumb {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}
.topbar-spacer { flex: 1; }

.icon-btn {
  width: 36px; height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  position: relative;
  transition: background .14s var(--ease), color .14s var(--ease), border-color .14s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn.has-dot::after {
  content: "";
  position: absolute;
  top: 8px; right: 8px;
  width: 7px; height: 7px;
  border-radius: 99px;
  background: var(--danger);
  border: 2px solid var(--bg);
}

.menu-btn { display: none; }

/* topbar search */
.topbar-search {
  position: relative;
  width: 260px;
}
.topbar-search svg {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.topbar-search input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 36px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}
.topbar-search input::placeholder { color: var(--faint); }
.topbar-search input:focus {
  outline: none;
  border-color: var(--primary-line);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* user chip */
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 9px 5px 5px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.user-chip:hover { border-color: var(--border-2); background: var(--surface-2); }
.user-chip .meta { text-align: left; line-height: 1.2; }
.user-chip .meta b { display: block; font-size: 12.5px; font-weight: 600; }
.user-chip .meta span { font-size: 10.5px; color: var(--muted); }
@media (max-width: 700px) { .user-chip .meta, .user-chip > svg { display: none; } }

/* ==========================================================================
   Impersonation banner
   ========================================================================== */
.impersonate-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 26px;
  background: var(--warning-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 32%, transparent);
  color: var(--warning);
  font-size: 12.5px;
  font-weight: 500;
}
.impersonate-bar b { color: var(--text); }
.impersonate-bar a { margin-left: auto; color: var(--warning); font-weight: 600; }

/* ==========================================================================
   Page header
   ========================================================================== */
.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h2 { font-size: 21px; letter-spacing: -.02em; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s var(--ease), border-color .14s var(--ease),
              color .14s var(--ease), transform .08s var(--ease), box-shadow .14s var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: .55; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: 0 2px 10px -3px rgba(91, 76, 245, .6);
}
.btn-primary:hover { background: var(--primary-2); color: var(--primary-ink); }

.btn-outline { background: transparent; border-color: var(--border-2); color: var(--text-2); }
.btn-outline:hover { background: var(--surface-2); color: var(--text); border-color: var(--faint); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 84%, #000); color: #fff; }

.btn-success { background: var(--success); color: #05271F; }
.btn-success:hover { background: color-mix(in srgb, var(--success) 88%, #000); }

.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; gap: 6px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 14.5px; }
.btn-block { width: 100%; }
.btn-square { width: 38px; padding: 0; }
.btn-square.btn-sm { width: 32px; }

.btn.is-loading { color: transparent !important; position: relative; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 99px;
  color: var(--primary-ink);
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 14.5px; }
.card-head .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ==========================================================================
   Stat tiles
   ========================================================================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 17px;
  overflow: hidden;
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.stat:hover { border-color: var(--border-2); transform: translateY(-1px); }

.stat-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.stat-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-2);
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.3;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-foot {
  margin-top: 7px;
  font-size: 11.5px;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 5px;
}

.stat.accent-success .stat-icon { background: var(--success-soft); color: var(--success); }
.stat.accent-success .stat-value { color: var(--success); }
.stat.accent-warning .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat.accent-warning .stat-value { color: var(--warning); }
.stat.accent-danger  .stat-icon { background: var(--danger-soft);  color: var(--danger); }
.stat.accent-danger  .stat-value { color: var(--danger); }
.stat.accent-info    .stat-icon { background: var(--info-soft);    color: var(--info); }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 12px 16px; text-align: left; vertical-align: middle; }
.table thead th {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); transition: background .12s var(--ease); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.shrink, .table th.shrink { width: 1%; white-space: nowrap; }
.table .row-title { font-weight: 600; color: var(--text); }
.table .row-sub { font-size: 12px; color: var(--muted); }

/* person cell */
.person { display: flex; align-items: center; gap: 11px; min-width: 0; }
.person .info { min-width: 0; }

/* ==========================================================================
   Avatars
   ========================================================================== */
.avatar {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .02em;
  background: var(--surface-3);
  color: var(--text-2);
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 28px; height: 28px; flex-basis: 28px; font-size: 11px; }
.avatar-lg { width: 52px; height: 52px; flex-basis: 52px; font-size: 17px; }

/* ==========================================================================
   Badges
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .01em;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary-2); }

.badge-dot::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 99px;
  background: currentColor;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span-2 { grid-column: span 2; }
@media (max-width: 640px) { .field.span-2 { grid-column: span 1; } }

.label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
}
.label .req { color: var(--danger); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease), background .14s var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-2); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--primary-line);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.input:disabled, .select:disabled, .textarea:disabled { opacity: .6; cursor: not-allowed; }

.textarea { min-height: 92px; resize: vertical; }

.select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237C8AA0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}
html[data-theme="light"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
  border-color: var(--danger);
  background: var(--danger-soft);
}
.field-error {
  font-size: 11.5px;
  color: var(--danger);
  display: flex;
  align-items: center;
  gap: 4px;
}
.field-hint { font-size: 11.5px; color: var(--muted); }

/* input with a leading symbol (currency, phone) */
.input-group { display: flex; align-items: stretch; }
.input-group .addon {
  display: grid;
  place-items: center;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: var(--r) 0 0 var(--r);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.input-group .input { border-radius: 0 var(--r) var(--r) 0; }

/* checkbox + radio */
.check {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-2);
  user-select: none;
}
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check .box {
  width: 18px; height: 18px;
  flex: 0 0 18px;
  border: 1.5px solid var(--border-2);
  border-radius: 5px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  transition: background .14s var(--ease), border-color .14s var(--ease);
}
.check .box svg { opacity: 0; color: #fff; transform: scale(.7); transition: opacity .12s var(--ease), transform .12s var(--ease); }
.check input:checked + .box { background: var(--primary); border-color: var(--primary); }
.check input:checked + .box svg { opacity: 1; transform: scale(1); }
.check input:focus-visible + .box { box-shadow: 0 0 0 3px var(--primary-soft); }
.check.radio .box { border-radius: 99px; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 21px;
  flex: 0 0 38px;
  border-radius: 99px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  position: relative;
  transition: background .16s var(--ease), border-color .16s var(--ease);
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 15px; height: 15px;
  border-radius: 99px;
  background: var(--muted);
  transition: transform .16s var(--ease), background .16s var(--ease);
}
.switch input:checked + .track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .track::after { transform: translateX(17px); background: #fff; }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--primary-soft); }

/* selectable option cards (attendance style, plan pickers, provider choice) */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.choice { display: block; cursor: pointer; }
.choice input { position: absolute; opacity: 0; width: 0; height: 0; }

.choice-body {
  position: relative;
  display: block;
  padding: 16px 17px 17px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
.choice:hover .choice-body { border-color: var(--border-2); }

.choice-mark {
  position: absolute;
  top: 13px; right: 13px;
  width: 20px; height: 20px;
  border-radius: 99px;
  border: 1.5px solid var(--border-2);
  background: var(--surface);
  display: grid;
  place-items: center;
  color: #fff;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.choice-mark svg { opacity: 0; transform: scale(.6); transition: opacity .12s var(--ease), transform .12s var(--ease); }

.choice-icon {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--muted);
  margin-bottom: 11px;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.choice-title { display: block; font-size: 14.5px; font-weight: 650; margin-bottom: 3px; }
.choice-hint  { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.choice-detail{ display: block; font-size: 11.5px; color: var(--muted); line-height: 1.45; }

.choice input:checked + .choice-body {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}
.choice input:checked + .choice-body .choice-mark { background: var(--primary); border-color: var(--primary); }
.choice input:checked + .choice-body .choice-mark svg { opacity: 1; transform: scale(1); }
.choice input:checked + .choice-body .choice-icon { background: var(--primary); color: #fff; }
.choice input:focus-visible + .choice-body { outline: 2px solid var(--primary-2); outline-offset: 2px; }

/* ==========================================================================
   Public join page
   ========================================================================== */
.public-body { background: var(--bg); }

.public-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 32px;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(91, 76, 245, .22), transparent 65%),
    var(--bg);
}
.public-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  padding: 26px 24px 28px;
}
.public-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.public-head h1 { font-size: 19px; letter-spacing: -.02em; }
.public-sub { font-size: 12.5px; color: var(--muted); margin: 2px 0 0; }
.public-logo {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 13px; object-fit: cover; border: 1px solid var(--border);
}
.public-mark {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 13px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--primary-2), var(--primary));
  color: #fff; font-weight: 700; font-size: 17px;
}
.public-intro { margin-bottom: 20px; }
.public-intro h2 { font-size: 23px; letter-spacing: -.025em; margin-bottom: 6px; }
.public-intro p { color: var(--muted); font-size: 14px; }
.public-note { font-size: 11.5px; color: var(--faint); text-align: center; margin: 4px 0 0; }
.public-foot { margin-top: 18px; font-size: 12px; color: var(--faint); }

.input-lg { min-height: 46px; font-size: 15px; }

/* honeypot — off-screen rather than display:none, which some bots skip */
.hp-field {
  position: absolute !important;
  left: -9999px !important;
  width: 1px; height: 1px;
  overflow: hidden;
}

.public-done { text-align: center; padding: 8px 0 4px; }
.public-tick {
  width: 68px; height: 68px;
  margin: 0 auto 18px;
  border-radius: 99px;
  display: grid; place-items: center;
  background: var(--success-soft);
  color: var(--success);
  border: 2px solid color-mix(in srgb, var(--success) 42%, transparent);
}
.public-done h2 { font-size: 23px; letter-spacing: -.02em; margin-bottom: 8px; }
.public-done p { color: var(--muted); font-size: 14.5px; margin-bottom: 22px; }

/* plan picker on the public form */
.plan-choices { display: flex; flex-direction: column; gap: 8px; }
.plan-choice { display: block; cursor: pointer; }
.plan-choice input { position: absolute; opacity: 0; width: 0; height: 0; }
.plan-choice-body {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  transition: border-color .14s var(--ease), background .14s var(--ease);
}
.plan-choice:hover .plan-choice-body { border-color: var(--border-2); }
.plan-choice-name { flex: 1; font-size: 14px; font-weight: 600; }
.plan-choice-price { font-size: 14px; font-weight: 700; color: var(--primary-2); font-variant-numeric: tabular-nums; }
.plan-choice-days { font-size: 11.5px; color: var(--muted); }
.plan-choice input:checked + .plan-choice-body {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}
.plan-choice input:focus-visible + .plan-choice-body { outline: 2px solid var(--primary-2); outline-offset: 2px; }

/* ==========================================================================
   QR
   ========================================================================== */
.qr-frame {
  display: inline-block;
  padding: 14px;
  background: #fff;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  line-height: 0;
}
.qr-frame svg { width: 100%; max-width: 260px; height: auto; display: block; }

/* ==========================================================================
   Timeline (call history)
   ========================================================================== */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before {
  content: "";
  position: absolute;
  left: 5px; top: 6px; bottom: 6px;
  width: 1px;
  background: var(--border);
}
.timeline-item { position: relative; padding: 0 0 16px 24px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute;
  left: 0; top: 5px;
  width: 11px; height: 11px;
  border-radius: 99px;
  background: var(--surface-3);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border-2);
}
.timeline-dot.is-good { background: var(--success); box-shadow: 0 0 0 1px var(--success); }
.timeline-dot.is-bad  { background: var(--danger);  box-shadow: 0 0 0 1px var(--danger); }
.timeline-body { min-width: 0; }

/* small inline link-style button, for destructive actions inside body text */
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  margin-left: 6px;
  font: inherit;
  font-size: inherit;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: var(--text); }
.link-btn.danger:hover { color: var(--danger); }

/* count bubble inside a pill tab */
.tab-count {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tab.is-active .tab-count { background: rgba(255, 255, 255, .22); color: #fff; }

/* ==========================================================================
   Customers
   ========================================================================== */
.customer-list { display: flex; flex-direction: column; }

.customer-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  transition: background .12s var(--ease);
}
.customer-row:last-child { border-bottom: 0; }
.customer-row:hover { background: var(--surface-2); }

.customer-main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 15px 8px 15px 18px;
  min-width: 0;
  color: inherit;
}
.customer-main:hover { text-decoration: none; color: inherit; }

.customer-info { flex: 1; min-width: 0; display: block; }

.customer-name {
  display: block;
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -.01em;
  margin-bottom: 2px;
}
.customer-code { color: var(--muted); font-weight: 600; margin-right: 3px; }

.customer-phone {
  display: block;
  font-size: 13px;
  color: var(--primary-2);
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.customer-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12.5px;
  color: var(--muted);
}
.customer-meta strong { color: var(--text-2); font-weight: 600; }

.customer-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  padding-left: 14px;
  flex: 0 0 auto;
  text-align: right;
}
.customer-side-label { font-size: 11.5px; color: var(--muted); }
.customer-side-value { font-size: 13px; font-weight: 600; color: var(--text-2); }
.customer-status {
  margin-top: 5px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .08em;
}
.customer-status.is-active { color: var(--success); }
.customer-status.is-closed { color: var(--danger); }

.customer-actions { display: flex; align-items: center; padding: 0 12px 0 4px; }

@media (max-width: 620px) {
  .customer-main { flex-wrap: wrap; padding: 14px 8px 14px 14px; }
  .customer-side {
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 9px 0 0 62px;
    text-align: left;
  }
  .customer-side-label { display: none; }
  .customer-status { margin-top: 0; }
}

/* photo picker on the customer form */
.photo-picker { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.photo-picker > div { flex: 1; min-width: 220px; }

.photo-drop { position: relative; cursor: pointer; display: inline-block; }
.avatar-xl { width: 76px; height: 76px; flex-basis: 76px; font-size: 24px; }
.photo-drop .avatar { border: 2px dashed var(--border-2); background: var(--surface-2); color: var(--muted); }
.photo-drop:hover .avatar { border-color: var(--primary); color: var(--primary-2); }
.photo-badge {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 26px; height: 26px;
  border-radius: 99px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  border: 2px solid var(--surface);
}

/* ==========================================================================
   Attendance calendar
   ========================================================================== */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.calendar-dow {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  padding-bottom: 4px;
}
.calendar-day {
  position: relative;
  min-height: 62px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 6px 7px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.calendar-day.is-empty { border: 0; background: transparent; }
.calendar-num { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.calendar-time { font-size: 10.5px; color: var(--text-2); font-variant-numeric: tabular-nums; line-height: 1.3; }
.calendar-dot { color: var(--success); margin-top: auto; }

.calendar-day.is-present { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 34%, transparent); }
.calendar-day.is-present .calendar-num { color: var(--success); }
.calendar-day.is-absent  { background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.calendar-day.is-absent  .calendar-num { color: var(--danger); }
.calendar-day.is-leave   { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.calendar-day.is-leave   .calendar-num { color: var(--warning); }
.calendar-day.is-today   { box-shadow: 0 0 0 2px var(--primary); }

.calendar-key {
  width: 12px; height: 12px;
  border-radius: 4px;
  display: inline-block;
  border: 1px solid var(--border-2);
}
.calendar-key.is-present { background: var(--success-soft); border-color: var(--success); }
.calendar-key.is-absent  { background: var(--danger-soft);  border-color: var(--danger); }
.calendar-key.is-leave   { background: var(--warning-soft); border-color: var(--warning); }

@media (max-width: 560px) {
  .calendar { gap: 4px; }
  .calendar-day { min-height: 46px; padding: 4px 5px; }
  .calendar-time { display: none; }
}

/* ==========================================================================
   Roles
   ========================================================================== */
.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}
.role-card { display: flex; flex-direction: column; }
.role-card .card-body { flex: 1; }
.role-card + .role-card { margin-top: 0; }

.role-card-new {
  border-style: dashed;
  border-color: var(--border-2);
  display: grid;
  place-items: center;
  min-height: 190px;
  text-decoration: none;
  color: inherit;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.role-card-new:hover { border-color: var(--primary); background: var(--primary-soft); text-decoration: none; }

.role-meter-bar {
  height: 6px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.role-meter-bar span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  transition: width .3s var(--ease);
}

/* --------------------------------------------------------- permission grid */
.perm-modules {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.perm-module {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  padding: 0 0 10px;
  margin: 0;
  min-width: 0;
}

.perm-head {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  float: left;   /* legend + flex needs this to fill the row in all browsers */
}
.perm-icon {
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text-2);
}
.perm-head-text { flex: 1; min-width: 0; }
.perm-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--text);
}
.perm-title .badge { padding: 1px 5px; }
.perm-blurb {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 1px;
}
.perm-toggle { flex: 0 0 auto; }

.perm-list { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; clear: both; }

.perm-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .12s var(--ease);
}
.perm-item:hover { background: var(--surface-3); }
.perm-item input { position: absolute; opacity: 0; width: 0; height: 0; }

.perm-box {
  width: 17px; height: 17px;
  flex: 0 0 17px;
  margin-top: 1px;
  border: 1.5px solid var(--border-2);
  border-radius: 5px;
  background: var(--surface);
  display: grid;
  place-items: center;
  color: #fff;
  transition: background .13s var(--ease), border-color .13s var(--ease);
}
.perm-box svg { opacity: 0; transform: scale(.6); transition: opacity .11s var(--ease), transform .11s var(--ease); }
.perm-item input:checked + .perm-box { background: var(--primary); border-color: var(--primary); }
.perm-item input:checked + .perm-box svg { opacity: 1; transform: scale(1); }
.perm-item input:focus-visible + .perm-box { box-shadow: 0 0 0 3px var(--primary-soft); }

.perm-label { font-size: 13px; color: var(--text-2); line-height: 1.35; min-width: 0; }
.perm-item input:checked ~ .perm-label { color: var(--text); }
.perm-code {
  display: block;
  font-size: 10.5px;
  color: var(--faint);
  margin-top: 1px;
}

/* key/value detail list */
.detail-list { display: flex; flex-direction: column; }
.detail {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.detail:last-child { border-bottom: 0; }
.detail .k { color: var(--muted); font-size: 12.5px; }
.detail .v { color: var(--text); min-width: 0; word-break: break-word; }
@media (max-width: 560px) {
  .detail { grid-template-columns: 1fr; gap: 3px; }
}

/* toolbar above a list */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.toolbar .search { position: relative; flex: 1; min-width: 190px; max-width: 340px; }
.toolbar .search svg {
  position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%); color: var(--muted); pointer-events: none;
}
.toolbar .search .input { padding-left: 36px; }
.toolbar .spacer { flex: 1; }

/* ==========================================================================
   Dropdown menu
   ========================================================================== */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  z-index: 70;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px) scale(.985);
  transform-origin: top right;
  transition: opacity .13s var(--ease), transform .13s var(--ease), visibility .13s;
}
.dropdown.is-open .dropdown-menu { opacity: 1; visibility: visible; transform: none; }
.dropdown-menu.to-left { right: auto; left: 0; transform-origin: top left; }

.dropdown-head {
  padding: 8px 11px 9px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 5px;
}
.dropdown-head b { display: block; font-size: 13px; }
.dropdown-head span { font-size: 11.5px; color: var(--muted); }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 11px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.dropdown-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.dropdown-item svg { color: var(--muted); flex: 0 0 auto; }
.dropdown-item:hover svg { color: var(--text-2); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); color: var(--danger); }
.dropdown-item.danger svg { color: var(--danger); }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 0; }

/* ==========================================================================
   Alerts
   ========================================================================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  font-size: 13.5px;
  color: var(--text-2);
  margin-bottom: 16px;
}
.alert svg { flex: 0 0 auto; margin-top: 1px; }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); color: var(--warning); }
.alert-danger  { background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 30%, transparent);  color: var(--danger); }
.alert-info    { background: var(--info-soft);    border-color: color-mix(in srgb, var(--info) 30%, transparent);    color: var(--info); }
.alert .close { margin-left: auto; background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 0; }
.alert .close:hover { opacity: 1; }

/* toast stack */
.toasts {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 9px;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r);
  border: 1px solid var(--border-2);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: toast-in .22s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(14px); } }
.toast.is-leaving { opacity: 0; transform: translateX(14px); transition: opacity .2s, transform .2s; }
.toast-success { border-left: 3px solid var(--success); }
.toast-danger  { border-left: 3px solid var(--danger); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-info    { border-left: 3px solid var(--info); }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs {
  display: flex;
  gap: 5px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow-x: auto;
  margin-bottom: 18px;
}
.tab {
  padding: 7px 15px;
  border-radius: var(--r);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { background: var(--primary); color: var(--primary-ink); }

.tabs-line { display: flex; gap: 22px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs-line .tab-link {
  padding: 10px 0 11px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tabs-line .tab-link:hover { color: var(--text); text-decoration: none; }
.tabs-line .tab-link.is-active { color: var(--primary-2); border-bottom-color: var(--primary-2); }

/* ==========================================================================
   Pagination
   ========================================================================== */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.pagination .count { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pagination .pages { margin-left: auto; display: flex; gap: 4px; }
.page-link {
  min-width: 32px; height: 32px;
  padding: 0 9px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  transition: background .13s var(--ease), border-color .13s var(--ease), color .13s var(--ease);
}
.page-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; border-color: var(--border-2); }
.page-link.is-active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.page-link.is-disabled { opacity: .4; pointer-events: none; }

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty {
  padding: 52px 24px;
  text-align: center;
  color: var(--muted);
}
.empty .icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--faint);
}
.empty h4 { font-size: 15px; margin-bottom: 5px; color: var(--text); }
.empty p { font-size: 13px; max-width: 42ch; margin: 0 auto 16px; }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .16s var(--ease), visibility .16s;
}
.modal-backdrop.is-open { opacity: 1; visibility: visible; }

.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  transform: translateY(10px) scale(.98);
  transition: transform .18s var(--ease);
}
.modal-backdrop.is-open .modal { transform: none; }
.modal-lg { max-width: 760px; }

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15.5px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ==========================================================================
   Auth screen
   ========================================================================== */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--bg);
}
@media (min-width: 940px) { .auth { grid-template-columns: 1.05fr .95fr; } }

.auth-aside {
  display: none;
  position: relative;
  padding: 48px;
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(91, 76, 245, .30), transparent 60%),
    radial-gradient(ellipse 70% 60% at 95% 100%, rgba(34, 199, 155, .16), transparent 55%),
    var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
@media (min-width: 940px) { .auth-aside { display: flex; } }

.auth-aside::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 46px 46px;
  opacity: .22;
  mask-image: radial-gradient(ellipse 70% 70% at 50% 40%, #000, transparent);
  pointer-events: none;
}
.auth-aside > * { position: relative; z-index: 1; }

.auth-quote { max-width: 30ch; }
.auth-quote h2 { font-size: 32px; line-height: 1.15; letter-spacing: -.03em; margin-bottom: 14px; }
.auth-quote p { color: var(--text-2); font-size: 15px; }

.auth-features { display: flex; flex-direction: column; gap: 14px; margin-top: 28px; }
.auth-feature { display: flex; align-items: center; gap: 11px; font-size: 13.5px; color: var(--text-2); }
.auth-feature .dot {
  width: 30px; height: 30px;
  flex: 0 0 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary-2);
  border: 1px solid var(--primary-line);
}

.auth-main {
  display: grid;
  place-items: center;
  padding: 32px 20px 48px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 30px; }
.auth-card h1 { font-size: 24px; letter-spacing: -.03em; margin-bottom: 6px; }
.auth-card .lede { color: var(--muted); font-size: 13.5px; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 15px; }
.auth-foot { margin-top: 22px; font-size: 12.5px; color: var(--faint); text-align: center; }

/* password visibility toggle */
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 42px; }
.pw-toggle {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.pw-toggle:hover { color: var(--text); background: var(--surface-3); }

/* ==========================================================================
   Error page
   ========================================================================== */
.error-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}
.error-code {
  font-family: var(--mono);
  font-size: 74px;
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: 1;
  color: var(--primary-2);
}
.error-page h1 { font-size: 22px; margin: 14px 0 8px; }
.error-page p { color: var(--muted); max-width: 44ch; margin: 0 auto 22px; }

/* ==========================================================================
   Utilities
   ========================================================================== */
.stack   { display: flex; flex-direction: column; gap: 16px; }
.row     { display: flex; align-items: center; gap: 10px; }
.row-wrap{ flex-wrap: wrap; }
.between { justify-content: space-between; }
.ml-auto { margin-left: auto; }
.grow    { flex: 1; min-width: 0; }
.muted   { color: var(--muted); }
.faint   { color: var(--faint); }
.small   { font-size: 12px; }
.strong  { font-weight: 650; }
.right   { text-align: right; }
.center  { text-align: center; }
.truncate{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap  { white-space: nowrap; }
.hide    { display: none !important; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 14px; }
.mb-4 { margin-bottom: 20px; }
.mt-3 { margin-top: 14px; }
.mt-4 { margin-top: 20px; }

.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary-2); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }

/* ==========================================================================
   Sidebar overlay (mobile)
   ========================================================================== */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 55;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s var(--ease), visibility .2s;
}
body.sidebar-open .sidebar-overlay { opacity: 1; visibility: visible; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
  .topbar-search { width: 190px; }
}

@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    width: var(--sidebar-w) !important;
  }
  body.sidebar-open .sidebar { transform: none; }

  /* the collapse state is desktop-only */
  body.sidebar-collapsed .sidebar .nav-text,
  body.sidebar-collapsed .sidebar .nav-count,
  body.sidebar-collapsed .sidebar .brand-text,
  body.sidebar-collapsed .sidebar-toggle span { display: revert; }
  body.sidebar-collapsed .sidebar .nav-link { justify-content: flex-start; padding: 9px 12px; }
  body.sidebar-collapsed .sidebar .nav-link::after { display: none; }
  body.sidebar-collapsed .sidebar .brand { padding: 0 18px; justify-content: flex-start; }
  body.sidebar-collapsed .sidebar .nav-label { font-size: 10px; text-align: left; padding: 6px 12px; }
  body.sidebar-collapsed .sidebar .nav-label::after { display: none; }

  .app-main,
  body.sidebar-collapsed .app-main { margin-left: 0; }

  .menu-btn { display: inline-grid; }
  .sidebar-foot { display: none; }
  .topbar, .content, .impersonate-bar { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 720px) {
  .topbar-search { display: none; }
  .content { padding: 16px 14px 44px; }
  .topbar { padding: 0 14px; gap: 8px; }
  .topbar-title h1 { font-size: 15.5px; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat-value { font-size: 23px; }
  .page-head { margin-bottom: 16px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .table th, .table td { padding: 10px 12px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .sidebar, .topbar, .impersonate-bar, .toasts, .page-head .actions { display: none !important; }
  .app-main { margin-left: 0 !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #ddd; box-shadow: none; }
}

/* ==========================================================================
   Expenses
   ========================================================================== */
.grid-side { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 1140px) {
  .grid-side { grid-template-columns: minmax(0, 1fr) 340px; }
}

.breakdown { display: flex; flex-direction: column; gap: 16px; }
.breakdown-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.breakdown-value { font-size: 13.5px; font-weight: 700; color: var(--text); }
.breakdown-bar {
  height: 7px;
  margin-top: 7px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.breakdown-bar span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--warning), var(--primary-2));
  transition: width .3s var(--ease);
}

.table tfoot td {
  border-top: 2px solid var(--border-2);
  background: var(--surface-2);
  padding-top: 12px;
  padding-bottom: 12px;
}

/* ---------------------------------------------------------------- WhatsApp
   The message bubble mimics WhatsApp's own so the preview reads the way the
   customer will see it, tail included. */
.wa-bubble {
  position: relative;
  max-width: 100%;
  padding: 10px 13px;
  border-radius: 10px 10px 10px 2px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.wa-bubble:empty::before {
  content: 'Nothing to preview yet.';
  color: var(--muted);
}
.wa-phone {
  padding: 18px 14px;
  border-radius: var(--r-lg);
  background:
    linear-gradient(180deg, rgba(37, 211, 102, .06), transparent 40%),
    var(--surface-2);
  border: 1px solid var(--border);
}
.wa-phone .wa-bubble { background: var(--surface); }
.wa-bubble-time {
  display: block;
  margin-top: 6px;
  text-align: right;
  font-size: 11px;
  color: var(--muted);
}

/* A table cell that opens a modal — reads as text, behaves as a button. */
.link-plain {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}
.link-plain:hover { color: var(--primary); }

.row-sub.danger { color: var(--danger); }

/* The template list: one card per event. */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}
.template-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  transition: border-color .18s var(--ease), transform .18s var(--ease);
}
.template-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.template-card.is-off { opacity: .62; }
.template-card .body {
  flex: 1;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 118px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent);
          mask-image: linear-gradient(180deg, #000 70%, transparent);
}

/* Placeholder chips under the template editor. */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 9px;
  border: 1px solid var(--border-2);
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 11.5px;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }

/* ================================================================ PORTAL
   The member's own view. Built phone-first: one column, a fixed tab bar at
   thumb height, and generous tap targets. Above 900px the tabs move into the
   header and the column centres instead of stretching. */
.portal-body { background: var(--bg); }

.portal {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.portal-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.portal-head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 780px;
  margin: 0 auto;
  padding: 11px 16px;
  padding-top: max(11px, env(safe-area-inset-top));
}
.portal-logo { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }
.portal-company { font-size: 14.5px; font-weight: 700; color: var(--text); }
.portal-greet   { font-size: 12px; color: var(--muted); }

.portal-content {
  flex: 1;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 16px;
  /* Clear of the fixed tab bar, plus the home indicator on an iPhone. */
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.portal-page-head h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.portal-page-head p  { margin: 3px 0 0; font-size: 13.5px; color: var(--muted); }

.portal-section-label {
  margin: 6px 0 -4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* The one number a member opens the app to see. */
.portal-hero {
  padding: 22px 20px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 60%),
    var(--surface-2);
}
.portal-hero-label { font-size: 13px; color: var(--text-2); }
.portal-hero-value {
  margin-top: 4px;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--text);
}
.portal-hero-sub { margin-top: 2px; font-size: 13px; color: var(--muted); }
.portal-hero-sub.danger { color: var(--danger); }

/* Tabs — bottom bar on a phone, inline in the header on a wide screen. */
.portal-tabs { display: flex; }
.portal-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  transition: color .15s var(--ease);
}
.portal-tab.is-active { color: var(--primary); }
.portal-tab:hover     { color: var(--text); }
.portal-tab.is-active:hover { color: var(--primary); }

.portal-tabs-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.portal-tabs-wide { display: none; }

@media (min-width: 900px) {
  .portal-tabs-bottom { display: none; }
  .portal-tabs-wide {
    display: flex;
    gap: 4px;
    max-width: 780px;
    margin: 0 auto;
    padding: 0 10px 4px;
  }
  .portal-tabs-wide .portal-tab {
    flex: 0 0 auto;
    flex-direction: row;
    gap: 7px;
    padding: 9px 13px;
    border-radius: var(--r) var(--r) 0 0;
    font-size: 13px;
  }
  .portal-tabs-wide .portal-tab.is-active {
    background: var(--surface-2);
    box-shadow: inset 0 -2px 0 var(--primary);
  }
  .portal-content { padding-bottom: 32px; }
}

/* A row inside a portal card: label on the left, value on the right. */
.plan-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}
a.link-row {
  color: inherit;
  text-decoration: none;
  transition: border-color .15s var(--ease), transform .15s var(--ease);
}
a.link-row:hover { border-color: var(--primary); transform: translateX(1px); }

.progress {
  height: 7px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
}

/* Attendance calendar. */
.cal {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.cal-dow {
  padding-bottom: 4px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--muted);
}
.cal-cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--muted);
}
.cal-cell.is-empty  { border: 0; background: none; }
.cal-cell.is-today  { outline: 2px solid var(--primary); outline-offset: 1px; }
.cal-cell.is-present {
  background: color-mix(in srgb, var(--success) 20%, var(--surface-2));
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
  color: var(--text);
  font-weight: 700;
}
.cal-cell.is-absent {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface-2));
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.cal-cell.is-leave {
  background: color-mix(in srgb, var(--warning) 14%, var(--surface-2));
  border-color: color-mix(in srgb, var(--warning) 35%, transparent);
}
.cal-time { font-size: 9px; color: var(--muted); }

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--muted);
}
.cal-legend span { display: flex; align-items: center; gap: 5px; }
.cal-legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.cal-legend .dot.is-present { background: color-mix(in srgb, var(--success) 45%, var(--surface-2)); }
.cal-legend .dot.is-absent  { background: color-mix(in srgb, var(--danger) 30%, var(--surface-2)); }
.cal-legend .dot.is-leave   { background: color-mix(in srgb, var(--warning) 35%, var(--surface-2)); }

/* Receipt. */
.receipt-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--border-2);
}
.receipt-company { font-size: 16px; font-weight: 800; letter-spacing: -.02em; }
.receipt-no { font-family: var(--mono); font-weight: 700; }
.receipt-to { padding: 14px 0; }
.receipt-to .label { display: block; margin-bottom: 3px; }
.receipt-table td { padding-left: 0; padding-right: 0; }
.receipt-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--r);
  font-size: 15px;
}
.receipt-total strong { font-size: 19px; }
.receipt-total.is-paid {
  background: color-mix(in srgb, var(--success) 14%, var(--surface-2));
  color: var(--success);
}
.receipt-total.is-due {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface-2));
  color: var(--danger);
}
.receipt-total span { display: flex; align-items: center; gap: 7px; }

/* Sign-in gate. */
.portal-gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.portal-gate-card {
  width: 100%;
  max-width: 400px;
  padding: 26px 22px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg, 0 20px 50px rgba(0, 0, 0, .35));
}
.gate-title { margin: 0; font-size: 23px; letter-spacing: -.02em; }
.gate-sub   { margin: 5px 0 20px; font-size: 13.5px; color: var(--muted); }
.gate-foot  { margin: 18px 0 0; text-align: center; font-size: 13px; color: var(--muted); }

.gate-or {
  position: relative;
  margin: 18px 0;
  text-align: center;
}
.gate-or::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}
.gate-or span {
  position: relative;
  padding: 0 12px;
  background: var(--surface);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}

.input-code {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: .4em;
  text-indent: .4em;   /* re-centres text that letter-spacing pushes left */
}

.stat-grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }

@media print {
  .portal-head, .portal-tabs, .portal-page-head, .card-foot { display: none !important; }
  .portal-content { padding: 0; }
  .card { border: 0; box-shadow: none; }
}

/* ================================================================ REPORTS
   A bar chart with no charting library: one flex column per period, two
   absolutely simple bars inside it. Heights are percentages of the tallest
   value, worked out in PHP, so there is nothing to measure at runtime and
   nothing to recalculate on resize. */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 190px;
  padding: 4px 2px 0;
  overflow-x: auto;
}
.chart-dense { gap: 3px; }

.chart-col {
  flex: 1 1 0;
  min-width: 26px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}
.chart-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: 100%;
}
.chart-bars span {
  flex: 1 1 0;
  max-width: 20px;
  /* A bar for a real but tiny value should still be visible, and a bar for
     zero should not — hence min-height on the element, not in the height. */
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  transition: height .35s var(--ease);
}
.chart-bars span[style*="height:0%"] { min-height: 0; }

.chart-in  { background: linear-gradient(180deg, var(--primary), var(--primary-2)); }
.chart-out { background: linear-gradient(180deg, var(--warning), color-mix(in srgb, var(--warning) 55%, transparent)); }

.chart-label {
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}
.chart-dense .chart-label { font-size: 9px; }

.chart-key {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}
.chart-key span { display: flex; align-items: center; gap: 6px; }
.chart-key i {
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

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

.table td.danger, .table .danger { color: var(--danger); }

.code-block {
  display: block;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-3);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-2);
  word-break: break-all;
}

/* Notification rows — a coloured left edge carries the severity. */
.notice {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s var(--ease), transform .15s var(--ease);
}
.notice:hover { transform: translateX(2px); text-decoration: none; }
.notice-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--surface-3);
}
.notice-body   { flex: 1; min-width: 0; }
.notice-title  { display: block; font-size: 14px; font-weight: 650; }
.notice-detail { display: block; margin-top: 2px; font-size: 12.5px; color: var(--muted); }

.notice-danger  { border-left-color: var(--danger); }
.notice-danger  .notice-icon { background: color-mix(in srgb, var(--danger) 16%, var(--surface-3)); color: var(--danger); }
.notice-warning { border-left-color: var(--warning); }
.notice-warning .notice-icon { background: color-mix(in srgb, var(--warning) 16%, var(--surface-3)); color: var(--warning); }
.notice-info    { border-left-color: var(--primary); }
.notice-info    .notice-icon { background: color-mix(in srgb, var(--primary) 16%, var(--surface-3)); color: var(--primary); }
