/* =============================================================
   Excel-Driven App · style.css
   ============================================================= */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  /* Apple Design System Colors */
  --clr-primary:   #0066cc;
  --clr-primary-focus: #0071e3;
  --clr-primary-dark: #2997ff;
  --clr-accent:    #34c759;
  --clr-danger:    #ff3b30;
  --clr-warning:   #ff9500;
  --clr-info:      #0066cc;

  /* Apple Surfaces */
  --clr-bg:        #f5f5f7;
  --clr-surface:   #ffffff;
  --clr-tile-dark-1: #272729;
  --clr-tile-dark-2: #2a2a2c;
  --clr-tile-dark-3: #252527;
  --clr-tile-pearl: #fafafc;
  
  --clr-border:    #f0f0f0;
  --clr-text:      #1d1d1f;
  --clr-text-dark: #ffffff;
  --clr-muted:     #7a7a7a;
  --clr-muted-light: #cccccc;
  --clr-input-bg:  #ffffff;
  --clr-sidebar:   #272729;
  --clr-sidebar-t: #ffffff;
  --clr-sidebar-m: rgba(255,255,255,.08);
  --clr-sidebar-a: rgba(255,255,255,.18);
  --clr-header:    #ffffff;

  --sidebar-w:     240px;
  --header-h:      56px;
  --radius:        8px;
  --radius-lg:     18px;
  --radius-pill:   9999px;
  /* Product shadow: the only shadow in the system */
  --shadow-product: 3px 5px 30px rgba(0,0,0,.22);
  --shadow:        0 1px 1px rgba(0,0,0,.04);
  --shadow-md:     0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:     0 4px 8px rgba(0,0,0,.08);
  --transition:    .18s ease;
}

/* ── Dark Mode ────────────────────────────────────────────── */
body.dark {
  --clr-bg:        #1a1a1c;
  --clr-surface:   #272729;
  --clr-border:    #333333;
  --clr-text:      #f5f5f7;
  --clr-muted:     #94a3b8;
  --clr-input-bg:  #333333;
  --clr-header:    #272729;
  --clr-sidebar:   #1a1a1c;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'SF Pro Text', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.47;
  letter-spacing: -0.374px;
  font-size: 17px;
  font-weight: 400;
  min-height: 100vh;
}
a { 
  color: var(--clr-primary); 
  text-decoration: none;
  font-weight: 400;
  transition: color var(--transition);
}
a:hover { color: var(--clr-primary-focus); }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
code { 
  font-family: 'Fira Mono', 'Cascadia Code', monospace; 
  font-size: .875em; 
  background: var(--clr-bg); 
  padding: 2px 6px; 
  border-radius: 4px;
  color: var(--clr-primary);
}

/* ── Setup Screen ─────────────────────────────────────────── */
#setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--clr-surface);
}
.setup-card {
  background: var(--clr-surface);
  border-radius: 20px;
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 480px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.setup-logo { 
  font-size: 3rem; 
  color: var(--clr-primary); 
  margin-bottom: 1.5rem; 
  line-height: 1; 
}
.setup-logo svg { width: 56px; height: 56px; }
.setup-title { 
  font-size: 2rem; 
  font-weight: 600; 
  margin-bottom: .5rem;
  letter-spacing: -0.028em;
  font-family: 'SF Pro Display', system-ui, -apple-system, sans-serif;
}
.setup-subtitle { color: var(--clr-muted); margin-bottom: 2rem; font-size: 1rem; }
.setup-actions {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-bottom: 1.5rem;
}
.setup-actions .btn { justify-content: center; width: 100%; }
.setup-hint {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  font-size: .8rem;
  color: var(--clr-muted);
  text-align: left;
  background: var(--clr-bg);
  border-radius: var(--radius);
  padding: .75rem;
}
.setup-hint svg { flex-shrink: 0; width: 16px; height: 16px; margin-top: 1px; }

/* ── Login Screen ─────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--clr-surface);
}
.login-card {
  background: var(--clr-surface);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  color: var(--clr-primary);
  margin-bottom: 1rem;
  line-height: 1;
}
.login-logo svg { width: 48px; height: 48px; }
.login-title { 
  font-size: 1.5rem; 
  font-weight: 600; 
  margin-bottom: .25rem;
  font-family: 'SF Pro Display', system-ui, -apple-system, sans-serif;
  letter-spacing: -0.028em;
}
.login-subtitle { color: var(--clr-muted); font-size: 1rem; margin-bottom: 1.5rem; }
.login-error {
  background: #fef2f2; border: 1px solid #fca5a5; color: #b91c1c;
  border-radius: var(--radius); padding: .6rem 1rem; font-size: .85rem;
  margin-bottom: 1rem; text-align: left;
}
body.dark .login-error { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }
.login-form { display: flex; flex-direction: column; gap: 1rem; text-align: left; }
.btn-login { width: 100%; justify-content: center; margin-top: .25rem; }
.pwd-wrap { position: relative; display: flex; align-items: center; }
.pwd-wrap .form-control { flex: 1; padding-right: 2.5rem; }
.pwd-eye {
  position: absolute; right: .5rem;
  background: none; border: none; color: var(--clr-muted);
  padding: .25rem; line-height: 1; border-radius: 4px;
  transition: color var(--transition);
}
.pwd-eye:hover { color: var(--clr-text); }
.pwd-eye svg { width: 17px; height: 17px; }
.login-footer { margin-top: 1.5rem; color: var(--clr-muted); font-size: 0.8rem; }

/* ── App Shell Layout ─────────────────────────────────────── */
#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--clr-tile-dark-1);
  color: var(--clr-sidebar-t);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--transition);
  z-index: 100;
}
/* Desktop-only icon rail: collapsing to 56px must not apply on mobile,
   where the sidebar is an off-canvas drawer that always shows labels. */
