:root {
  --bg: #13161d;
  --surface: #1a1e27;
  --surface-2: #20242f;
  --line: #2a2f3a;
  --line-soft: #232833;
  --text: #e8e6df;
  --muted: #8a909c;
  --muted-dim: #5a606c;
  --accent: #6e8bff;
  --accent-dim: #3b4a7a;
  --empty-cell: #171a22;
  --danger: #e8795f;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
}

* {
  box-sizing: border-box;
}

/* the [hidden] attribute must win over display rules like `.stats{display:grid}` */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1100px 600px at 80% -10%, #1c2230 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a {
  color: var(--accent);
}

/* ---------- shared chrome ---------- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted-dim);
}

.app-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.01em;
  margin: 6px 0 0;
}

.brand h1 .dot {
  color: var(--accent);
}

.clock {
  text-align: right;
  line-height: 1.3;
}

.clock .time {
  font-family: var(--font-mono);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.clock .zone {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* ---------- controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 22px 0 18px;
}

.control-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface);
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  padding: 9px 15px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.seg-btn + .seg-btn {
  border-left: 1px solid var(--line);
}

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

.seg-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #0d1018;
  font-weight: 600;
}

.metric-group .seg-btn[aria-pressed="true"][data-metric="credits"] {
  background: #f4b645;
  color: #1b1305;
}

.metric-group .seg-btn[aria-pressed="true"][data-metric="count"] {
  background: #74e6c5;
  color: #06231c;
}

select.filter,
button.icon-btn {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 9px 13px;
  cursor: pointer;
}

select.filter {
  max-width: 320px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

button.icon-btn:hover,
select.filter:hover {
  border-color: var(--accent-dim);
}

.spacer {
  flex: 1 1 auto;
}

/* ---------- readout ---------- */
.readout {
  min-height: 20px;
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.readout strong {
  color: var(--text);
  font-weight: 600;
}

/* ---------- heatmap ---------- */
.heatmap-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px 20px 16px;
}

.heatmap-scroll {
  overflow-x: auto;
}

.heatmap {
  --cell-h: 26px;
  display: grid;
  grid-template-columns: 58px repeat(24, minmax(22px, 1fr)) minmax(56px, auto);
  gap: 3px;
  min-width: 720px;
}

.hm-total-head {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--muted-dim);
  text-align: right;
  align-self: end;
  padding: 0 2px 4px 8px;
  white-space: nowrap;
}

.hm-total {
  height: var(--cell-h);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 11px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 2px 0 8px;
  border-left: 1px solid var(--line-soft);
}

.hm-corner {
  grid-column: 1;
}

.hm-hour {
  font-size: 10px;
  color: var(--muted-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding-bottom: 4px;
}

.hm-hour.tick {
  color: var(--muted);
}

.hm-day {
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--cell-h);
  font-size: 10.5px;
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

.hm-day .hm-wd {
  color: var(--muted-dim);
}

.hm-day.weekend .hm-date {
  color: var(--text);
}

.hm-day.weekend .hm-wd {
  color: var(--accent);
}

.hm-cell {
  height: var(--cell-h);
  border-radius: 3px;
  background: var(--empty-cell);
  cursor: default;
  transition: outline-color 0.1s ease;
  outline: 1.5px solid transparent;
  outline-offset: -1.5px;
}

.hm-cell:hover {
  outline-color: var(--text);
}

.hm-cell.now {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* legend */
.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  font-size: 11px;
  color: var(--muted);
}

.legend .bar {
  height: 10px;
  width: 180px;
  border-radius: 5px;
  border: 1px solid var(--line);
}

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
}

.stat .label {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-dim);
}

.stat .value {
  font-family: var(--font-display);
  font-size: 22px;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.stat .sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.footnote {
  margin-top: 22px;
  font-size: 11px;
  color: var(--muted-dim);
}

.logout {
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.logout:hover {
  color: var(--danger);
}

/* ---------- states ---------- */
.banner {
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-size: 12.5px;
  margin: 0 0 14px;
  display: none;
}

.banner.error {
  display: block;
  background: rgba(232, 121, 95, 0.1);
  border: 1px solid rgba(232, 121, 95, 0.4);
  color: #f3b3a3;
}

.is-loading .heatmap-card {
  opacity: 0.45;
  transition: opacity 0.2s ease;
}

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 30px 28px 26px;
}

.login-card .eyebrow {
  margin-bottom: 10px;
}

.login-card h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
}

.login-card h1 .dot {
  color: var(--accent);
}

