@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Instrument+Sans:wght@400;500;600&family=Space+Mono:wght@400;700&display=swap');

/* ==========================================================================
   TDP Brand Design System — ported from the tdp-website source of truth.
   Editorial brutalism: warm paper, near-black ink, one gray, no accent hue.
   2px ink borders, 2px (near-sharp) corners, hard offset shadow on focus,
   invert-to-ink for emphasis. Shared by every admin surface.
   ========================================================================== */

:root {
  --paper:     #f4f3ef;
  --white:     #ffffff;
  --ink:       #0e0e0e;
  --ink-soft:  #2a2a28;
  --muted:     #6f6e69;
  --line:      rgba(14, 14, 14, 0.12);
  --line-soft: rgba(14, 14, 14, 0.07);

  --ok:    #1c6b3f;   /* deep green — used sparingly, on-paper */
  --warn:  #8a5a12;
  --bad:   #9a2723;

  --ease:   cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 4px 4px 0 0 var(--ink);
  --radius: 2px;

  --font-display: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-body:    'Instrument Sans', system-ui, sans-serif;
  --font-mono:    'Space Mono', ui-monospace, monospace;
}

/* ---- base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

body.tdp {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.tdp a { color: var(--ink); text-decoration: none; }
.tdp a:hover { opacity: 0.55; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 40px; }
@media (max-width: 768px) { .wrap { padding: 0 22px; } }

/* ---- header -------------------------------------------------------------- */
.tdp-nav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.tdp-nav-inner { display: flex; align-items: center; justify-content: space-between;
  gap: 24px; height: 72px; }
.tdp-nav img { height: 30px; width: auto; display: block; }
.tdp-nav .crumb {
  font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
}

/* ---- typography ---------------------------------------------------------- */
.display { font-family: var(--font-display); font-weight: 800;
  letter-spacing: -0.03em; line-height: 1; }
h1.display { font-size: clamp(1.8rem, 3vw, 2.4rem); }

.eyebrow {
  font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
  display: inline-flex; align-items: center; gap: 10px;
}
.eyebrow.rule::before { content: ""; width: 20px; height: 2px; background: var(--ink); }

.mono { font-family: var(--font-mono); }

/* ---- panels -------------------------------------------------------------- */
.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.panel.ink { background: var(--ink); color: var(--paper); }
.panel.ink .eyebrow { color: color-mix(in srgb, var(--paper) 60%, transparent); }
.panel-divider { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---- forms --------------------------------------------------------------- */
.field { display: block; }
.field > label, .lbl {
  display: block; margin-bottom: 6px;
  font-family: var(--font-mono); font-size: 0.66rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink);
}
.input {
  width: 100%; font-family: var(--font-body); font-size: 0.95rem; color: var(--ink);
  background: var(--white); border: 1px solid var(--line); border-radius: 3px;
  padding: 11px 13px; appearance: none;
  transition: background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.input::placeholder { color: color-mix(in srgb, var(--muted) 72%, transparent); }
.input:focus { outline: none; background: var(--white); border-color: var(--ink);
  box-shadow: 3px 3px 0 0 var(--ink); }
select.input {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%),
                    linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 34px; cursor: pointer;
}

/* ---- buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-body); font-weight: 600; font-size: 0.82rem;
  letter-spacing: 0; text-transform: none;
  padding: 9px 15px; border: 1px solid var(--line); border-radius: var(--radius);
  background: transparent; color: var(--ink); cursor: pointer; text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease,
              transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.btn:hover { background: var(--white); border-color: var(--ink); opacity: 1; }
.btn:active { background: var(--paper); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover {
  background: var(--ink);
  transform: translate(-2px, -2px);
  box-shadow: 3px 3px 0 0 color-mix(in srgb, var(--ink) 35%, transparent);
}
.btn.primary:active { transform: translate(0, 0); box-shadow: none; }
.btn.small { padding: 6px 11px; font-size: 0.76rem; }

/* ---- stat readouts ------------------------------------------------------- */
.stat-num { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.03em;
  font-size: clamp(1.5rem, 2.4vw, 2rem); line-height: 1; }

/* margin signal colors (used sparingly on the number itself) */
.sig-ok   { color: var(--ok); }
.sig-warn { color: var(--warn); }
.sig-bad  { color: var(--bad); }

/* ---- nav links (shared header) ------------------------------------------ */
.tdp-nav-links { display: flex; align-items: center; gap: 26px; }
.tdp-nav-links a { font-family: var(--font-body); font-weight: 600; font-size: 0.86rem;
  letter-spacing: -0.01em; }