@media (min-width: 901px) {
  #sidebar.collapsed { width: 56px; }
  #sidebar.collapsed .nav-lbl,
  #sidebar.collapsed .nav-arr,
  #sidebar.collapsed .app-name,
  #sidebar.collapsed .sidebar-footer span { display: none; }
  #sidebar.collapsed #app-logo { display: none; }
  /* Center the lone icons when collapsed so the rail reads cleanly */
  #sidebar.collapsed .nav-link,
  #sidebar.collapsed .btn-icon-text { justify-content: center; }
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .9rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--header-h);
}
#app-logo { height: 28px; border-radius: 6px; flex-shrink: 0; }
.app-name { 
  font-weight: 600; 
  font-size: 1rem; 
  white-space: nowrap; 
  overflow: hidden; 
  flex: 1;
  font-family: 'SF Pro Display', system-ui, -apple-system, sans-serif;
  letter-spacing: -0.022em;
}
.sidebar-toggle-btn {
  background: none; border: none; color: rgba(255,255,255,.7);
  padding: 4px; border-radius: 6px; line-height: 1;
  margin-left: auto; flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
}
.sidebar-toggle-btn:hover { 
  color: #fff;
  background: rgba(255,255,255,.12);
}
.sidebar-toggle-btn svg { width: 18px; height: 18px; }

