/* ============================================================
   PAYROLL TAX CALCULATOR — STYLESHEET
   Apple-inspired flat design: clean, minimal, light
============================================================ */

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

:root {
  --brand:      #007AFF;
  --brand-dark: #0062CC;
  --blue:       #007AFF;
  --blue-dark:  #0062CC;
  --blue-light: #F0F5FF;
  --green:      #34C759;
  --green-dark: #28A745;
  --green-bg:   #F0FFF4;
  --red:        #FF3B30;
  --red-bg:     #FFF5F5;
  --orange:     #FF9500;
  --orange-bg:  #FFFBF0;
  --gray-50:    #FAFAFA;
  --gray-100:   #F5F5F7;
  --gray-200:   #E8E8ED;
  --gray-400:   #AEAEB2;
  --gray-600:   #86868B;
  --gray-800:   #1D1D1F;
  --xero-blue:  #13B5EA;
  --shadow:     0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 2px 8px rgba(0,0,0,0.06);
  --radius:     12px;
  --radius-sm:  8px;
  --font:       -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  /* Spacing scale */
  --space-xs:   4px;
  --space-sm:   8px;
  --space-md:   16px;
  --space-lg:   24px;
  --space-xl:   32px;
  /* Min interactive target */
  --min-target: 44px;
  /* Semantic surface tokens — used by dark mode overrides */
  --surface:           #ffffff;
  --surface-secondary: var(--gray-50);
  --surface-elevated:  #ffffff;
  --text-primary:      var(--gray-800);
  --text-secondary:    var(--gray-600);
  --text-muted:        var(--gray-400);
  --border-color:      var(--gray-200);
}

body {
  font-family: var(--font);
  font-size: 14px;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Accessible focus ring for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================================
   HEADER
============================================================ */
.header {
  background: rgba(255,255,255,0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-icon { font-size: 20px; }

.header-title h1 {
  font-size: 17px;
  font-weight: 600;
  color: var(--gray-800);
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.xero-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--gray-100);
  transition: background 0.2s;
}

.xero-status.connected { background: var(--green-bg); color: var(--green-dark); }
.xero-status.disconnected { background: var(--gray-100); color: var(--gray-600); }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--gray-400);
}
.connected .status-dot { background: var(--green); }

/* ============================================================
   CONTAINER
============================================================ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px;
}

/* ============================================================
   BUTTONS
============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  letter-spacing: -0.01em;
  min-height: 36px;
}

.btn:active { transform: scale(0.97); }

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

.btn-secondary { background: var(--gray-200); color: var(--gray-800); }
.btn-secondary:hover { background: #D8D8DC; }

.btn-danger   { background: var(--red); color: #fff; }
.btn-danger:hover   { background: #E0342B; }

.btn-success  { background: var(--green); color: #fff; }
.btn-success:hover  { background: var(--green-dark); }

.btn-ghost {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--gray-200);
}
.btn-ghost:hover { background: var(--blue-light); border-color: var(--blue); }

.btn-xero     { background: var(--xero-blue); color: #fff; }
.btn-xero:hover     { background: #0f9dc9; }

.btn-lg  { padding: 10px 22px; font-size: 15px; }
.btn-sm  { padding: 6px 12px; font-size: 12px; min-height: 32px; }

.btn-calculate {
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  padding: 10px 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.btn-calculate:hover { background: var(--blue-dark); }

/* ============================================================
   CARDS
============================================================ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 0.5px solid var(--border-color);
  margin-bottom: 16px;
}

.card-header {
  padding: 18px 22px 0;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
  letter-spacing: -0.01em;
}

.card-sub {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 14px;
}

.card-footer {
  padding: 14px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 0.5px solid var(--gray-200);
  margin-top: 14px;
}

/* ============================================================
   CONNECT PROMPT
============================================================ */
.connect-prompt {
  text-align: center;
  padding: 60px 40px;
  max-width: 560px;
  margin: 60px auto;
}

.connect-icon { font-size: 48px; margin-bottom: 16px; }

.connect-prompt h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

.connect-prompt p {
  color: var(--gray-600);
  margin-bottom: 20px;
  line-height: 1.6;
  font-size: 15px;
}

.feature-list {
  text-align: left;
  display: inline-block;
  margin-bottom: 24px;
  list-style: none;
}

.feature-list li {
  padding: 3px 0;
  color: var(--gray-600);
  font-size: 14px;
}

/* ============================================================
   TABS
============================================================ */
.tabs {
  display: flex;
  background: var(--gray-100);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 4px;
  gap: 2px;
  margin-bottom: 0;
}

