/*
 * bycracus ops dashboard.
 *
 * Colour roles come from the data-viz reference palette: status colours are the
 * fixed four (good / warning / serious / critical) and are never reused as
 * decoration, chart chrome and ink follow the documented steps. There are no
 * charts here on purpose - with a handful of clients and prospects a chart
 * would be decoration, so the record is shown as tiles, ranked lists and tables.
 */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --accent: #2a78d6;
  --wash: rgba(42, 120, 214, 0.08);

  --radius: 14px;
  --radius-sm: 9px;
  --gap: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text",
    "Segoe UI", system-ui, sans-serif;

  /* Depth is one soft shadow and a hairline, never a heavy border. */
  --lift: 0 1px 2px rgba(11, 11, 11, 0.04), 0 6px 18px rgba(11, 11, 11, 0.05);
  --lift-hover: 0 1px 2px rgba(11, 11, 11, 0.05), 0 10px 28px rgba(11, 11, 11, 0.09);
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --fast: 0.18s var(--ease);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
  --lift: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.36);
  --lift-hover: 0 1px 2px rgba(0, 0, 0, 0.55), 0 14px 34px rgba(0, 0, 0, 0.46);
    --accent: #3987e5;
    --wash: rgba(57, 135, 229, 0.14);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --lift: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.36);
  --lift-hover: 0 1px 2px rgba(0, 0, 0, 0.55), 0 14px 34px rgba(0, 0, 0, 0.46);
  --accent: #3987e5;
  --wash: rgba(57, 135, 229, 0.14);
}

* { box-sizing: border-box; }

.detail-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }
.detail-hint { color: var(--text-secondary); }
.detail-notes { margin-top: 24px; border-top: 1px solid var(--border); }
.detail-notes > summary { padding: 16px 0; min-height: 48px; cursor: pointer; font-weight: 600; }
.detail-invoice { padding: 12px 0; border-top: 1px solid var(--border); }
.detail-job { display: flex; flex-direction: column; gap: 5px; width: 100%; min-height: 56px; margin: 8px 0; padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); font: inherit; text-align: left; cursor: pointer; }
.detail-job small { color: var(--text-secondary); }
.detail-job:hover { background: var(--wash); }
.detail-job:focus-visible, .detail-notes > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.drawer .row-val { overflow-wrap: anywhere; }

/*
 * `hidden` must win over any display value a component sets, or a panel with
 * `display: flex` stays on screen while the markup says it is closed.
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--plane);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 11px 22px;
  background: color-mix(in srgb, var(--surface-1) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

@supports not (backdrop-filter: blur(1px)) {
  .topbar { background: var(--surface-1); }
}

.topbar-left { display: flex; align-items: center; gap: 20px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.wordmark {
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.wordmark-dim { color: var(--text-muted); font-weight: 450; }

.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px;
  border-radius: 11px;
  background: var(--gridline);
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  padding: 5px 12px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: color var(--fast), background var(--fast), box-shadow var(--fast);
}
.tab:hover { color: var(--text-primary); }
.tab[aria-selected="true"] {
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 590;
  box-shadow: 0 1px 2px rgba(11, 11, 11, 0.10);
}

.tab-badge {
  min-width: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--status-warning);
  color: #0b0b0b;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 14px;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--fast), color var(--fast), transform var(--fast);
}
.icon-btn:hover { background: var(--gridline); color: var(--text-primary); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.spinning { animation: spin 0.8s linear infinite; }

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

.sync {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sync.stale { color: var(--status-serious); }

/* ---------- layout ---------- */

.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 22px 80px;
}

/* Every view says what it is before it says what is in it. */
.page-head { margin: 0 0 26px; max-width: 62ch; }

.page-title {
  margin: 0;
  font-size: 27px;
  line-height: 1.15;
  font-weight: 640;
  letter-spacing: -0.021em;
}

.page-sub {
  margin: 7px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-secondary);
}

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  padding: 60px 0;
  justify-content: center;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--baseline);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.section { margin-bottom: 34px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

h2.section-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.011em;
  color: var(--text-primary);
  margin: 0;
}

.section-note { font-size: 12.5px; color: var(--text-muted); text-align: right; }

/* ---------- stat tiles ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 17px;
  box-shadow: var(--lift);
}

.tile-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.tile-value {
  font-size: 32px;
  line-height: 1.08;
  font-weight: 600;
  letter-spacing: -0.024em;
  font-variant-numeric: tabular-nums;
}

/* A figure the record does not have is said in words, never as a number. */
.tile-value .tile-none {
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text-muted);
}

.tile-sub {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.tile-value .unit { font-size: 17px; color: var(--text-secondary); font-weight: 500; }

/* ---------- attention feed ---------- */

.feed { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--baseline);
  border-radius: var(--radius);
  padding: 13px 15px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  box-shadow: var(--lift);
  transition: transform var(--fast), box-shadow var(--fast), background var(--fast);
}
.item:hover { background: var(--wash); transform: translateY(-1px); box-shadow: var(--lift-hover); }
.item:active { transform: translateY(0); box-shadow: var(--lift); }

.item[data-severity="overdue"] { border-left-color: var(--status-critical); }
.item[data-severity="soon"] { border-left-color: var(--status-warning); }
.item[data-severity="blocked"] { border-left-color: var(--status-serious); }
.item[data-severity="scheduled"] { border-left-color: var(--accent); }
.item[data-severity="undated"] { border-left-color: var(--baseline); }

.item-main { flex: 1; min-width: 0; }

.item-title {
  font-weight: 550;
  margin-bottom: 3px;
  overflow-wrap: anywhere;
}

