@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============================================
   DESIGN TOKENS
============================================ */
:root, [data-theme="light"] {
  --primary: hsl(248, 75%, 52%);
  --primary-light: hsl(248, 75%, 62%);
  --primary-dark: hsl(248, 75%, 42%);
  --primary-glow: hsla(248, 75%, 52%, 0.18);
  --secondary: hsl(210, 85%, 50%);
  --secondary-glow: hsla(210, 85%, 50%, 0.18);
  --accent: hsl(168, 75%, 38%);

  /* Light Theme Backgrounds */
  --bg-base: hsl(210, 25%, 95%);          /* Clean slate grey #f1f5f9 */
  --bg-surface: hsl(0, 0%, 100%);         /* Pure white #ffffff for top header / sidebar */
  --bg-card: hsl(0, 0%, 100%);            /* Pure white #ffffff for cards and popup forms */
  --bg-card-hover: hsl(210, 20%, 98%);
  --bg-elevated: hsl(210, 25%, 93%);
  --bg-input: hsl(0, 0%, 100%);           /* Pure white inputs */
  --bg-hover: hsl(210, 20%, 93%);

  /* Light Theme Borders */
  --border: hsl(215, 20%, 82%);           /* Soft border #cbd5e1 */
  --border-focus: var(--primary);
  --border-light: hsl(214, 20%, 90%);     /* Gentle divider #e2e8f0 */

  /* Light Theme Typography */
  --text-primary: hsl(222, 47%, 11%);     /* High contrast dark slate #0f172a */
  --text-secondary: hsl(215, 25%, 32%);   /* Readable grey #334155 */
  --text-muted: hsl(215, 16%, 47%);       /* Muted grey #64748b */
  --text-disabled: hsl(215, 14%, 65%);

  --success: hsl(145, 75%, 33%);
  --success-bg: hsla(145, 75%, 33%, 0.1);
  --warning: hsl(38, 92%, 45%);
  --warning-bg: hsla(38, 92%, 45%, 0.12);
  --danger: hsl(0, 75%, 52%);
  --danger-bg: hsla(0, 75%, 52%, 0.1);
  --info: hsl(200, 85%, 42%);
  --info-bg: hsla(200, 85%, 42%, 0.1);

  --sidebar-w: 260px;
  --sidebar-collapsed: 70px;
  --header-h: 62px;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 4px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.15);
  --shadow-glow: 0 0 20px var(--primary-glow);

  --transition: 0.2s ease;
  --transition-slow: 0.35s ease;

  --glass: rgba(255,255,255,0.7);
  --glass-border: rgba(15,23,42,0.08);
}

[data-theme="dark"] {
  --primary: hsl(250, 80%, 62%);
  --primary-light: hsl(250, 80%, 72%);
  --primary-dark: hsl(250, 80%, 50%);
  --primary-glow: hsla(250, 80%, 62%, 0.3);
  --secondary: hsl(210, 90%, 58%);
  --secondary-glow: hsla(210, 90%, 58%, 0.3);
  --accent: hsl(170, 70%, 50%);

  --bg-base: hsl(222, 35%, 7%);
  --bg-surface: hsl(222, 28%, 11%);
  --bg-card: hsl(222, 25%, 14%);
  --bg-card-hover: hsl(222, 25%, 17%);
  --bg-elevated: hsl(222, 22%, 19%);
  --bg-input: hsl(222, 25%, 10%);
  --bg-hover: hsl(222, 25%, 19%);

  --border: hsl(222, 20%, 22%);
  --border-focus: var(--primary);
  --border-light: hsl(222, 18%, 28%);

  --text-primary: hsl(220, 15%, 95%);
  --text-secondary: hsl(220, 12%, 72%);
  --text-muted: hsl(220, 10%, 48%);
  --text-disabled: hsl(220, 8%, 35%);

  --success: hsl(145, 65%, 50%);
  --success-bg: hsla(145, 65%, 50%, 0.12);
  --warning: hsl(38, 92%, 58%);
  --warning-bg: hsla(38, 92%, 58%, 0.12);
  --danger: hsl(0, 72%, 62%);
  --danger-bg: hsla(0, 72%, 62%, 0.12);
  --info: hsl(200, 80%, 58%);
  --info-bg: hsla(200, 80%, 58%, 0.12);

  --shadow-sm: 0 1px 4px rgba(0,0,0,0.3);
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px var(--primary-glow);

  --glass: rgba(255,255,255,0.04);
  --glass-border: rgba(255,255,255,0.08);
}

/* ============================================
   RESET & BASE
============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

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

img { max-width: 100%; }

input, select, textarea, button { font-family: inherit; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ============================================
   TYPOGRAPHY
============================================ */
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 1.2rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }
h5 { font-size: 0.9rem; font-weight: 600; }
h6 { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-info { color: var(--info); }
.text-accent { color: var(--accent); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.85rem; }
.text-lg { font-size: 1.1rem; }
.text-xl { font-size: 1.3rem; }
.text-2xl { font-size: 1.6rem; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }

/* ============================================
   LAYOUT
============================================ */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition-slow);
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-logo {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-logo .logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 800; color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-glow);
}

.sidebar-logo .logo-text {
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-logo .logo-text .brand { font-size: 1.1rem; font-weight: 800; color: var(--text-primary); }
.sidebar-logo .logo-text .tagline { font-size: 0.7rem; color: var(--text-muted); margin-top: -2px; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.nav-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 18px 4px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition);
}

.sidebar.collapsed .nav-section-title { opacity: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  color: var(--text-secondary);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  border-left: 3px solid transparent;
  margin: 1px 0;
  user-select: none;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(90deg, hsla(250,80%,62%,0.18), transparent);
  color: var(--primary-light);
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-item .nav-icon {
  font-size: 1.05rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item .nav-label { overflow: hidden; transition: opacity var(--transition); }
.sidebar.collapsed .nav-item .nav-label { opacity: 0; width: 0; }

.nav-item .nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  flex-shrink: 0;
}

.sidebar.collapsed .nav-badge { display: none; }

/* Sub-menu */
.nav-submenu { display: none; }
.nav-submenu.open { display: block; }
.nav-submenu .nav-item { padding-left: 52px; font-size: 0.9rem; }
.sidebar.collapsed .nav-submenu { display: none; }

.nav-arrow {
  margin-left: auto;
  font-size: 0.75rem;
  transition: transform var(--transition);
  flex-shrink: 0;
}
.nav-item.has-sub.open .nav-arrow { transform: rotate(90deg); }
.sidebar.collapsed .nav-arrow { display: none; }

/* Sidebar Footer */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px;
  flex-shrink: 0;
}

/* MAIN CONTENT */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

/* HEADER */
.app-header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 99;
}

.header-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
  line-height: 1;
  transition: color var(--transition), background var(--transition);
}

.header-toggle:hover { color: var(--text-primary); background: var(--bg-card); }

.header-breadcrumb {
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-breadcrumb .current { color: var(--text-primary); font-weight: 600; }

.header-spacer { flex: 1; }

.company-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  transition: border-color var(--transition);
  font-size: 0.85rem;
}

.company-switcher:hover { border-color: var(--primary); }
.company-switcher .company-name { font-weight: 600; color: var(--text-primary); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-switcher .fy-label { color: var(--text-muted); font-size: 0.75rem; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.header-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  transition: color var(--transition), background var(--transition);
  position: relative;
}

.header-btn:hover { color: var(--text-primary); background: var(--bg-card); }

.notification-dot {
  position: absolute;
  top: 4px; right: 4px;
  width: 7px; height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

.user-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

/* PAGE CONTENT */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* PAGE HEADER */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title { font-size: 1.4rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }

.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ============================================
   CARDS
============================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.card-body { padding: 20px; }
.card-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

/* KPI Cards */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  cursor: default;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.kpi-card.kpi-blue::before { background: linear-gradient(90deg, var(--secondary), var(--primary)); }
.kpi-card.kpi-green::before { background: linear-gradient(90deg, var(--success), var(--accent)); }
.kpi-card.kpi-orange::before { background: linear-gradient(90deg, var(--warning), hsl(20, 90%, 58%)); }
.kpi-card.kpi-red::before { background: linear-gradient(90deg, var(--danger), hsl(330, 70%, 60%)); }
.kpi-card.kpi-purple::before { background: linear-gradient(90deg, var(--primary), var(--primary-light)); }
.kpi-card.kpi-teal::before { background: linear-gradient(90deg, var(--accent), var(--secondary)); }

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-light);
}