.tab {
  flex: 1;
  padding: 9px 8px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  letter-spacing: -0.01em;
}

.tab:hover { background: rgba(255,255,255,0.6); color: var(--gray-800); }

.tab.active {
  background: #fff;
  color: var(--gray-800);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-content > .card { border-radius: 0 0 var(--radius) var(--radius); padding: 18px 22px 0; }

/* ============================================================
   TABLES
============================================================ */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  background: var(--gray-50);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-600);
  border-bottom: 0.5px solid var(--gray-200);
}

.table td {
  padding: 8px 12px;
  border-bottom: 0.5px solid var(--gray-100);
  vertical-align: middle;
}

.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr:last-child td { border-bottom: none; }

.table tfoot td {
  padding: 9px 12px;
  font-weight: 600;
  background: var(--gray-50);
  border-top: 0.5px solid var(--gray-200);
}

.text-right { text-align: right; }
.total-row { font-weight: 600; }

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-800);
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

/* ============================================================
   ADJUSTMENTS TAB LAYOUT
============================================================ */
.adj-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 0 22px 18px;
}

.adj-section h4 {
  font-size: 13px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.deduction-label { background: var(--red-bg); color: var(--red); }
.addition-label  { background: var(--orange-bg); color: var(--orange); }
.section-label   { display: block; }

/* Per-state adjustment rows */
.state-adj-row {
  display: grid;
  grid-template-columns: 90px 1fr 1fr 1fr 1fr 30px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  padding: 7px 8px;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--gray-200);
}

.state-adj-row select,
.state-adj-row input {
  font-family: var(--font);
  font-size: 12px;
  padding: 5px 8px;
}

.btn-remove {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 16px;
  padding: 2px;
}

/* ============================================================
   RESULTS TAB
============================================================ */
.national-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 14px 22px 18px;
}

.nat-item {
  background: var(--gray-50);
  border: 0.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.nat-item.highlight {
  background: var(--blue-light);
  border-color: rgba(0,122,255,0.15);
}

.nat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.nat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--gray-800);
  letter-spacing: -0.02em;
}

.nat-value.deduction { color: var(--red); }
.nat-value.tax-amount { color: var(--blue); }

/* State result cards */
.state-result-card {
  border: 0.5px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.state-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 0.5px solid var(--gray-200);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.state-result-header:hover { background: var(--gray-50); }

.state-name-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.state-code {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  letter-spacing: 0.02em;
}

.state-full-name {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.state-monthly-tax {
  font-size: 18px;
  font-weight: 600;
  color: var(--blue);
  letter-spacing: -0.02em;
}

.state-monthly-tax.zero { color: var(--gray-400); font-size: 15px; }

.state-result-body {
  padding: 0 16px 4px;
  display: none;
  background: var(--gray-50);
}

.state-result-body.open { display: block; }

.state-breakdown-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 0.5px solid var(--gray-200);
  font-size: 13px;
}

.breakdown-row:last-child { border-bottom: none; }
.breakdown-row.total {
  font-weight: 600;
  background: #fff;
  padding: 7px 8px;
  border-radius: 6px;
  margin-top: 4px;
}
.breakdown-row.tax-row { font-weight: 600; color: var(--blue); }
.breakdown-label { color: var(--gray-600); }
.breakdown-value { font-weight: 500; text-align: right; }

.divider { width: 0.5px; background: var(--gray-200); margin: 0 16px; }

/* Expand toggle arrow */
.expand-arrow { font-size: 11px; color: var(--gray-400); margin-left: 8px; }

/* ============================================================
   CONTRACTORS
============================================================ */
.contractors-row td input,
.contractors-row td select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 13px;
}

/* ============================================================
   EXPORT TAB
============================================================ */
.export-preview {
  background: var(--gray-50);
  border: 0.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px 22px;
}

.export-preview h4 {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

.sheet-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-list li {
  font-size: 13px;
  color: var(--gray-600);
  padding: 8px 12px;
  background: #fff;
  border: 0.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
}

.export-actions { display: flex; gap: 10px; }

/* ============================================================
   UTILITIES
============================================================ */
.hidden { display: none !important; }
.mb-16  { margin-bottom: 16px; }
.mt-16  { margin-top: 16px; }

/* Layout utilities — replace inline styles */
.pad-card          { padding: 0 var(--space-lg) var(--space-md); }
.pad-card-sm       { padding: var(--space-sm) var(--space-lg) var(--space-md); }
.pad-section       { padding: var(--space-md); }
.flex-row          { display: flex; gap: var(--space-sm); flex-wrap: wrap; }
.flex-row-between  { display: flex; justify-content: space-between; align-items: center; }
.flex-center       { display: flex; align-items: center; }
.gap-sm            { gap: var(--space-sm); }
.gap-md            { gap: var(--space-md); }
.grid-2col         { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-xl); }
.text-center       { text-align: center; }
.text-muted        { color: var(--gray-600); }
.font-sm           { font-size: 13px; }
.no-display        { display: none; }