.nav-items { flex: 1; overflow-y: auto; padding: .5rem 0; }
.nav-items::-webkit-scrollbar { width: 4px; }
.nav-items::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.nav-item { }
.nav-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem 1rem;
  cursor: pointer;
  border-radius: var(--radius);
  margin: 2px .5rem;
  color: rgba(255,255,255,.7);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
  font-size: 0.95rem;
}
.nav-link:hover { 
  background: rgba(255,255,255,.12); 
  color: #fff; 
}
.nav-item.active > .nav-link { 
  background: var(--clr-primary); 
  color: #fff;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-lbl { flex: 1; font-size: .9rem; font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.nav-arr { width: 14px !important; height: 14px !important; transition: transform var(--transition); margin-left: auto; flex-shrink: 0; }
.nav-item.open > .nav-link .nav-arr { transform: rotate(180deg); }

.nav-kids { overflow: hidden; max-height: 0; transition: max-height var(--transition); }
.nav-item.open > .nav-kids { max-height: 1000px; }
.nav-kids .nav-link { padding-left: 2.2rem; font-size: .85rem; }
.nav-kids .nav-link svg { width: 14px; height: 14px; }
#sidebar.collapsed .nav-kids { display: none; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: .5rem 0;
}
.btn-icon-text {
  display: flex;
  align-items: center;
  gap: .6rem;
  width: 100%;
  background: none;
  border: none;
  color: rgba(255,255,255,.65);
  padding: .6rem 1rem;
  font-size: .85rem;
  border-radius: var(--radius);
  margin: 2px .5rem;
  width: calc(100% - 1rem);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.btn-icon-text:hover { 
  background: rgba(255,255,255,.12); 
  color: #fff; 
}
.btn-icon-text svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Main Wrapper ─────────────────────────────────────────── */
#main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Header ───────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--clr-header);
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 50;
}
.header-left { display: flex; align-items: center; gap: .75rem; }
.header-right { display: flex; align-items: center; gap: .5rem; }
.hamburger {
  background: none; 
  border: none; 
  color: var(--clr-muted); 
  padding: .4rem;
  border-radius: var(--radius);
  display: none;
  transition: background var(--transition);
}
.hamburger:hover {
  background: var(--clr-bg);
}
.hamburger svg { width: 20px; height: 20px; }
.page-title { 
  font-size: 1.1rem; 
  font-weight: 600; 
  white-space: nowrap;
  font-family: 'SF Pro Display', system-ui, -apple-system, sans-serif;
  letter-spacing: -0.022em;
}
.offline-badge {
  display: flex; align-items: center; gap: .3rem;
  background: var(--clr-danger); color: #fff;
  padding: .3rem .75rem; 
  border-radius: var(--radius-pill); 
  font-size: .8rem; 
  font-weight: 600;
}
.offline-badge svg { width: 13px; height: 13px; }
.sync-badge {
  font-size: .8rem; 
  color: var(--clr-muted);
  border-radius: var(--radius-pill); 
  padding: .3rem .75rem;
  border: 1px solid var(--clr-border);
  transition: border-color var(--transition), background var(--transition);
  white-space: nowrap;
}
.sync-badge:hover { 
  border-color: var(--clr-primary);
  background: rgba(0, 102, 204, 0.05);
}
.btn-sheets { 
  background: #188038; 
  color: #fff;
}
.btn-sheets:hover { 
  filter: brightness(1.12); 
}
.sheets-item { color: #188038 !important; font-weight: 600; }

/* ── User Chip ─────────────────────────────────────────────── */
.user-chip {
  display: flex; align-items: center; gap: .5rem;
  padding: .25rem .6rem .25rem .25rem;
  border-radius: 99px;
  border: 1px solid var(--clr-border);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  user-select: none;
}
.user-chip:hover { background: var(--clr-bg); border-color: var(--clr-primary); }
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--clr-primary);
  color: #fff;
  font-weight: 700; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-name { font-size: .8rem; font-weight: 600; white-space: nowrap; }
