/* ============ FONTS ============ */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700;9..144,900&family=DM+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Caveat:wght@500;700&display=swap');

/* ============ TOKENS ============ */
:root {
  --cream-50: #fdfaf3;
  --cream-100: #faf3e4;
  --cream-200: #f4e7cc;
  --cream-300: #ecd8aa;
  --paper:    #fffdf6;
  --ink:      #1c1410;
  --ink-soft: #4a3a2e;
  --ink-mute: #8a7a6a;
  --orange-300: #fdba74;
  --orange-400: #fb923c;
  --orange-500: #f97316;
  --orange-600: #ea580c;
  --orange-700: #c2410c;
  --orange-900: #7c2d12;
  --line:     #ead9b8;
  --line-soft:#f0e3c4;
  --good:     #65a30d;
  --warn:     #d97706;
  --info:     #0369a1;
  --shadow-sm: 0 1px 2px rgba(124, 45, 18, 0.06);
  --shadow-md: 0 4px 12px rgba(124, 45, 18, 0.08);
  --shadow-lg: 0 12px 32px rgba(124, 45, 18, 0.10);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--cream-50);
  color: var(--ink);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* Decorative cream paper texture */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(249, 115, 22, 0.04) 0, transparent 35%),
    radial-gradient(circle at 80% 80%, rgba(234, 88, 12, 0.05) 0, transparent 40%);
  pointer-events: none; z-index: 0;
}

/* ============ LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  position: relative; z-index: 1;
}

.sidebar {
  background: var(--cream-100);
  border-right: 1px solid var(--line);
  padding: 28px 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 32px;
}
.brand-mark {
  font-family: 'Fraunces', serif;
  font-weight: 900; font-size: 28px;
  color: var(--orange-600);
  letter-spacing: -0.02em;
}
.brand-sub {
  font-family: 'Caveat', cursive;
  color: var(--ink-mute); font-size: 18px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 9px;
  text-decoration: none; color: var(--ink-soft);
  font-weight: 500; font-size: 14px;
  transition: all 0.15s;
}
.nav a:hover { background: var(--cream-200); color: var(--ink); }
.nav a.active {
  background: var(--orange-500); color: white;
  box-shadow: var(--shadow-sm);
}
.nav-icon { font-family: 'Fraunces', serif; font-style: italic; opacity: 0.7; width: 14px; }
.nav a.active .nav-icon { opacity: 1; }

.nav-section {
  font-family: 'Caveat', cursive;
  color: var(--ink-mute);
  margin: 18px 0 4px 12px;
  font-size: 16px;
}

.sidebar-footer {
  margin-top: 24px; padding-top: 18px;
  border-top: 1px dashed var(--line);
  font-size: 12px; color: var(--ink-mute);
  font-family: 'Caveat', cursive; font-size: 15px;
}

.main {
  padding: 40px 56px 80px;
  max-width: 1200px;
  width: 100%;
}

/* ============ TYPOGRAPHY ============ */
h1 {
  font-family: 'Fraunces', serif;
  font-weight: 900; font-size: 52px;
  letter-spacing: -0.03em; line-height: 1.05;
  color: var(--ink);
  margin-bottom: 12px;
}
h1 em { font-style: italic; color: var(--orange-600); font-weight: 400; }
h2 {
  font-family: 'Fraunces', serif;
  font-weight: 700; font-size: 30px;
  letter-spacing: -0.02em;
  color: var(--ink); margin: 48px 0 18px;
}
h3 {
  font-family: 'Fraunces', serif;
  font-weight: 600; font-size: 20px;
  color: var(--ink); margin-bottom: 8px;
}
h4 {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--orange-700); margin-bottom: 10px;
}
.eyebrow {
  font-family: 'Caveat', cursive;
  color: var(--orange-600); font-size: 22px;
  margin-bottom: 4px;
}
.lede {
  font-family: 'Fraunces', serif;
  font-size: 19px; color: var(--ink-soft);
  font-weight: 400; max-width: 720px;
  margin-bottom: 36px;
}
code, .mono { font-family: 'JetBrains Mono', monospace; font-size: 13px; }

/* ============ CARDS ============ */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card-clickable { cursor: pointer; }
.card-clickable:hover { border-color: var(--orange-400); }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}