/* Org switcher */
.org-switcher {
  display: none;
  align-items: center;
  gap: 6px;
}
.org-switcher.visible { display: flex; }
.org-switcher label {
  font-size: 12px;
  color: var(--gray-600);
  white-space: nowrap;
  margin-bottom: 0;
}
.org-switcher select {
  height: 36px;
  font-size: 13px;
  padding: 0 var(--space-sm);
  min-width: 180px;
}

/* Detect banner */
.detect-banner {
  background: var(--orange-bg);
  border: 0.5px solid rgba(255,149,0,0.3);
  border-radius: var(--radius);
  padding: 10px var(--space-md);
  margin-bottom: 12px;
  font-size: 13px;
  color: #78350f;
}

/* Directors modal layout */
.directors-modal-inner {
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.directors-modal-desc {
  padding: 12px var(--space-lg) var(--space-xs);
  font-size: 13px;
  color: var(--gray-600);
  border-bottom: 0.5px solid var(--gray-200);
}
.directors-modal-body {
  overflow-y: auto;
  flex: 1;
  padding: var(--space-md) var(--space-lg);
}
.directors-modal-footer {
  padding: 12px var(--space-lg);
  border-top: 0.5px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
}

/* Table checkboxes — meet min target size */
.table input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Responsive table wrapper */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Month pill wrapper */
.month-pill-wrap { margin: 0 var(--space-lg) var(--space-md); }

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

.row-inline {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.row-inline .form-group { flex: 1; min-width: 180px; }

.loading-msg, .empty-msg {
  text-align: center;
  padding: 32px;
  color: var(--gray-400);
  font-size: 14px;
}

.selection-count { font-size: 13px; color: var(--gray-600); }

.hint {
  font-size: 12px;
  color: var(--gray-400);
  line-height: 1.6;
}

.contractor-warning {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--orange-bg);
  border-left: 3px solid var(--orange);
  border-radius: 4px;
  font-size: 12px;
  color: #6b5900;
  line-height: 1.6;
}

/* ============================================================
   LOADING OVERLAY
============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.loading-spinner {
  background: #fff;
  border-radius: 16px;
  padding: 28px 44px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

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

#loadingMsg {
  font-size: 14px;
  color: var(--gray-600);
  font-weight: 500;
}

/* ============================================================
   TOAST NOTIFICATIONS
============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background: var(--gray-800);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.25s ease;
}

.toast.success { background: var(--green-dark); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--orange); }

@keyframes slideIn {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ============================================================
   RESPONSIVE
============================================================ */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; gap: 10px; }
  .national-grid { grid-template-columns: 1fr 1fr; }
  .adj-grid { grid-template-columns: 1fr; }
  .state-breakdown-grid { grid-template-columns: 1fr; }
  .divider { display: none; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .tab { flex: 0 0 auto; min-width: 100px; white-space: nowrap; }
}

/* ============================================================
   BRAND — dynamic colour applied via JS
============================================================ */
.tab.active              { background: #fff; color: var(--gray-800); }
.btn-primary             { background: var(--brand); }
.btn-primary:hover       { background: var(--brand-dark); }
.btn-calculate           { background: var(--brand); }
.btn-calculate:hover     { background: var(--brand-dark); }
.state-code              { background: var(--brand); }
.form-control:focus      { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }
.nat-item.highlight      { background: var(--blue-light); border-color: rgba(0,122,255,0.15); }
.nat-value.tax-amount    { color: var(--brand); }
.state-monthly-tax       { color: var(--brand); }
.breakdown-row.tax-row   { color: var(--brand); }

.jurisdiction-notes {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--orange-bg);
  border-left: 3px solid var(--orange);
  border-radius: 4px;
  font-size: 12px;
  color: #6b5900;
  line-height: 1.5;
}

/* Confidence badges */
.confidence-badge {
  display: inline-block;
  width: 14px;
  height: 14px;
  text-align: center;
  line-height: 14px;
  font-size: 12px;
  border-radius: 50%;
  cursor: help;
}
.confidence-green { color: var(--green); }
.confidence-amber { color: var(--orange); }
.confidence-red   { color: var(--red); }