.tdp-nav-links a.active { border-bottom: 2px solid var(--ink); }
@media (max-width: 720px) { .tdp-nav-links { gap: 16px; font-size: 0.78rem; } }

/* ==========================================================================
   App shell — one shared left sidebar + flex content.
   Used by every admin surface: bookkeeping pages, estimator, and the SPA.
   ========================================================================== */
body.tdp.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  flex: 0 0 240px;
  width: 240px;
  align-self: stretch;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: color-mix(in srgb, var(--paper) 55%, var(--white));
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 22px 0 14px;
  z-index: 40;
}

.sidebar-logo { padding: 0 20px; margin-bottom: 22px; }
.sidebar-logo img { height: 26px; width: auto; display: block; }

.sidebar-actions {
  padding: 0 14px; margin-bottom: 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-actions .btn {
  width: 100%; justify-content: flex-start;
  font-family: var(--font-body); font-weight: 600; font-size: 0.82rem;
  text-transform: none; letter-spacing: 0;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 13px;
}
.sidebar-actions .btn:hover { transform: none; box-shadow: none; background: var(--white); }
.sidebar-actions .btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.sidebar-actions .btn.primary:hover { background: var(--ink-soft); }

.sidebar-nav { flex: 1; padding: 0; overflow-y: auto; }

.sidebar-group {
  font-family: var(--font-mono); font-weight: 700;
  font-size: 0.6rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted);
  padding: 16px 20px 7px;
}
.sidebar-group:first-child { padding-top: 4px; }

/* Collapsible group header (Bookkeeping) — looks like .sidebar-group, acts as a button */
.sidebar-group-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; background: none; border: 0; cursor: pointer; text-align: left;
}
.sidebar-group-toggle:hover { color: var(--ink); }
.sidebar-group-toggle .bk-chevron {
  font-size: 1rem; line-height: 1; transition: transform 0.15s var(--ease);
  transform: rotate(0deg);
}
.sidebar-group-toggle.open .bk-chevron { transform: rotate(90deg); }
.sidebar-collapsible[hidden] { display: none; }

.sidebar-nav a {
  display: flex; align-items: center; gap: 9px;
  margin: 1px 10px; padding: 7px 11px; border-radius: var(--radius);
  font-family: var(--font-body); font-size: 0.85rem; font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--muted); text-decoration: none; cursor: pointer;
  transition: color 0.12s, background 0.12s;
}
.sidebar-nav a:hover { color: var(--ink); background: var(--line-soft); opacity: 1; }
/* Active item inverts to ink — the system's stated emphasis move */
.sidebar-nav a.active { color: var(--paper); background: var(--ink); }
.sidebar-nav a .ext { font-size: 0.7rem; opacity: 0.5; margin-left: auto; }
.sidebar-nav a:hover .ext { opacity: 0.8; }

/* Index numerals — they're also live shortcuts (press 1–9 to jump) */
.sidebar-nav a .nav-idx {
  font-family: var(--font-mono); font-size: 0.58rem; font-weight: 700;
  letter-spacing: 0.06em; color: var(--muted); opacity: 0.55;
  width: 16px; flex: none;
}
.sidebar-nav a:hover .nav-idx { color: var(--ink); opacity: 0.9; }
.sidebar-nav a.active .nav-idx { color: var(--paper); opacity: 0.75; }

/* Editorial empty state — eyebrow + human line + optional CTA */
.empty-state { padding: 34px 0 26px; }
.empty-state .es-eyebrow {
  font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted);
  display: inline-flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.empty-state .es-eyebrow::before { content: ""; width: 20px; height: 2px; background: var(--ink); }
.empty-state .es-line {
  font-family: var(--font-display); font-weight: 700; letter-spacing: -0.02em;
  font-size: 1.15rem; color: var(--ink); margin: 0 0 4px;
}
.empty-state .es-sub { font-size: 0.88rem; color: var(--muted); margin: 0 0 16px; }


.sidebar-footer {
  padding: 12px 20px 2px; margin-top: 6px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 0.6rem; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}

/* Content child — fills remaining width, scrolls independently */
.app-shell > main,
.app-shell > .main-content {
  flex: 1 1 auto;
  min-width: 0;
}