/* ============ BADGES & CHIPS ============ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: var(--cream-200); color: var(--ink-soft);
  border: 1px solid var(--line);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.chip-orange { background: var(--orange-500); color: white; border-color: var(--orange-600); }
.chip-cream  { background: var(--cream-300); color: var(--orange-900); border-color: var(--orange-300); }
.chip-good   { background: #ecfccb; color: var(--good); border-color: #d9f99d; }
.chip-warn   { background: #fef3c7; color: var(--warn); border-color: #fde68a; }
.chip-info   { background: #dbeafe; color: var(--info); border-color: #bfdbfe; }
.chip-ghost  { background: transparent; }

/* ============ STAT TILES ============ */
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  position: relative; overflow: hidden;
}
.stat::before {
  content: ''; position: absolute;
  top: 0; left: 0; height: 4px; width: 100%;
  background: linear-gradient(90deg, var(--orange-500), var(--orange-300));
}
.stat-num {
  font-family: 'Fraunces', serif;
  font-weight: 900; font-size: 42px;
  color: var(--orange-600); letter-spacing: -0.02em;
  line-height: 1;
}
.stat-label {
  font-size: 12px; color: var(--ink-mute);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-top: 6px; font-weight: 600;
}

/* ============ COMPONENT TILES (clickable drill-downs) ============ */
.tile {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.tile:hover {
  border-color: var(--orange-400);
  background: var(--cream-50);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.tile-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--cream-200);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif; font-weight: 900;
  font-size: 22px; color: var(--orange-600);
  margin-bottom: 12px;
}
.tile h3 { margin-bottom: 4px; }
.tile-desc { font-size: 13px; color: var(--ink-soft); }
.tile-arrow {
  position: absolute; top: 22px; right: 22px;
  color: var(--ink-mute); font-family: 'Fraunces', serif;
  font-size: 18px; transition: transform 0.2s;
}
.tile:hover .tile-arrow { transform: translateX(4px); color: var(--orange-600); }

/* ============ DRILL-DOWN PANEL ============ */
.drilldown {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: 16px;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
  border: none;
}
.drilldown.open {
  max-height: 2000px;
  border: 1px solid var(--orange-300);
  padding: 24px;
  margin-top: 12px;
}
.drilldown.open + .drilldown-spacer { height: 8px; }

/* ============ FLOW DIAGRAMS ============ */
.flow {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 24px;
  margin: 24px 0;
}
.flow-row {
  display: flex; align-items: center; justify-content: space-around;
  gap: 12px; flex-wrap: wrap;
}
.flow-node {
  background: var(--cream-100);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  text-align: center;
  min-width: 110px;
  font-weight: 600; font-size: 13px;
  color: var(--ink); transition: all 0.2s;
}
.flow-node.accent {
  background: var(--orange-500);
  color: white; border-color: var(--orange-600);
  font-family: 'Fraunces', serif; font-size: 15px;
}
.flow-node small {
  display: block; font-weight: 400; font-size: 11px;
  opacity: 0.7; margin-top: 2px;
}
.flow-arrow {
  font-family: 'Fraunces', serif;
  font-size: 24px; color: var(--orange-500);
  font-style: italic;
}

/* ============ CUSTOMER CARDS ============ */
.customer {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  transition: all 0.2s;
}
.customer-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.customer-name {
  font-family: 'Fraunces', serif;
  font-weight: 700; font-size: 22px; color: var(--ink);
}
.customer-industry {
  font-family: 'Caveat', cursive;
  color: var(--orange-600); font-size: 18px;
}
.customer:hover { border-color: var(--orange-400); box-shadow: var(--shadow-md); }
.customer.active { border-color: var(--orange-500); box-shadow: var(--shadow-lg); }

/* ============ BAR CHARTS (CSS-only) ============ */
.bars { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.bar-row {
  display: grid; grid-template-columns: 140px 1fr 50px;
  align-items: center; gap: 12px;
  font-size: 13px;
}
.bar-label { color: var(--ink-soft); font-weight: 500; }
.bar-track {
  height: 18px; background: var(--cream-200);
  border-radius: 9px; overflow: hidden;
}
.bar-fill {
  height: 100%; border-radius: 9px;
  background: linear-gradient(90deg, var(--orange-400), var(--orange-600));
  transition: width 0.6s ease;
}
.bar-val { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--ink-mute); text-align: right; }