/* State exemptions section */
.exemptions-grid {
  display: grid;
  gap: 20px;
}
.exemption-item {
  padding: 16px;
  background: var(--gray-50);
  border-radius: 8px;
  border: 1px solid var(--gray-200);
}
.exemption-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.exemption-desc {
  font-size: 12px;
  color: var(--gray-600);
  margin-bottom: 10px;
  line-height: 1.5;
}
.state-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.state-badge.vic { background: #1B3A5C; }
.state-badge.nt  { background: #C25700; }
.state-badge.act { background: #5A2D82; }
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.brand-btn {
  background: var(--brand);
  color: #fff;
}
.brand-btn:hover { opacity: 0.9; }

/* ============================================================
   LOGIN / SETUP AUTH OVERLAY
============================================================ */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.auth-overlay.hidden { display: none !important; }

.auth-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.08);
  padding: 36px 44px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.auth-logo {
  margin-bottom: 8px;
}
.auth-logo img {
  max-height: 48px;
  max-width: 180px;
  object-fit: contain;
}
.auth-logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--brand);
  display: inline-block;
  letter-spacing: -0.02em;
}

.auth-box h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 10px 0 5px;
  color: var(--gray-800);
  letter-spacing: -0.01em;
}

.auth-box p.auth-sub {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 22px;
}

.auth-box .form-group { text-align: left; }

.auth-box .btn-full {
  width: 100%;
  justify-content: center;
  padding: 10px;
  font-size: 15px;
  margin-top: 4px;
}

.auth-switch {
  margin-top: 14px;
  font-size: 13px;
  color: var(--gray-600);
}
.auth-switch a {
  color: var(--brand);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.auth-switch a:hover { text-decoration: underline; }

.auth-error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}
.auth-error.visible { display: block; }

/* ============================================================
   HEADER — brand logo + user pill
============================================================ */
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo img {
  max-height: 32px;
  max-width: 110px;
  object-fit: contain;
}

.header-logo-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--gray-800);
  letter-spacing: -0.02em;
}

.user-pill {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 4px;
  border-radius: 20px;
  background: var(--gray-100);
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-800);
  border: 0.5px solid var(--gray-200);
  transition: background 0.15s;
}

.user-pill:hover { background: var(--gray-200); }
.user-pill:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 0.5px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  min-width: 200px;
  z-index: 300;
  display: none;
  overflow: hidden;
}

.user-dropdown.open { display: block; }

.dropdown-item {
  display: block;
  width: 100%;
  padding: 9px 16px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--gray-800);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  border-bottom: 0.5px solid var(--gray-100);
  transition: background 0.1s;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--gray-50); }
.dropdown-item.danger { color: var(--red); }

.btn-help {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gray-100);
  border: 0.5px solid var(--gray-200);
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.btn-help:hover { background: var(--gray-200); }

/* FY Alert Banner */
.fy-alert {
  background: var(--orange-bg);
  border-bottom: 1px solid rgba(255,149,0,0.2);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #996300;
  gap: 12px;
}
.fy-alert strong { font-weight: 600; }
.fy-alert .btn-sm { background: var(--orange); color: #fff; }

/* ============================================================
   MONTH SELECTOR
============================================================ */
.month-selector-pill {
  background: var(--blue-light);
  border: 0.5px solid rgba(0,122,255,0.12);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.month-selector-pill .form-group {
  margin-bottom: 0;
  flex: 0 0 auto;
  min-width: 130px;
}

.month-selector-pill .period-label-display {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand);
  margin-left: auto;
  letter-spacing: -0.01em;
}

/* ============================================================
   HISTORY TAB
============================================================ */
.history-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 22px;
  border-bottom: 0.5px solid var(--gray-200);
}

.history-toolbar .form-group {
  margin-bottom: 0;
  min-width: 110px;
  flex: 0 0 auto;
}

.history-toolbar .spacer { flex: 1; }

