/* ---------------------------------------------------------------
   Vraj Polyraw Ledger — design tokens
   Dark navy "workshop" shell, ledger-paper panels, spec-plate cards
   (an evolution of the machine nameplate motif used on the main site)
------------------------------------------------------------------ */
:root {
  --navy-950: #0b1d3a;
  --navy-900: #0f2445;
  --navy-800: #163a73;
  --navy-700: #1e4a8f;
  --paper: #f5f1e8;
  --paper-line: #e3dcc9;
  --ink: #1c1a15;
  --ink-soft: #5c584c;
  --orange: #f2790a;
  --orange-soft: #fbead6;
  --moss: #3f6d54;
  --rust: #b23a2e;
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--navy-950);
  background-image:
    radial-gradient(circle at 15% -10%, rgba(242, 121, 10, 0.10), transparent 45%),
    radial-gradient(circle at 100% 0%, rgba(30, 74, 143, 0.35), transparent 55%);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(245, 241, 232, 0.12);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--paper);
}
.mark { color: var(--orange); display: flex; }
.brand-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.06em;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
}
.brand-sub {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--orange);
  margin-top: 2px;
}
.topnav { display: flex; gap: 4px; }
.topnav a {
  text-decoration: none;
  color: rgba(245, 241, 232, 0.65);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.topnav a:hover { color: var(--paper); background: rgba(245, 241, 232, 0.06); }
.topnav a.active { color: var(--navy-950); background: var(--orange); }

.content { flex: 1; display: flex; min-height: 0; }

/* ---------------- Chat page ---------------- */
.chat-page {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 28px;
  min-height: 0;
}
.chat-panel {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
  overflow: hidden;
  min-height: 0;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.chat-empty {
  margin: auto 0;
  text-align: left;
}
.chat-empty-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  margin: 0 0 6px;
}
.chat-empty-sub {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 20px;
  max-width: 46ch;
}
.chat-examples { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.example-chip {
  font-family: var(--font-body);
  font-size: 13px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--paper-line);
  color: var(--ink);
  padding: 9px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.example-chip:hover { border-color: var(--orange); }
.example-chip:active { transform: scale(0.98); }

.msg { display: flex; }
.msg-user { justify-content: flex-end; }
.msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg-user .msg-bubble {
  background: var(--navy-800);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.msg-assistant .msg-bubble {
  background: transparent;
  border-left: 2px solid var(--orange);
  padding-left: 14px;
  border-radius: 0;
  color: var(--ink);
}
.msg-assistant.pending .msg-bubble { color: var(--ink-soft); font-style: italic; }

.action-stub {
  margin-top: 8px;
  border: 1px dashed var(--ink-soft);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: rgba(255,255,255,0.6);
}
.action-stub-row { display: flex; justify-content: space-between; gap: 12px; padding: 1px 0; }
.action-stub-label { color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; }
.action-stub-badge {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--orange-soft);
  color: #a35509;
  margin-bottom: 4px;
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--paper-line);
  background: var(--paper);
}
.chat-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--paper-line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 14.5px;
  background: #fff;
  color: var(--ink);
  max-height: 140px;
}
.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--orange);
}
.chat-input-row button {
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: filter 0.15s;
}
.chat-input-row button:hover { filter: brightness(1.08); }
.chat-input-row button:disabled { opacity: 0.5; cursor: default; }

/* ---------------- Dashboard ---------------- */
.dash-page { flex: 1; padding: 28px; max-width: 1180px; margin: 0 auto; width: 100%; }
.dash-loading { font-family: var(--font-mono); color: rgba(245,241,232,0.6); padding: 60px 0; text-align: center; }

.dash-section { margin-bottom: 32px; }
.dash-section:last-child { margin-bottom: 0; }
.section-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(245, 241, 232, 0.55);
  margin: 0 0 12px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.section-sub {
  font-family: var(--font-body);
  font-size: 11.5px;
  letter-spacing: normal;
  text-transform: none;
  color: rgba(245, 241, 232, 0.35);
}

.plate-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.dash-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

/* Business vertical cards */
.vertical-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.vertical-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  border-top: 3px solid var(--orange);
}
.vertical-card.vertical-2 { border-top-color: var(--navy-700); }
.vertical-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.vertical-card-head h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}
.vertical-stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--paper-line);
}
.vertical-stat-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 3px;
}
.vertical-stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
}
.vertical-stat-value.negative { color: var(--rust); }
.production-bar-wrap { margin-top: 4px; }
.production-bar-label {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.production-bar-track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--paper-line);
  overflow: hidden;
}
.production-bar-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  border-radius: 4px;
  background: var(--moss);
}
.production-bar-fill.over { background: var(--orange); }
.production-marker {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  background: var(--rust);
}
.production-bar-note { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-soft); margin-top: 5px; }