.item-note {
  font-size: 13px;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

.item-when {
  text-align: right;
  white-space: nowrap;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}
.item-when .rel { display: block; color: var(--text-muted); }

/*
 * Status is never colour alone: every badge ships an icon and a word.
 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 2px 7px 2px 6px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--baseline); flex: none; }

.badge[data-tone="critical"] .dot { background: var(--status-critical); }
.badge[data-tone="warning"] .dot { background: var(--status-warning); }
.badge[data-tone="serious"] .dot { background: var(--status-serious); }
.badge[data-tone="good"] .dot { background: var(--status-good); }
.badge[data-tone="accent"] .dot { background: var(--accent); }

.badge[data-tone="critical"] { color: var(--status-critical); }

/* ---------- cards & tables ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  box-shadow: var(--lift);
  transition: transform var(--fast), box-shadow var(--fast), background var(--fast);
}
.card:hover { background: var(--wash); transform: translateY(-1px); box-shadow: var(--lift-hover); }
.card:active { transform: translateY(0); box-shadow: var(--lift); }

/* Finished work stays readable but stops competing with live work. */
.card-quiet { background: transparent; box-shadow: none; }
.card-quiet .card-title { font-weight: 550; color: var(--text-secondary); }
.card-quiet:hover { background: var(--wash); box-shadow: var(--lift); }

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

.card-title { font-weight: 600; overflow-wrap: anywhere; }

.card-rows { display: flex; flex-direction: column; gap: 4px; }

.row {
  display: flex;
  gap: 10px;
  font-size: 13px;
  align-items: baseline;
}
.row-key { color: var(--text-muted); min-width: 82px; flex: none; }
.row-val { color: var(--text-secondary); overflow-wrap: anywhere; }
.row-val.unknown { color: var(--text-muted); font-style: italic; }

/* Finished work, folded away at the bottom of Jobs. */
.fold {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: var(--lift);
  overflow: hidden;
}

.fold-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  cursor: pointer;
  list-style: none;
  transition: background var(--fast);
}
.fold-head::-webkit-details-marker { display: none; }
.fold-head:hover { background: var(--wash); }
.fold-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.fold-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.011em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
/* A disclosure chevron that rotates with the fold. */
.fold-title::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.6px solid var(--text-muted);
  border-bottom: 1.6px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform var(--fast);
}
.fold[open] .fold-title::before { transform: rotate(45deg); }

.fold-note { font-size: 12.5px; color: var(--text-muted); text-align: right; }

.fold-body {
  padding: 2px 16px 16px;
  border-top: 1px solid var(--gridline);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  text-align: left;
  padding: 9px 13px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
}
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty {
  background: var(--surface-1);
  border: 1px dashed var(--baseline);
  border-radius: var(--radius);
  padding: 22px;
  color: var(--text-secondary);
  text-align: center;
}
.empty strong { color: var(--text-primary); }

/* ---------- stage strip ---------- */

.stages { display: flex; flex-wrap: wrap; gap: 8px; }

.stage {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 13px;
  min-width: 96px;
}
.stage-name { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.stage-count { font-size: 20px; font-weight: 600; margin-top: 2px; }
.stage.zero .stage-count { color: var(--text-muted); font-weight: 450; }

/* ---------- drawer ---------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(680px, 100vw);
  height: 100dvh;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: -18px 0 44px rgba(0, 0, 0, 0.16);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.drawer-title { margin: 0; font-size: 19px; letter-spacing: -0.01em; }

.drawer-body { padding: 18px 20px 44px; overflow-y: auto; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.36);
}

.meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 14px;
  font-size: 13px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gridline);
}
.meta-grid dt { color: var(--text-muted); }
.meta-grid dd { margin: 0; color: var(--text-secondary); overflow-wrap: anywhere; }

/* ---------- rendered markdown ---------- */

.md { overflow-wrap: anywhere; }
.md h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 22px 0 8px;
}
.md h4 { font-size: 14px; margin: 18px 0 6px; }
.md p { margin: 0 0 10px; color: var(--text-secondary); }
.md strong { color: var(--text-primary); font-weight: 650; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 20px; color: var(--text-secondary); }
.md li { margin-bottom: 4px; }
.md code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  background: var(--gridline);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text-primary);
}
.md pre {
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}
.md pre code { background: none; padding: 0; }
.md blockquote {
  margin: 0 0 12px;
  padding: 2px 0 2px 13px;
  border-left: 3px solid var(--baseline);
  color: var(--text-secondary);
}
.md a { color: var(--accent); }
.md del { color: var(--text-muted); }
.md table { margin-bottom: 12px; }
.md td, .md th { white-space: normal; }
.md hr { border: 0; border-top: 1px solid var(--gridline); margin: 18px 0; }

/* ---------- footer & errors ---------- */

.footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 26px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.footer-note { color: var(--text-muted); }

.error {
  background: var(--surface-1);
  border: 1px solid var(--status-critical);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 20px;
}
.error h3 { margin: 0 0 6px; font-size: 15px; color: var(--status-critical); }
.error p { margin: 0 0 6px; color: var(--text-secondary); }
.error code { font-size: 12px; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 9px 14px; }
  .topbar-left { width: 100%; gap: 12px; }
  .main { padding: 16px 14px 50px; }
  .tile-value { font-size: 26px; }
  .item-when { display: none; }
  .page-title { font-size: 23px; }
  .page-head { margin-bottom: 20px; }
  .footer { padding: 0 14px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .card:hover, .item:hover { transform: none; }
}
