:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  /* Signature Sheet Orange (#E69138) */
  --orange: #e69138;
  --orange-dark: #c26d18;
  --orange-bg: #fff7ed;
  --orange-border: #fed7aa;

  /* Split Guide / Car Colors */
  --guide-bg: #fefce8;
  --guide-border: #fde047;
  --guide-text: #854d0e;

  --car-bg: #f0f9ff;
  --car-border: #bae6fd;
  --car-text: #0369a1;

  /* Semantic */
  --success: #059669;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;

  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;

  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;

  --info: #2563eb;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;

  --purple: #7c3aed;
  --purple-bg: #f5f3ff;
  --purple-border: #ddd6fe;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.16);

  --font-sans: "Plus Jakarta Sans", "IBM Plex Sans Thai", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 5px;
  color: #334155;
}

/* ==================== LOGIN SCREEN ==================== */
.login-overlay {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 15% 15%, rgba(230, 145, 56, 0.14), transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(37, 99, 235, 0.1), transparent 40%),
    #f1f5f9;
}

.login-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.login-brand h2 {
  margin: 0;
  font-size: 19px;
}

.brand-logo.lg {
  width: 48px;
  height: 48px;
  font-size: 18px;
  border-radius: 12px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 10px 16px;
  font-size: 14px;
}

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
}