/* Pie chart + legend */
.pie-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.pie-legend { display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 160px; }
.pie-legend-row { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 12px; }
.pie-legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.pie-legend-label { flex: 1; color: var(--ink); }
.pie-legend-value { color: var(--ink-soft); }

/* Spec-plate: the signature element, echoing the machine nameplates
   on the main Vraj Polyraw site — riveted corners, mono digits. */
.spec-plate {
  position: relative;
  background: linear-gradient(160deg, var(--navy-800), var(--navy-900));
  border: 1px solid rgba(245,241,232,0.15);
  border-radius: 10px;
  padding: 16px 18px;
}
.spec-plate::before, .spec-plate::after,
.spec-plate .rivet-tl, .spec-plate .rivet-br {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(245,241,232,0.35);
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.4);
}
.spec-plate::before { top: 8px; left: 8px; }
.spec-plate::after { top: 8px; right: 8px; }
.spec-plate .rivet-tl { bottom: 8px; left: 8px; }
.spec-plate .rivet-br { bottom: 8px; right: 8px; }
.spec-plate-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(245,241,232,0.55);
  margin-bottom: 8px;
}
.spec-plate-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 26px;
  color: var(--paper);
  letter-spacing: 0.01em;
}
.spec-plate-value.positive { color: #8fd4ac; }
.spec-plate-value.negative { color: #f3a397; }
.spec-plate-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(245,241,232,0.5);
  margin-top: 6px;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
.panel {
  background: var(--paper);
  color: var(--ink);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
}
.panel-wide { grid-column: 1 / -1; }
.panel-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 14px; }
.panel-head h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.panel-sub { font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); }

.ledger-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ledger-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--paper-line);
}
.ledger-table td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--paper-line);
  font-family: var(--font-mono);
  font-size: 12.5px;
}
.ledger-table td:first-child, .ledger-table th:first-child { font-family: var(--font-body); font-size: 13px; }
.ledger-table tbody tr:last-child td { border-bottom: none; }
.ledger-table .empty-row td { color: var(--ink-soft); font-style: italic; font-family: var(--font-body); padding: 14px 8px; }
.type-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
}
.type-sale { background: #e2f3e8; color: var(--moss); }
.type-purchase { background: var(--orange-soft); color: #a35509; }
.type-expense { background: #fbe4e0; color: var(--rust); }
.type-payment_in { background: #e2f3e8; color: var(--moss); }
.type-payment_out { background: #fbe4e0; color: var(--rust); }
.status-pending, .status-partial { color: var(--rust); }
.status-paid { color: var(--moss); }

.chart-box { width: 100%; overflow-x: auto; }
.chart-box svg { display: block; }
.chart-empty { color: var(--ink-soft); font-family: var(--font-mono); font-size: 12px; padding: 40px 0; text-align: center; }

@media (max-width: 780px) {
  .dash-grid { grid-template-columns: 1fr; }
  .topbar { padding: 14px 16px; }
  .chat-page, .dash-page { padding: 14px; }
}

/* ---------------- Insights ---------------- */
.insight-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.insight {
  background: var(--paper); color: var(--ink); border-radius: 10px; padding: 14px 16px;
  border-left: 4px solid var(--ink-soft); box-shadow: 0 10px 24px rgba(0,0,0,0.22);
}
.insight-bad { border-left-color: var(--rust); }
.insight-warn { border-left-color: var(--orange); }
.insight-good { border-left-color: var(--moss); }
.insight-info { border-left-color: var(--navy-700); }
.insight-tag {
  display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px;
}
.insight-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); }
.insight-bad .insight-dot { background: var(--rust); }
.insight-warn .insight-dot { background: var(--orange); }
.insight-good .insight-dot { background: var(--moss); }
.insight-info .insight-dot { background: var(--navy-700); }
.insight-title { font-family: var(--font-display); font-weight: 600; font-size: 14.5px; line-height: 1.3; margin-bottom: 5px; }
.insight-detail { font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); }

/* ---------------- Monthly expenses drill-down ---------------- */
.cost-head-row, .cost-row {
  display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr; gap: 10px; align-items: center;
}
.cost-head-row {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-soft); padding: 0 12px 8px 30px; border-bottom: 1px solid var(--paper-line);
}
.cost-head-row span:not(:first-child), .cost-row span:not(:first-child) { text-align: right; }
.cost-month { border-bottom: 1px solid var(--paper-line); }
.cost-month > summary {
  list-style: none; cursor: pointer; padding: 12px 12px 12px 30px; position: relative;
  font-family: var(--font-mono); font-size: 13px;
}
.cost-month > summary::-webkit-details-marker, .cost-cat > summary::-webkit-details-marker { display: none; }
.cost-month > summary::before, .cost-cat > summary::before {
  content: "▸"; position: absolute; left: 10px; color: var(--orange); transition: transform 0.15s;
}
.cost-month[open] > summary::before, .cost-cat[open] > summary::before { transform: rotate(90deg); }
.cost-month > summary:hover, .cost-cat > summary:hover { background: rgba(242,121,10,0.06); }
.cost-month-label { font-family: var(--font-body); font-weight: 600; }
.cost-total { font-weight: 700; }
.cost-month-body { padding: 0 0 12px 22px; }
.cost-missing {
  margin: 0 0 8px 8px; font-family: var(--font-mono); font-size: 11px; color: #a35509;
  background: var(--orange-soft); padding: 6px 10px; border-radius: 6px; display: inline-block;
}
.cost-cat > summary {
  list-style: none; cursor: pointer; display: grid; grid-template-columns: 1fr auto 130px; gap: 10px;
  padding: 8px 12px 8px 30px; position: relative; border-top: 1px dashed var(--paper-line); font-size: 13px;
}
.cost-cat-count { font-family: var(--font-mono); font-size: 11px; color: var(--ink-soft); }
.cost-cat-total { font-family: var(--font-mono); text-align: right; font-weight: 600; }
.cost-kind {
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px; margin-right: 8px;
}
.kind-fixed { background: #e3e9f4; color: var(--navy-700); }
.kind-var { background: var(--orange-soft); color: #a35509; }
.cost-entries { margin: 4px 0 10px 30px; width: calc(100% - 30px); }
.cost-desc { font-family: var(--font-body) !important; font-size: 12px !important; color: var(--ink-soft); max-width: 420px; }
.ledger-table .num { text-align: right; }
.ledger-table td.strong { font-weight: 700; }
.panel-foot { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-soft); margin-top: 12px; line-height: 1.5; }

/* ---------------- Production log ---------------- */
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.filter-btn {
  font-family: var(--font-mono); font-size: 11.5px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--paper-line); background: #fff; color: var(--ink); cursor: pointer;
}
.filter-btn:hover { border-color: var(--orange); }
.filter-btn[aria-selected="true"] { background: var(--navy-900); color: var(--paper); border-color: var(--navy-900); }
.prod-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px;
  padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--paper-line);
}
.prod-charts { margin-bottom: 8px; }
.chart-title { font-family: var(--font-display); font-weight: 600; font-size: 13.5px; margin-bottom: 6px; }
.axis-txt { font-family: var(--font-mono); font-size: 9px; fill: var(--ink-soft); }
.ref-txt { fill: var(--ink); font-size: 9.5px; }
.chart-box rect.bar { transition: opacity 0.1s; }
.chart-box rect.bar.on { opacity: 0.75; }
.chart-box rect.hit { cursor: default; outline: none; }
.prod-row-sum { grid-template-columns: 1fr auto; }
.table-scroll { overflow-x: auto; }
.prod-table th, .prod-table td { white-space: nowrap; }
.chart-tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--navy-950); color: var(--paper);
  border-radius: 8px; padding: 8px 10px; font-family: var(--font-mono); font-size: 11.5px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35); min-width: 120px;
}
.tip-val { font-weight: 700; font-size: 13px; }
.tip-lab { color: rgba(245,241,232,0.6); margin-bottom: 4px; }
.tip-row { display: flex; justify-content: space-between; gap: 12px; color: rgba(245,241,232,0.8); }
.tip-row b { color: var(--paper); }