.login-card p.hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 22px;
}

.field label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 11px 13px;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-card button.submit {
  width: 100%;
  margin-top: 18px;
  background: var(--accent);
  color: #0d1018;
  border: 0;
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13.5px;
  padding: 12px;
  cursor: pointer;
}

.login-card button.submit:hover {
  filter: brightness(1.06);
}

.login-card button.submit:disabled {
  opacity: 0.6;
  cursor: progress;
}

.login-error {
  display: none;
  color: var(--danger);
  font-size: 12px;
  margin-top: 12px;
}

.login-error.show {
  display: block;
}

/* ---------- accessibility ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- comparison view ---------- */
.compare {
  margin-top: 4px;
}

.compare-table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 6px 8px;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}

.compare-table th,
.compare-table td {
  text-align: right;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

.compare-table th {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-dim);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.compare-table th:hover {
  color: var(--text);
}

.compare-table th.sorted::after {
  content: " ↓";
  color: var(--accent);
}

.compare-table th.sorted.asc::after {
  content: " ↑";
}

/* first column (employee name) is left-aligned; numeric columns stay right */
.compare-table th:first-child,
.compare-table td:first-child {
  text-align: left;
}

/* the column carrying the histogram for the active metric */
.compare-table th.col-bar,
.compare-table td.col-bar {
  text-align: left;
  width: 52%;
}

/* status table: tier + subscription-date columns read better left-aligned */
#compare-status th:nth-child(3),
#compare-status td:nth-child(3),
#compare-status th:nth-child(4),
#compare-status td:nth-child(4) {
  text-align: left;
}

.compare-caption {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 18px 0 8px;
}
.compare-caption:first-child {
  margin-top: 0;
}

.compare-table .bal.low {
  color: var(--danger);
  font-weight: 600;
}

.compare-table td.tier {
  color: var(--text);
}

.compare-table .muted {
  color: var(--muted-dim);
}

.compare-table .sub-canceled {
  color: var(--danger);
  font-size: 11px;
}

.compare-table tbody tr:last-child td {
  border-bottom: 0;
}

.compare-table tbody tr:hover td {
  background: var(--surface-2);
}

.compare-table .name {
  color: var(--text);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.compare-table .swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

/* histogram cell: right-aligned value, then a bar that grows rightward */
.bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bar-val {
  min-width: 84px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.bar-track {
  flex: 1;
  min-width: 90px;
}

.compare-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--accent);
  min-width: 2px;
}

.compare-table .err {
  color: var(--danger);
  font-weight: 500;
}

/* small-multiple heatmaps per employee */
.compare-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.mini-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 14px 12px;
}

.mini-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.mini-head .mini-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
}

.mini-head .mini-total {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 1.5px;
}

.mini-grid .mc {
  aspect-ratio: 1 / 1;
  border-radius: 1.5px;
  background: var(--empty-cell);
}

.mini-empty {
  font-size: 11px;
  color: var(--muted-dim);
  padding: 8px 0;
}

/* ---------- manage modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.66);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px 22px 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--text);
}

.modal-hint {
  color: var(--muted);
  font-size: 12px;
  margin: 8px 0 18px;
}

.acct-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.acct-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 9px 12px;
}

.acct-row .acct-info {
  flex: 1 1 auto;
  min-width: 0;
}

.acct-row .acct-name {
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}

.acct-row .acct-key {
  font-size: 11px;
  color: var(--muted-dim);
}

.acct-row input.acct-edit {
  flex: 1 1 auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 7px 9px;
  min-width: 0;
}

.acct-row .acct-btn {
  appearance: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 6px 10px;
  cursor: pointer;
  flex: none;
}

.acct-row .acct-btn:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.acct-row .acct-btn.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.acct-empty {
  font-size: 12px;
  color: var(--muted-dim);
  padding: 4px 2px;
}

.acct-form-row {
  display: flex;
  gap: 8px;
}

.acct-form-row input {
  flex: 1 1 0;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px 12px;
}

.acct-form-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.acct-add {
  appearance: none;
  background: var(--accent);
  color: #0d1018;
  border: 0;
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12.5px;
  padding: 10px 16px;
  cursor: pointer;
  flex: none;
}

.acct-add:hover {
  filter: brightness(1.06);
}

.acct-form-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 8px;
  min-height: 16px;
}

@media (max-width: 620px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .brand h1 {
    font-size: 21px;
  }
  .clock .time {
    font-size: 18px;
  }
  .acct-form-row {
    flex-wrap: wrap;
  }
}