.user-role-badge {
  font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 1px 6px; border-radius: 99px; white-space: nowrap;
}
.role-admin  { background: #cce5ff; color: #0066cc; }
.role-staff  { background: #d1fae5; color: #065f46; }
.role-viewer { background: #fef3c7; color: #92400e; }
body.dark .role-admin  { background: #1e3a6e; color: #93c5fd; }
body.dark .role-staff  { background: #064e3b; color: #6ee7b7; }
body.dark .role-viewer { background: #451a03; color: #fcd34d; }

/* ── User Dropdown ─────────────────────────────────────────── */
.user-dropdown {
  bottom: auto;
  top: calc(var(--header-h) + 4px);
  left: auto;
  right: 1rem;
  min-width: 220px;
}
.user-menu-header {
  padding: .75rem 1rem;
  font-size: .875rem;
}
.user-menu-header strong { display: block; font-size: .95rem; margin-bottom: .15rem; }
.user-menu-header small { color: var(--clr-muted); }

/* ── Main Content ─────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  background: var(--clr-bg);
}
#content::-webkit-scrollbar { width: 6px; }
#content::-webkit-scrollbar-thumb { background: var(--clr-border); border-radius: 3px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
}
.page-header h2 { 
  font-size: 1.35rem; 
  font-weight: 600;
  font-family: 'SF Pro Display', system-ui, -apple-system, sans-serif;
  letter-spacing: -0.022em;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.2rem;
  border-radius: var(--radius-pill);
  border: none;
  font-weight: 400;
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--transition), transform .1s, box-shadow var(--transition);
  white-space: nowrap;
  text-decoration: none;
  font-family: 'SF Pro Text', system-ui, -apple-system, sans-serif;
}
.btn:active { transform: scale(0.95); }
.btn svg { width: 15px; height: 15px; }

.btn-primary  { 
  background: var(--clr-primary); 
  color: #fff;
}
.btn-accent   { 
  background: var(--clr-accent);  
  color: #fff; 
}
.btn-secondary{ 
  background: transparent;
  color: var(--clr-primary);
  border: 1px solid var(--clr-primary);
}
.btn-danger   { 
  background: var(--clr-danger);  
  color: #fff; 
}

.btn-primary:hover  { 
  background: var(--clr-primary-focus);
  box-shadow: var(--shadow-md);
}
.btn-accent:hover   { 
  filter: brightness(1.1);
}
.btn-secondary:hover{ 
  background: rgba(0, 102, 204, 0.05);
}
.btn-danger:hover   { 
  filter: brightness(1.1);
}

.btn:focus {
  outline: 2px solid var(--clr-primary-focus);
  outline-offset: 2px;
}

.btn-lg { 
  padding: .7rem 1.8rem; 
  font-size: 1.125rem;
}
.btn-sm { 
  padding: .35rem .9rem; 
  font-size: .875rem; 
}

.btn-icon {
  background: none; 
  border: none; 
  color: var(--clr-primary);
  padding: .4rem; 
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  display: inline-flex; 
  align-items: center;
}
.btn-icon:hover { 
  background: var(--clr-bg);
  color: var(--clr-primary-focus);
}
.btn-icon svg { width: 17px; height: 17px; }
.btn-icon-danger { color: var(--clr-danger); }
.btn-icon-danger:hover { 
  background: rgba(255, 59, 48, 0.1);
  color: var(--clr-danger);
}

/* ── Forms ────────────────────────────────────────────────── */
.app-form { display: flex; flex-direction: column; gap: 1.5rem; }

.form-section {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--clr-border);
}
.section-title {
  font-size: .9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--clr-muted);
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--clr-border);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.form-field { display: flex; flex-direction: column; gap: .35rem; }
.form-field.width-full  { grid-column: 1 / -1; }
.form-field.width-half  { grid-column: span 1; }
.form-field.width-third { grid-column: span 1; }

.form-label {
  font-size: .9rem;
  font-weight: 500;
  color: var(--clr-text);
}
.form-label.required::after { content: ' *'; color: var(--clr-danger); }

.form-control {
  background: var(--clr-input-bg);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: .6rem .85rem;
  color: var(--clr-text);
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
  font-size: 1rem;
}
.form-control:focus {
  outline: none;
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}
.form-control.readonly { 
  background: var(--clr-bg); 
  color: var(--clr-muted); 
  cursor: not-allowed; 
}
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { cursor: pointer; }

.has-error .form-control,
.has-error .multiselect-wrap,
.has-error .radio-group { border-color: var(--clr-danger) !important; }
.has-error .form-control:focus { box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.1) !important; }

.field-error { font-size: .85rem; color: var(--clr-danger); display: none; }
.field-help  { font-size: .85rem; color: var(--clr-muted); }

.autogen-display {
  background: var(--clr-bg); 
  border-radius: var(--radius);
  padding: .6rem .85rem; 
  font-family: 'Fira Mono', monospace; 
  font-size: .9rem;
  border: 1px solid var(--clr-border); 
  color: var(--clr-primary); 
  font-weight: 500;
}
.autogen-display em.muted { color: var(--clr-muted); font-style: italic; font-weight: normal; }

/* ── Computed fields (E1) ─────────────────────────────────── */
.computed-display {
  background: var(--clr-bg); border-radius: var(--radius);
  padding: .5rem .75rem; font-variant-numeric: tabular-nums; font-size: .9rem;
  border: 1px solid var(--clr-border); color: var(--clr-text); font-weight: 600;
  text-align: right; min-height: 2.25rem;
}

/* ── Line-item grid field (E2) ────────────────────────────── */
.grid-field { grid-column: 1 / -1; }
.grid-scroll { overflow-x: auto; border: 1px solid var(--clr-border); border-radius: var(--radius); }
.grid-table { width: 100%; border-collapse: collapse; font-size: .85rem; min-width: 520px; }
.grid-table th, .grid-table td {
  padding: .35rem .5rem; border-bottom: 1px solid var(--clr-border); text-align: left; vertical-align: middle;
}
.grid-table thead th {
  background: var(--clr-bg); font-weight: 600; color: var(--clr-muted);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.grid-table th.num, .grid-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid-table th.grid-actions, .grid-table td.grid-actions { width: 34px; text-align: center; }
.grid-table .req { color: var(--clr-danger); }
.grid-table tfoot td { background: var(--clr-bg); border-top: 2px solid var(--clr-border); border-bottom: none; }
.grid-input {
  width: 100%; min-width: 70px; box-sizing: border-box;
  padding: .3rem .4rem; border: 1px solid var(--clr-border); border-radius: 5px;
  background: var(--clr-input-bg); color: var(--clr-text); font-size: .85rem;
}
.grid-input.num { text-align: right; }
.grid-input:focus { outline: none; border-color: var(--clr-primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--clr-primary) 18%, transparent); }
.grid-comp { font-variant-numeric: tabular-nums; font-weight: 600; }
.grid-empty { color: var(--clr-muted); text-align: center; font-style: italic; padding: .75rem; }
.grid-add { margin-top: .6rem; }

/* numeric / status emphasis reused by reports */
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .danger, .num.danger { color: var(--clr-danger); }
.data-table .positive, .num.positive { color: var(--clr-accent); }
.pl-table .pl-head th { background: var(--clr-bg); text-transform: uppercase; font-size: .72rem; letter-spacing: .03em; }
.pl-table .pl-subtotal td { border-top: 1px solid var(--clr-border); }
.pl-table .pl-net td { border-top: 2px solid var(--clr-border); font-size: 1rem; }
.report-note { margin: .85rem .25rem 0; font-size: .82rem; color: var(--clr-muted); }

.multiselect-wrap {
  display: flex; flex-wrap: wrap; gap: .4rem;
  border: 1px solid var(--clr-border); border-radius: var(--radius);
  padding: .5rem; background: var(--clr-input-bg);
}
.checkbox-option, .radio-option {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .9rem; cursor: pointer;
  background: var(--clr-bg); border-radius: var(--radius-pill); padding: .35rem .85rem;
  border: 1px solid var(--clr-border); transition: all var(--transition);
}
.checkbox-option:hover, .radio-option:hover { 
  border-color: var(--clr-primary);
  background: rgba(0, 102, 204, 0.05);
}
.checkbox-option input:checked + *, .radio-option input:checked + * { 
  color: var(--clr-primary); 
  font-weight: 500;
}
.checkbox-option input[type="checkbox"],
.radio-option input[type="radio"] {
  accent-color: var(--clr-primary);
}
.checkbox-single { display: flex; align-items: center; gap: .5rem; cursor: pointer; }
.radio-group { display: flex; flex-wrap: wrap; gap: .5rem; }
.file-current { font-size: .8rem; color: var(--clr-muted); margin-top: .25rem; }

.form-actions {
  display: flex;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--clr-border);
  box-shadow: var(--shadow);
}

/* ── List View ────────────────────────────────────────────── */
.list-container { display: flex; flex-direction: column; gap: 1rem; }

.filter-bar {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: .85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  box-shadow: var(--shadow);
}
.filter-input {
  background: var(--clr-input-bg);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-pill);
  padding: .4rem .85rem;
  font-size: .95rem;
  color: var(--clr-text);
  min-width: 160px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.filter-input:focus { 
  outline: none; 
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}
.filter-sm { min-width: 120px; }
.filter-actions { display: flex; gap: .75rem; margin-left: auto; align-items: center; }

/* Per-page export dropdown in list view */
.export-drop-wrap { position: relative; }
.export-drop-menu {
  position: absolute; right: 0; top: calc(100% + 4px);
  background: var(--clr-surface); border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  min-width: 220px; z-index: 200; padding: .3rem 0;
  animation: fadeIn .12s ease;
}
.edm-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .45rem 1rem; font-size: .85rem; cursor: pointer;
  color: var(--clr-text); transition: background var(--transition);
}
.edm-item:hover { background: var(--clr-bg); }
.edm-item.muted  { color: var(--clr-muted); }
.edm-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.edm-divider { border-top: 1px solid var(--clr-border); margin: .3rem 0; }

.bulk-bar {
  background: #eff6ff;
  border: 1px solid var(--clr-primary);
  border-radius: var(--radius);
  padding: .5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: .875rem;
  color: var(--clr-primary);
  font-weight: 600;
}
body.dark .bulk-bar { background: #1e3a5f; }

.table-wrap { 
  background: var(--clr-surface); 
  border-radius: var(--radius-lg); 
  overflow: auto; 
  box-shadow: var(--shadow-md); 
  border: 1px solid var(--clr-border); 
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
  white-space: nowrap;
}
.data-table thead { position: sticky; top: 0; z-index: 5; }
.data-table th {
  background: var(--clr-bg);
  padding: .7rem 1rem;
  text-align: left;
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--clr-muted);
  border-bottom: 1px solid var(--clr-border);
  white-space: nowrap;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--clr-primary); }
