* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f6f3;
  color: #0f2e24;
  font-size: 14px;
  line-height: 1.5;
}
a { color: #0ea56a; text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #e2e8f0; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
h2, h3, h4 { margin: 0 0 10px; color: #0f2e24; }
h3 { font-size: 1rem; font-weight: 600; }
h4 { font-size: 0.9rem; font-weight: 600; }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 228px; min-width: 228px;
  background: #0f2e24;
  color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 20px 18px; font-size: 0.95rem; font-weight: 600; color: #fff; line-height: 1.35; }
.sidebar .brand b { display: block; color: #f4faf6; }
.sidebar .brand span { display: block; color: #64748b; font-size: 0.75rem; font-weight: 400; margin-top: 2px; }
.sidebar nav { padding: 8px 0; flex: 1; }
.sidebar nav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 18px; color: #cbd5e1; font-size: 0.88rem;
}
.sidebar nav a:hover { background: #123c2f; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: #0ea56a; color: #fff; }
.sidebar nav a .badge { font-size: 11px; padding: 1px 7px; }
.sidebar .side-foot { padding: 14px 18px; font-size: 0.75rem; color: #64748b; border-top: 1px solid #123c2f; }

/* Role switch (top of main) */
.role-switch { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 18px; }
.role-switch .btn { background: #fff; border-color: #cbd5e1; color: #334155; font-size: 0.78rem; padding: 5px 12px; }
.role-switch .btn:hover { background: #e6f7f0; border-color: #0ea56a; color: #0ea56a; text-decoration: none; }
.role-switch .btn.current { background: #0ea56a; border-color: #0ea56a; color: #fff; }
.role-switch form { margin: 0; }
.flash {
  background: #e6f7f0; border: 1px solid #a7e8cf; color: #065f46;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 0.88rem;
}
.content { max-width: 1280px; }

/* Main */
.main { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.topbar h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }
.topbar .crumb { color: #64748b; font-size: 0.82rem; }
.topbar .who { font-size: 0.85rem; color: #475569; }
.topbar .who b { color: #0f2e24; }

.panel {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 18px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.panel h3 { margin-top: 0; }
.muted { color: #64748b; }
.small { font-size: 0.8rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82em; }
.right { text-align: right; }
.center { text-align: center; }
.strong { font-weight: 700; }
.red { color: #dc2626; }
.orange { color: #d97706; }
.gray { color: #475569; }

/* Metric row */
.pv { display: flex; gap: 34px; flex-wrap: wrap; align-items: flex-start; }
.metric-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; }
.metric-value { font-size: 1.5rem; font-weight: 700; color: #0f2e24; line-height: 1.25; }
.metric-value.gray { color: #475569; }
.metric-value.orange { color: #d97706; }
.metric-value.red { color: #dc2626; }
.metric-sub { font-size: 0.75rem; color: #94a3b8; }

/* Forms */
.text-input, .select, textarea.text-input {
  width: 100%; padding: 8px 10px; font-size: 0.9rem;
  border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: #0f2e24;
}
.text-input:focus, .select:focus, textarea.text-input:focus { outline: none; border-color: #0ea56a; box-shadow: 0 0 0 3px rgba(14, 165, 106, 0.15); }
.text-input.num, .price-input, .qty-input { font-family: ui-monospace, Menlo, monospace; }
.input-row { display: flex; gap: 10px; margin-bottom: 10px; }
.input-row > * { flex: 1; }
.field-label { display: block; font-size: 0.78rem; color: #64748b; margin: 12px 0 4px; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0; }
.check-label { display: inline-flex; align-items: center; gap: 7px; font-size: 0.85rem; color: #334155; margin-right: 16px; cursor: pointer; }
.select { width: auto; min-width: 150px; }
.search { max-width: 260px; }

.btn {
  display: inline-block; padding: 8px 14px; font-size: 0.85rem; font-weight: 500;
  border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: #0f2e24; cursor: pointer;
  transition: all 0.12s ease; text-decoration: none;
}
.btn:hover { background: #f4faf6; border-color: #94a3b8; text-decoration: none; }
.btn-primary { background: #0ea56a; border-color: #0ea56a; color: #fff; }
.btn-primary:hover { background: #0a8f5b; border-color: #0a8f5b; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; border-radius: 6px; }
.btn i { font-style: normal; margin-right: 5px; }
.add-row { margin-top: 14px; }

/* Badges & chips */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600; color: #fff; white-space: nowrap;
}
.chip {
  display: inline-block; padding: 6px 13px; margin: 0 6px 6px 0;
  border: 1px solid #cbd5e1; border-radius: 20px; font-size: 0.82rem; color: #334155; background: #fff;
}
.chip:hover { border-color: #0ea56a; color: #0ea56a; text-decoration: none; }
.chip.active { background: #0ea56a; border-color: #0ea56a; color: #fff; }
.filters { margin-bottom: 16px; }

/* Tables */
.est-table, .smeta-table, .min-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.est-table th, .est-table td, .smeta-table th, .smeta-table td, .min-table th, .min-table td {
  padding: 8px 10px; border-bottom: 1px solid #e8f2ec; text-align: left; vertical-align: top;
}
.est-table thead th, .smeta-table thead th, .min-table thead th {
  background: #f4faf6; color: #475569; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.03em;
  position: sticky; top: 0;
}
.smeta-table { font-size: 0.84rem; }
.smeta-table th, .smeta-table td { padding: 7px 8px; border-right: 1px solid #f0f6f3; }
.smeta-table .group-row th { background: #d7f3e6; color: #065f46; text-transform: none; letter-spacing: 0; }
.table-scroll { overflow-x: auto; }
.min-table td, .min-table th { font-size: 0.82rem; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f4faf6; }
tr.sec-head td { background: #f0f6f3; font-weight: 700; color: #334155; padding-top: 12px; }
tr.sec-total td { background: #f4faf6; font-weight: 600; border-top: 1px solid #e2e8f0; }
tr.grand-row td { font-weight: 700; background: #f4faf6; border-top: 2px solid #cbd5e1; }
tr.row-blocker td { background: #fef2f2; }
tr.row-loss td { background: #fff1f1; }
tr.row-reserve td { background: #fffbeb; }

/* Status cells */
.cell-calc { white-space: nowrap; }
.cell-price { white-space: nowrap; }
.manual-dot { color: #0ea56a; font-size: 12px; margin-right: 3px; }

/* Inline editors */
.price-form { display: flex; gap: 4px; margin-top: 4px; }
.price-input { width: 78px; padding: 4px 6px; font-size: 0.78rem; border: 1px solid #cbd5e1; border-radius: 6px; }
.qty-form { display: inline-block; }
.qty-input { width: 64px; padding: 4px 6px; font-size: 0.78rem; border: 1px solid #cbd5e1; border-radius: 6px; text-align: center; }
.note-form { margin: 0; }
.note-input { width: 130px; padding: 4px 6px; font-size: 0.78rem; border: 1px solid transparent; border-radius: 6px; background: transparent; }
.note-input:hover { border-color: #cbd5e1; background: #fff; }
.note-input:focus { border-color: #0ea56a; outline: none; background: #fff; }

/* Zones */
.zone { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.72rem; font-weight: 600; }
.zone.ok { background: #dcfce7; color: #15803d; }
.zone.reserve { background: #fef9c3; color: #a16207; }
.zone.loss { background: #fee2e2; color: #b91c1c; }

/* Markup panel */
.markup-panel { border-color: #a7e8cf; }
.markup-head { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; align-items: flex-start; }
.markup-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.markup-form { margin-top: 16px; }
.mk-forms { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.mk-forms .markup-form { flex: 1; min-width: 320px; }
.preset-form { max-width: 380px; }
.preset-form .stepper { align-items: flex-end; }
.mk-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.mk-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .text-input { width: 84px; text-align: center; }
.mk-aggregates { display: flex; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.agg-box {
  flex: 1; min-width: 160px; background: #f4faf6; border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.agg-box b { font-size: 1.1rem; }
.mk-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 10px; flex-wrap: wrap; }
.settings-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }

/* Doc head */
.doc-head { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.doc-title { flex: 1; min-width: 220px; }
.doc-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Two columns, queue, steps */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.two-col .panel { margin-bottom: 0; }
@media (max-width: 960px) { .two-col { grid-template-columns: 1fr; } }

.queue-card { border-left: 3px solid #f59e0b; }
.q-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.q-title { font-size: 1.05rem; font-weight: 600; }
.q-badges { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }
.q-tiers { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.tier { border: 1px solid #e2e8f0; border-radius: 8px; padding: 8px 10px; font-size: 0.82rem; flex: 1; min-width: 200px; }
.tier-label { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; }
.tier.ok { background: #f0fdf4; border-color: #bbf7d0; }
.tier.bad { background: #fef2f2; border-color: #fecaca; }
.tier.muted2 { background: #f4faf6; }
.q-action { background: #f4faf6; border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.q-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.q-form .text-input { flex: 1; min-width: 130px; }

/* Flow & steps */
.flow { display: flex; align-items: stretch; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.flow-item { flex: 1; min-width: 150px; background: #f4faf6; border: 1px solid #e2e8f0; border-radius: 10px; padding: 12px; }
.flow-item b { display: block; margin-bottom: 4px; }
.flow-item span { font-size: 0.78rem; color: #64748b; }
.flow-arrow { align-self: center; color: #94a3b8; font-weight: 700; }
.steps { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.step { border-left: 3px solid #a7e8cf; padding: 6px 12px; }
.step b { display: block; }
.step span { font-size: 0.82rem; color: #64748b; }

/* Try classifier */
.try-panel { border-color: #a7e8cf; }
.try-form { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.try-form .text-input { flex: 1; min-width: 280px; }
.parse-result { display: flex; gap: 30px; flex-wrap: wrap; align-items: center; }
.parse-col { min-width: 200px; }
.parse-big { font-size: 1.1rem; font-weight: 600; }
.parse-big.red { color: #dc2626; }
.conf-track { width: 200px; height: 8px; background: #e2e8f0; border-radius: 6px; margin-top: 6px; overflow: hidden; }
.conf-fill { height: 100%; background: #0ea56a; border-radius: 6px; }
.attrs-box { margin-top: 14px; }
.attrs-box h4 { margin-bottom: 6px; }
.ok-bar {
  background: #dcfce7; border: 1px solid #bbf7d0; color: #15803d;
  border-radius: 10px; padding: 12px 14px; margin-bottom: 18px;
}
.bind-block { margin-bottom: 12px; }
.bind-block b { display: block; margin-bottom: 3px; }

/* Lists & log */
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 5px 0; border-bottom: 1px solid #f0f6f3; }
ul.plain li:last-child { border-bottom: none; }
.log li { display: flex; gap: 8px; }

/* Portfolio bar */
.portfolio-bar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.portfolio-bar .pv { gap: 26px; }

@media (max-width: 820px) {
  .sidebar { display: none; }
  .main { padding: 16px 14px 40px; }
  .pv { gap: 18px; }
}