:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #0f1b14;
  --ink-soft: #5a6b61;
  --ink-faint: #8b9990;
  --line: #e4e9e6;
  --brand: #16a34a;
  --brand-dark: #0f7a38;
  --brand-soft: #e7f6ed;
  --pos: #16a34a;
  --neg: #dc2626;
  --warn: #d97706;
  --shadow: 0 1px 3px rgba(16,40,28,.06), 0 6px 24px rgba(16,40,28,.05);
  --radius: 14px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: #0c1f16;
  color: #cfe3d7;
  padding: 22px 16px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #22c55e, #0f7a38);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px;
  box-shadow: 0 4px 14px rgba(34,197,94,.4);
}
.brand .name { font-weight: 700; color: #fff; font-size: 15px; letter-spacing: .2px; }
.brand .sub { font-size: 11px; color: #6f8a7b; margin-top: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: #aec5b8; font-size: 14px; font-weight: 500; transition: .15s;
  border: 1px solid transparent;
}
.nav-item:hover { background: #142a1e; color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(22,163,74,.35); }
.nav-item .ic { width: 18px; height: 18px; opacity: .9; }
.nav-spacer { flex: 1; }
.side-foot { font-size: 11px; color: #6f8a7b; padding: 10px 10px 0; border-top: 1px solid #18301f; line-height: 1.5; }
.side-foot b { color: #9fbdac; font-weight: 600; }

/* ---------- Main ---------- */
.main { padding: 24px 30px 60px; max-width: 1200px; width: 100%; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 23px; font-weight: 720; letter-spacing: -.3px; margin: 0; }
.page-sub { color: var(--ink-soft); font-size: 13px; margin-top: 3px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.period {
  appearance: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 34px 9px 13px; font-size: 13.5px; font-weight: 600; color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235a6b61' stroke-width='2.2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 11px center;
}
.btn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--ink);
  box-shadow: var(--shadow); transition: .15s; display:inline-flex; align-items:center; gap:7px;
}
.btn:hover { border-color: #cbd5d0; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: 0 4px 14px rgba(22,163,74,.3); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--neg); }

/* ---------- Cards / KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpis.five { grid-template-columns: repeat(5, 1fr); }
.kpis.five .kpi .val { font-size: 22px; }
.kpis.six { grid-template-columns: repeat(6, 1fr); }
.kpis.six .kpi { padding: 14px; }
.kpis.six .kpi .val { font-size: 19px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 17px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; display:flex; align-items:center; gap:6px; }
.kpi .val { font-size: 26px; font-weight: 760; margin-top: 8px; letter-spacing: -.5px; }
.kpi .val.big { font-size: 30px; }
.kpi .delta { font-size: 12.5px; font-weight: 600; margin-top: 7px; display:flex; align-items:center; gap:5px; }
.kpi.hero { background: linear-gradient(135deg, #0f7a38, #16a34a); color: #fff; border: none; }
.kpi.hero .label { color: #c9f0d8; }
.kpi.hero .val { color: #fff; }
.kpi.hero .delta { color: #d6f5e2; }
.up { color: var(--pos); } .down { color: var(--neg); }
.kpi.hero .up, .kpi.hero .down { color: #eafff1; }
.dot { width:7px; height:7px; border-radius:50%; display:inline-block; }

.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .hd { padding: 16px 18px 0; display:flex; justify-content:space-between; align-items:center; }
.card .hd h3 { margin: 0; font-size: 15px; font-weight: 700; }
.card .hd .sub { font-size: 12px; color: var(--ink-faint); }
.card .bd { padding: 16px 18px 18px; }

/* P&L breakdown */
.pnl { display:flex; flex-direction:column; gap: 2px; }
.pnl .row { display:flex; align-items:center; justify-content:space-between; padding: 11px 4px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.pnl .row:last-child { border-bottom: none; }
.pnl .row .lhs { display:flex; align-items:center; gap:9px; color: var(--ink-soft); font-weight:500; }
.pnl .row .amt { font-weight: 650; font-variant-numeric: tabular-nums; }
.pnl .row.minus .amt { color: var(--neg); }
.pnl .row.total { margin-top: 6px; border-top: 2px solid var(--ink); border-bottom:none; padding-top: 14px; }
.pnl .row.total .lhs { color: var(--ink); font-weight: 750; font-size: 15px; }
.pnl .row.total .amt { font-size: 20px; font-weight: 780; }
.pnl .row .swatch { width:9px;height:9px;border-radius:2px;display:inline-block; }
.tag { font-size: 10.5px; font-weight:700; padding:2px 7px; border-radius:20px; background: var(--brand-soft); color: var(--brand-dark); text-transform:uppercase; letter-spacing:.3px; }
.tag.est { background:#fff4e5; color: var(--warn); }

/* chart */
.chart-wrap { width:100%; }
svg.chart { width: 100%; height: 230px; display:block; }
.legend { display:flex; gap:16px; font-size:12px; color:var(--ink-soft); margin-top:6px; }
.legend span { display:flex; align-items:center; gap:6px; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x:auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th { text-align: left; padding: 11px 14px; color: var(--ink-soft); font-weight: 650; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--line); white-space:nowrap; }
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl th.r, table.tbl td.r { text-align: right; }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl tbody tr.clickable:hover { background: #f7faf8; }
.ordno { font-weight: 700; color: var(--brand-dark); }
.muted { color: var(--ink-faint); }
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.pill.pos { background: var(--brand-soft); color: var(--brand-dark); }
.pill.neg { background: #fdecec; color: var(--neg); }
.pill.mid { background: #fff4e5; color: var(--warn); }
.expand td { background: #fafdfb; padding: 0; }
.line-items { padding: 6px 14px 12px 38px; }
.line-items .li { display:flex; justify-content:space-between; padding: 6px 0; font-size: 13px; border-bottom: 1px dashed var(--line); }
.line-items .li:last-child { border-bottom:none; }
.li .lname { color: var(--ink); }
.li .lmeta { color: var(--ink-faint); font-size: 12px; }

/* settings / expenses forms */
.form-grid { display:grid; grid-template-columns: repeat(2,1fr); gap: 16px 22px; }
.field { display:flex; flex-direction:column; gap:6px; }
.field label { font-size: 12.5px; font-weight:650; color: var(--ink-soft); }
.field .hint { font-size: 11.5px; color: var(--ink-faint); }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; font-size: 14px; color: var(--ink);
  background: #fff; outline: none; width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.inline-prefix { position:relative; }
.inline-prefix .pfx { position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--ink-faint); font-size:14px; }
.inline-prefix input { padding-left: 24px; }

.exp-add { display:grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 10px; align-items:end; margin-bottom: 18px; }
.empty { text-align:center; color: var(--ink-faint); padding: 30px; font-size: 14px; }

.note { background: #f0f7f3; border:1px solid #d6ebdf; border-radius:10px; padding:11px 13px; font-size:12.5px; color:#37614c; display:flex; gap:9px; }
.note svg { flex-shrink:0; }

.section-title { font-size: 13px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:var(--ink-soft); margin: 8px 0 12px; }
.mt { margin-top: 16px; }
.row-actions { display:flex; gap:8px; }
.icon-btn { background:none; border:none; cursor:pointer; color:var(--ink-faint); padding:4px; border-radius:6px; }
.icon-btn:hover { background:#f0f2f1; color:var(--neg); }
.sources { display:flex; align-items:center; gap:14px; flex-wrap:wrap; background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:9px 14px; box-shadow:var(--shadow); margin-bottom:16px; font-size:12.5px; }
.sources .src { display:flex; align-items:center; gap:7px; color:var(--ink-soft); font-weight:600; }
.sources .src em { font-style:normal; color:var(--ink-faint); font-weight:500; }
.sources .btn.xs { margin-left:auto; padding:6px 11px; font-size:12.5px; }
.btn.xs { padding:6px 11px; font-size:12.5px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color:#fff; padding: 11px 18px; border-radius: 10px; font-size: 13.5px; font-weight:600; box-shadow: 0 8px 30px rgba(0,0,0,.25); opacity:0; pointer-events:none; transition:.25s; }
.toast.show { opacity:1; transform: translateX(-50%) translateY(-4px); }

/* P&L subtotal (channel blending) */
.pnl .row.subtotal { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding-top: 11px; }
.pnl .row.subtotal .lhs { color: var(--ink); font-weight: 700; }
.pnl .row.subtotal .amt { font-weight: 750; }
.tag.est ~ * , .tag[style] { vertical-align: middle; }

/* filter bar (products) */
.filterbar { display:flex; align-items:center; gap:12px; flex-wrap:wrap; margin-bottom:14px; }
.search { border:1px solid var(--line); border-radius:10px; padding:9px 13px; font-size:13.5px; min-width:220px; outline:none; background:var(--panel); box-shadow:var(--shadow); }
.search:focus { border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-soft); }

/* AI Assistant nav item pinned near the bottom of the sidebar */
.nav-ai { margin-top:auto; margin-bottom:2px; border-top:1px solid #18301f; border-radius:10px; padding-top:14px; }
@media (max-width:900px){ .nav-ai { margin-top:0; border-top:none; padding-top:10px; } }

/* sub-tabs (marketing channels) */
.subtabs { display:flex; gap:8px; flex-wrap:wrap; margin: 2px 0 16px; }
.subtab-off { opacity:.5; }
.subtab { background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:8px 15px; font-size:13.5px; font-weight:650; color:var(--ink-soft); cursor:pointer; box-shadow:var(--shadow); }
.subtab:hover { border-color:#cbd5d0; }
.subtab.active { background:var(--brand); color:#fff; border-color:var(--brand); box-shadow:0 4px 14px rgba(22,163,74,.3); }

/* recipe gallery (Costs & Recipes → Recipes) */
.recipe-grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(320px, 1fr)); gap:14px; margin-bottom:4px; }
.recipe-lines { margin-top:10px; }
.recipe-lines .li { display:flex; justify-content:space-between; gap:10px; font-size:13px; padding:4px 0; border-bottom:1px dashed var(--line); }
.recipe-lines .li:last-child { border-bottom:none; }
.recipe-lines .lname { color:var(--ink); }
.build-pill { margin-top:9px; font-size:12.5px; background:#f0fdf4; border:1px solid #bbf7d0; color:#166534; border-radius:8px; padding:5px 9px; display:inline-block; }
td.caret { width:24px; text-align:center; padding-right:0; }
.caret-ic { color:var(--ink-faint); font-size:11px; }
table.tbl tbody tr.is-hidden td { opacity:.55; }
table.tbl tbody tr.cmp-strong td { font-weight:750; border-top:2px solid var(--line); font-size:15px; }
table.tbl tbody tr.grp-row td { background:#f7faf8; font-size:13px; }
.exp-panel { position:absolute; top:34px; left:0; z-index:40; background:var(--panel); border:1px solid var(--line); border-radius:10px; box-shadow:0 8px 30px rgba(0,0,0,.12); padding:8px 4px; min-width:190px; max-height:260px; overflow-y:auto; }
.exp-panel label { display:flex; align-items:center; gap:8px; padding:6px 12px; font-size:13px; cursor:pointer; border-radius:6px; }
.exp-panel label:hover { background:#f2f6f3; }
.mode-sel, .bom-sel { border:1px solid var(--line); border-radius:8px; padding:8px 9px; font-size:12.5px; background:#fff; color:var(--ink); max-width:100%; }
.bom-total { background:#f0f7f3; border:1px solid #d6ebdf; border-radius:10px; padding:10px 13px; font-size:13.5px; color:#37614c; }

/* order detail breakdown */
.order-detail { display:grid; grid-template-columns:1fr 1fr; gap:26px; padding:14px 18px 18px 38px; background:#fafdfb; }
.bd-title { font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.4px; color:var(--ink-soft); margin-bottom:8px; }
.bd-row { display:flex; justify-content:space-between; align-items:center; padding:7px 0; font-size:13px; border-bottom:1px dashed var(--line); }
.bd-row:last-child { border-bottom:none; }
.bd-row .r { font-variant-numeric:tabular-nums; font-weight:650; }
.bd-row .r.neg { color:var(--neg); }
.bd-row.strong { font-weight:750; } .bd-row.strong .lname { font-weight:750; color:var(--ink); } .bd-row.strong .r { font-size:15px; }
@media (max-width:700px){ .order-detail { grid-template-columns:1fr; gap:14px; } }

/* integrations */
.intg-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:14px; }
.intg { background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); padding:16px 17px; box-shadow:var(--shadow); border-left:4px solid #c2ccc6; }
.intg.ok { border-left-color:var(--pos); } .intg.warn { border-left-color:var(--warn); } .intg.off { border-left-color:#c2ccc6; }
.intg-hd { display:flex; align-items:center; gap:8px; font-size:15px; }
.intg-badge { margin-left:auto; font-size:10.5px; font-weight:700; padding:2px 8px; border-radius:20px; text-transform:uppercase; letter-spacing:.3px; background:#eef2f0; color:var(--ink-soft); }
.intg-badge.ok { background:var(--brand-soft); color:var(--brand-dark); } .intg-badge.warn { background:#fff4e5; color:var(--warn); }
.intg-msg { color:var(--ink-soft); font-size:13px; margin-top:9px; }
.intg-at { color:var(--ink-faint); font-size:11.5px; margin-top:8px; }
@media (max-width:900px){ .intg-grid { grid-template-columns:1fr; } }

/* read-only cost input */
input.ro { border:1px solid var(--line); border-radius:9px; padding:9px 11px; font-size:13.5px; width:100%; text-align:right; background:#f1f4f2; color:var(--ink-faint); cursor:not-allowed; font-variant-numeric:tabular-nums; }

/* AI assistant chat */
.chat-card { display:flex; flex-direction:column; height:calc(100vh - 190px); min-height:420px; }
.chat-scroll { flex:1; overflow-y:auto; padding:20px; display:flex; flex-direction:column; gap:14px; }
.msg { display:flex; } .msg.user { justify-content:flex-end; }
.bub { max-width:78%; padding:11px 15px; border-radius:16px; font-size:14px; line-height:1.5; }
.msg.user .bub { background:var(--brand); color:#fff; border-bottom-right-radius:5px; }
.msg.assistant .bub { background:#f2f5f3; color:var(--ink); border-bottom-left-radius:5px; }
.chat-input { display:flex; gap:10px; padding:14px 16px; border-top:1px solid var(--line); }
.chat-input input { flex:1; border:1px solid var(--line); border-radius:12px; padding:12px 15px; font-size:14px; outline:none; }
.chat-input input:focus { border-color:var(--brand); box-shadow:0 0 0 3px var(--brand-soft); }
.chat-empty { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px; color:var(--ink-faint); text-align:center; }
.chat-logo { width:52px; height:52px; border-radius:14px; background:linear-gradient(135deg,#22c55e,#0f7a38); color:#fff; font-size:26px; display:grid; place-items:center; box-shadow:0 6px 18px rgba(34,197,94,.35); }
.chips { display:flex; flex-wrap:wrap; gap:8px; justify-content:center; max-width:520px; }
.chip { background:var(--panel); border:1px solid var(--line); border-radius:20px; padding:8px 14px; font-size:12.5px; color:var(--ink-soft); cursor:pointer; box-shadow:var(--shadow); }
.chip:hover { border-color:var(--brand); color:var(--brand-dark); }
code { background:#eef2f0; padding:1px 6px; border-radius:5px; font-size:12.5px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height:auto; flex-direction: row; flex-wrap:wrap; }
  .nav-spacer, .side-foot, .brand .sub { display:none; }
  .kpis, .kpis.five, .kpis.six { grid-template-columns: repeat(2,1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