.kpi-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 14px;
}

.kpi-blue .kpi-icon { background: var(--info-bg); color: var(--info); }
.kpi-green .kpi-icon { background: var(--success-bg); color: var(--success); }
.kpi-orange .kpi-icon { background: var(--warning-bg); color: var(--warning); }
.kpi-red .kpi-icon { background: var(--danger-bg); color: var(--danger); }
.kpi-purple .kpi-icon { background: var(--primary-glow); color: var(--primary-light); }
.kpi-teal .kpi-icon { background: hsla(170,70%,50%,0.12); color: var(--accent); }

.kpi-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; margin-bottom: 6px; }
.kpi-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.kpi-change { font-size: 0.75rem; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.kpi-change.up { color: var(--success); }
.kpi-change.down { color: var(--danger); }

/* ============================================
   GRID
============================================ */
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); gap: 20px; }
.grid-5 { grid-template-columns: repeat(5, 1fr); gap: 16px; }
.grid-6 { grid-template-columns: repeat(6, 1fr); gap: 16px; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }

/* ============================================
   FORMS
============================================ */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-control::placeholder { color: var(--text-muted); }

.form-control:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

textarea.form-control { min-height: 80px; resize: vertical; }
select.form-control { cursor: pointer; }
select.form-control option { background: var(--bg-card); color: var(--text-primary); }

.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 0.75rem; color: var(--danger); margin-top: 4px; }

.form-row { display: grid; gap: 14px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: repeat(4, 1fr); }
.form-row.cols-5 { grid-template-columns: repeat(5, 1fr); }
.form-row.cols-6 { grid-template-columns: repeat(6, 1fr); }

/* Compact mode for fast billing & high data density */
.form-row.compact { gap: 10px; }
.form-row.compact .form-group { margin-bottom: 0; }
.form-row.compact .form-label { margin-bottom: 4px; font-size: 0.8rem; font-weight: 600; }
.form-row.compact .form-control { padding: 6px 10px; font-size: 0.88rem; min-height: 36px; height: 36px; }
.form-row.compact select.form-control { padding-right: 24px; }

/* Input Group */
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); flex: 1; }
.input-group .input-addon {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: none;
  padding: 9px 12px;
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex; align-items: center;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  white-space: nowrap;
}

/* Checkbox & Radio */
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox], .form-check input[type=radio] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.form-check-label { font-size: 0.9rem; color: var(--text-secondary); cursor: pointer; }

/* Switch */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.switch input { display: none; }
.switch-track {
  width: 40px; height: 22px;
  background: var(--border-light);
  border-radius: 11px;
  position: relative;
  transition: background var(--transition);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch-track::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform var(--transition);
}
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch-label { font-size: 0.9rem; color: var(--text-secondary); }

/* ============================================
   BUTTONS
============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  outline: none;
  font-family: inherit;
  letter-spacing: 0.01em;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: 0 4px 16px var(--primary-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-light);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); border-color: var(--border-focus); }

.btn-success {
  background: linear-gradient(135deg, var(--success), hsl(145,65%,40%));
  color: #fff;
  box-shadow: 0 2px 8px hsla(145,65%,50%,0.3);
}
.btn-success:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }

.btn-danger {
  background: linear-gradient(135deg, var(--danger), hsl(0,72%,52%));
  color: #fff;
  box-shadow: 0 2px 8px hsla(0,72%,62%,0.3);
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }

.btn-warning {
  background: linear-gradient(135deg, var(--warning), hsl(38,92%,48%));
  color: #000;
  box-shadow: 0 2px 8px hsla(38,92%,58%,0.3);
}
.btn-warning:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--primary-light);
  border-color: var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-glow); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-card); color: var(--text-primary); }

.btn-icon {
  padding: 8px;
  aspect-ratio: 1;
}

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 11px 24px; font-size: 0.95rem; }
.btn-full { width: 100%; }

/* ============================================
   TABLES
============================================ */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead { background: var(--bg-elevated); }
/* Long lists: the table scrolls inside its box and the column names stay on top */
.table-wrapper.sticky-wrap { max-height: calc(100vh - 230px); overflow: auto; }
.data-table.sticky-head thead th { position: sticky; top: 0; z-index: 3; background: var(--bg-elevated); box-shadow: inset 0 -1px 0 var(--border); }
.data-table th {
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

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

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

.data-table tbody tr:hover td {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.data-table .td-number { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-primary); }
.data-table .td-center { text-align: center; }
.data-table .td-actions { white-space: nowrap; text-align: right; }

/* ============================================
   BADGES / TAGS
============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-success { background: var(--success-bg); color: var(--success); border: 1px solid hsla(145,65%,50%,0.25); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid hsla(38,92%,58%,0.25); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid hsla(0,72%,62%,0.25); }
.badge-info { background: var(--info-bg); color: var(--info); border: 1px solid hsla(200,80%,58%,0.25); }
.badge-primary { background: var(--primary-glow); color: var(--primary-light); border: 1px solid hsla(250,80%,62%,0.25); }
.badge-muted { background: var(--bg-elevated); color: var(--text-muted); border: 1px solid var(--border); }

/* ============================================
   MODAL
============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

#confirm-overlay {
  z-index: 9999999 !important;
}

#quick-master-modal {
  z-index: 10000000 !important;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95) translateY(20px);
  transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: scale(1) translateY(0); }

.modal-sm { max-width: 440px; }
.modal-lg { max-width: 1000px; }
.modal-xl { max-width: 1200px; }

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 1.3rem; line-height: 1;
  padding: 4px; border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-elevated); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ============================================
   TABS
============================================ */
.tabs { display: flex; flex-direction: column; }

.tab-list {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 10px 18px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: inherit;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--primary-light); border-bottom-color: var(--primary); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ============================================
   ALERT / TOAST
============================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.alert-success { background: var(--success-bg); border: 1px solid hsla(145,65%,50%,0.25); color: var(--success); }
.alert-warning { background: var(--warning-bg); border: 1px solid hsla(38,92%,58%,0.25); color: var(--warning); }
.alert-danger { background: var(--danger-bg); border: 1px solid hsla(0,72%,62%,0.25); color: var(--danger); }
.alert-info { background: var(--info-bg); border: 1px solid hsla(200,80%,58%,0.25); color: var(--info); }

#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2147483000; /* always above modals (.modal-overlay is 999999+) */
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 260px;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.875rem;
  animation: slideInRight 0.3s ease;
  border-left: 4px solid var(--primary);
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info { border-left-color: var(--info); }

.toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.toast-msg { flex: 1; color: var(--text-primary); font-weight: 500; }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; padding: 2px; }

@keyframes slideInRight {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateX(40px); }
}

/* ============================================
   MISC UTILITIES
============================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-20 { gap: 20px; }
.gap-24 { gap: 24px; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }

.p-0 { padding: 0; }
.p-8 { padding: 8px; }
.p-16 { padding: 16px; }
.p-20 { padding: 20px; }
.p-24 { padding: 24px; }

.w-full { width: 100%; }
.h-full { height: 100%; }
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state .empty-title { font-size: 1rem; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.empty-state .empty-msg { font-size: 0.85rem; }

.loading-spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes scanProgress {
  0%   { transform: translateX(-100%); }
  50%  { transform: translateX(80%); }
  100% { transform: translateX(200%); }
}


.highlight { background: var(--primary-glow); color: var(--primary-light); padding: 0 4px; border-radius: 3px; }

/* Separator */
.sep { display: flex; align-items: center; gap: 12px; color: var(--text-muted); font-size: 0.8rem; margin: 20px 0; }
.sep::before, .sep::after { content: ''; flex: 1; border-top: 1px solid var(--border); }