@media (max-width: 780px) {
  .dash-grid-2 { grid-template-columns: 1fr; }
  .cost-head-row { display: none; }
  .cost-row { grid-template-columns: 1fr 1fr; }
  .cost-row span:nth-child(2)::before { content: "Fixed "; color: var(--ink-soft); font-size: 10px; }
  .cost-row span:nth-child(3), .cost-row span:nth-child(4) { display: none; }
  .cost-cat > summary { grid-template-columns: 1fr auto; }
  .cost-cat-count { display: none; }
}
.chart-key { display: flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-soft); margin-top: 4px; }
.key-dash { width: 18px; border-top: 1.5px dashed var(--ink); }
.prod-charts > div, .dash-grid-2 > * { min-width: 0; }
.prod-row-sum span:nth-child(2)::before { content: none !important; }

.asset-total { font-weight: 600; border-top: 1px solid var(--line, rgba(255,255,255,.15)); padding-top: 10px; margin-top: 4px; }
.asset-body { overflow-x: auto; }
@media (max-width: 780px) {
  .asset-row span:nth-child(2), .asset-row span:nth-child(3), .asset-row span:nth-child(4) { display: none; }
  .asset-row span:nth-child(2)::before { content: none; }
  .asset-row > span:nth-child(5) { display: inline; }
  .asset-row > span:nth-child(5)::before { content: "Book value "; color: var(--ink-soft); font-size: 10px; font-weight: 400; }
  .asset-body table th:nth-child(1), .asset-body table td:nth-child(1), .asset-body table th:nth-child(4), .asset-body table td:nth-child(4) { display: none; }
}