.login-roles-box {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.login-roles-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.quick-roles {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.quick-role-btn {
  text-align: left;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  font-family: inherit;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  align-items: center;
  transition: all 0.14s ease;
}

.quick-role-btn:hover {
  border-color: var(--orange);
  background: var(--orange-bg);
}

.quick-role-btn small {
  grid-column: 1 / -1;
  color: var(--text-muted);
  font-size: 11.5px;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

.role-admin {
  background: var(--orange-bg);
  color: var(--orange-dark);
  border: 1px solid var(--orange-border);
}

.role-accountant {
  background: var(--info-bg);
  color: var(--info);
  border: 1px solid var(--info-border);
}

.role-viewer {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

/* ==================== TOPBAR ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #e69138, #c2590a);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  display: grid;
  place-items: center;
  letter-spacing: -0.02em;
  box-shadow: 0 3px 10px rgba(230, 145, 56, 0.35);
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.main-tabs {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 10px;
  gap: 4px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

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

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px 4px 5px;
  font-size: 12.5px;
  font-weight: 600;
}

.readonly-banner {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 13px;
}

/* Main Container */
.container {
  max-width: 1560px;
  margin: 0 auto;
  padding: 18px 20px 56px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.14s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-primary {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange-dark);
}
.btn-primary:hover {
  background: var(--orange-dark);
}

.btn-secondary {
  background: #0f172a;
  color: #fff;
}
.btn-secondary:hover {
  background: #1e293b;
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-outline:hover {
  background: var(--surface-muted);
  border-color: #94a3b8;
}

.btn-outline.danger-text {
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn-outline.danger-text:hover {
  background: var(--danger-bg);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: #e2e8f0;
  color: var(--text);
}

.btn-link {
  background: none;
  border: none;
  color: var(--orange-dark);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}
.btn-link:hover {
  text-decoration: underline;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  display: grid;
  place-items: center;
}
.icon-btn:hover {
  background: #f1f5f9;
  color: var(--text);
}

/* Orange Strip */
.orange-strip {
  background: var(--orange-bg);
  border: 1px solid var(--orange-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 14px;
}

.orange-strip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.orange-strip-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.saved-edits-pill {
  font-size: 12px;
  font-weight: 700;
  color: #1d4ed8;
  background: #dbeafe;
  border: 1px solid #93c5fd;
  padding: 2px 10px;
  border-radius: 999px;
}

.orange-strip-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #7c2d12;
}

.orange-dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--orange);
  display: inline-block;
  flex-shrink: 0;
}

.orange-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.orange-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #ffffff;
  border: 1px solid #f5b97a;
  color: #7c2d12;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

.orange-chip b {
  background: var(--orange);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 0 5px;
  border-radius: 4px;
}

.support-chip {
  font-size: 12px;
  color: #9a3412;
  opacity: 0.9;
  margin-left: 4px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.input-card {
  padding: 16px;
  margin-bottom: 16px;
}

.input-card.collapsed .paste-area,
.input-card.collapsed .input-footer {
  display: none;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.muted {
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 3px 0 0;
}

.card-head-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.paste-area {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fcfcfd;
  color: var(--text);
  resize: vertical;
  min-height: 110px;
}

.paste-area:focus {
  outline: 2px solid rgba(230, 145, 56, 0.35);
  border-color: var(--orange);
}

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  gap: 12px;
}

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 4px;
  background: var(--border-strong);
}

.kpi-card.kpi-success::before { background: var(--success); }
.kpi-card.kpi-danger::before { background: var(--danger); }
.kpi-card.kpi-info::before { background: var(--info); }
.kpi-card.kpi-orange::before { background: var(--orange); }
.kpi-card.kpi-purple::before { background: var(--purple); }

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kpi-card.kpi-success .kpi-value { color: var(--success); }
.kpi-card.kpi-danger .kpi-value { color: var(--danger); }
.kpi-card.kpi-info .kpi-value { color: var(--info); }

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: #e2e8f0;
  padding: 3px;
  border-radius: 9px;
}

.seg-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: #475569;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.seg-tag {
  font-size: 10px;
  background: var(--orange-bg);
  color: var(--orange-dark);
  border: 1px solid var(--orange-border);
  padding: 1px 5px;
  border-radius: 4px;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.12s ease;
}

.pill:hover { background: var(--surface-muted); }

.pill.active {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}

.pill.pill-danger.active { background: var(--danger); border-color: var(--danger); }
.pill.pill-success.active { background: var(--success); border-color: var(--success); }
.pill.pill-info.active { background: var(--info); border-color: var(--info); }
.pill.pill-purple.active { background: var(--purple); border-color: var(--purple); }

.pill-count {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.85;
}

.search-input,
.date-input {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-width: 220px;
}

.search-wide { min-width: 300px; }
.date-input { min-width: 150px; }

.date-nav-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.toolbar-lbl {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.date-select {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

/* ==================== CUSTOM CALENDAR PICKER ==================== */
.cal-picker-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.cal-step-btn {
  width: 32px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.12s ease;
}

.cal-step-btn:hover:not(:disabled) {
  border-color: var(--orange);
  background: var(--orange-bg);
  color: var(--orange-dark);
}

.cal-step-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.cal-trigger-btn {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  box-shadow: var(--shadow-sm);
  transition: all 0.14s ease;
}

.cal-trigger-btn:hover,
.cal-trigger-btn.open {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(230, 145, 56, 0.18);
}

.cal-trigger-count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  background: var(--orange-bg);
  color: var(--orange-dark);
  border: 1px solid var(--orange-border);
  padding: 1px 7px;
  border-radius: 999px;
}

.cal-caret {
  color: var(--text-muted);
  font-size: 11px;
}

.cal-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 55;
  width: 344px;
  max-width: 94vw;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
}

.cal-pop-months {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.cal-month-pill {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
}

.cal-month-pill:hover {
  border-color: var(--orange);
  color: var(--orange-dark);
  background: var(--orange-bg);
}

.cal-month-pill.active {
  background: var(--orange);
  border-color: var(--orange-dark);
  color: #fff;
}

.cal-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.cal-pop-head strong {
  font-size: 14.5px;
  color: var(--text);
}

.cal-nav-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.cal-nav-btn:hover {
  background: var(--orange-bg);
  border-color: var(--orange);
  color: var(--orange-dark);
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.cal-weekdays span:first-child { color: #dc2626; }
.cal-weekdays span:last-child { color: #2563eb; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day {
  position: relative;
  height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 2px;
  transition: all 0.12s ease;
}

.cal-day.empty {
  cursor: default;
  pointer-events: none;
}

.cal-day.no-data {
  color: #cbd5e1;
}

.cal-day.has-data {
  background: #fffbf5;
  border-color: #fed7aa;
}

.cal-day.has-data:hover {
  background: #ffedd5;
  border-color: var(--orange);
}

.cal-day.selected {
  background: var(--orange) !important;
  border-color: var(--orange-dark) !important;
  color: #ffffff !important;
  box-shadow: 0 2px 8px rgba(230, 145, 56, 0.38);
}

.cal-day-num {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
}

.cal-day-jobs {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--orange-dark);
  line-height: 1;
}

.cal-day.selected .cal-day-jobs {
  color: #fff7ed;
}

.cal-day-done {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--success);
}

.cal-day.selected .cal-day-done {
  background: #ffffff;
}

.cal-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.cal-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.cal-dot-job {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--orange);
  display: inline-block;
}

.cal-dot-done {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--success);
  display: inline-block;
}

.cal-pop-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 10px;
}

/* ==================== INLINE EXCEL FORMULA BAR & CELLS ==================== */
.inline-fx-bar {
  background: #0f172a;
  color: #f8fafc;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.inline-fx-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.inline-fx-cell-ref {
  font-size: 12px;
  font-family: var(--font-mono);
  color: #93c5fd;
  white-space: nowrap;
}

.inline-fx-input {
  flex: 1;
  min-width: 220px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #ffffff;
}

.inline-fx-input:focus {
  outline: 2px solid rgba(230, 145, 56, 0.55);
  border-color: var(--orange);
}

.inline-fx-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.inline-fx-result {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: #4ade80;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px 10px;
  border-radius: 6px;
  min-width: 82px;
  text-align: right;
}

.inline-fx-result.err {
  color: #f87171;
}

.inline-fx-save-state {
  font-size: 12px;
  font-weight: 600;
  color: #4ade80;
  white-space: nowrap;
}