/* Number input */
.num-input { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================================
   THEME COLOR TRANSITION
   All primary color vars transition smoothly when company theme changes
============================================ */
:root {
  transition:
    --primary 0.4s ease,
    --primary-light 0.4s ease,
    --primary-dark 0.4s ease,
    --primary-glow 0.4s ease;
}

/* ============================================
   PRINT STYLES
============================================ */
@media print {
  .sidebar, .app-header, .top-header, .page-actions, .no-print,
  .bottom-nav, .sidebar-overlay { display: none !important; }
  .main-content, .main-area { width: 100%; }
  .page-content, .module-wrapper { padding: 0; overflow: visible; }
  body { background: #fff; color: #000; overflow: auto; }
  .card { border: 1px solid #ccc; page-break-inside: avoid; }
  .data-table { font-size: 0.75rem; }
}

/* ============================================
   RESPONSIVE — TABLET (≤ 1024px)
============================================ */
@media (max-width: 1024px) {
  .grid-5, .grid-6 { grid-template-columns: repeat(3, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================
   RESPONSIVE — TABLET PORTRAIT (≤ 900px)
============================================ */
@media (max-width: 900px) {
  .grid-4, .grid-5, .grid-6 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-5, .form-row.cols-6 { grid-template-columns: repeat(3, 1fr); }
  .form-row.cols-4 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-3 { grid-template-columns: 1fr 1fr; }
  .data-table { font-size: 0.82rem; }
  .data-table th, .data-table td { padding: 9px 10px; }
}

/* ============================================
   RESPONSIVE — MOBILE (≤ 768px)
   Sidebar: slide-over overlay
   Bottom nav bar: 5 quick-access tabs
============================================ */
@media (max-width: 768px) {

  /* ── App Shell ── */
  body { overflow: hidden; height: 100dvh; }
  .app-shell { height: 100dvh; overflow: hidden; }

  /* ── Sidebar: slide-over drawer ── */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    height: 100dvh !important;
    z-index: 99999 !important;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1), box-shadow 0.28s !important;
    width: 280px !important;
    min-width: 280px !important;
    max-width: 85vw !important;
    background: var(--bg-surface) !important;
    box-shadow: none;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    pointer-events: auto !important;
  }
  .sidebar.mobile-open {
    transform: translateX(0) !important;
    box-shadow: 10px 0 40px rgba(0,0,0,0.4) !important;
  }
  .sidebar.collapsed { width: 280px !important; min-width: 280px !important; }
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .nav-badge { display: flex; opacity: 1; width: auto; }
  .sidebar.collapsed .nav-section-title { opacity: 1; }
  .sidebar.collapsed .nav-arrow { display: flex; }

  /* ── Sidebar overlay backdrop ── */
  .sidebar-overlay {
    display: none;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(15, 23, 42, 0.6) !important;
    z-index: 99990 !important;
    backdrop-filter: blur(3px);
  }
  .sidebar-overlay.active { display: block !important; }

  /* ── Main area: full width & touch scrolling container ── */
  .main-area {
    width: 100%;
    min-width: 0;
    height: 100dvh !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* ── Top header: compact ── */
  .top-header { padding: 0 12px; gap: 8px; flex-shrink: 0; }
  .header-breadcrumb { display: none; } /* hide on mobile */
  .user-info { display: none; }
  .header-company strong { font-size: 0.65rem; }
  .header-company { max-width: 130px; }
  .header-fy { display: none; }

  /* Show shortcuts button text only as icon on mobile */
  .top-header .nav-label { display: none; }

  /* ── Module wrapper: smooth vertical touch scrolling container ── */
  .module-wrapper {
    flex: 1;
    min-height: 0;
    height: 100% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: contain;
    padding: 12px;
    padding-bottom: 60px;
  }

  /* ── Bottom Navigation Bar (Hidden to prevent blocking Save buttons) ── */
  .bottom-nav {
    display: none !important;
  }
  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s, background 0.2s;
    border: none;
    background: none;
    font-family: inherit;
    padding: 6px 4px;
    min-height: 44px;
    position: relative;
  }
  .bottom-nav-item:active { background: var(--bg-elevated); }
  .bottom-nav-item.active { color: var(--primary-light); }
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 2px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
  }
  .bottom-nav-icon { font-size: 1.3rem; line-height: 1; }
  .bottom-nav-label { font-size: 0.6rem; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap; }

  /* ── Page Header: stack on mobile ── */
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
  .page-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }
  .page-actions .btn { flex: 1; min-width: 100px; justify-content: center; }
  .page-actions .form-control { width: 100% !important; }

  /* ── Page Title ── */
  .page-title { font-size: 1.15rem; }

  /* ── Grids: all single column on mobile ── */
  .grid-2, .grid-3, .grid-4, .grid-5, .grid-6 { grid-template-columns: 1fr; gap: 12px; }
  .col-2, .col-3 { grid-column: span 1; }

  /* ── Form rows: single column on mobile, with compact density ── */
  .form-row.cols-2,
  .form-row.cols-3,
  .form-row.cols-4,
  .form-row.cols-5,
  .form-row.cols-6 { grid-template-columns: 1fr; gap: 8px; }

  /* Compact mode on mobile: keep fields tight and not oversized */
  .form-row.compact { gap: 6px; }
  .form-row.compact .form-control { min-height: 38px; height: 38px; font-size: 0.9rem; padding: 7px 10px; }
  .form-row.compact .form-label { font-size: 0.76rem; margin-bottom: 2px; }

  /* Mobile 2-column grid for paired fields like Dates, Series & Inv No */
  .mobile-grid-2 { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 8px !important; }

  /* ── Mobile Form Controls: clean, sleek and compact ── */
  .form-group { margin-bottom: 6px; }
  .form-label { font-size: 0.8rem; margin-bottom: 3px; font-weight: 600; }
  .form-control { padding: 8px 10px; font-size: 0.9rem; min-height: 38px; height: 38px; }
  textarea.form-control { min-height: 70px; height: auto; }
  .btn { min-height: 38px; font-size: 0.88rem; padding: 8px 14px; }
  .btn-sm { min-height: 32px; font-size: 0.8rem; padding: 5px 10px; }
  .btn-icon { min-height: 36px; min-width: 36px; }

  /* ── KPI Cards ── */
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 1.35rem; }

  /* ── Tables: horizontal scroll with sticky first column ── */
  .table-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
    width: 100% !important;
    touch-action: pan-x pan-y;
  }
  .data-table { min-width: 560px; }
  .data-table th, .data-table td { padding: 10px 10px; white-space: nowrap; }

  /* ── Modals: full screen on mobile ── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
    max-height: 92dvh;
    max-width: 100% !important;
    width: 100%;
    transform: translateY(100px) !important;
  }
  .modal-overlay.open .modal { transform: translateY(0) !important; }
  .modal-body { max-height: 65dvh; }

  /* ── Cards ── */
  .card { border-radius: var(--radius); }
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px 10px; }

  /* ── Item table in entry forms: scrollable ── */
  #pur-items-table, #sal-items-table { min-width: 700px; }

  /* ── Totals grid: stack ── */
  .grid-2[style*="align-items:start"] { grid-template-columns: 1fr !important; }

  /* ── Voucher items: visible as card ── */
  .voucher-ledger-row { grid-template-columns: 1fr 90px; grid-template-rows: auto auto; gap: 4px; }
}

/* ============================================
   RESPONSIVE — SMALL PHONES (≤ 380px)
============================================ */
@media (max-width: 380px) {
  .page-content, .module-wrapper { padding: 10px; }
  .kpi-value { font-size: 1.15rem; }
  .page-title { font-size: 1rem; }
  .form-control { font-size: 0.95rem; }
  .bottom-nav-label { display: none; }
  .bottom-nav-icon { font-size: 1.5rem; }
  .bottom-nav-item { gap: 0; }
}

/* ============================================
   DESKTOP BOTTOM NAV — hidden
============================================ */
.bottom-nav { display: none !important; }