.badge-source {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-source.xero  { background: #E0F5FD; color: #0B7EA3; }
.badge-source.manual { background: var(--orange-bg); color: #996300; }

.history-actions { display: flex; gap: 4px; }
.history-actions .btn-sm { padding: 4px 10px; font-size: 12px; }

/* Reconciliation grid */
.recon-grid {
  overflow-x: auto;
}
.recon-table {
  min-width: 900px;
}
.recon-table th { font-size: 11px; white-space: nowrap; }
.recon-table .missing { color: var(--gray-400); font-style: italic; }
.recon-table .has-data { color: var(--green-dark); font-weight: 600; }
.recon-table .variance-pos { color: var(--green-dark); }
.recon-table .variance-neg { color: var(--red); }

/* ============================================================
   MODAL OVERLAY (shared)
============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}
.modal-overlay.hidden { display: none !important; }

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  width: 90%;
  max-width: 720px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
}

.modal-box.modal-wide { max-width: 960px; }
.modal-box.modal-narrow { max-width: 440px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.btn-modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-400);
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}
.btn-modal-close:hover { color: var(--gray-800); }

/* ============================================================
   SETTINGS TAB
============================================================ */
.settings-section {
  border: 0.5px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.settings-section-header {
  background: var(--gray-50);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 0.5px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-section-body {
  padding: 18px;
}

.rates-table { font-size: 13px; }
.rates-table td input.form-control { padding: 5px 8px; font-size: 13px; }
.rates-table .fy-col { font-weight: 600; color: var(--brand); }

.ai-research-panel {
  border: 0.5px solid rgba(0,122,255,0.15);
  background: var(--blue-light);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-top: 14px;
}

.ai-research-panel h4 { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.ai-research-panel p { font-size: 13px; color: var(--gray-600); margin-bottom: 10px; }

.comparison-table th { font-size: 11px; }
.comparison-table td input { width: 110px; padding: 4px 8px; font-size: 13px; }
.comparison-table .changed { background: var(--orange-bg); }

.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--green-bg);
  color: var(--green-dark);
}

.audit-entry {
  display: flex;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 0.5px solid var(--gray-100);
  font-size: 13px;
}
.audit-time { color: var(--gray-400); white-space: nowrap; font-size: 12px; min-width: 130px; }
.audit-action { font-weight: 600; }
.audit-detail { color: var(--gray-600); font-size: 12px; }

/* ============================================================
   DASHBOARD
============================================================ */
.dashboard-kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi-card {
  background: var(--surface, #fff);
  border: 0.5px solid var(--border-color, var(--gray-200));
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  position: relative;
  overflow: hidden;
}
.kpi-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.10);
  transform: translateY(-1px);
}
/* Brand accent top bar */
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--brand);
  border-radius: var(--radius) var(--radius) 0 0;
}
/* KPI card color variants */
.kpi-card.kpi-danger::before  { background: var(--red); }
.kpi-card.kpi-warning::before { background: var(--orange); }
.kpi-card.kpi-success::before { background: var(--green); }
.kpi-label { font-size: 12px; color: var(--gray-600); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--gray-800); }
.kpi-sub { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* Sparkline */
.kpi-sparkline {
  margin-top: 8px;
  display: flex;
  justify-content: center;
  opacity: 0.65;
}
.kpi-sparkline svg polyline { stroke: var(--brand); }

/* Trend indicator */
.kpi-trend {
  font-size: 11px;
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 3px;
  justify-content: center;
  font-weight: 500;
}
.kpi-trend.up   { color: var(--green-dark); }
.kpi-trend.down { color: var(--red); }
.kpi-trend.flat { color: var(--gray-400); }

.dashboard-row { display: flex; gap: 12px; margin-bottom: 16px; }
.dashboard-row > .card { flex: 1; }

/* CSS-only bar chart */
.bar-chart-bar { background: var(--brand); border-radius: 3px 3px 0 0; min-width: 16px; flex: 1; position: relative; transition: height 0.3s ease; }
.bar-chart-bar:hover { opacity: 0.8; }
.bar-chart-bar .bar-label { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--gray-400); white-space: nowrap; }
.bar-chart-bar .bar-value { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--gray-600); white-space: nowrap; }
.bar-chart-bar.empty { background: var(--gray-100); }

/* Status badges */
.badge-status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-status.draft { background: var(--gray-100); color: var(--gray-600); }
.badge-status.locked { background: var(--orange-bg); color: var(--orange); }
.badge-status.approved { background: var(--green-bg); color: var(--green-dark); }