.data-table th svg { width: 12px; height: 12px; vertical-align: middle; margin-left: 4px; }

.data-table td {
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--clr-border);
  color: var(--clr-text);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--clr-bg); }
.data-table tfoot th {
  background: var(--clr-bg);
  border-top: 2px solid var(--clr-border);
  color: var(--clr-text);
}

.col-check { width: 36px; }
.col-actions { width: 110px; text-align: center; }
.actions-cell { text-align: center; }
.empty-row { text-align: center; color: var(--clr-muted); padding: 2.5rem 1rem !important; }
.empty-row svg { width: 28px; height: 28px; display: block; margin: 0 auto .5rem; opacity: .4; }

.pagination {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: .75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.pg-info { font-size: .9rem; color: var(--clr-muted); }
.pg-controls { display: flex; gap: .35rem; }
.page-btn {
  background: var(--clr-bg); 
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: .35rem .65rem; 
  font-size: .9rem;
  cursor: pointer; 
  color: var(--clr-text); 
  min-width: 36px; 
  text-align: center;
  transition: all var(--transition);
  display: inline-flex; 
  align-items: center; 
  justify-content: center;
}
.page-btn:hover:not(:disabled) { 
  background: var(--clr-primary); 
  color: #fff; 
  border-color: var(--clr-primary);
}
.page-btn.active { 
  background: var(--clr-primary); 
  color: #fff; 
  border-color: var(--clr-primary);
}
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-btn svg { width: 15px; height: 15px; }

/* ── View Record Modal ────────────────────────────────────── */
.view-record { display: flex; flex-direction: column; gap: 1.25rem; }
.modal-title { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.modal-title svg { width: 18px; height: 18px; color: var(--clr-primary); }
.view-section h4 { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--clr-muted); margin-bottom: .6rem; }
.view-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.view-field { background: var(--clr-bg); border-radius: var(--radius); padding: .5rem .75rem; }
.vf-label { font-size: .75rem; color: var(--clr-muted); display: block; }
.vf-value { font-size: .9rem; font-weight: 500; word-break: break-all; }
.view-meta { display: flex; gap: 1.5rem; font-size: .78rem; color: var(--clr-muted); }
.view-meta svg { width: 12px; height: 12px; vertical-align: middle; }
.modal-actions { display: flex; gap: .75rem; padding-top: .5rem; border-top: 1px solid var(--clr-border); }

/* ── Modal ────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.3);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem; backdrop-filter: blur(4px);
}
#modal-overlay.active { display: flex; }
#modal-box {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 10px 40px rgba(0,0,0,.15);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-close-btn {
  position: absolute; top: 1.5rem; right: 1.5rem;
  background: var(--clr-bg); border: none; border-radius: var(--radius);
  padding: .4rem; cursor: pointer; color: var(--clr-muted);
  transition: background var(--transition), color var(--transition);
}
.modal-close-btn:hover { 
  background: var(--clr-border);
  color: var(--clr-text);
}
.modal-close-btn svg { width: 20px; height: 20px; display: block; }

/* ── Reports ──────────────────────────────────────────────── */
.report-wrap { display: flex; flex-direction: column; gap: 1rem; }
.report-toolbar {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: .75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  box-shadow: var(--shadow);
}
.report-filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; flex: 1; }
.report-exports { display: flex; gap: .5rem; margin-left: auto; }

