/* Atlas — Brand CSS */
:root {
  --atlas-navy: #081330;
  --atlas-blue: #2563EB;
  --atlas-sky: #38BDF8;
  --atlas-teal: #10B981;
  --atlas-light: #F8FAFC;
  --atlas-sidebar-width: 240px;
}

/* Satoshi font fallback stack */
body {
  font-family: 'Satoshi', 'Inter', 'Segoe UI', system-ui, sans-serif;
}

/* ─── Sidebar ─────────────────────────────────────────── */
.atlas-sidebar {
  width: var(--atlas-sidebar-width);
  min-height: 100vh;
  background-color: var(--atlas-navy);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.atlas-sidebar .brand {
  padding: 1rem 1rem 1rem 0.85rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.atlas-sidebar .brand-icon {
  height: 36px;
  width: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.atlas-sidebar .brand-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.atlas-sidebar .nav-link {
  color: rgba(255,255,255,0.65);
  padding: 0.55rem 1rem;
  border-radius: 6px;
  margin: 2px 8px;
  font-size: 0.875rem;
  transition: all 0.15s;
}

.atlas-sidebar .nav-link:hover,
.atlas-sidebar .nav-link.active {
  color: #fff;
  background-color: rgba(56, 189, 248, 0.15);
}

.atlas-sidebar .nav-link.active {
  border-left: 3px solid var(--atlas-sky);
  padding-left: calc(1rem - 3px);
}

.atlas-sidebar .nav-link i {
  width: 20px;
  margin-right: 8px;
  color: var(--atlas-sky);
  opacity: 0.7;
}

.atlas-sidebar .nav-link:hover i,
.atlas-sidebar .nav-link.active i {
  opacity: 1;
}

/* ─── Main content ─────────────────────────────────────── */
.atlas-main {
  margin-left: var(--atlas-sidebar-width);
  min-height: 100vh;
}

/* ─── Topbar ───────────────────────────────────────────── */
.atlas-topbar {
  background-color: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.atlas-topbar .page-title {
  font-weight: 600;
  font-size: 1rem;
  margin: 0;
}

/* ─── Dashboard tiles ──────────────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem;
  padding: 1.5rem;
}

.tile-card {
  border-radius: 12px;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
}

.tile-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(8,19,48,0.12);
  text-decoration: none;
}

.tile-card i {
  font-size: 2rem;
  color: var(--atlas-sky);
}

.tile-card .tile-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--bs-body-color);
}

.tile-card.placeholder-tile i {
  color: var(--bs-secondary-color);
  opacity: 0.5;
}

/* Wrapper so the favourite star can sit over the tile without being nested
   inside the <a> (a button inside a link is invalid and breaks keyboard use). */
.tile-card-wrap {
  position: relative;
  display: flex;
}

.tile-card-wrap > .tile-card {
  flex: 1 1 auto;
}

.tile-fav {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 2;
  border: 0;
  background: transparent;
  padding: 0.15rem 0.3rem;
  line-height: 1;
  border-radius: 6px;
  color: var(--bs-secondary-color);
  /* Hidden until the tile is hovered, so an unstarred grid stays clean. */
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.tile-fav i { font-size: 1rem; }

.tile-card-wrap:hover .tile-fav,
.tile-fav:focus-visible,
.tile-fav.is-fav {
  opacity: 1;
}

.tile-fav:hover { color: #f59e0b; }
.tile-fav.is-fav { color: #f59e0b; }
.tile-fav:disabled { cursor: default; }

/* ─── Dark mode ────────────────────────────────────────── */
[data-bs-theme="dark"] .atlas-sidebar {
  border-right: 1px solid rgba(255,255,255,0.05);
}

[data-bs-theme="dark"] .tile-card:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* ─── Tables ───────────────────────────────────────────── */
.table-responsive {
  border-radius: 8px;
  overflow: hidden;
}

/* ─── Forms ────────────────────────────────────────────── */
.form-section {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.form-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--atlas-sky);
  margin-bottom: 1rem;
}

/* ─── Item rows ────────────────────────────────────────── */
.item-row {
  border: 1px solid var(--bs-border-color);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  position: relative;
  background: var(--bs-body-bg);
}

.item-row .remove-item {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}

/* ─── Status badges ────────────────────────────────────── */
.badge-paid { background-color: var(--atlas-teal); }
.badge-not_paid { background-color: #ef4444; }
.badge-partially_paid { background-color: #f59e0b; }

/* ─── Auth layout — split panel ────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
}

/* Left: brand visual panel */
.auth-brand-panel {
  flex: 0 0 46%;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* Visual.png fills the panel */
.auth-visual-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center top;
}

/* Overlay: fades visual edges into background */
.auth-visual-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to right, transparent 30%, var(--bs-body-bg, #F8FAFC) 100%),
    linear-gradient(to left, transparent 85%, var(--bs-body-bg, #F8FAFC) 100%);
}

/* Logo + wordmark centered on the visual */
.auth-brand-content {
  position: relative;
  z-index: 2;
  text-align: center;
  padding-top: 3rem;
}

.auth-brand-icon {
  width: 88px;
  height: 88px;
  border-radius: 20px;
  object-fit: contain;
  margin-bottom: 1.25rem;
}

.auth-brand-wordmark {
  font-family: 'Satoshi', 'Inter', system-ui, sans-serif;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #fff;
  line-height: 1;
  text-shadow: 0 2px 12px rgba(8,19,48,0.5);
}

.auth-brand-tagline {
  margin-top: 0.65rem;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.05em;
  text-shadow: 0 1px 6px rgba(8,19,48,0.6);
}

/* Right: form panel */
.auth-form-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-body-bg, #F8FAFC);
  padding: 2rem;
  min-height: 100vh;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  height: 56px;
  width: 56px;
  border-radius: 12px;
  object-fit: contain;
}

@media (max-width: 991px) {
  .auth-brand-panel { display: none; }
  .auth-form-panel { padding: 2.5rem 1.5rem; }
}

/* ─── Under construction ───────────────────────────────── */
.construction-icon {
  font-size: 4rem;
  color: var(--atlas-sky);
}

/* ─── Computed fields ──────────────────────────────────── */
.computed-field {
  background-color: var(--bs-secondary-bg) !important;
  color: var(--bs-secondary-color) !important;
}

/* ─── Responsive sidebar ───────────────────────────────── */
@media (max-width: 768px) {
  .atlas-sidebar {
    transform: translateX(-100%);
  }
  .atlas-sidebar.show {
    transform: translateX(0);
  }
  .atlas-main {
    margin-left: 0;
  }
}

/* ═══ Analytics / reports ═══════════════════════════════════════════════════
 *
 * The chart palette. Both modes are *selected*, not flipped: the dark column is
 * the same three hues re-stepped for the dark surface. The set was checked with
 * the data-viz validator against Atlas's own surfaces (#fff / #212529) and
 * clears the lightness band, chroma floor, colour-vision separation (worst
 * all-pairs deutan dE 9.2 light / 9.4 dark) and the normal-vision floor.
 *
 * Slot 3 sits below 3:1 contrast on white, which is allowed only with relief —
 * every chart on these screens ships the same figures as a data table beneath
 * it, which is that relief. Do not use slot 3 without one.
 *
 * Status colours (ok/warn/serious/bad) are reserved for the aging buckets,
 * where the colour *means* good-to-bad, and always ride a written label. They
 * are never used as a fourth series.
 */
:root {
  --viz-1: #2563EB;
  --viz-2: #eb6834;
  --viz-3: #1baf7a;
  --viz-ok: #0ca30c;
  --viz-warn: #fab219;
  --viz-serious: #ec835a;
  --viz-bad: #d03b3b;
  --viz-unknown: #898781;
  --viz-surface: #ffffff;
  --viz-grid: #e9e9e4;
  --viz-axis: #c3c2b7;
  --viz-muted: #6c757d;
  --viz-ink: #0b0b0b;
}
[data-bs-theme="dark"] {
  --viz-1: #3987e5;
  --viz-2: #d95926;
  --viz-3: #199e70;
  --viz-surface: #212529;
  --viz-grid: #2f3439;
  --viz-axis: #454b51;
  --viz-muted: #9aa0a6;
  --viz-ink: #ffffff;
}

/* ─── Filter row ───────────────────────────────────────── */
/* One row above everything it scopes — never a filter inside a chart card. */
.report-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
}
.report-toolbar .tb-group { display: flex; flex-direction: column; gap: 0.2rem; }
.report-toolbar .tb-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bs-secondary-color);
  margin: 0;
}
.report-toolbar .form-select, .report-toolbar .form-control { min-width: 8.5rem; }
.report-toolbar .tb-spacer { margin-left: auto; }

/* ─── Stat tiles ───────────────────────────────────────── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.9rem 1rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
}
a.stat-tile:hover { border-color: var(--atlas-blue); }
.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bs-secondary-color);
}
/* Proportional figures: tabular-nums makes a standalone number look loose. */
.stat-value { font-size: 1.55rem; font-weight: 600; line-height: 1.2; }
.stat-unit { font-size: 0.8rem; font-weight: 500; color: var(--bs-secondary-color); margin-left: 0.25rem; }
.stat-sub, .stat-delta-note { font-size: 0.72rem; color: var(--bs-secondary-color); }
.stat-delta { font-size: 0.78rem; color: var(--bs-secondary-color); }
.stat-delta.is-good { color: var(--viz-ok); }
.stat-delta.is-bad { color: var(--viz-bad); }
.stat-tile.tone-ok .stat-value { color: var(--viz-ok); }
.stat-tile.tone-warn .stat-value { color: var(--viz-serious); }
.stat-tile.tone-bad .stat-value { color: var(--viz-bad); }

/* ─── Chart blocks ─────────────────────────────────────── */
.chart-block {
  margin: 0 0 1.25rem;
  padding: 1rem 1.1rem 0.75rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
}
.chart-block figcaption { margin-bottom: 0.75rem; }
.chart-title { font-weight: 600; font-size: 0.95rem; }
.chart-subtitle { display: block; font-size: 0.78rem; color: var(--bs-secondary-color); }
/* Sized to include the axis band, so the card never grows a nested scrollbar. */
.chart-canvas { position: relative; }
.chart-table { margin-top: 0.5rem; border-top: 1px solid var(--bs-border-color); }
.chart-table > summary {
  cursor: pointer;
  padding: 0.5rem 0;
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
}
.chart-table > summary:hover { color: var(--bs-body-color); }

/* ─── Report tables ────────────────────────────────────── */
/* Columns of figures align, so these DO get tabular figures. */
.report-table .num, .report-table td.num, .report-table th.num {
  font-variant-numeric: tabular-nums;
}
.report-table thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--bs-secondary-color);
  font-weight: 600;
  border-bottom: 1px solid var(--bs-border-color);
}
.report-table tfoot th {
  border-top: 2px solid var(--bs-border-color);
  font-size: 0.85rem;
}
.report-table td.is-zero { color: var(--bs-tertiary-color, #adb5bd); }

.share-col { width: 12rem; white-space: nowrap; }
.share-bar {
  display: inline-block;
  width: 7.5rem;
  height: 6px;
  border-radius: 3px;
  background: var(--bs-secondary-bg);
  overflow: hidden;
  vertical-align: middle;
}
.share-fill { display: block; height: 100%; background: var(--viz-1); border-radius: 3px; }
.share-pct { font-size: 0.75rem; color: var(--bs-secondary-color); margin-left: 0.5rem; }

.pivot-table .sticky-col {
  position: sticky;
  left: 0;
  background: var(--bs-body-bg);
  z-index: 1;
}

/* ─── Aging buckets ────────────────────────────────────── */
/* The colour repeats what the label already says — it never carries it alone. */
.bucket-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.bucket-tile {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
  border-top-width: 3px;
  background: var(--bs-body-bg);
}
.bucket-tile.tone-ok { border-top-color: var(--viz-ok); }
.bucket-tile.tone-warn { border-top-color: var(--viz-warn); }
.bucket-tile.tone-bad { border-top-color: var(--viz-bad); }
.bucket-tile.tone-unknown { border-top-color: var(--viz-unknown); }
.bucket-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--bs-secondary-color); }
.bucket-value { font-size: 1.15rem; font-weight: 600; }

/* Report section headings */
.report-section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bs-secondary-color);
  margin: 1.5rem 0 0.6rem;
}

/* Age badge: icon + written label, so the status colour never carries alone. */
.badge-age {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  white-space: nowrap;
  color: var(--bs-secondary-color);
}
.badge-age i { font-size: 0.85rem; }
.badge-age.tone-ok i { color: var(--viz-ok); }
.badge-age.tone-warn i { color: var(--viz-serious); }
.badge-age.tone-bad i { color: var(--viz-bad); }
.badge-age.tone-unknown i { color: var(--viz-unknown); }

/* Per-column list filters + sortable headers (partials/list-thead.ejs) */
.list-table thead .list-filter-row th { padding-top: .2rem; padding-bottom: .5rem; vertical-align: top; }
.list-table thead .list-filter-row .form-control-sm,
.list-table thead .list-filter-row .form-select-sm { font-weight: 400; }
a.list-sort { cursor: pointer; }
a.list-sort:hover { text-decoration: underline !important; }