/* Lodgement status */
.badge-lodgement { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-lodgement.pending { background: var(--gray-100); color: var(--gray-600); }
.badge-lodgement.overdue { background: var(--red-bg); color: var(--red); }
.badge-lodgement.lodged { background: #E3F2FD; color: #1565C0; }
.badge-lodgement.paid { background: var(--green-bg); color: var(--green-dark); }

/* Recalculate prompt */
.recalc-prompt { background: var(--orange-bg); border: 1px solid var(--orange); border-radius: var(--radius-sm); padding: 10px 16px; margin: 12px 0; display: flex; align-items: center; justify-content: space-between; }

/* Dashboard alert */
.dashboard-alert { background: var(--orange-bg); border: 1px solid var(--orange); border-radius: var(--radius); padding: 12px 16px; font-size: 13px; }
.dashboard-alert.error { background: var(--red-bg); border-color: var(--red); }

@media (max-width: 768px) {
  .dashboard-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-row { flex-direction: column; }
}

/* ============================================================
   DIFF HIGHLIGHTS (Ruleset Candidate Comparison)
============================================================ */
.diff-changed { background: #FFF8E1; }
.diff-added   { background: var(--green-bg); color: var(--green-dark); }
.diff-removed { background: var(--red-bg); color: var(--red); text-decoration: line-through; }
.badge        { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; background: var(--gray-100); }
.badge-warn   { background: var(--orange-bg); color: var(--orange); }

/* ============================================================
   RATE MANAGEMENT — Candidate Card (D-02)
============================================================ */

.candidate-card {
  background: var(--surface, #fff);
  border: 0.5px solid var(--border-color, var(--gray-200));
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.candidate-card-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid var(--border-color, var(--gray-200));
  background: var(--surface-secondary, var(--gray-50));
}

.candidate-card-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary, var(--gray-800));
}

.candidate-card-header .candidate-meta {
  font-size: 12px;
  color: var(--text-secondary, var(--gray-600));
  margin-top: 2px;
}

.candidate-card-body {
  padding: 0;
}

.candidate-card-footer {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 0.5px solid var(--border-color, var(--gray-200));
  background: var(--surface-secondary, var(--gray-50));
}

.candidate-actions {
  display: flex;
  gap: 8px;
}

.candidate-hint {
  font-size: 12px;
  color: var(--text-secondary, var(--gray-600));
  padding: 8px 16px;
  font-style: italic;
}

/* Drift warning banner */
.drift-warning {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 16px;
  background: var(--orange-bg, #FFFBF0);
  border-bottom: 0.5px solid rgba(255,149,0,0.25);
  font-size: 13px;
  color: var(--text-primary, var(--gray-800));
}
.drift-warning strong { color: var(--orange); }

/* Approval notes input inside candidate card */
.candidate-notes-row {
  padding: 8px 16px 12px;
  border-top: 0.5px solid var(--border-color, var(--gray-200));
}
.candidate-notes-row label {
  font-size: 12px;
  color: var(--text-secondary, var(--gray-600));
  display: block;
  margin-bottom: 4px;
}

/* Dark mode tint for diff rows */
[data-theme="dark"] .diff-changed { background: rgba(255,204,0,0.12); color: inherit; }
[data-theme="dark"] .diff-added   { background: rgba(52,199,89,0.12); color: var(--green); }
[data-theme="dark"] .diff-removed { background: rgba(255,59,48,0.12); color: var(--red); }

/* ============================================================
   HELP DRAWER (right-side slide-in)
============================================================ */
.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 95vw;
  height: 100%;
  background: var(--surface);
  border-left: 0.5px solid var(--border-color);
  box-shadow: -4px 0 20px rgba(0,0,0,0.08);
  z-index: 1400;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

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

.help-drawer-header {
  padding: 14px 18px;
  border-bottom: 0.5px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--gray-50);
}

.help-drawer-header h3 { font-size: 15px; font-weight: 600; }

.help-drawer-search {
  padding: 10px 18px;
  border-bottom: 0.5px solid var(--gray-200);
}

.help-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 18px 20px;
}

.help-section {
  border-bottom: 0.5px solid var(--gray-100);
  padding: 2px 0;
}

.help-section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.help-section-title:hover { color: var(--brand); }
.help-section-arrow { font-size: 11px; color: var(--gray-400); }

.help-section-body {
  display: none;
  font-size: 13px;
  line-height: 1.7;
  color: var(--gray-600);
  padding-bottom: 10px;
}

.help-section-body.open { display: block; }

.help-section-body h5 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-800);
  margin: 12px 0 5px;
}

.help-section-body ol,
.help-section-body ul {
  padding-left: 18px;
  margin-bottom: 8px;
}

.help-section-body li { margin-bottom: 3px; }

.help-section-body code {
  background: var(--gray-100);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', ui-monospace, monospace;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.2);
  z-index: 1300;
}