.inline-fx-save-state.saving { color: #fbbf24; }
.inline-fx-save-state.err { color: #f87171; }

.inline-fx-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.inline-fx-lbl {
  font-size: 11px;
  color: #94a3b8;
}

.inline-fx-sep {
  color: #334155;
  margin: 0 4px;
}

.inline-fx-vars {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
}

.inline-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  cursor: pointer;
}

.inline-chip:hover {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}

.inline-chip.var {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
}

.inline-chip.var:hover {
  background: #0284c7;
  color: #fff;
}

/* Inline Spreadsheet Cell Styling */
.col-edit-head {
  min-width: 155px;
}

.inline-sheet-table td.cell-inline {
  padding: 5px 8px;
  vertical-align: middle;
}

.cell-input-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.cell-input {
  width: 100%;
  min-width: 132px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  transition: all 0.12s ease;
}

.cell-input::placeholder {
  color: #cbd5e1;
  font-weight: 400;
}

.cell-input:hover:not(:disabled) {
  border-color: #94a3b8;
  background: #ffffff;
}

.cell-input:focus {
  outline: 2px solid rgba(230, 145, 56, 0.4);
  border-color: var(--orange);
  background: #ffffff;
}

.cell-input.is-formula {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1e3a8a;
}

.cell-input.has-error {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
}

.cell-input:disabled {
  background: transparent;
  border-color: transparent;
  color: var(--text);
  cursor: default;
}

.cell-meta-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 2px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-height: 15px;
}

.cell-meta-row.err {
  color: var(--danger);
  font-weight: 600;
}

.grand-diff-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  margin-top: 3px;
}

.grand-diff-pill.ok {
  background: var(--success-bg);
  color: var(--success);
}

.grand-diff-pill.diff {
  background: var(--danger-bg);
  color: var(--danger);
}

.data-table th.col-grand-head {
  background: #ecfdf5;
  color: #065f46;
  border-bottom-color: #a7f3d0;
}

.data-table td.cell-grand-inline {
  background: rgba(236, 253, 245, 0.55);
}

.cell-input.grand-input {
  border-color: #6ee7b7;
  background: rgba(255, 255, 255, 0.9);
  color: #065f46;
}

.cell-input.grand-input.is-custom-formula {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1e3a8a;
}

.inline-sheet-table tfoot td {
  background: #0f172a;
  color: #f8fafc;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 10px 12px;
  border-top: 2px solid #334155;
  font-size: 13px;
}

.inline-sheet-table tfoot td.tfoot-label {
  font-family: var(--font-sans);
  color: #cbd5e1;
}

.inline-sheet-table tfoot td.tfoot-grand {
  color: #4ade80;
  font-size: 14px;
}

.search-input:focus,
.date-input:focus,
select:focus,
input[type="text"]:focus,
input[type="password"]:focus {
  outline: 2px solid rgba(230, 145, 56, 0.3);
  border-color: var(--orange);
}

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

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

.data-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  padding: 10px 11px;
  border-bottom: 1px solid var(--border-strong);
  background: #f8fafc;
  color: #334155;
  white-space: nowrap;
}

.data-table th.col-num,
.data-table td.col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.group-header-row th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
}

.th-group-acc {
  background: #fef9c3 !important;
  color: #713f12 !important;
  border-right: 2px solid #e2e8f0;
}

.th-group-orange {
  background: var(--orange) !important;
  color: #ffffff !important;
  border-right: 2px solid #e2e8f0;
}

.th-group-result {
  background: #1e293b !important;
  color: #ffffff !important;
}

.data-table th.col-split-guide {
  background: var(--guide-bg);
  color: var(--guide-text);
  border-bottom-color: var(--guide-border);
}

.data-table th.col-split-car {
  background: var(--car-bg);
  color: var(--car-text);
  border-bottom-color: var(--car-border);
  border-right: 2px solid #e2e8f0;
}

.data-table td.cell-guide {
  background: rgba(254, 252, 232, 0.45);
}

.data-table td.cell-car {
  background: rgba(240, 249, 255, 0.55);
}

.data-table th.col-orange {
  background: #ffedd5;
  color: #7c2d12;
  border-bottom-color: #fdba74;
}

.col-letter {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  background: rgba(124, 45, 18, 0.14);
  color: #7c2d12;
  padding: 0 4px;
  border-radius: 3px;
  margin-left: 3px;
}

.data-table td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.reconcile-table tbody tr {
  cursor: pointer;
  transition: background 0.1s ease;
}

