:root {
  color-scheme: light;
  --page-a:         #f3f6fb;
  --page-b:         #fbfbf9;
  --surface-1:      #ffffff;
  --surface-2:      #f7f9fc;
  --text-primary:   #12181f;
  --text-secondary: #55606b;
  --text-muted:     #8b93a0;
  --border:         rgba(18,24,31,0.08);
  --gridline:       #e7eaf0;
  --accent:         #2a78d6;
  --accent-deep:    #184f95;
  --accent-soft:    #e8f0fc;
  --shadow-sm:      0 1px 2px rgba(18,24,31,0.05);
  --shadow-md:      0 10px 30px -12px rgba(18,24,31,0.18);
  --status-good:    #0ca30c;
  --status-warn:    #eda100;
  --status-serious: #e2762f;
  --status-risk:    #d03b3b;
  --status-new:     #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-a: #0f1420; --page-b: #0d0d0d;
    --surface-1: #1a1f27; --surface-2: #20262f;
    --text-primary: #f5f6f8; --text-secondary: #b9c0cb; --text-muted: #838c99;
    --border: rgba(255,255,255,0.10); --gridline: #2a303b;
    --accent: #3987e5; --accent-deep: #6ea6ee; --accent-soft: #16263b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3); --shadow-md: 0 14px 34px -14px rgba(0,0,0,0.6);
    --status-good: #17c517; --status-warn: #f0b429; --status-serious: #f0895a; --status-risk: #e66767; --status-new: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page-a: #0f1420; --page-b: #0d0d0d;
  --surface-1: #1a1f27; --surface-2: #20262f;
  --text-primary: #f5f6f8; --text-secondary: #b9c0cb; --text-muted: #838c99;
  --border: rgba(255,255,255,0.10); --gridline: #2a303b;
  --accent: #3987e5; --accent-deep: #6ea6ee; --accent-soft: #16263b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3); --shadow-md: 0 14px 34px -14px rgba(0,0,0,0.6);
  --status-good: #17c517; --status-warn: #f0b429; --status-serious: #f0895a; --status-risk: #e66767; --status-new: #3987e5;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(1100px 420px at 85% -10%, var(--accent-soft), transparent 60%),
    linear-gradient(180deg, var(--page-a), var(--page-b) 55%);
  color: var(--text-primary);
  min-height: 100vh;
  margin: 0;
  padding: clamp(18px, 2.4vw, 44px);
}

/* ---------- Header ---------- */
.banner {
  position: relative;
  overflow: hidden;
  background: linear-gradient(120deg, var(--accent-deep), var(--accent) 65%, #4a3aa7);
  border-radius: 18px;
  padding: clamp(18px, 2.4vw, 30px) clamp(20px, 2.6vw, 34px);
  margin-bottom: clamp(16px, 2vw, 26px);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: #ffffff;
}
.banner svg.gauge {
  position: absolute;
  right: -30px; top: 50%; transform: translateY(-50%);
  width: clamp(140px, 16vw, 220px); height: auto;
  opacity: 0.14;
}
.header-left { display: flex; align-items: center; gap: 16px; position: relative; z-index: 1; }
.logo-mark {
  font-size: clamp(20px, 1.7vw, 27px);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: 10px;
  padding: 6px 12px;
}
.title-block h1 {
  margin: 0;
  font-size: clamp(22px, 2.5vw, 34px);
  font-weight: 800;
  letter-spacing: -0.015em;
}
.title-block p {
  margin: 3px 0 0;
  color: rgba(255,255,255,0.82);
  font-size: clamp(12px, 1vw, 15px);
}
.meta {
  text-align: right;
  position: relative;
  z-index: 1;
  font-size: clamp(11px, 0.9vw, 13px);
  color: rgba(255,255,255,0.82);
}
.beta-pill {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.32);
  font-size: clamp(10px, 0.8vw, 12px);
  font-weight: 700;
  padding: 3px 11px;
  border-radius: 100px;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  color: #ffffff;
}