/* Help drawer: flow diagram */
.help-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin: 8px 0;
}
.help-flow-step {
  background: var(--brand-bg, #eef2ff);
  color: var(--brand, #4f46e5);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.help-flow-arrow {
  color: var(--gray-300);
  font-size: 13px;
}

/* Help drawer: tip callout */
.help-tip {
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 7px 10px;
  margin: 8px 0;
  border-radius: 0 6px 6px 0;
  font-size: 12px;
  line-height: 1.6;
  color: #92400e;
}

/* Help drawer: example block */
.help-example {
  background: var(--gray-50);
  border: 0.5px solid var(--gray-200);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.6;
}
.help-example-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
  margin-bottom: 3px;
}

/* ============================================================
   SAVE CALCULATION BUTTON (Results tab)
============================================================ */
.save-calc-row {
  padding: 10px 22px;
  background: var(--green-bg);
  border: 0.5px solid rgba(52,199,89,0.2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.save-calc-row p { font-size: 13px; color: var(--green-dark); font-weight: 500; margin: 0; }

/* ============================================================
   COMPLIANCE WARNINGS CARD (Results tab)
============================================================ */
.compliance-warnings-card {
  background: #fff;
  border: 0.5px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}

.compliance-warnings-card.collapsed .compliance-body { display: none; }

.compliance-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--orange-bg);
  border-bottom: 0.5px solid rgba(255,149,0,0.15);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--orange);
  user-select: none;
}

.compliance-header .toggle-icon {
  font-size: 12px;
  color: var(--gray-400);
  transition: transform 0.2s;
}

.compliance-warnings-card.collapsed .toggle-icon { transform: rotate(-90deg); }

.compliance-body {
  padding: 12px 18px;
}

.compliance-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.5;
}

.compliance-item:last-child { margin-bottom: 0; }

.compliance-icon {
  flex-shrink: 0;
  font-size: 14px;
  margin-top: 1px;
}

.compliance-warning {
  background: var(--orange-bg);
  border: 0.5px solid rgba(255,149,0,0.12);
  color: var(--gray-800);
}

.compliance-info {
  background: var(--blue-light);
  border: 0.5px solid rgba(0,122,255,0.1);
  color: var(--gray-800);
}

.compliance-error {
  background: var(--red-bg);
  border: 0.5px solid rgba(255,59,48,0.15);
  color: var(--gray-800);
  font-weight: 500;
}

/* ============================================================
   RESPONSIVE ADDITIONS
============================================================ */
/* ============================================================
   CLICKABLE KPI CARDS
============================================================ */
.kpi-clickable { cursor: pointer; transition: box-shadow 0.15s; }
.kpi-clickable:hover { box-shadow: 0 0 0 2px var(--brand); }

/* ============================================================
   LEGISLATION BAR
============================================================ */
.legislation-bar {
  padding: 8px 16px;
  background: var(--blue-light, #EBF5FF);
  border-radius: var(--radius-sm, 6px);
  font-size: 12px;
  margin-bottom: 12px;
  line-height: 1.8;
}
.legislation-bar-title { font-weight: 600; margin-right: 4px; }
.legislation-bar a { color: var(--brand); text-decoration: none; }
.legislation-bar a:hover { text-decoration: underline; }

/* ============================================================
   HELP SECTION CALLOUTS
============================================================ */
.help-legislation {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--blue-light, #EBF5FF);
  border-radius: var(--radius-sm, 6px);
  font-size: 12px;
}
.help-legislation a { color: var(--brand); text-decoration: none; display: block; padding: 2px 0; }
.help-legislation a:hover { text-decoration: underline; }
.help-mistakes {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--red-bg, #FFF0F0);
  border-radius: var(--radius-sm, 6px);
  font-size: 12px;
}

/* ============================================================
   AI CHAT BUBBLE & PANEL
============================================================ */
.chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 80px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md, 0 2px 8px rgba(0,0,0,0.12));
  z-index: 1100;
  transition: transform 0.15s;
}
.chat-bubble:hover { transform: scale(1.08); }
.chat-bubble-icon { font-size: 20px; }