.report-tabs { display: flex; gap: .25rem; }
.tab-btn {
  background: var(--clr-bg); border: 1px solid var(--clr-border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: .4rem 1.1rem; font-size: .875rem; cursor: pointer;
  color: var(--clr-muted); font-weight: 600; transition: all var(--transition);
}
.tab-btn.active { background: var(--clr-surface); border-bottom-color: var(--clr-surface); color: var(--clr-primary); }
.tab-panel { display: none; background: var(--clr-surface); border: 1px solid var(--clr-border); border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow); }
.tab-panel.active { display: block; }
.chart-wrap { height: 360px; position: relative; }

/* ── Summary Cards ────────────────────────────────────────── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.sc {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--clr-border);
  border-left: 4px solid var(--clr-border);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.sc-primary { border-left-color: var(--clr-primary); }
.sc-success  { border-left-color: var(--clr-accent); }
.sc-warning  { border-left-color: var(--clr-warning); }
.sc-icon { 
  color: var(--clr-muted); 
  margin-bottom: .3rem;
}
.sc-icon svg { width: 24px; height: 24px; }
.sc-val { 
  font-size: 1.75rem; 
  font-weight: 600; 
  color: var(--clr-text); 
  line-height: 1.1;
  font-family: 'SF Pro Display', system-ui, -apple-system, sans-serif;
  letter-spacing: -0.022em;
}
.sc-lbl { 
  font-size: .85rem; 
  color: var(--clr-muted); 
  font-weight: 400;
  text-transform: uppercase; 
  letter-spacing: .05em;
}

/* ── Dashboard ────────────────────────────────────────────── */
.dashboard { display: flex; flex-direction: column; gap: 2rem; }
.quick-access h3 { 
  font-size: .95rem; 
  font-weight: 600; 
  text-transform: uppercase; 
  letter-spacing: .06em; 
  color: var(--clr-muted); 
  margin-bottom: 1rem;
}
.quick-cards { 
  display: grid; 
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); 
  gap: 1rem; 
}
.qc {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.25rem;
  cursor: pointer;
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  gap: .75rem;
  font-size: .95rem; 
  font-weight: 500; 
  text-align: center;
  color: var(--clr-text); 
  transition: all var(--transition);
  box-shadow: var(--shadow);
}
.qc:hover { 
  border-color: var(--clr-primary); 
  color: var(--clr-primary); 
  transform: translateY(-2px); 
  box-shadow: var(--shadow-lg);
}
.qc svg { width: 28px; height: 28px; }