/* Mobile slide-in sidebar + hamburger */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.32);
  z-index: 45;
}
.sidebar-toggle {
  display: none;
  position: fixed; top: 14px; left: 14px;
  z-index: 60;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: var(--paper); color: var(--ink);
  border: 2px solid var(--ink); border-radius: var(--radius);
  cursor: pointer;
}
.sidebar-toggle svg { width: 20px; height: 20px; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: -260px; top: 0;
    transition: left 0.25s var(--ease);
  }
  .sidebar.open { left: 0; box-shadow: 4px 0 22px rgba(0,0,0,0.14); }
  .sidebar-backdrop.open { display: block; }
  .sidebar-toggle { display: inline-flex; }
  /* keep page content clear of the fixed hamburger */
  .app-shell > main,
  .app-shell > .main-content { padding-top: 8px; }
}

/* ---- chips / stat cards -------------------------------------------------- */
.chip { border: 1px solid var(--line); border-radius: var(--radius); background: var(--white);
  padding: 16px 18px; }
.chip .lbl { margin-bottom: 6px; }

/* ---- tables -------------------------------------------------------------- */
.tdp-table { width: 100%; border-collapse: collapse; border: 0;
  background: transparent; font-size: 0.9rem; }
.tdp-table thead th {
  font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
  text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.tdp-table tbody td { padding: 13px 14px; border-top: 1px solid rgba(14, 14, 14, 0.07); vertical-align: top; }
.tdp-table tbody tr:hover { background: var(--white); }

/* Horizontal scroll wrapper so wide tables don't clip off-page on mobile */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

/* ---- status badges (editorial tones, not neon) -------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: none;
  padding: 4px 10px; border: 0; border-radius: 999px;
  background: rgba(14, 14, 14, 0.06); color: var(--muted); }
.badge.muted   { background: rgba(14, 14, 14, 0.06); color: var(--muted); }
.badge.ok      { background: rgba(28, 107, 63, 0.10);  color: var(--ok); }
.badge.warn    { background: rgba(138, 90, 18, 0.12);  color: var(--warn); }
.badge.bad     { background: rgba(154, 39, 35, 0.10);  color: var(--bad); }
.badge.solid   { background: var(--ink); color: var(--paper); }

/* ---- filter pills -------------------------------------------------------- */
.pill { font-family: var(--font-mono); font-size: 0.64rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; padding: 6px 13px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent;
  color: var(--muted); cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.pill:hover { background: var(--white); color: var(--ink); }
.pill.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---- toast --------------------------------------------------------------- */
.toast { position: fixed; bottom: 24px; right: 24px; z-index: 80;
  background: var(--ink); color: var(--paper); border-radius: var(--radius);
  padding: 13px 18px; font-family: var(--font-mono); font-size: 0.72rem;
  letter-spacing: 0.04em; box-shadow: var(--shadow); }

/* ---- scrollbar ----------------------------------------------------------- */
.tdp ::-webkit-scrollbar { width: 8px; height: 8px; }
.tdp ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 0; }

/* ---- date picker (datePicker component) ---------------------------------- */
.dp { position: relative; }
.dp-trigger { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; cursor: pointer; text-align: left; }
.dp-trigger .dp-placeholder { color: var(--muted); }
.dp-trigger .dp-cal { color: var(--muted); font-size: 0.7rem; }
.dp-pop { position: absolute; z-index: 60; top: calc(100% + 6px); left: 0;
  width: 268px; background: var(--white); border: 1px solid var(--ink);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dp-head span { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.04em; color: var(--ink); }
.dp-head button { border: 0; background: none; cursor: pointer; font-size: 1.1rem; line-height: 1;
  color: var(--muted); padding: 2px 8px; border-radius: var(--radius); }
.dp-head button:hover { color: var(--ink); background: var(--paper); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-wd { font-family: var(--font-mono); font-size: 0.56rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); text-align: center; padding: 4px 0; }
.dp-day { border: 0; background: none; cursor: pointer; aspect-ratio: 1; border-radius: var(--radius);
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink); }
.dp-day:hover { background: var(--paper); }
.dp-day.dp-other { color: var(--muted); opacity: 0.45; }
.dp-day.dp-today { box-shadow: inset 0 0 0 1px var(--line); }
.dp-day.dp-sel { background: var(--ink); color: var(--white); }
.dp-foot { display: flex; justify-content: space-between; margin-top: 10px;
  border-top: 1px solid var(--line); padding-top: 8px; }
.dp-foot button { border: 0; background: none; cursor: pointer; font-family: var(--font-mono);
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); }
.dp-foot button:hover { color: var(--ink); }
