/* TempusGuard — global stylesheet
   Bootstrap 5.3.2 is loaded via CDN before this file. */

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --tg-navy:        #1e3358;
  --tg-navy-dark:   #152743;
  --tg-navy-hover:  #253f6b;
  --tg-gold:        #b8952a;
  --tg-gold-lt:     #fdf3dc;
  --tg-sidebar-w:   240px;
  --tg-topbar-h:    56px;

  --bs-body-font-family: 'Segoe UI', system-ui, sans-serif;
  --bs-body-color:        #1a2332;
}

body {
  background: #f0f2f5;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.tg-sidebar {
  width: var(--tg-sidebar-w);
  background: var(--tg-navy);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.tg-sidebar .brand {
  padding: 16px 20px;
  border-bottom: 1px solid #2a4a78;
}
.tg-sidebar .brand h5 {
  color: #fff;
  font-weight: 700;
  margin: 0;
  font-size: 18px;
}
.tg-sidebar .brand small {
  color: var(--tg-gold);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.tg-sidebar .nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #5a7a9a;
  padding: 14px 20px 4px;
}

.tg-sidebar .nav-link {
  color: #a8c4e0;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  border-left: 3px solid transparent;
  border-radius: 0;
  transition: background .15s, color .15s;
}
.tg-sidebar .nav-link:hover {
  background: var(--tg-navy-hover);
  color: #fff;
}
.tg-sidebar .nav-link.active {
  background: var(--tg-navy-hover);
  color: #fff;
  border-left-color: var(--tg-gold);
}
.tg-sidebar .nav-link i {
  width: 16px;
  text-align: center;
  opacity: .8;
  flex-shrink: 0;
}

.tg-sidebar .quick-actions {
  padding: 14px 16px;
  border-top: 1px solid #2a4a78;
  margin-top: auto;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.tg-topbar {
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  padding: 0 24px;
  height: var(--tg-topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-left: var(--tg-sidebar-w);
  position: sticky;
  top: 0;
  z-index: 99;
}
.tg-topbar .breadcrumb {
  margin: 0;
  padding: 0;
  background: none;
  font-size: 13px;
}

/* ── Main content area ───────────────────────────────────────────────────── */
.tg-main {
  margin-left: var(--tg-sidebar-w);
  padding: 24px;
}

/* Auth pages — no sidebar/topbar */
.layout-auth .tg-sidebar,
.layout-auth .tg-topbar {
  display: none;
}
.layout-auth .tg-main {
  margin-left: 0;
  padding: 0;
}

/* ── Forms & tabs ────────────────────────────────────────────────────────── */
/* App-wide 13px baseline for form fields and tab labels — Bootstrap's default
   is 16px, which is what made pages like Settings look out of step with the
   denser 13px/12px sizing already used for tables, filter selects, and row
   action buttons. This had already been done ad hoc via one-off inline
   font-size styles on some pages (e.g. the login form) and never on others;
   consolidated into one rule so it's automatic everywhere, including future
   forms, rather than something to remember to add per page. */
.form-label,
.form-control,
.form-select,
textarea.form-control,
.form-check-label,
.input-group-text,
.nav-tabs .nav-link,
.dropdown-item {
  font-size: 13px;
}

/* Primary form-submit / confirm button (Save Changes, Save Draft, Create
   Batch, wizard step Continue, Connect to QuickBooks, etc.) — distinct role
   from .btn-page-action (page-header CTA) and .btn-row-action (per-row table
   action), both already sized on their own. Bare .btn-primary/.btn-success
   now only ever mean "the one main action to complete this form/step", so a
   blanket rule matches them to the 13px form fields they sit directly
   beneath without needing to touch every view individually. */
.btn-primary,
.btn-success {
  font-size: 13px;
}

/* Upload page mode toggle (Assign Automatically / Choose an Estate) — matches
   the 13px form fields it sits above. */
.upload-mode-toggle .btn {
  font-size: 13px;
}

/* Estate-assign modal candidate cards — on hover, swap the descriptive
   ward-name/match-reason text (illegible against the darker hover background
   Bootstrap's own .btn-outline-secondary:hover applies) for a clear white
   "Assign invoice to X" call to action. */
.candidate-pick .candidate-hover-label {
  display: none;
}
.candidate-pick:hover .candidate-info {
  display: none;
}
.candidate-pick:hover .candidate-hover-label {
  display: block;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.tg-card {
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e9ecef;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.tg-card-header {
  padding: 14px 20px;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tg-card-header h6 {
  font-weight: 600;
  color: #1a2332;
  margin: 0;
  font-size: 14px;
}
.tg-card-body {
  padding: 20px;
}

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: 6px;
  padding: 20px;
  border-left: 4px solid #dee2e6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .07);
}
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #1a2332;
}
.stat-card .stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6c757d;
  margin-top: 2px;
}
.stat-card .stat-sub {
  font-size: 12px;
  color: #6c757d;
  margin-top: 6px;
}
.stat-card.border-primary { border-left-color: #0d6efd; }
.stat-card.border-warning  { border-left-color: #ffc107; }
.stat-card.border-success  { border-left-color: #198754; }
.stat-card.border-danger   { border-left-color: #dc3545; }
.stat-card.border-info     { border-left-color: #0dcaf0; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.tg-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6c757d;
  font-weight: 600;
  background: #f8f9fa;
  border-top: none;
}
.tg-table td {
  font-size: 13px;
  vertical-align: middle;
  color: #343a40;
}
.tg-table tbody tr:hover td {
  background: #f8f9fa;
}
.btn-row-action {
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}
.filter-select {
  font-size: 13px;
}

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge-needs-review { background: #cce5ff; color: #004085; }
.badge-approved     { background: #d4edda; color: #155724; }
.badge-on-hold      { background: #fff3cd; color: #856404; }
.badge-paid         { background: #e2e3e5; color: #383d41; }
.badge-partial      { background: #fde8d0; color: #7d3c07; }
.badge-exported     { background: #d1ecf1; color: #0c5460; }
.badge-duplicate    { background: #f8d7da; color: #721c24; }
.badge-cancelled    { background: #e2e3e5; color: #383d41; }
.badge-queued       { background: #d1ecf1; color: #0c5460; }
.badge-processing   { background: #cce5ff; color: #004085; }
.badge-high-pri     { background: #f8d7da; color: #721c24; }
.badge-med-pri      { background: #fff3cd; color: #856404; }
.badge-low-pri      { background: #d4edda; color: #155724; }

/* ── OCR confidence indicators ───────────────────────────────────────────── */
.conf-high { color: #198754; font-size: 11px; font-weight: 600; }
.conf-med  { color: #ffc107; font-size: 11px; font-weight: 600; }
.conf-low  { color: #dc3545; font-size: 11px; font-weight: 600; }
.field-low { border-color: #dc3545 !important; background: #fff8f8; }
.field-med { border-color: #ffc107 !important; }

/* ── Upload drop zone ────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed #adb5bd;
  border-radius: 8px;
  padding: 48px 20px;
  text-align: center;
  background: #f8f9fa;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-zone:hover,
.upload-zone.dragover {
  border-color: #0d6efd;
  background: #f0f7ff;
}
.upload-zone i {
  font-size: 36px;
  color: #adb5bd;
  margin-bottom: 12px;
  display: block;
}

/* ── Wizard steps ────────────────────────────────────────────────────────── */
.wizard-steps { display: flex; align-items: center; margin-bottom: 28px; }
.wizard-step  { display: flex; flex-direction: column; align-items: center;
  gap: 6px; flex: 1; position: relative; }
.wizard-step:not(:last-child)::after {
  content: ''; position: absolute; top: 16px; left: 60%;
  width: 80%; height: 2px; background: #dee2e6; z-index: 0;
}
.wizard-step.completed:not(:last-child)::after { background: #198754; }
.step-circle {
  width: 32px; height: 32px; border-radius: 50%; background: #dee2e6;
  color: #6c757d; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; z-index: 1;
}
.wizard-step.active    .step-circle { background: #0d6efd; color: #fff; }
.wizard-step.completed .step-circle { background: #198754; color: #fff; }
.step-label { font-size: 11px; color: #6c757d; font-weight: 500; }
.wizard-step.active    .step-label { color: #0d6efd; font-weight: 600; }
.wizard-step.completed .step-label { color: #198754; }

/* ── Split-screen invoice review ─────────────────────────────────────────── */
.split-review {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  height: calc(100vh - 160px);
  min-height: 600px;
}
.split-left {
  border-right: 1px solid #dee2e6;
  background: #f8f9fa;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.split-right  { overflow-y: auto; }
.split-toolbar {
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  display: flex;
  align-items: center;
  gap: 6px;
}
.doc-preview {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.doc-page {
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .15);
  width: 100%;
  max-width: 480px;
  min-height: 640px;
  padding: 24px;
  border-radius: 2px;
}

/* ── Activity feed ───────────────────────────────────────────────────────── */
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #f0f2f5;
  font-size: 13px;
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.activity-meta { font-size: 11px; color: #6c757d; margin-top: 2px; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--tg-navy) 0%, #2c5282 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  border-radius: 8px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon {
  width: 52px;
  height: 52px;
  background: var(--tg-navy);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}
.login-logo .logo-icon i { color: var(--tg-gold); font-size: 22px; }

/* ── Toast notifications ─────────────────────────────────────────────────── */
.tg-toast-container {
  position: fixed;
  top: calc(var(--tg-topbar-h) + 12px);
  right: 16px;
  z-index: 1090;
  min-width: 280px;
}

/* ── Typography helpers ──────────────────────────────────────────────────── */
.page-title { font-size: 22px; font-weight: 700; color: #1a2332; margin-bottom: 2px; }
.page-sub   { color: #6c757d; font-size: 13px; }
.section-divider {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6c757d;
  font-weight: 600;
  padding-bottom: 8px;
  border-bottom: 1px solid #dee2e6;
  margin-bottom: 16px;
}

/* ── BS5 btn-block replacement ───────────────────────────────────────────── */
.btn-block-wrap { display: grid; }

/* ── Page-header primary action button ───────────────────────────────────── */
/* Used for the single CTA opposite a page-title (Upload Invoice, New Estate,
   Add Vendor, Invite User, etc.) — pair with the Bootstrap `btn btn-sm`
   classes for sizing so it always matches, rather than repeating the navy
   color as an inline style (and risking a page forgetting `btn-sm`, which is
   how these drifted out of sync in the first place). */
.btn-page-action {
  background: var(--tg-navy);
  border-color: var(--tg-navy);
  color: #fff;
}
.btn-page-action:hover,
.btn-page-action:focus {
  background: var(--tg-navy-hover);
  border-color: var(--tg-navy-hover);
  color: #fff;
}

/* ── Sidebar backdrop (mobile overlay) ───────────────────────────────────── */
.sidebar-backdrop {
  display: none;          /* hidden on desktop */
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 1039;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

/* ── Responsive — below Bootstrap lg breakpoint (< 992px) ────────────────── */
@media (max-width: 991.98px) {
  /* Sidebar slides in from the left as an overlay */
  .tg-sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease-in-out;
    z-index: 1040;
  }
  .tg-sidebar.show {
    transform: translateX(0);
  }

  /* Backdrop activates on mobile when sidebar is open */
  .sidebar-backdrop {
    display: block;
  }
  .sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* Topbar and main no longer need to clear the sidebar */
  .tg-topbar {
    margin-left: 0;
    padding: 0 14px;
  }
  .tg-main {
    margin-left: 0;
    padding: 16px;
  }

  /* Breadcrumbs — clip long paths on small screens */
  .tg-topbar .breadcrumb {
    max-width: 240px;
    overflow: hidden;
    white-space: nowrap;
    display: block;
    text-overflow: ellipsis;
  }
}

/* ── Responsive — small phones (< 576px) ─────────────────────────────────── */
@media (max-width: 575.98px) {
  .tg-main { padding: 12px; }
  .page-title { font-size: 18px; }

  /* Login card fills the screen */
  .login-card { padding: 28px 20px; }

  /* Invoice split-review: stack panels */
  .split-review {
    grid-template-columns: 1fr;
    height: auto;
  }
  .split-left {
    height: 50vh;
    min-height: 320px;
    border-right: none;
    border-bottom: 1px solid #dee2e6;
  }
  .split-right { overflow-y: visible; }
}