/* ============================================
   MOBILE ITEM ENTRY FORMS & MOBILE MENU REFINEMENT
============================================ */
@media (max-width: 768px) {
  .top-header {
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
  }
  .sidebar.mobile-open {
    background: var(--bg-surface);
  }

  /* Transform entry item tables into clean Mobile Cards */
  #pur-items-table, #sal-items-table,
  #so-items-table, #po-items-table,
  #sr-items-table, #pr-items-table, #qt-items-table {
    min-width: 0 !important;
    width: 100% !important;
    display: block !important;
  }
  #pur-items-table thead, #sal-items-table thead,
  #so-items-table thead, #po-items-table thead,
  #sr-items-table thead, #pr-items-table thead, #qt-items-table thead {
    display: none !important;
  }
  #pur-items-table tbody, #sal-items-table tbody,
  #so-items-table tbody, #po-items-table tbody,
  #sr-items-table tbody, #pr-items-table tbody, #qt-items-table tbody {
    display: flex !important;
    flex-direction: column !important;
    gap: 14px !important;
    width: 100% !important;
  }
  #pur-items-table tbody tr, #sal-items-table tbody tr,
  #so-items-table tbody tr, #po-items-table tbody tr,
  #sr-items-table tbody tr, #pr-items-table tbody tr, #qt-items-table tbody tr {
    display: flex !important;
    flex-wrap: wrap !important;
    background: var(--bg-card) !important;
    border: 1px solid var(--border-light) !important;
    border-radius: var(--radius-lg) !important;
    padding: 14px !important;
    box-shadow: var(--shadow-sm) !important;
    position: relative !important;
    gap: 10px !important;
  }
  #pur-items-table tbody tr td, #sal-items-table tbody tr td,
  #so-items-table tbody tr td, #po-items-table tbody tr td,
  #sr-items-table tbody tr td, #pr-items-table tbody tr td, #qt-items-table tbody tr td {
    border: none !important;
    padding: 4px 0 !important;
    white-space: normal !important;
    display: flex !important;
    flex-direction: column !important;
  }
  #pur-items-table tbody tr td:first-child, #sal-items-table tbody tr td:first-child,
  #so-items-table tbody tr td:first-child, #po-items-table tbody tr td:first-child,
  #sr-items-table tbody tr td:first-child, #pr-items-table tbody tr td:first-child, #qt-items-table tbody tr td:first-child {
    width: 100% !important;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border-light) !important;
    padding-bottom: 6px !important;
    margin-bottom: 4px;
    flex-direction: row !important;
    justify-content: space-between !important;
  }
  #pur-items-table tbody tr td:nth-child(2), #sal-items-table tbody tr td:nth-child(2),
  #so-items-table tbody tr td:nth-child(2), #po-items-table tbody tr td:nth-child(2),
  #sr-items-table tbody tr td:nth-child(2), #pr-items-table tbody tr td:nth-child(2), #qt-items-table tbody tr td:nth-child(2) {
    width: 100% !important;
  }
  #pur-items-table tbody tr td:nth-child(n+3):not(:last-child),
  #sal-items-table tbody tr td:nth-child(n+3):not(:last-child),
  #so-items-table tbody tr td:nth-child(n+3):not(:last-child),
  #po-items-table tbody tr td:nth-child(n+3):not(:last-child),
  #sr-items-table tbody tr td:nth-child(n+3):not(:last-child),
  #pr-items-table tbody tr td:nth-child(n+3):not(:last-child),
  #qt-items-table tbody tr td:nth-child(n+3):not(:last-child) {
    flex: 1 1 calc(50% - 8px) !important;
    min-width: 130px;
  }
  #pur-items-table tbody tr td[data-label]::before,
  #sal-items-table tbody tr td[data-label]::before,
  #so-items-table tbody tr td[data-label]::before,
  #po-items-table tbody tr td[data-label]::before,
  #sr-items-table tbody tr td[data-label]::before,
  #pr-items-table tbody tr td[data-label]::before,
  #qt-items-table tbody tr td[data-label]::before {
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 4px;
  }
  #pur-items-table tbody tr td:last-child, #sal-items-table tbody tr td:last-child,
  #so-items-table tbody tr td:last-child, #po-items-table tbody tr td:last-child,
  #sr-items-table tbody tr td:last-child, #pr-items-table tbody tr td:last-child, #qt-items-table tbody tr td:last-child {
    position: absolute !important;
    top: 10px;
    right: 10px;
    width: auto !important;
  }
}