/* ---------- Grid & cards ---------- */
.grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: clamp(14px, 1.6vw, 22px);
}
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: clamp(18px, 1.7vw, 28px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm), var(--shadow-md);
  position: relative;
}
.card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  border-radius: 16px 16px 0 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-deep));
}
.card h2 {
  margin: 0 0 clamp(12px, 1.3vw, 20px);
  font-size: clamp(14px, 1.15vw, 18px);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card h2 .h2-left { display: flex; align-items: center; gap: 10px; }
.card h2 .icon {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.card h2 .icon svg { width: 17px; height: 17px; }
.card-total {
  display: flex;
  align-items: baseline;
  gap: 5px;
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 100px;
}
.card-total .n { font-size: clamp(15px, 1.3vw, 19px); font-weight: 800; color: var(--accent-deep); }
.card-total .l { font-size: clamp(9px, 0.75vw, 11px); color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Customers card ---------- */
.customers-card { grid-column: 1; grid-row: 1; }
.customer-list, .project-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 8px;
  margin-bottom: clamp(12px, 1.4vw, 18px);
}
.customer-pill, .project-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--gridline);
  color: var(--text-secondary);
  font-size: clamp(11px, 0.95vw, 13.5px);
  padding: 5px 10px 5px 8px;
  border-radius: 100px;
  white-space: nowrap;
}
.customer-pill .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.customer-pill.has-opportunity {
  border-color: rgba(211,166,37,0.45);
  background: linear-gradient(0deg, rgba(211,166,37,0.10), rgba(211,166,37,0.10)), var(--surface-2);
}
.customer-pill .crown { flex: none; display: flex; }
.customer-pill .crown svg { width: 12px; height: 12px; }
.status-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: clamp(10px, 0.8vw, 12px);
  color: var(--text-muted);
  padding-bottom: clamp(12px, 1.4vw, 18px);
  border-bottom: 1px solid var(--gridline);
  margin-bottom: clamp(12px, 1.4vw, 18px);
}
.status-legend span { display: inline-flex; align-items: center; gap: 5px; }
.status-legend .dot { width: 8px; height: 8px; border-radius: 50%; }