.reconcile-table tbody tr:hover { background: #f8fafc; }

.reconcile-table tbody tr.row-mismatch { background: #fff5f5; }
.reconcile-table tbody tr.row-mismatch:hover { background: #fee2e2; }

.reconcile-table tbody tr.row-missing-acc { background: #f8faff; }

.cell-divider { border-right: 2px solid #e2e8f0; }

.tour-title {
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.sub-line {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.blank-pill {
  display: inline-block;
  font-size: 11px;
  color: var(--text-subtle);
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  padding: 1px 7px;
  border-radius: 5px;
}

.fx-mini {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  background: #dbeafe;
  color: #1d4ed8;
  padding: 0 5px;
  border-radius: 4px;
  margin-left: 4px;
}

.edited-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 700;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  padding: 1px 6px;
  border-radius: 999px;
}

.row-edit-btn {
  margin-top: 5px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.row-edit-btn:hover {
  border-color: var(--orange);
  background: var(--orange-bg);
  color: var(--orange-dark);
}

.transport-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: #e0f2fe;
  color: #0369a1;
}

.transport-tag.ext {
  background: #f1f5f9;
  color: #475569;
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.amt-main {
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 13px;
}

.amt-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.diff-zero { color: var(--success); font-weight: 700; font-family: var(--font-mono); }
.diff-pos { color: var(--danger); font-weight: 700; font-family: var(--font-mono); }
.diff-neg { color: #b91c1c; font-weight: 700; font-family: var(--font-mono); }

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-matched { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.badge-mismatch { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.badge-missing_in_accounting { background: var(--info-bg); color: var(--info); border: 1px solid var(--info-border); }
.badge-missing_in_log { background: var(--purple-bg); color: var(--purple); border: 1px solid var(--purple-border); }

.match-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  max-width: 210px;
  line-height: 1.35;
}

/* Tab 2: Rate Matrix */
.filter-card { padding: 14px 16px; margin-bottom: 16px; }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.field select,
.field input[type="date"],
.field input[type="text"],
.field input[type="password"] {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  padding: 6px 0;
}

.rates-list { display: flex; flex-direction: column; gap: 12px; }

.rate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.rate-card-head {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  background: #fcfcfd;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.rate-card-head:hover { background: #f8fafc; }

.rate-tour-info { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rate-tour-name { font-weight: 700; font-size: 14.5px; }

.round-badge {
  font-size: 11.5px;
  font-weight: 700;
  background: #f1f5f9;
  color: #334155;
  padding: 2px 8px;
  border-radius: 6px;
}

.variance-badge {
  font-size: 11.5px;
  font-weight: 700;
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid var(--warning-border);
  padding: 2px 8px;
  border-radius: 999px;
}

.rate-stats { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.rate-stat { text-align: right; }
.rate-stat-lbl { font-size: 11px; color: var(--text-muted); }
.rate-stat-val { font-family: var(--font-mono); font-weight: 700; font-size: 13.5px; }
.rate-card.collapsed .rate-card-body { display: none; }

.rate-bar-wrap {
  width: 110px;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}

.rate-bar-fill { height: 100%; background: var(--orange); border-radius: 999px; }
.rate-bar-fill.outlier { background: var(--danger); }

/* Raw Table */
.raw-table.hide-extra .extra-col { display: none; }
.raw-table tbody tr { cursor: pointer; }
.raw-table tbody tr:hover { background: #fff7ed; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #fcfcfd;
  font-size: 12.5px;
  color: var(--text-muted);
}

.page-btns { display: flex; gap: 6px; }

/* ==================== SLIDE-OVER DRAWER ==================== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 60;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 95vw);
  background: var(--surface);
  z-index: 70;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}

.drawer.open { transform: translateX(0); }

.drawer-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.drawer-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.drawer-eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--orange-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.drawer-head h3 { margin: 2px 0 0; font-size: 16px; line-height: 1.3; }
.drawer-body { padding: 18px 20px 32px; overflow-y: auto; flex: 1; }
.drawer-section { margin-bottom: 18px; }
.drawer-section h4 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: #334155; }

.compare-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.cbox {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-muted);
}

.cbox.cbox-acc { background: #fefce8; border-color: #fde047; }
.cbox.cbox-orange { background: var(--orange-bg); border-color: var(--orange-border); }

.cbox-title { font-size: 11.5px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.kv-list { display: flex; flex-direction: column; gap: 5px; }
.kv-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.kv-row span:first-child { color: var(--text-muted); }
.kv-row strong { font-family: var(--font-mono); }

.formula-box {
  background: #f1f5f9;
  border-left: 3px solid var(--orange);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  color: #1e293b;
}

.items-mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.items-mini-table th,
.items-mini-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.items-mini-table th { text-align: left; background: #f8fafc; font-size: 11.5px; color: var(--text-muted); }

/* ==================== MODALS & EXCEL FORMULA FORM ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: min(560px, 100%);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.modal.modal-lg {
  width: min(820px, 100%);
}

.modal-head {
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 { margin: 2px 0 0; font-size: 16px; }

.modal-body {
  padding: 18px 20px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-foot-right {
  display: flex;
  gap: 8px;
}

/* Excel Formula Bar */
.fx-bar {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.fx-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.fx-badge {
  font-family: var(--font-mono);
  font-style: italic;
  font-weight: 800;
  font-size: 13px;
  background: var(--orange);
  color: #fff;
  padding: 2px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.fx-target-label {
  font-size: 12.5px;
  color: #cbd5e1;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fx-live-result {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 700;
  color: #4ade80;
  background: rgba(255, 255, 255, 0.08);
  padding: 3px 10px;
  border-radius: 6px;
}

.fx-live-result.err { color: #f87171; }

.fx-chips-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.fx-chips-lbl {
  font-size: 11px;
  color: #94a3b8;
  margin-right: 4px;
}

.fx-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.12s ease;
}

.fx-chip:hover {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}

.fx-chip.var {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
}

.fx-chip.var:hover {
  background: #0284c7;
  color: #fff;
}

/* Edit Form Sections */
.edit-section {
  margin-bottom: 16px;
}

.edit-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  font-size: 13.5px;
}

.edit-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.formula-field-card {
  border-radius: 10px;
  padding: 12px;
  border: 1px solid var(--border);
}

.formula-field-card.guide-card {
  background: var(--guide-bg);
  border-color: var(--guide-border);
}

.formula-field-card.car-card {
  background: var(--car-bg);
  border-color: var(--car-border);
}

.ff-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.ff-head label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
}

.ff-quick-btns {
  display: flex;
  gap: 4px;
}

.mini-btn {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: #fff;
  color: #334155;
  cursor: pointer;
}

.mini-btn:hover { background: #0f172a; color: #fff; }
.mini-btn.warn { color: #b45309; border-color: #fcd34d; }
.mini-btn.warn:hover { background: #d97706; color: #fff; }

.formula-input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}

.ff-preview {
  margin-top: 5px;
  font-size: 12px;
  font-family: var(--font-mono);
  min-height: 18px;
}

.ff-preview.ok { color: var(--success); font-weight: 600; }
.ff-preview.blank { color: var(--text-muted); font-style: italic; }
.ff-preview.err { color: var(--danger); font-weight: 600; }

.extra-table-wrap {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.extra-items-table input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 7px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
}

.extra-items-table input.extra-name-input {
  font-family: var(--font-sans);
}

.edit-live-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
}

.els-box {
  display: flex;
  flex-direction: column;
}

.els-lbl { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.els-val { font-family: var(--font-mono); font-size: 15px; font-weight: 800; }

.edit-audit-line {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  background: #f1f5f9;
  padding: 6px 10px;
  border-radius: 6px;
}

/* User Management Form */
.user-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}

.settings-section h4 { margin: 0 0 4px; font-size: 14px; }
.settings-section .field { margin-top: 10px; }
.settings-actions { margin-top: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.sync-msg { font-size: 12.5px; font-weight: 600; }
.sync-msg.ok { color: var(--success); }
.sync-msg.err { color: var(--danger); }

.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.empty-state { text-align: center; padding: 36px 16px; color: var(--text-muted); }

@media (max-width: 780px) {
  .compare-boxes,
  .edit-grid-2 {
    grid-template-columns: 1fr;
  }
  .search-input, .search-wide {
    min-width: 100%;
  }
}


/* =====================================================================
   UI REFRESH LAYER (v2) — modern, soft, spreadsheet-friendly
   ===================================================================== */
:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-muted: #faf9f7;
  --border: #ebe7e0;
  --border-strong: #d9d3c9;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-subtle: #a8a29e;
  --orange: #ea8a2e;
  --orange-dark: #c2650f;
  --orange-bg: #fff6ec;
  --orange-border: #fcd9b1;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.04), 0 1px 3px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 6px 20px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 24px 60px rgba(28, 25, 23, 0.18);
}

body {
  background:
    radial-gradient(1200px 500px at 0% -10%, rgba(234, 138, 46, 0.09), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(59, 130, 246, 0.05), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

/* ---------- Topbar ---------- */
.topbar {
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid rgba(217, 211, 201, 0.7);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset;
}

.topbar-inner {
  padding: 12px 24px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(140deg, #f5a54a 0%, #ea8a2e 45%, #b8560a 100%);
  box-shadow: 0 6px 16px rgba(234, 138, 46, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.brand-text h1 {
  font-size: 16.5px;
  letter-spacing: -0.01em;
}

.main-tabs {
  background: #efebe5;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}

.tab-btn {
  border-radius: 9px;
  padding: 8px 16px;
  color: #6b635b;
}

.tab-btn.active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08), 0 2px 8px rgba(28, 25, 23, 0.05);
}

.tab-btn.active .tab-icon {
  filter: saturate(1.3);
}

.user-pill {
  background: #ffffff;
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
  padding: 5px 13px 5px 6px;
}

/* ---------- Container ---------- */
.container {
  padding: 22px 24px 64px;
}

/* ---------- Buttons ---------- */
.btn {
  border-radius: 10px;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(180deg, #f09a45 0%, #ea8a2e 100%);
  border-color: #d1741a;
  box-shadow: 0 2px 6px rgba(234, 138, 46, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #ea8a2e 0%, #d97716 100%);
}

.btn-outline {
  background: #ffffff;
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.btn-outline:hover {
  border-color: var(--orange);
  color: var(--orange-dark);
  background: var(--orange-bg);
}

/* ---------- Orange info strip ---------- */
.orange-strip {
  background: linear-gradient(135deg, #fff8ef 0%, #fff3e4 100%);
  border: 1px solid var(--orange-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}

.orange-chip {
  background: rgba(255, 255, 255, 0.9);
  border-color: #f6c592;
  padding: 4px 10px 4px 5px;
  box-shadow: 0 1px 2px rgba(194, 101, 15, 0.08);
}

.orange-chip b {
  border-radius: 6px;
  padding: 1px 6px;
}

/* ---------- KPI cards ---------- */
.kpi-grid {
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  border-radius: var(--radius);
  padding: 16px 18px 15px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card::before {
  top: 0;
  left: 0;
  right: 0;
  bottom: auto;
  width: auto;
  height: 3px;
  border-radius: 16px 16px 0 0;
}

.kpi-card.kpi-orange::before { background: linear-gradient(90deg, #f5a54a, #ea8a2e); }
.kpi-card.kpi-success::before { background: linear-gradient(90deg, #34d399, #059669); }
.kpi-card.kpi-info::before { background: linear-gradient(90deg, #60a5fa, #2563eb); }
.kpi-card.kpi-danger::before { background: linear-gradient(90deg, #f87171, #dc2626); }
.kpi-card.kpi-purple::before { background: linear-gradient(90deg, #a78bfa, #7c3aed); }

.kpi-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #8a8178;
}

.kpi-value {
  font-size: 26px;
  margin: 6px 0 3px;
  color: var(--text);
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Toolbar & pills ---------- */
.toolbar {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

.pill {
  border-color: var(--border);
  background: #ffffff;
  padding: 6px 12px;
}

.pill:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.pill.active {
  background: #1c1917;
  border-color: #1c1917;
  box-shadow: 0 2px 6px rgba(28, 25, 23, 0.2);
}

.pill-count {
  background: rgba(120, 113, 108, 0.12);
  padding: 0 6px;
  border-radius: 999px;
}

.pill.active .pill-count {
  background: rgba(255, 255, 255, 0.2);
}

.search-input {
  border-radius: 10px;
  border-color: var(--border-strong);
  padding: 8px 12px 8px 34px;
  background: #ffffff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a8a29e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 11px center;
}

/* ---------- Calendar trigger ---------- */
.cal-trigger-btn,
.cal-step-btn {
  border-radius: 10px;
  border-color: var(--border-strong);
}

.cal-trigger-btn {
  height: 36px;
  padding: 0 14px;
}

.cal-step-btn {
  height: 36px;
  width: 34px;
}

.cal-popover {
  border-radius: 18px;
  padding: 14px;
  border-color: var(--border);
}

.cal-day {
  border-radius: 10px;
}

/* ---------- Inline formula bar ---------- */
.inline-fx-bar {
  background: linear-gradient(180deg, #1f1b18 0%, #181513 100%);
  border: 1px solid #2c2622;
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(28, 25, 23, 0.18);
}

.inline-fx-input {
  background: #2a2420;
  border-color: #3b332d;
  border-radius: 8px;
  padding: 8px 12px;
}

.inline-fx-result {
  background: rgba(74, 222, 128, 0.1);
  border: 1px solid rgba(74, 222, 128, 0.25);
}

.inline-fx-cell-ref {
  background: rgba(147, 197, 253, 0.1);
  border: 1px solid rgba(147, 197, 253, 0.2);
  padding: 3px 9px;
  border-radius: 6px;
}

/* ---------- Main sheet table ---------- */
.table-card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.inline-sheet-table + * {
  margin: 0;
}

.table-card .table-wrap {
  max-height: 68vh;
  overflow: auto;
}

.data-table th {
  background: #faf8f5;
  color: #57534e;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-strong);
}

.inline-sheet-table thead tr:not(.group-header-row) th {
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 var(--border-strong);
}

.th-group-orange {
  background: linear-gradient(90deg, #ea8a2e 0%, #f5a54a 100%) !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 12.5px !important;
  font-weight: 700;
}

.data-table th.col-orange {
  background: #fff4e6;
  color: #9a4a0b;
  border-bottom-color: #f6c592;
}

.data-table th.col-grand-head {
  background: #eafaf2;
  color: #0b6b47;
  border-bottom-color: #a7e8c8;
}

.col-letter {
  background: rgba(154, 74, 11, 0.1);
  border-radius: 4px;
  padding: 0 5px;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1ede7;
}

.inline-sheet-table tbody tr {
  transition: background 0.1s ease;
}

.inline-sheet-table tbody tr:nth-child(even) {
  background: #fcfbf9;
}

.inline-sheet-table tbody tr:hover {
  background: #fff8ef;
}

.inline-sheet-table tbody tr.row-missing-acc {
  background: #f3fbf7;
}

.inline-sheet-table tbody tr.row-mismatch {
  background: #fff6f5;
}

.inline-sheet-table td.cell-clickable {
  cursor: pointer;
}

.inline-sheet-table td.cell-guide,
.inline-sheet-table td.cell-car,
.inline-sheet-table td.cell-grand-inline {
  background: transparent;
}

.tour-title {
  font-weight: 600;
  font-size: 13px;
  line-height: 1.4;
}

.sub-line {
  font-size: 11px;
}

/* Spreadsheet-like inline cells */
.cell-input {
  border-radius: 8px;
  border: 1px solid transparent;
  background: #f7f4ef;
  padding: 8px 11px;
  font-size: 13.5px;
  box-shadow: inset 0 0 0 1px rgba(217, 211, 201, 0.55);
}

.cell-input::placeholder {
  color: #c9c2b8;
  font-weight: 500;
  font-size: 12px;
}

.cell-input:hover:not(:disabled) {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--border-strong), 0 1px 3px rgba(28, 25, 23, 0.06);
}

.cell-input:focus {
  outline: none;
  background: #ffffff;
  box-shadow: 0 0 0 2px var(--orange), 0 4px 14px rgba(234, 138, 46, 0.18);
}

.cell-input.is-formula {
  background: #eef5ff;
  color: #1e40af;
  box-shadow: inset 0 0 0 1px #bfd6fb;
}

.cell-input.grand-input {
  background: #edfaf3;
  color: #065f46;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px #b4ead0;
}

.cell-input.grand-input:focus {
  box-shadow: 0 0 0 2px #10b981, 0 4px 14px rgba(16, 185, 129, 0.18);
}

.cell-input.grand-input.is-custom-formula {
  background: #eef5ff;
  color: #1e40af;
  box-shadow: inset 0 0 0 1px #bfd6fb;
}

.cell-input.has-error {
  background: #fff1f1;
  color: #b91c1c;
  box-shadow: 0 0 0 2px #f87171;
}

.cell-input:disabled {
  background: transparent;
  box-shadow: none;
}

.cell-meta-row {
  font-size: 10px;
  opacity: 0.85;
}

.fx-mini {
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 4px;
  padding: 0 5px;
}

/* Table footer totals */
.inline-sheet-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: linear-gradient(180deg, #24201c 0%, #1c1917 100%);
  border-top: none;
  padding: 12px;
}

.inline-sheet-table tfoot td.tfoot-grand {
  color: #6ee7b7;
  font-size: 15px;
}

/* Pagination */
.pagination {
  background: #faf8f5;
  border-top: 1px solid var(--border);
  padding: 12px 18px;
}

/* ---------- Badges ---------- */
.badge {
  padding: 3px 10px;
  font-weight: 700;
}

.role-badge {
  padding: 3px 9px;
}

/* ---------- Login ---------- */
.login-overlay {
  background:
    radial-gradient(700px 400px at 10% 10%, rgba(234, 138, 46, 0.18), transparent 60%),
    radial-gradient(700px 400px at 90% 90%, rgba(59, 130, 246, 0.12), transparent 60%),
    linear-gradient(180deg, #f7f4ef 0%, #efeae2 100%);
}

.login-card {
  border-radius: 22px;
  padding: 30px;
  border: 1px solid rgba(217, 211, 201, 0.8);
  box-shadow: 0 30px 80px rgba(28, 25, 23, 0.16);
}

.login-card .field input {
  padding: 10px 12px;
  border-radius: 10px;
}

.quick-role-btn {
  border-radius: 12px;
  padding: 10px 12px;
  background: #faf8f5;
  transition: all 0.15s ease;
}

.quick-role-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ---------- Drawer & modals ---------- */
.drawer {
  border-radius: 20px 0 0 20px;
}

.drawer-backdrop,
.modal-backdrop {
  backdrop-filter: blur(3px);
}

.modal {
  border-radius: 20px;
}

/* ---------- Scrollbars ---------- */
.table-wrap::-webkit-scrollbar,
.drawer-body::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.table-wrap::-webkit-scrollbar-thumb,
.drawer-body::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: #d9d3c9;
  border-radius: 999px;
  border: 2px solid #faf8f5;
}

.table-wrap::-webkit-scrollbar-track {
  background: #faf8f5;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .topbar-inner {
    padding: 10px 14px;
  }
  .container {
    padding: 16px 14px 48px;
  }
  .main-tabs {
    width: 100%;
    overflow-x: auto;
  }
  .tab-btn {
    white-space: nowrap;
  }
  .toolbar {
    padding: 10px;
  }
  .kpi-value {
    font-size: 22px;
  }
}


/* =====================================================================
   FLOATING CALCULATOR / FORMULA PICKER POPOVER
   ===================================================================== */
.cell-calc-trigger {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.cell-calc-trigger:hover {
  border-color: var(--orange);
  background: var(--orange-bg);
  color: var(--orange-dark);
}

.calc-popover {
  position: fixed;
  z-index: 95;
  width: 332px;
  max-width: calc(100vw - 16px);
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(28, 25, 23, 0.24), 0 0 0 1px rgba(255, 255, 255, 0.7) inset;
  padding: 13px;
  user-select: none;
}

.calc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}

.calc-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.calc-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.calc-close-btn {
  width: 26px;
  height: 26px;
  font-size: 12px;
}

.calc-screen {
  background: linear-gradient(180deg, #1f1b18 0%, #171412 100%);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.calc-expr-input {
  width: 100%;
  background: transparent;
  border: none;
  color: #e7e5e4;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  padding: 0 0 4px;
}

.calc-expr-input:focus {
  outline: none;
  color: #ffffff;
}

.calc-result {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 800;
  color: #6ee7b7;
  text-align: right;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.calc-result.err {
  font-size: 12.5px;
  color: #f87171;
  font-weight: 600;
}

.calc-section-lbl {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 6px 0 5px;
}

.calc-presets,
.calc-vars {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.calc-preset-btn {
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--orange-border);
  background: var(--orange-bg);
  color: var(--orange-dark);
  cursor: pointer;
  transition: all 0.12s ease;
}

.calc-preset-btn:hover {
  background: var(--orange);
  border-color: var(--orange-dark);
  color: #ffffff;
}

.calc-var-btn {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  cursor: pointer;
  transition: all 0.12s ease;
}

.calc-var-btn:hover {
  background: #2563eb;
  border-color: #1d4ed8;
  color: #ffffff;
}

.calc-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.calc-key {
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #faf8f5;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.1s ease;
}

.calc-key:hover {
  background: #f1ece4;
  border-color: var(--border-strong);
}

.calc-key:active {
  transform: scale(0.96);
}

.calc-key.fn {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

.calc-key.op {
  background: #f5f3ef;
  color: #57534e;
}

.calc-key.op.accent {
  background: #fff4e6;
  color: var(--orange-dark);
  border-color: var(--orange-border);
  font-size: 16px;
}

.calc-key.op.accent:hover {
  background: var(--orange);
  color: #ffffff;
}

.calc-key.eq {
  font-family: var(--font-sans);
  font-size: 12.5px;
  background: linear-gradient(180deg, #10b981 0%, #059669 100%);
  border-color: #047857;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.28);
}

.calc-key.eq:hover {
  background: linear-gradient(180deg, #059669 0%, #047857 100%);
}

.calc-key.span-2 {
  grid-column: span 2;
}

.calc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--border);
}


/* =====================================================================
   CUSTOM EXPENSE COLUMNS (DYNAMIC)
   ===================================================================== */
.data-table th.col-custom-head {
  background: #f5f3ff;
  color: #5b21b6;
  border-bottom-color: #ddd6fe;
}

.col-head-inner {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}

.col-del-btn {
  border: none;
  background: rgba(109, 40, 217, 0.12);
  color: #5b21b6;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: all 0.12s ease;
}

.col-del-btn:hover {
  background: var(--danger);
  color: #ffffff;
}

.cell-input.custom-col-input {
  background: #faf8ff;
  box-shadow: inset 0 0 0 1px #e4ddfe;
}

.cell-input.custom-col-input:focus {
  background: #ffffff;
  box-shadow: 0 0 0 2px #7c3aed, 0 4px 14px rgba(124, 58, 237, 0.16);
}

.add-col-input-row {
  display: flex;
  gap: 8px;
}

.add-col-input-row input {
  flex: 1;
}

.quick-col-suggestions {
  margin-top: 12px;
}

.quick-col-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.quick-col-chip {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #ddd6fe;
  background: #f5f3ff;
  color: #5b21b6;
  cursor: pointer;
  transition: all 0.12s ease;
}

.quick-col-chip:hover {
  background: #7c3aed;
  border-color: #6d28d9;
  color: #ffffff;
}

.custom-cols-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.custom-col-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: #faf8ff;
  border: 1px solid #e4ddfe;
  border-radius: 10px;
  font-size: 13px;
}

.calc-key.span-3 {
  grid-column: span 3;
}

.exp-short-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  color: #9a4a0b;
  background: #fff4e6;
  border: 1px solid #f6c592;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

/* =====================================================================
   EXCEL-STYLE RIGHT-CLICK CONTEXT MENU FOR INSERTING COLUMNS
   ===================================================================== */
.ctx-menu {
  position: fixed;
  z-index: 100;
  min-width: 230px;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(28, 25, 23, 0.22);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ctx-menu-head {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 5px 10px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 3px;
}

.ctx-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s ease, color 0.1s ease;
}

.ctx-item:hover {
  background: var(--orange-bg);
  color: var(--orange-dark);
}

.ctx-item.danger {
  color: var(--danger);
}

.ctx-item.danger:hover {
  background: var(--danger-bg);
  color: #b91c1c;
}

.ctx-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}