/* ============================================
   PROFESSIONAL POLISH (Nov 2026) — denser, calmer ERP look
============================================ */
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
.page-title { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
.page-header { padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.card { box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05); }
.card-header { padding-top: 12px; padding-bottom: 12px; }

/* tables: compact rows, subtle stripes, tabular numbers, one-line amounts */
.data-table th { padding: 10px 12px; font-size: 0.72rem; letter-spacing: 0.06em; }
.data-table td { padding: 9px 12px; }
.data-table tbody tr:nth-child(even) td { background: rgba(127, 127, 127, 0.035); }
.data-table tbody tr:hover td { background: var(--bg-card-hover); }
.data-table .td-number, .data-table td.td-number * { white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-wrapper { border-radius: var(--radius); }

/* forms: consistent control height and a clear focus ring */
.form-control { min-height: 38px; }
textarea.form-control { min-height: 0; }
.form-control:focus { box-shadow: 0 0 0 3px var(--primary-glow); border-color: var(--primary-light); }
.form-label { font-weight: 600; }
.btn { font-weight: 600; letter-spacing: 0.01em; }

/* slim scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(127, 127, 127, 0.35) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(127, 127, 127, 0.35); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(127, 127, 127, 0.55); }

/* Bill-scan preview: let searchable dropdowns shrink inside the compact item grid */
#bill-scan-modal [data-scan-item] .combo-wrapper { min-width: 0 !important; }
#bill-scan-modal [data-scan-item] .form-control { min-width: 0; }
#bill-scan-modal [data-scan-item] > div[style*="grid"] > div { min-width: 0; }

/* ===== Ledger Master ===== */
.lm-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.lm-groups { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow: auto; }
.lm-gtitle { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding: 12px 14px 4px; }
.lm-group { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 14px; cursor: pointer; font-size: 0.86rem; border-left: 3px solid transparent; color: var(--text-secondary); }
.lm-group:hover { background: var(--bg-hover, rgba(99,102,241,0.06)); }
.lm-group.active { background: var(--primary-light, rgba(99,102,241,0.1)); border-left-color: var(--primary); color: var(--primary); font-weight: 700; }
.lm-gname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lm-count { font-size: 0.72rem; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 10px; padding: 0 7px; color: var(--text-muted); }
.lm-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lm-pick-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card, #fff); color: var(--text-primary); cursor: pointer; text-align: left; transition: transform .15s, border-color .15s, box-shadow .15s; }
.lm-pick-btn:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 6px 16px rgba(99,102,241,.15); }
.lm-pick-btn span { font-size: 1.2rem; } .lm-pick-btn b { font-size: 0.85rem; } .lm-pick-btn small { font-size: 0.72rem; color: var(--text-muted); }
@media (max-width: 900px) { .lm-layout { grid-template-columns: 1fr; } .lm-groups { position: static; max-height: none; } .lm-pick { grid-template-columns: repeat(2, 1fr); } }

/* ===== Dashboard (3D) ===== */
.dash { display: flex; flex-direction: column; gap: 18px; }
.dash-hero { position: relative; overflow: hidden; border-radius: 20px; padding: 26px 30px; color: #fff; display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 20px; align-items: center;
  background: radial-gradient(120% 140% at 0% 0%, #4f46e5 0%, #312e81 45%, #0f172a 100%); box-shadow: 0 18px 40px -18px rgba(49, 46, 129, .65); }
.dash-hero-grid { position: absolute; inset: auto -20% -60% -20%; height: 120%; pointer-events: none; opacity: .35;
  background-image: linear-gradient(rgba(165, 180, 252, .35) 1px, transparent 1px), linear-gradient(90deg, rgba(165, 180, 252, .35) 1px, transparent 1px);
  background-size: 44px 44px; transform: perspective(500px) rotateX(62deg); transform-origin: top; animation: dashGrid 14s linear infinite; }
@keyframes dashGrid { to { background-position: 0 44px, 0 0; } }
.dash-hero-main { position: relative; z-index: 1; min-width: 0; }
.dash-hello { font-size: .95rem; opacity: .85; font-weight: 600; }
.dash-firm { font-size: 1.85rem; font-weight: 900; letter-spacing: -.02em; line-height: 1.15; margin: 2px 0 8px; text-shadow: 0 6px 20px rgba(0, 0, 0, .35); }
.dash-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: .82rem; opacity: .9; }
.dash-live { color: #6ee7b7; font-weight: 700; }
.dash-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dash-action { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .22); background: rgba(255, 255, 255, .1);
  color: #fff; font-weight: 700; font-size: .82rem; cursor: pointer; backdrop-filter: blur(8px); transition: transform .15s, background .15s, box-shadow .15s; }
.dash-action:hover { transform: translateY(-2px); background: rgba(255, 255, 255, .2); box-shadow: 0 8px 18px rgba(0, 0, 0, .25); }
.dash-action span { font-size: 1rem; }
.dash-hero-cube { position: relative; z-index: 1; height: 170px; display: flex; align-items: center; justify-content: center; perspective: 700px; }
.cube { --s: 110px; width: var(--s); height: var(--s); position: relative; transform-style: preserve-3d; animation: cubeSpin 18s linear infinite; }
.cube-face { position: absolute; inset: 0; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: linear-gradient(135deg, #6366f1, #312e81); border: 1px solid rgba(199, 210, 254, .55); box-shadow: inset 0 0 26px rgba(165, 180, 252, .45); backface-visibility: hidden; }
.cube-face small { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
.cube-face b { font-size: 1.15rem; font-weight: 900; }
.cube .f0 { transform: translateZ(calc(var(--s) / 2)); } .cube .f1 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.cube .f2 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); } .cube .f3 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.cube .f4 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); } .cube .f5 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
@keyframes cubeSpin { from { transform: rotateX(-18deg) rotateY(0); } to { transform: rotateX(-18deg) rotateY(360deg); } }

.dash-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.dash-kpi { --c1: #6366f1; --c2: #a5b4fc; position: relative; overflow: hidden; cursor: pointer; border-radius: 18px; padding: 16px 18px 14px; background: var(--bg-card); border: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset, 0 10px 24px -14px rgba(15, 23, 42, .35); transition: transform .18s ease, box-shadow .18s ease; transform-style: preserve-3d; will-change: transform; }
.dash-kpi::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: linear-gradient(90deg, var(--c1), var(--c2)); }
.dash-kpi::after { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .2s;
  background: radial-gradient(260px circle at var(--gx, 50%) var(--gy, 50%), color-mix(in srgb, var(--c1) 18%, transparent), transparent 60%); }
.dash-kpi:hover { box-shadow: 0 22px 38px -18px color-mix(in srgb, var(--c1) 60%, transparent); }
.dash-kpi:hover::after { opacity: 1; }
.dash-kpi:focus-visible { outline: 2px solid var(--c1); outline-offset: 2px; }
.dash-kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.dash-kpi-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; transform: translateZ(30px);
  background: linear-gradient(145deg, color-mix(in srgb, var(--c2) 55%, #fff), color-mix(in srgb, var(--c1) 35%, #fff));
  box-shadow: 0 8px 16px -6px color-mix(in srgb, var(--c1) 70%, transparent), inset 0 -3px 0 color-mix(in srgb, var(--c1) 35%, transparent), inset 0 2px 0 rgba(255, 255, 255, .7); }
.dash-spark { width: 96px; height: 34px; flex-shrink: 0; }
.spark-line { fill: none; stroke: var(--c1); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-area { fill: color-mix(in srgb, var(--c1) 16%, transparent); }
.dash-kpi-value { font-size: 1.45rem; font-weight: 900; letter-spacing: -.02em; color: var(--text-primary); transform: translateZ(20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-kpi-label { font-size: .82rem; font-weight: 700; color: var(--text-secondary); margin-top: 2px; }
.dash-kpi-foot { font-size: .74rem; color: var(--text-muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tone-indigo { --c1: #6366f1; --c2: #a5b4fc; } .tone-amber { --c1: #f59e0b; --c2: #fcd34d; } .tone-emerald { --c1: #10b981; --c2: #6ee7b7; }
.tone-rose { --c1: #f43f5e; --c2: #fda4af; } .tone-violet { --c1: #8b5cf6; --c2: #c4b5fd; } .tone-teal { --c1: #14b8a6; --c2: #5eead4; }
.tone-sky { --c1: #0ea5e9; --c2: #7dd3fc; } .tone-orange { --c1: #f97316; --c2: #fdba74; }

.dash-row { display: grid; gap: 16px; align-items: stretch; }
.dash-row-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.dash-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dash-card { margin: 0; border-radius: 18px; min-width: 0; }
.dash-legend { display: flex; gap: 12px; font-size: .78rem; color: var(--text-secondary); }
.dash-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dash-chart-wrap { position: relative; padding: 8px 12px 4px; }
.b3 { width: 100%; height: auto; display: block; overflow: visible; }
.b3-grid { stroke: var(--border); stroke-dasharray: 3 4; }
.b3-axis { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
.b3-floor { fill: color-mix(in srgb, var(--primary) 8%, transparent); }
.b3-empty { fill: var(--text-muted); font-size: 14px; }
.b3-bar { transform-box: fill-box; transform-origin: bottom; transform: scaleY(0); transition: transform .7s cubic-bezier(.2, .9, .25, 1.15) var(--d), filter .15s; cursor: pointer; }
.dash.ready .b3-bar { transform: scaleY(1); }
.b3-bar:hover { filter: brightness(1.15) drop-shadow(0 4px 6px rgba(0, 0, 0, .25)); }
.dash-tip { position: absolute; pointer-events: none; opacity: 0; transition: opacity .12s; background: #0f172a; color: #fff; font-size: .78rem; font-weight: 600; padding: 6px 10px; border-radius: 8px; white-space: nowrap; box-shadow: 0 8px 20px rgba(0, 0, 0, .3); z-index: 5; }

.d3-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.d3-stage { position: relative; width: 200px; height: 170px; perspective: 600px; display: grid; place-items: center; }
.d3-tilt { position: relative; width: 180px; height: 180px; transform-style: preserve-3d; transform: rotateX(56deg) rotateZ(-20deg); animation: donutTurn 16s linear infinite; }
.d3-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
@keyframes donutTurn { to { transform: rotateX(56deg) rotateZ(340deg); } }
.d3-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -62%); text-align: center; pointer-events: none; }
.d3-center b { display: block; font-size: 1.05rem; font-weight: 900; color: var(--text-primary); }
.d3-center small { font-size: .7rem; color: var(--text-muted); }
.d3-legend { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: .8rem; }
.d3-legend div { display: flex; align-items: center; gap: 6px; min-width: 0; }
.d3-legend i { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.d3-legend span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.d3-legend b { color: var(--text-primary); }

.bal-list { display: flex; flex-direction: column; gap: 12px; }
.bal-top { display: flex; justify-content: space-between; gap: 8px; font-size: .84rem; margin-bottom: 5px; color: var(--text-secondary); }
.bal-top span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bal-top b { color: var(--text-primary); white-space: nowrap; }
.bal-track { height: 10px; border-radius: 6px; background: var(--bg-elevated); overflow: hidden; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .12); }
.bal-fill { height: 100%; width: 0; border-radius: 6px; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15), inset 0 2px 0 rgba(255, 255, 255, .35); transition: width .9s cubic-bezier(.2, .9, .25, 1); }
.dash.ready .bal-fill { width: var(--w); }
.bal-net { margin-top: 4px; padding: 10px 12px; border-radius: 10px; font-size: .84rem; text-align: center; }
.bal-net.up { background: color-mix(in srgb, #10b981 12%, transparent); color: #047857; }
.bal-net.down { background: color-mix(in srgb, #ef4444 12%, transparent); color: #b91c1c; }
.rank { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; margin-right: 8px; font-size: .7rem; color: #fff; background: linear-gradient(135deg, #6366f1, #a855f7); }

.dash-alerts { display: flex; flex-direction: column; }
.dash-alert { display: flex; gap: 10px; align-items: center; padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: .84rem; font-weight: 600; }
.dash-alert[role=button] { cursor: pointer; } .dash-alert[role=button]:hover { background: var(--bg-elevated); }
.a-danger { color: #dc2626; } .a-warning { color: #d97706; } .a-info { color: #0284c7; } .a-success { color: #059669; }
.dash-low { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.dash-low-title { font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.dash-low-row { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; font-size: .8rem; }
.dash-low-row .bal-track { grid-column: 1 / -1; height: 6px; }
.dash-people, .dash-recent { display: flex; flex-direction: column; }
.dash-person, .dash-recent-row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: .85rem; }
.dash-person span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.dash-person b { color: var(--success); }
.dash-avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff; flex-shrink: 0;
  background: linear-gradient(135deg, hsl(var(--h) 75% 58%), hsl(calc(var(--h) + 40) 75% 45%)); box-shadow: 0 4px 10px -3px hsl(var(--h) 75% 45% / .6); }
.dash-recent-row > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dash-recent-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); }
.dash-recent-row small { font-size: .74rem; color: var(--text-muted); }
.amt-success { color: var(--success); font-weight: 700; white-space: nowrap; } .amt-warning { color: var(--warning); font-weight: 700; white-space: nowrap; }

[data-theme="dark"] .dash-kpi-icon { background: linear-gradient(145deg, color-mix(in srgb, var(--c1) 55%, #1e293b), color-mix(in srgb, var(--c1) 25%, #0f172a)); }
[data-theme="dark"] .bal-net.up { color: #6ee7b7; } [data-theme="dark"] .bal-net.down { color: #fca5a5; }
@media (max-width: 1200px) { .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .dash-row-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) { .dash-row-main, .dash-row-3 { grid-template-columns: 1fr; } .dash-hero { grid-template-columns: 1fr; } .dash-hero-cube { display: none; } }
@media (max-width: 560px) { .dash-kpis { grid-template-columns: 1fr; } .dash-hero { padding: 20px; } .dash-firm { font-size: 1.4rem; } }
@media (prefers-reduced-motion: reduce) { .cube, .d3-tilt, .dash-hero-grid { animation: none; } .b3-bar { transition: none; transform: none; } .bal-fill { transition: none; } }
.d3-total { font-size: .82rem; color: var(--text-muted); margin-top: -6px; } .d3-total b { color: var(--text-primary); font-size: 1rem; }

/* ============================================
   3D DEPTH LOOK (Nov 2026) — raised cards, sunken inputs, pressable buttons, tilting modals
============================================ */
:root { --hi: rgba(255, 255, 255, .75); --depth-1: 0 1px 2px rgba(16, 24, 40, .06); --depth-2: 0 10px 28px -14px rgba(16, 24, 40, .22); }
[data-theme="dark"] { --hi: rgba(255, 255, 255, .05); --depth-1: 0 1px 2px rgba(0, 0, 0, .35); --depth-2: 0 14px 30px -16px rgba(0, 0, 0, .7); }

/* raised surfaces */
.card { border-radius: 14px; box-shadow: inset 0 1px 0 var(--hi), var(--depth-1), var(--depth-2); }
.card-header { background: linear-gradient(180deg, color-mix(in srgb, var(--bg-elevated) 55%, transparent), transparent); }
.card-title { letter-spacing: -.005em; }
.kpi-card { transition: transform .18s ease, box-shadow .18s ease; box-shadow: inset 0 1px 0 var(--hi), var(--depth-1), var(--depth-2); }
.kpi-card:hover { transform: translateY(-3px) perspective(600px) rotateX(2deg); box-shadow: inset 0 1px 0 var(--hi), 0 18px 34px -16px rgba(79, 70, 229, .35); }
.page-header .page-title { text-shadow: 0 1px 0 var(--hi); }
.app-header { box-shadow: 0 1px 0 var(--border), 0 8px 22px -16px rgba(16, 24, 40, .4); }

/* sunken inputs that lift when focused */
.form-control { box-shadow: inset 0 1px 2px rgba(16, 24, 40, .07), 0 1px 0 var(--hi); transition: border-color .15s, box-shadow .15s, transform .15s; }
.form-control:hover:not(:focus):not(:disabled) { border-color: var(--border-focus, var(--primary-light)); }
.form-control:focus { box-shadow: 0 0 0 3px var(--primary-glow), 0 8px 16px -10px var(--primary); transform: translateY(-1px); }
.data-table .form-control:focus, .combo-input:focus { transform: none; }
.form-label { letter-spacing: .01em; }

/* pressable buttons: a solid lip underneath that collapses on click */
.btn-primary, .btn-success, .btn-danger, .btn-warning, .btn-info { position: relative; }
.btn-primary { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 3px 0 var(--primary-dark), 0 8px 16px -8px var(--primary); }
.btn-success { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 3px 0 hsl(145, 65%, 30%), 0 8px 16px -8px hsla(145, 65%, 40%, .6); }
.btn-danger { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 3px 0 hsl(0, 72%, 38%), 0 8px 16px -8px hsla(0, 72%, 50%, .6); }
.btn-warning { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 3px 0 hsl(38, 92%, 36%), 0 8px 16px -8px hsla(38, 92%, 50%, .6); }
.btn-info { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 3px 0 hsl(200, 80%, 32%), 0 8px 16px -8px hsla(200, 80%, 45%, .6); }
.btn-secondary { box-shadow: inset 0 1px 0 var(--hi), 0 2px 0 var(--border-light, var(--border)), 0 6px 12px -8px rgba(16, 24, 40, .3); }
.btn-primary:hover:not(:disabled), .btn-success:hover:not(:disabled), .btn-danger:hover:not(:disabled), .btn-warning:hover:not(:disabled), .btn-info:hover:not(:disabled), .btn-secondary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary:active:not(:disabled), .btn-success:active:not(:disabled), .btn-danger:active:not(:disabled), .btn-warning:active:not(:disabled), .btn-info:active:not(:disabled) { transform: translateY(3px); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .2), 0 0 0 transparent; }
.btn-secondary:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 2px 4px rgba(16, 24, 40, .15); }
.btn-ghost:active:not(:disabled) { transform: scale(.96); }

/* tables: header with a lit top edge and a shadow below */
.data-table thead th { background: linear-gradient(180deg, color-mix(in srgb, var(--bg-elevated) 70%, var(--bg-card)), var(--bg-elevated)); box-shadow: inset 0 1px 0 var(--hi), inset 0 -1px 0 var(--border); }
.data-table tbody tr { transition: transform .12s ease, box-shadow .12s ease; }
.data-table tbody tr:hover { box-shadow: 0 6px 14px -10px rgba(16, 24, 40, .35); position: relative; z-index: 1; }

/* modals swing in with perspective */
.modal-overlay { perspective: 1400px; }
.modal { transform: rotateX(10deg) translateY(30px) scale(.96); transform-origin: 50% 0; transition: transform .28s cubic-bezier(.2, .9, .25, 1.1), opacity .2s;
  box-shadow: inset 0 1px 0 var(--hi), 0 40px 80px -30px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .03); }
.modal-overlay.open .modal { transform: none; }
.modal-header { background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 7%, var(--bg-card)), var(--bg-card)); }

/* nav dropdowns float above */
.nav-dropdown { box-shadow: inset 0 1px 0 var(--hi), 0 18px 40px -16px rgba(16, 24, 40, .45) !important; }

@media (prefers-reduced-motion: reduce) { .modal, .form-control, .kpi-card, .data-table tbody tr { transition: none; } .modal { transform: none; } }

/* ===== Voice typing button ===== */
#voice-fab { position: fixed; left: 18px; bottom: 18px; z-index: 99999; display: flex; align-items: center; gap: 6px; }
@media (min-width: 769px) { body.menu-left:not(.sidebar-collapsed) #voice-fab { left: 258px; } }
#voice-fab button { border: none; cursor: pointer; font-family: inherit; }
#voice-fab .vf-mic { width: 52px; height: 52px; border-radius: 50%; font-size: 1.4rem; color: #fff; background: radial-gradient(circle at 35% 30%, #818cf8, #4f46e5 60%, #3730a3);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), 0 4px 0 #312e81, 0 12px 24px -8px rgba(79, 70, 229, .7); transition: transform .12s, box-shadow .12s; }
#voice-fab .vf-mic:active { transform: translateY(3px); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .3); }
#voice-fab .vf-lang { order: 1; height: 30px; min-width: 38px; padding: 0 8px; border-radius: 16px; font-weight: 800; font-size: .78rem; color: var(--text-primary); background: var(--bg-card);
  box-shadow: inset 0 1px 0 var(--hi), 0 2px 0 var(--border), 0 6px 14px -8px rgba(16, 24, 40, .4); }
#voice-fab.listening .vf-mic { background: radial-gradient(circle at 35% 30%, #fca5a5, #ef4444 60%, #b91c1c); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), 0 4px 0 #7f1d1d, 0 0 0 0 rgba(239, 68, 68, .6); animation: vfPulse 1.4s infinite; }
@keyframes vfPulse { 0% { box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 4px 0 #7f1d1d, 0 0 0 0 rgba(239,68,68,.55); } 100% { box-shadow: inset 0 2px 0 rgba(255,255,255,.35), 0 4px 0 #7f1d1d, 0 0 0 18px rgba(239,68,68,0); } }
#voice-fab .vf-bubble { display: none; position: absolute; left: 0; bottom: 64px; max-width: min(360px, 80vw); padding: 8px 12px; border-radius: 12px; font-size: .85rem; font-weight: 600;
  background: #0f172a; color: #fff; box-shadow: 0 12px 28px -10px rgba(0, 0, 0, .5); white-space: normal; }
.voice-target { outline: 2px solid #ef4444 !important; outline-offset: 2px; }
@media print { #voice-fab { display: none !important; } }
#module-content { padding-bottom: 72px; }

/* item grids: searchable dropdowns stay compact, qty + unit sit side by side */
#sal-items-body .combo-wrapper, #pur-items-body .combo-wrapper { min-width: 0 !important; }
#sal-items-body td[data-label="GST%"], #pur-items-body td[data-label="GST%"] { width: 92px; }
#sal-items-body td[data-label="GST%"] .combo-wrapper, #pur-items-body td[data-label="GST%"] .combo-wrapper { width: 84px !important; display: inline-block; }
#sal-items-body td[data-label="GST%"] .combo-input, #pur-items-body td[data-label="GST%"] .combo-input { padding-right: 18px; }
#sal-items-body td[data-label="Qty"], #pur-items-body td[data-label="Qty"] { white-space: nowrap; }
#sal-items-body td[data-label="Qty"] > input, #pur-items-body td[data-label="Qty"] > input { display: inline-block; vertical-align: middle; }
#sal-items-body td[data-label="HSN"] input, #pur-items-body td[data-label="HSN"] input { width: 96px !important; }

/* item search popup: the row picked with ↑ / ↓ must stand out */
/* keyboard cursor in searchable lists: what Enter will pick */
.combo-option.combo-active { background: var(--primary) !important; color: #fff !important; font-weight: 600; box-shadow: inset 4px 0 0 rgba(0,0,0,0.25); }
.combo-option.combo-active strong { color: #fff; }
.combo-option.combo-create { color: var(--primary); font-weight: 700; background: var(--primary-light, #eff6ff); border-bottom: 2px solid var(--primary); padding: 7px 10px; cursor: pointer; font-size: 0.82rem; }
#scp-results-container .scp-row:hover td { background: #f1f5f9; }
#scp-results-container .scp-row.scp-active td { background: #dbeafe !important; }
#scp-results-container .scp-row.scp-active td:first-child { box-shadow: inset 4px 0 0 #1e40af; }
.gip-item-row.gip-active-row td { background: color-mix(in srgb, var(--primary) 16%, var(--bg-card)) !important; }
.gip-item-row.gip-active-row td:first-child { box-shadow: inset 4px 0 0 var(--primary); }
.gip-item-row.gip-active-row td:nth-child(2) > div:first-child { text-decoration: underline; text-underline-offset: 3px; }

/* keyboard: Go To palette and the list row picked with ↑ ↓ */
.goto-box { max-width: 620px; padding: 14px; gap: 10px; align-self: flex-start; margin-top: 12vh; }
.goto-box #goto-input { font-size: 1.05rem; padding: 12px 14px; border: 2px solid var(--primary); }
.goto-list { max-height: 52vh; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.goto-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--text-primary); }
.goto-row small { color: var(--text-muted); font-size: .75rem; white-space: nowrap; }
.goto-row.on { background: color-mix(in srgb, var(--primary) 16%, var(--bg-card)); box-shadow: inset 3px 0 0 var(--primary); font-weight: 600; }
.goto-empty { padding: 16px; text-align: center; color: var(--text-muted); }
.goto-foot { display: flex; gap: 16px; font-size: .75rem; color: var(--text-muted); padding-top: 6px; border-top: 1px solid var(--border); }
.goto-foot kbd, .goto-row kbd, .kb-kbd { background: var(--bg-elevated); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: .72rem; font-family: inherit; }
.kb-kbd { background: #fff; color: #111; font-weight: 600; white-space: nowrap; }
#module-content table.data-table tbody tr.kb-row td { background: color-mix(in srgb, var(--primary) 14%, var(--bg-card)) !important; }
#module-content table.data-table tbody tr.kb-row td:first-child { box-shadow: inset 4px 0 0 var(--primary); }
#sidebar .nav-group-btn:focus-visible, #sidebar .nav-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

/* e-Invoice / e-Way Bill screen */
.einv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.einv-chk { font-size: .82rem; padding: 3px 0; }
.einv-chk.bad { color: var(--danger); font-weight: 600; }
.einv-steps { font-size: .78rem; color: var(--text-muted); background: var(--bg-elevated); border-radius: 8px; padding: 8px 10px; margin: 10px 0; }
@media (max-width: 860px) { .einv-grid { grid-template-columns: 1fr; } }

/* ===== Unified voucher entry (js/vouchers.js) ===== */
.vch-tabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; }
.vch-tab { display:flex; align-items:center; gap:6px; padding:8px 14px; border-radius:10px; border:1px solid var(--border); background:var(--bg-card); color:var(--text-primary); cursor:pointer; font-weight:600; font-size:0.86rem; box-shadow:0 2px 0 var(--border); }
.vch-tab small { font-size:0.68rem; color:var(--text-muted); border:1px solid var(--border); border-radius:4px; padding:0 4px; }
.vch-tab.on { background:var(--primary); color:#fff; border-color:var(--primary); box-shadow:0 3px 10px rgba(79,70,229,.35); }
.vch-tab.on small { color:#fff; border-color:rgba(255,255,255,.6); }
.vch-tab:disabled:not(.on) { opacity:.45; cursor:not-allowed; }
.vch-sec { border:1px solid var(--border); border-radius:10px; padding:10px 12px; margin:10px 0; background:var(--bg-elevated); }
.vch-sec-h { display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; gap:8px; font-size:0.88rem; }
.vch-row { display:grid; grid-template-columns:minmax(220px,2.2fr) 130px auto 34px; gap:8px; align-items:center; margin-bottom:6px; }
.vch-row.vch-mode { grid-template-columns:170px minmax(180px,1.6fr) 130px 1fr 140px 34px; }
.vch-row.vch-jrow { grid-template-columns:minmax(220px,2fr) 130px 130px 1fr 34px; }
.vch-row .vch-info { grid-column:1 / -1; font-size:0.76rem; color:var(--text-muted); margin-top:-2px; }
.vch-mlabel { font-weight:700; color:var(--text-muted); font-size:0.82rem; }
.vch-tot { padding:10px 12px; border-radius:8px; font-weight:700; margin-top:6px; }
.vch-tot.ok { background:rgba(16,185,129,.12); color:var(--success); }
.vch-tot.bad { background:rgba(245,158,11,.12); color:var(--warning); }
.vch-paybox { margin:10px 0; padding:10px; border:1px dashed var(--border); border-radius:10px; }
.vch-payrow { display:grid; grid-template-columns:120px 1fr 100px 100px 30px; gap:6px; margin-bottom:6px; }
.vch-info { font-size:0.76rem; color:var(--text-muted); }
@media (max-width: 760px) {
  .vch-row, .vch-row.vch-mode, .vch-row.vch-jrow, .vch-payrow { grid-template-columns:1fr 1fr; }
}

/* ===== CRM pipeline board (js/biz-tools.js) ===== */
.pl-board { display:grid; grid-template-columns:repeat(4, minmax(220px, 1fr)); gap:12px; align-items:start; overflow-x:auto; }
.pl-col { background:var(--bg-elevated); border:1px solid var(--border); border-radius:10px; padding:8px; min-height:120px; }
.pl-head { font-weight:700; padding:6px 8px 8px; margin:-8px -8px 8px; border-radius:10px 10px 0 0; background:var(--bg-card); }
.pl-card { background:var(--bg-card); border:1px solid var(--border); border-radius:8px; padding:8px 10px; margin-bottom:8px; font-size:0.84rem; box-shadow:0 1px 3px rgba(0,0,0,.06); }
.pl-sub { font-size:0.75rem; color:var(--text-muted); margin-top:2px; }
.pl-btns { display:flex; gap:2px; flex-wrap:wrap; margin-top:6px; }
.pl-btns .btn { padding:2px 6px; font-size:0.74rem; min-height:24px; }
@media (max-width: 900px) { .pl-board { grid-template-columns:repeat(4, 240px); } }

/* ---- phone app: comfortable typing and tapping ---- */
@media (max-width: 768px) {
  /* below 16px iPhones zoom the whole page on every tap into a box */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px !important; }
  .form-control, .form-row.compact .form-control { min-height: 44px; height: 44px; }
  textarea.form-control { height: auto; }
  .btn-sm { min-height: 38px; }
  .grid-3:has(> .kpi-card), .grid-4:has(> .kpi-card) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .grid-3 > .kpi-card, .grid-4 > .kpi-card { padding: 10px 12px; }
  .grid-3 > .kpi-card .kpi-icon, .grid-4 > .kpi-card .kpi-icon { width: 30px; height: 30px; font-size: 0.95rem; margin-bottom: 6px; }
  .grid-3 > .kpi-card .kpi-value, .grid-4 > .kpi-card .kpi-value { font-size: 1.02rem; overflow-wrap: anywhere; }
  #module-content { padding-bottom: 84px; }
  #voice-fab { left: 10px; bottom: 10px; }
  #voice-fab .vf-mic { width: 44px; height: 44px; font-size: 1.15rem; }
  #license-warning-banner { padding: 4px 10px !important; font-size: 0.72rem !important; line-height: 1.25; }
  #license-warning-banner button { padding: 3px 8px !important; font-size: 0.7rem !important; }
}

/* Bill item grid (sale / purchase): number columns line up under their right-aligned headings */
@media (min-width: 769px) {
  :is(#sal-items-body, #pur-items-body) > tr > td:is([data-label="Qty"], [data-label="Rate (₹)"], [data-label="Disc 1"], [data-label="Disc 2"], [data-label="Amount (₹)"]) { text-align: right; white-space: nowrap; }
  :is(#sal-items-body, #pur-items-body) > tr > td:is([data-label="Disc 1"], [data-label="Disc 2"]) > div { margin-left: auto; }
  :is(#sal-items-body, #pur-items-body) > tr > td:is([data-label="Qty"], [data-label="Rate (₹)"], [data-label="Amount (₹)"]) > :is(input, select) { display: inline-block; vertical-align: middle; }
  :is(#sal-items-body, #pur-items-body) > tr > td:is([data-label="HSN"], [data-label="GST%"]) { text-align: left; }
  :is(#sal-items-body, #pur-items-body) input.num-input { text-align: right; }
}

/* ===== Analysis (js/analysis.js) ===== */
:root { --anl-sale:#2563eb; --anl-pur:#d97706; --anl-c3:#059669; --anl-c4:#9333ea; --anl-c5:#dc2626; --anl-c6:#0891b2; }
[data-theme="dark"], body.dark, body.dark-mode { --anl-sale:#60a5fa; --anl-pur:#fbbf24; --anl-c3:#34d399; --anl-c4:#c084fc; --anl-c5:#f87171; --anl-c6:#22d3ee; }
.anl-tabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; }
.anl-tab { border:1px solid var(--border); background:var(--bg-card); color:var(--text-primary); padding:8px 14px; border-radius:8px; font-weight:600; cursor:pointer; font-size:.88rem; }
.anl-tab.on { background:var(--primary); border-color:var(--primary); color:#fff; }
.anl-subtabs { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:12px; }
.anl-filters { display:flex; flex-direction:column; gap:10px; }
.anl-frow { display:flex; flex-wrap:wrap; gap:10px; align-items:flex-end; }
.anl-fg { display:flex; flex-direction:column; min-width:150px; flex:1 1 150px; max-width:260px; }
.anl-fg .form-label { margin-bottom:4px; }
.anl-firms { display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
.anl-flabel { font-size:.8rem; font-weight:700; color:var(--text-muted); margin-right:2px; }
.anl-chip { display:inline-flex; align-items:center; gap:6px; border:1px solid var(--border); border-radius:999px; padding:4px 10px; font-size:.8rem; cursor:pointer; background:var(--bg-card); }
.anl-chip.on { border-color:var(--primary); background:var(--primary-light, rgba(37,99,235,.08)); font-weight:600; }
.anl-kpis { display:grid; grid-template-columns:repeat(auto-fit, minmax(210px, 1fr)); gap:12px; margin-bottom:16px; }
.anl-kpi { background:var(--bg-card); border:1px solid var(--border); border-radius:12px; padding:14px 16px; min-width:0; }
.anl-klabel { font-size:.78rem; color:var(--text-muted); font-weight:600; }
.anl-kval { font-size:1.35rem; font-weight:800; margin:4px 0 2px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--text-primary); }
.anl-ksub { font-size:.75rem; color:var(--text-muted); }
.anl-up { color:var(--success); font-weight:700; } .anl-down { color:var(--danger); font-weight:700; }
.anl-h { font-weight:700; font-size:.95rem; margin-bottom:10px; color:var(--text-primary); }
.anl-h small { font-weight:500; color:var(--text-muted); font-size:.76rem; margin-left:6px; }
.anl-grid2 { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:16px; margin-bottom:16px; }
.anl-empty { padding:18px; text-align:center; color:var(--text-muted); font-size:.85rem; }
.anl-note { font-size:.74rem; color:var(--text-muted); margin-top:8px; }
.anl-svgwrap { position:relative; width:100%; }
.anl-svg { width:100%; height:auto; display:block; overflow:visible; }
.anl-svg .anl-grid { stroke:var(--border); stroke-width:1; }
.anl-svg .anl-ax { fill:var(--text-muted); font-size:11px; }
.anl-svg .anl-cross { stroke:var(--text-muted); stroke-width:1; stroke-dasharray:3 3; }
.anl-tip { display:none; position:absolute; top:6px; background:var(--bg-card); border:1px solid var(--border); box-shadow:0 6px 18px rgba(0,0,0,.15); border-radius:8px; padding:8px 10px; font-size:.78rem; pointer-events:none; white-space:nowrap; z-index:5; color:var(--text-primary); }
.anl-tip div { margin-top:2px; }
.anl-tip i, .anl-legend i { display:inline-block; width:10px; height:10px; border-radius:3px; margin-right:5px; vertical-align:-1px; }
.anl-legend { display:flex; gap:14px; flex-wrap:wrap; font-size:.8rem; margin-bottom:6px; color:var(--text-secondary, var(--text-primary)); }
.anl-bars { display:flex; flex-direction:column; gap:7px; }
.anl-bar { display:grid; grid-template-columns:minmax(0, 38%) 1fr auto; gap:10px; align-items:center; font-size:.82rem; }
.anl-blabel { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--text-primary); }
.anl-blabel small { color:var(--text-muted); margin-left:6px; font-size:.72rem; }
.anl-btrack { height:10px; background:var(--bg-elevated, rgba(0,0,0,.05)); border-radius:4px; overflow:hidden; }
.anl-bfill { height:100%; border-radius:0 4px 4px 0; }
.anl-bval { font-weight:700; font-variant-numeric:tabular-nums; min-width:64px; text-align:right; color:var(--text-primary); }
.anl-cols { display:flex; gap:3px; align-items:flex-end; }
.anl-col { flex:1; display:flex; flex-direction:column; align-items:center; min-width:0; }
.anl-ctrack { height:90px; width:100%; display:flex; align-items:flex-end; }
.anl-cfill { width:100%; border-radius:4px 4px 0 0; }
.anl-clabel { font-size:.68rem; color:var(--text-muted); margin-top:4px; height:12px; white-space:nowrap; }
.anl-heat td, .anl-heat th { padding:6px 8px !important; font-size:.8rem; }
@media (max-width: 900px) { .anl-grid2 { grid-template-columns:1fr; } }
@media (max-width: 600px) { .anl-fg { max-width:none; flex-basis:45%; } .anl-bar { grid-template-columns:minmax(0, 45%) 1fr auto; } }

/* ===== Shortcut keys on the menu (js/shortkeys.js) ===== */
.nav-item .nav-key { margin-left: auto; padding-left: 14px; font-size: .68rem; font-weight: 600; color: var(--text-muted); font-family: ui-monospace, Consolas, monospace; letter-spacing: .2px; opacity: .85; }
.nav-item .nav-key::before { content: ''; }
.nav-item:hover .nav-key, .nav-item.active .nav-key, .nav-item:focus .nav-key { opacity: 1; }
.nav-group-btn .nav-gkey { display: inline-flex; align-items: center; justify-content: center; min-width: 15px; height: 15px; padding: 0 3px; margin-left: 4px; border-radius: 4px; font-size: .6rem; font-weight: 700; line-height: 1; border: 1px solid var(--border); color: var(--text-muted); background: var(--bg-card); vertical-align: 1px; }
.sidebar.collapsed .nav-key, .sidebar.collapsed .nav-gkey { display: none; }
@media (max-width: 768px) { .nav-item .nav-key, .nav-group-btn .nav-gkey { display: none; } }
/* top menu bar is full: the menu number takes the place of the ▼ */
body:not(.menu-left) .top-header .nav-group-btn:has(.nav-gkey) .nav-caret { display: none; }
body:not(.menu-left) .top-header .nav-group-btn .nav-gkey { border: none; background: none; min-width: 0; padding: 0; margin-left: 3px; font-size: .62rem; opacity: .75; }
body:not(.menu-left) .top-header .nav-group.nav-single > .nav-item .nav-key { display: none; }