.opps-row {
  margin-top: auto;
  padding-top: clamp(10px, 1.2vw, 16px);
  border-top: 1px solid var(--gridline);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.opps-label {
  font-size: clamp(11px, 0.95vw, 13.5px);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.opps-values { display: flex; gap: clamp(18px, 2vw, 32px); }
.opps-item { text-align: center; }
.opps-item .n {
  font-size: clamp(22px, 2vw, 30px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent-deep);
}
.opps-item .l { font-size: clamp(10px, 0.8vw, 12px); color: var(--text-muted); margin-top: 3px; }

/* ---------- Single-stat cards ---------- */
.stat-card { justify-content: space-between; }
.stat-value {
  font-size: clamp(46px, 5.4vw, 78px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin-top: auto;
  background: linear-gradient(180deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat-caption { color: var(--text-muted); font-size: clamp(11px, 0.85vw, 13px); margin-top: 8px; font-weight: 500; }
.finance-card { grid-column: 2; grid-row: 1; }
.opportunities-card { grid-column: 3; grid-row: 1; }
.subhead {
  font-size: clamp(11px, 0.95vw, 13.5px);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: clamp(10px, 1.2vw, 14px);
}
.card-subsection {
  margin-top: auto;
  padding-top: clamp(10px, 1.2vw, 16px);
  border-top: 1px solid var(--gridline);
}

/* ---------- Twin-stat cards ---------- */
.twin-card { grid-column: 1; grid-row: 2; }
.marketing-card { grid-column: 2 / span 2; grid-row: 2; }
.twin-row { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(12px, 1.6vw, 24px); flex: 1; }
.twin-item { display: flex; flex-direction: column; padding: 4px 0; }
.twin-item + .twin-item { border-left: 1px solid var(--gridline); padding-left: clamp(12px, 1.6vw, 24px); }
.twin-item .stat-value { font-size: clamp(36px, 4vw, 60px); }
.twin-item .stat-caption { order: -1; margin: 0 0 4px; }

/* ---------- Upcoming leaves card ---------- */
.leaves-card { grid-column: 1 / -1; grid-row: 3; }
.leaves-card h2 { margin-bottom: 2px; }
.card-subtitle {
  font-size: clamp(11px, 0.95vw, 13.5px);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  text-align: center;
  margin: 0 0 clamp(12px, 1.3vw, 20px);
}
.leave-table { display: flex; flex-direction: column; }
.leave-head, .leave-row {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.8fr 1.1fr 0.9fr;
  gap: 10px;
  align-items: center;
}
.leave-company { color: var(--text-secondary); }
.leave-head {
  font-size: clamp(10px, 0.78vw, 12px);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gridline);
  margin-bottom: 4px;
}
.leave-row {
  padding: 10px 8px;
  border-radius: 10px;
  border-bottom: 1px solid var(--gridline);
  font-size: clamp(12px, 0.95vw, 14.5px);
}
.leave-row:last-child { border-bottom: none; }
.leave-row.away { background: var(--accent-soft); border-bottom-color: transparent; }
.leave-name { font-weight: 700; }
.leave-type, .leave-dates { color: var(--text-secondary); }
.leave-chip {
  justify-self: start;
  font-size: clamp(10px, 0.8vw, 12px);
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 100px;
  background: var(--surface-2);
  color: var(--text-secondary);
  white-space: nowrap;
}
.leave-row.away .leave-chip { background: var(--accent); color: #ffffff; }
.leave-empty { color: var(--text-muted); font-size: clamp(12px, 0.95vw, 14px); padding: 6px 0; }

/* ---------- Clickable stats ---------- */
.clickable-stat {
  cursor: pointer;
  border: none;
  padding: 0;
  margin: 0;
  text-align: inherit;
  font-family: inherit;
  background: none;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border-radius: 8px;
  transition: opacity 0.15s ease;
}
.clickable-stat .chevron { font-size: 0.4em; opacity: 0.55; }
.clickable-stat:hover, .clickable-stat:focus-visible { opacity: 0.78; }
.clickable-stat:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.opps-item .clickable-stat { justify-content: center; }
/* .clickable-stat's `background: none` reset would otherwise wipe out
   .stat-value's gradient-text background-clip trick — restore it here
   with higher specificity so the numbers stay visible. */
.stat-value.clickable-stat {
  background: linear-gradient(180deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---------- Detail modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,12,16,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal-panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 760px;
  width: 100%;
  max-height: 82vh;
  overflow: auto;
  box-shadow: var(--shadow-md);
  padding: clamp(18px, 2.2vw, 28px);
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: clamp(12px, 1.6vw, 20px);
}
.modal-header h3 { margin: 0; font-size: clamp(16px, 1.5vw, 21px); font-weight: 800; }
.modal-header p { margin: 4px 0 0; color: var(--text-muted); font-size: clamp(11px, 0.9vw, 13px); }
.modal-close {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 9px;
  border: 1px solid var(--gridline);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
}
.modal-table { width: 100%; border-collapse: collapse; font-size: clamp(12px, 0.95vw, 14px); }
.modal-table th {
  text-align: left;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: clamp(9.5px, 0.75vw, 11px);
  letter-spacing: 0.05em;
  font-weight: 700;
  padding: 0 10px 8px 0;
  border-bottom: 1px solid var(--gridline);
}
.modal-table td {
  padding: 10px 10px 10px 0;
  border-bottom: 1px solid var(--gridline);
  color: var(--text-primary);
}
.modal-table tr:last-child td { border-bottom: none; }
.modal-table td:first-child, .modal-table th:first-child { font-weight: 700; }

.footer {
  margin-top: clamp(16px, 1.8vw, 24px);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--text-muted);
  font-size: clamp(10px, 0.85vw, 12.5px);
}
.footer strong { color: var(--text-secondary); }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .customers-card, .finance-card, .opportunities-card, .twin-card, .marketing-card, .leaves-card { grid-column: 1; grid-row: auto; }
  .leave-head, .leave-row { grid-template-columns: 1.3fr 1fr; grid-template-areas: "name chip" "company dates" "type type"; }
  .leave-head { display: none; }
  .leave-name { grid-area: name; } .leave-chip { grid-area: chip; justify-self: end; }
  .leave-company { grid-area: company; } .leave-dates { grid-area: dates; justify-self: end; }
  .leave-type { grid-area: type; }
  .banner svg.gauge { display: none; }
}