/* ============ TIMELINE ============ */
.timeline {
  position: relative; padding-left: 24px;
  border-left: 2px dashed var(--orange-300);
  margin: 24px 0;
}
.timeline-item { position: relative; margin-bottom: 28px; }
.timeline-item::before {
  content: ''; position: absolute; left: -31px; top: 6px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--orange-500); border: 3px solid var(--cream-50);
  box-shadow: 0 0 0 1px var(--orange-500);
}
.timeline-date {
  font-family: 'Caveat', cursive;
  color: var(--orange-600); font-size: 18px;
}
.timeline-title {
  font-family: 'Fraunces', serif;
  font-weight: 700; font-size: 17px;
  color: var(--ink); margin-top: 2px;
}
.timeline-body { font-size: 14px; color: var(--ink-soft); margin-top: 4px; }

/* ============ PLACEHOLDER CARDS (TODO) ============ */
.placeholder {
  background: repeating-linear-gradient(
    45deg, var(--cream-100), var(--cream-100) 10px,
    var(--cream-50) 10px, var(--cream-50) 20px
  );
  border: 2px dashed var(--orange-300);
  border-radius: var(--radius);
  padding: 18px; color: var(--ink-mute);
  font-family: 'Caveat', cursive; font-size: 16px;
  position: relative;
}
.placeholder::after {
  content: 'TBD';
  position: absolute; top: 8px; right: 12px;
  background: var(--orange-500); color: white;
  font-family: 'DM Sans', sans-serif;
  font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  letter-spacing: 0.06em;
}

/* ============ CALLOUTS / QUOTES ============ */
.callout {
  background: var(--cream-100);
  border-left: 4px solid var(--orange-500);
  padding: 16px 20px; border-radius: 8px;
  font-family: 'Fraunces', serif;
  font-style: italic; font-size: 17px;
  color: var(--ink-soft);
  margin: 20px 0;
}

/* ============ HORIZONTAL DIVIDER ============ */
.divider {
  height: 1px; background: var(--line);
  margin: 36px 0; position: relative;
}
.divider::after {
  content: '✦'; position: absolute;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--cream-50);
  padding: 0 12px; color: var(--orange-400);
  font-size: 14px;
}

/* ============ LINKS ============ */
a.inline {
  color: var(--orange-700);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  text-decoration-color: var(--orange-300);
}
a.inline:hover { text-decoration-color: var(--orange-600); }

/* ============ TAG LIST ============ */
.taglist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ============ SVG diagram styles ============ */
svg.diagram { width: 100%; height: auto; display: block; }
svg .node-box { fill: var(--paper); stroke: var(--line); stroke-width: 1.5; }
svg .node-box-accent { fill: var(--orange-500); stroke: var(--orange-600); }
svg .node-box-cream { fill: var(--cream-100); stroke: var(--line); }
svg .node-text { font-family: 'DM Sans', sans-serif; font-size: 13px; fill: var(--ink); font-weight: 600; }
svg .node-text-white { fill: white; }
svg .node-sub { font-family: 'DM Sans', sans-serif; font-size: 11px; fill: var(--ink-mute); }
svg .edge { stroke: var(--orange-400); stroke-width: 2; fill: none; }
svg .edge-dashed { stroke-dasharray: 5 4; }
svg .label { font-family: 'Caveat', cursive; font-size: 14px; fill: var(--orange-700); }

/* ============ PAGE HEADER ============ */
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 8px;
}
.page-meta {
  font-family: 'Caveat', cursive;
  color: var(--ink-mute); font-size: 17px;
  text-align: right;
}

/* ============ DONUT / RING (CSS) ============ */
.ring {
  --p: 70; --size: 100px; --thick: 12px;
  width: var(--size); height: var(--size);
  border-radius: 50%;
  background:
    conic-gradient(var(--orange-500) calc(var(--p) * 1%), var(--cream-200) 0);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.ring::after {
  content: ''; position: absolute;
  inset: var(--thick); border-radius: 50%;
  background: var(--paper);
}
.ring-val {
  position: relative; z-index: 1;
  font-family: 'Fraunces', serif; font-weight: 700;
  font-size: 22px; color: var(--ink);
}

/* ============ FEEDBACK WIDGET ============ */
#fb-widget {
  position: fixed; top: 16px; right: 18px;
  z-index: 80;
  display: flex; gap: 6px;
}
#fb-widget button, #fb-widget a {
  background: var(--paper);
  border: 1px solid var(--orange-400);
  color: var(--orange-700);
  padding: 6px 13px;
  border-radius: 999px;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}