.chat-panel {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 360px;
  max-width: 90vw;
  max-height: 480px;
  background: #fff;
  border-radius: var(--radius, 8px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-panel.hidden { display: none; }
.chat-panel-header {
  padding: 12px 16px;
  background: var(--brand);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
}
.chat-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
}
.chat-msg {
  padding: 8px 12px;
  border-radius: var(--radius-sm, 6px);
  font-size: 13px;
  line-height: 1.4;
  max-width: 85%;
}
.chat-msg.user { background: var(--blue-light, #EBF5FF); align-self: flex-end; }
.chat-msg.assistant { background: var(--gray-100, #f5f5f7); align-self: flex-start; }
.chat-panel-input {
  padding: 10px 12px;
  border-top: 0.5px solid var(--gray-200, #e5e5e7);
  display: flex;
  gap: 8px;
}
.chat-panel-input .form-control { flex: 1; }

/* ============================================================
   RESPONSIVE ADDITIONS
============================================================ */
@media (max-width: 600px) {
  .auth-box { padding: 24px 18px; }
  .help-drawer { width: 100vw; }
  .month-selector-pill { flex-direction: column; align-items: flex-start; }
  .history-toolbar { flex-direction: column; align-items: flex-start; }
  .chat-panel { width: 100vw; right: 0; bottom: 0; max-height: 60vh; border-radius: var(--radius) var(--radius) 0 0; }
  .chat-bubble { right: 16px; bottom: 16px; }
}

/* ============================================================
   CONSISTENCY PASS — Apple iCloud/Keynote aesthetic (D-03)
   Standardises spacing, typography, and visual weight
   across all tabs.
============================================================ */

/* Consistent card header weight */
.card-header h3,
.card-header h4 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

/* Section spacing inside cards */
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary, var(--gray-600));
  margin-bottom: var(--space-sm);
}

/* Generous row spacing in data tables */
.table th,
.table td {
  padding: 10px 12px;
}

/* Subtle dividers between sections within a card */
.card-section + .card-section {
  border-top: 0.5px solid var(--border-color, var(--gray-200));
  margin-top: var(--space-md);
  padding-top: var(--space-md);
}

/* Form groups consistent spacing */
.form-group { margin-bottom: var(--space-md); }
.form-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary, var(--gray-600));
  display: block;
  margin-bottom: 6px;
}

/* Minimum touch target on interactive elements */
.btn, input[type="text"], input[type="password"],
input[type="email"], input[type="number"],
select, textarea {
  min-height: var(--min-target, 44px);
}

/* Exception for compact-sized buttons in tables */
.btn.btn-sm { min-height: 32px; }

/* Badge refinement — consistent padding and weight */
.badge-status, .badge-lodgement, .badge-source {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 6px;
  letter-spacing: 0.01em;
}

/* Header visual hierarchy */
.header-actions { gap: var(--space-md); }

/* Tab navigation active state — stronger visual cue */
.tab-btn.active {
  font-weight: 600;
}

/* Reduce orphaned whitespace in empty-state messages */
.empty-state, [class$="-empty"] {
  padding: var(--space-xl) var(--space-lg);
  text-align: center;
  color: var(--text-muted, var(--gray-400));
  font-size: 13px;
}

/* ============================================================
   DARK MODE — Apple system dark palette
   Activated by [data-theme="dark"] on <html> (manual toggle)
   or @media prefers-color-scheme: dark (system preference)
============================================================ */

[data-theme="dark"] {
  /* Surface colours */
  --surface:           #1C1C1E;
  --surface-secondary: #2C2C2E;
  --surface-elevated:  #3A3A3C;
  /* Text */
  --text-primary:      #F2F2F7;
  --text-secondary:    #AEAEB2;
  --text-muted:        #636366;
  /* Borders & shadows */
  --border-color:      #38383A;
  --shadow:            0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:         0 2px 8px rgba(0,0,0,0.4);
  /* Gray scale remapped to dark equivalents */
  --gray-50:    #1C1C1E;
  --gray-100:   #2C2C2E;
  --gray-200:   #38383A;
  --gray-400:   #636366;
  --gray-600:   #AEAEB2;
  --gray-800:   #F2F2F7;
  /* Semantic colours unchanged — keep brand, green, red, orange */
  /* Background */
  background: #000000;
}

[data-theme="dark"] body {
  background: #000000;
  color: var(--text-primary);
}

/* Tint semantic colour backgrounds for dark mode */
[data-theme="dark"] .green-bg,
[data-theme="dark"] [style*="--green-bg"] { background: rgba(52,199,89,0.15); }
[data-theme="dark"] .red-bg    { background: rgba(255,59,48,0.15); }
[data-theme="dark"] .orange-bg { background: rgba(255,149,0,0.15); }

/* Input fields in dark mode */
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: var(--surface-secondary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

/* Tables */
[data-theme="dark"] .table th {
  background: var(--surface-secondary);
  color: var(--text-secondary);
}

/* System preference fallback — only applies when no manual override */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface:           #1C1C1E;
    --surface-secondary: #2C2C2E;
    --surface-elevated:  #3A3A3C;
    --text-primary:      #F2F2F7;
    --text-secondary:    #AEAEB2;
    --text-muted:        #636366;
    --border-color:      #38383A;
    --shadow:            0 1px 2px rgba(0,0,0,0.3);
    --shadow-md:         0 2px 8px rgba(0,0,0,0.4);
    --gray-50:    #1C1C1E;
    --gray-100:   #2C2C2E;
    --gray-200:   #38383A;
    --gray-400:   #636366;
    --gray-600:   #AEAEB2;
    --gray-800:   #F2F2F7;
  }
  :root:not([data-theme="light"]) body {
    background: #000000;
    color: var(--text-primary);
  }
}