/* ── Workflow ─────────────────────────────────────────────── */
.workflow-wrap { display: flex; flex-direction: column; gap: 1.5rem; }
.stepper {
  display: flex;
  align-items: center;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.step-item {
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  flex-shrink: 0; min-width: 80px;
}
.step-dot {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--clr-border); background: var(--clr-bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem; color: var(--clr-muted);
  transition: all var(--transition);
}
.step-item.active .step-dot { border-color: var(--clr-primary); background: var(--clr-primary); color: #fff; }
.step-item.done .step-dot { border-color: var(--clr-accent); background: var(--clr-accent); color: #fff; }
.step-item.done .step-dot svg { width: 16px; height: 16px; }
.step-name { font-size: .75rem; color: var(--clr-muted); text-align: center; }
.step-item.active .step-name { color: var(--clr-primary); font-weight: 600; }
.step-line { flex: 1; height: 2px; background: var(--clr-border); margin: 0 .5rem; align-self: flex-start; margin-top: 15px; min-width: 32px; }
.wf-content { background: var(--clr-surface); border-radius: var(--radius-lg); padding: 1.5rem; border: 1px solid var(--clr-border); box-shadow: var(--shadow); }
.wf-step-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--clr-primary); }
.wf-nav { display: flex; align-items: center; justify-content: space-between; background: var(--clr-surface); border-radius: var(--radius-lg); padding: 1rem 1.5rem; border: 1px solid var(--clr-border); box-shadow: var(--shadow); }

/* ── Pivot Table ──────────────────────────────────────────── */
.pivot-tbl thead th { background: var(--clr-primary); color: #fff; }

/* ── Toast ────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: .75rem;
  z-index: 2000; max-width: 380px; width: 100%;
}
.toast {
  display: flex; align-items: center; gap: .75rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  background: #1d1d1f; 
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  font-size: .95rem;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }
.toast span { flex: 1; }
.toast-x { 
  background: none; 
  border: none; 
  color: rgba(255,255,255,.7); 
  cursor: pointer; 
  font-size: 1.2rem; 
  line-height: 1; 
  padding: 0;
  transition: color var(--transition);
}
.toast-x:hover { color: #fff; }
.toast-success { background: #34c759; }
.toast-error   { background: #ff3b30; }
.toast-warning { background: #ff9500; }
.toast-info    { background: #0066cc; }

/* ── Dropdown Menu ────────────────────────────────────────── */
.dropdown-menu {
  position: fixed;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 500;
  padding: .4rem 0;
  bottom: 70px;
  left: 10px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.dropdown-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 1rem; font-size: .875rem; cursor: pointer;
  color: var(--clr-text); transition: background var(--transition);
}
.dropdown-item:hover { background: var(--clr-bg); }
.dropdown-item.danger { color: var(--clr-danger); }
.dropdown-item svg { width: 15px; height: 15px; }
.dropdown-divider { border-top: 1px solid var(--clr-border); margin: .3rem 0; }

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 4rem 2rem; color: var(--clr-muted); text-align: center; gap: .75rem;
}
.empty-state svg { width: 40px; height: 40px; opacity: .4; }

/* ── Loading Spinner ──────────────────────────────────────── */
.loading-spinner {
  display: flex; flex-direction: column; align-items: center; gap: .75rem;
  padding: 4rem; color: var(--clr-muted);
}
.loading-spinner svg { width: 32px; height: 32px; }
.spin { animation: spin 1s linear infinite; display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Misc helpers ─────────────────────────────────────────── */
.muted { color: var(--clr-muted); }
.text-sm { font-size: .85rem; }

/* ── User Management Page ─────────────────────────────────── */
.user-mgmt { display: flex; flex-direction: column; gap: 1.25rem; }
.um-toolbar {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .75rem 1rem;
  background: var(--clr-surface); border-radius: var(--radius);
  border: 1px solid var(--clr-border);
}
.um-toolbar input[type=text] { flex: 1; min-width: 200px; }
.um-table-wrap { background: var(--clr-surface); border-radius: var(--radius); border: 1px solid var(--clr-border); overflow: auto; }
.um-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.um-table th {
  background: var(--clr-bg); font-weight: 600; text-align: left;
  padding: .6rem .9rem; border-bottom: 1px solid var(--clr-border);
  white-space: nowrap; color: var(--clr-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
}
.um-table td { padding: .55rem .9rem; border-bottom: 1px solid var(--clr-border); vertical-align: middle; }
.um-table tr:last-child td { border-bottom: none; }
.um-table tr:hover td { background: var(--clr-bg); }
.um-actions { display: flex; gap: .4rem; }
.status-chip {
  display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600;
}
.status-active   { background: #d1fae5; color: #065f46; }
.status-inactive { background: #fee2e2; color: #991b1b; }
body.dark .status-active   { background: #064e3b; color: #6ee7b7; }
body.dark .status-inactive { background: #450a0a; color: #fca5a5; }
.um-empty { padding: 2.5rem; text-align: center; color: var(--clr-muted); }

/* ── Hash Tool ─────────────────────────────────────────────── */
.hash-tool { display: flex; flex-direction: column; gap: .75rem; }
.hash-result {
  font-family: monospace; font-size: .8rem; word-break: break-all;
  padding: .6rem .8rem; background: var(--clr-bg); border-radius: var(--radius);
  border: 1px solid var(--clr-border); color: var(--clr-text);
  user-select: all;
}

/* ── Permission Checkboxes Grid (role dialog) ──────────────── */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .4rem .75rem;
  margin-top: .5rem;
  padding: .75rem;
  background: var(--clr-bg);
  border-radius: var(--radius);
  border: 1px solid var(--clr-border);
}
.perm-item {
  display: flex; align-items: center; gap: .5rem;
  font-size: .875rem; cursor: pointer; padding: .25rem .3rem;
  border-radius: 4px; transition: background var(--transition);
}
.perm-item:hover { background: var(--clr-border); }
.perm-item input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--clr-primary); cursor: pointer; flex-shrink: 0; }
@media (max-width: 520px) { .perm-grid { grid-template-columns: 1fr; } }

/* ── Mobile sidebar drawer backdrop ───────────────────────── */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 1050;
  animation: fadeIn .15s ease;
}
/* Only ever visible while the drawer pattern is active (≤900px) */
@media (max-width: 900px) {
  #sidebar-backdrop.show { display: block; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  /* The sidebar becomes an off-canvas drawer that slides in over the
     content (with labels + icons), instead of a permanently-shrunk rail
     the hamburger could never expand. */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w) !important;   /* full width — labels visible */
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-product);
    z-index: 1100;
  }
  #sidebar.mobile-open { transform: translateX(0); }
  /* Inside the drawer, the toggle button collapses it (closes the drawer) */
  .sidebar-toggle-btn svg { transform: none; }

  .hamburger { display: inline-flex; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.width-half, .form-field.width-third { grid-column: 1 / -1; }
  .view-grid { grid-template-columns: 1fr; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }

  /* Keep the account chip on-screen: let the title shrink, not the chip */
  .header-left { min-width: 0; flex: 1; }
  .page-title { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .header-right { flex-shrink: 0; }
}

@media (max-width: 640px) {
  #content { padding: .75rem; }
  #header { padding: 0 .75rem; gap: .5rem; }
  .header-right .btn span { display: none; }
  /* Compact account chip — show just the avatar + caret so Sign Out stays reachable */
  .user-chip { padding: .2rem; gap: .25rem; }
  .user-info { display: none; }
  .pagination { flex-direction: column; gap: .5rem; align-items: flex-start; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-input { min-width: unset; width: 100%; }
  .filter-actions { justify-content: flex-end; }
  .page-header { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .modal-actions { flex-wrap: wrap; }
}

/* ── Print ────────────────────────────────────────────────── */
@media print {
  #sidebar, #header, #toast-container, #modal-overlay,
  .form-actions, .filter-bar, .pagination, .bulk-bar,
  .report-toolbar, .report-tabs { display: none !important; }
  #content { padding: 0; overflow: visible; }
  #main-wrapper { overflow: visible; }
  #app-shell { display: block; height: auto; }
  .data-table { border: 1px solid #ccc; }
  .data-table th, .data-table td { border: 1px solid #ccc; padding: 4px 8px; }
}