#fb-widget button:hover, #fb-widget a:hover {
  background: var(--orange-500);
  color: white;
  border-color: var(--orange-500);
}

#fb-modal {
  position: fixed; inset: 0;
  background: rgba(28, 20, 16, 0.45);
  z-index: 200;
  display: none; align-items: center; justify-content: center;
  padding: 24px;
}
#fb-modal.open { display: flex; }
.fb-modal-card {
  background: var(--paper);
  border-radius: 18px;
  padding: 28px 30px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
}
.fb-modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 18px;
}
.fb-modal-eyebrow {
  font-family: 'Caveat', cursive;
  color: var(--orange-600); font-size: 17px;
}
.fb-modal-title {
  font-family: 'Fraunces', serif;
  font-weight: 700; font-size: 22px; color: var(--ink);
  margin: 0;
}
#fb-close {
  background: transparent; border: none;
  font-size: 22px; line-height: 1;
  color: var(--ink-mute); cursor: pointer;
  padding: 4px 10px; border-radius: 6px;
}
#fb-close:hover { background: var(--cream-200); color: var(--ink); }

.fb-label {
  display: block; margin-bottom: 14px;
}
.fb-label > span {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--ink-mute); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.fb-label > span em {
  font-style: normal; font-weight: 400;
  text-transform: none; letter-spacing: 0; color: var(--ink-mute);
}
.fb-label input, .fb-label textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cream-50);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px; color: var(--ink);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
}
.fb-label input:focus, .fb-label textarea:focus {
  border-color: var(--orange-400);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.12);
}
.fb-label input[readonly] {
  background: var(--cream-100); color: var(--ink-mute);
  cursor: default;
}

.fb-actions {
  display: flex; gap: 12px; align-items: center;
  margin-top: 4px;
}
#fb-submit {
  padding: 10px 18px;
  background: var(--orange-500);
  color: white; border: none;
  border-radius: 999px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600; font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
#fb-submit:hover { background: var(--orange-600); }
#fb-status {
  font-family: 'Caveat', cursive;
  font-size: 15px; color: var(--ink-mute);
}
#fb-status.fb-status-ok { color: var(--good); }
#fb-status.fb-status-err { color: var(--orange-700); }

/* ============ AUTH OVERLAY ============ */
#nix-auth-overlay {
  position: fixed; inset: 0;
  background: var(--cream-50);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  padding: 24px;
}
#nix-auth-overlay::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 25% 20%, rgba(249, 115, 22, 0.08) 0, transparent 40%),
    radial-gradient(circle at 75% 80%, rgba(234, 88, 12, 0.10) 0, transparent 45%);
  pointer-events: none;
}
.nix-auth-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 44px 40px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative; z-index: 1;
  text-align: center;
}
.nix-auth-brand {
  font-family: 'Fraunces', serif;
  font-weight: 900; font-size: 48px;
  color: var(--orange-600);
  letter-spacing: -0.03em;
  line-height: 1;
}
.nix-auth-sub {
  font-family: 'Caveat', cursive;
  color: var(--ink-mute); font-size: 18px;
  margin-top: 4px;
}
.nix-auth-lede {
  font-family: 'Fraunces', serif;
  font-size: 16px; color: var(--ink-soft);
  margin: 22px 0 24px;
}
#nix-auth-form {
  display: flex; flex-direction: column; gap: 10px;
}
#nix-auth-pw {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--cream-50);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#nix-auth-pw:focus {
  border-color: var(--orange-400);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}
#nix-auth-form button {
  padding: 12px 14px;
  background: var(--orange-500);
  color: white;
  border: none;
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  letter-spacing: 0.02em;
}
#nix-auth-form button:hover { background: var(--orange-600); }
#nix-auth-form button:active { transform: scale(0.99); }
#nix-auth-err {
  margin-top: 12px;
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: var(--orange-700);
  min-height: 22px;
}

/* ============ UTILITY ============ */
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--ink-mute); }
.center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mt-lg { margin-top: 32px; }
.full { width: 100%; }
hr { border: none; border-top: 1px solid var(--line); margin: 24px 0; }
ul.clean { list-style: none; }
ul.clean li {
  padding: 6px 0; border-bottom: 1px dashed var(--line-soft);
  font-size: 14px; color: var(--ink-soft);
}
ul.clean li:last-child { border-bottom: none; }
ul.clean li::before {
  content: '◆'; color: var(--orange-400); margin-right: 8px; font-size: 10px;
}
