/* ============================================================
   Verdura — Vegetable Trading Console
   Design system: "the greengrocer's ledger"
   ============================================================ */

:root {
  /* Palette */
  --pine: #173a2e;
  --pine-700: #1f4a3a;
  --pine-600: #275a46;
  --leaf: #3fa66a;
  --leaf-deep: #2f8553;
  --leaf-soft: #e6f2ea;
  --canvas: #f6f5ef;
  --surface: #ffffff;
  --surface-2: #fbfaf5;
  --ink: #1b2a24;
  --ink-soft: #5c6b63;
  --ink-faint: #8a978f;
  --line: #e3e7e0;
  --line-strong: #cfd6cd;

  /* Signal colors (semantic only) */
  --carrot: #e07b39;
  --gold: #d9a441;
  --tomato: #c7445a;
  --teal: #2e8c9e;
  --berry: #7a5aa6;

  /* Type */
  --font-display: "Fraunces", Georgia, serif;
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  /* Shape */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --shadow: 0 1px 2px rgba(23, 58, 46, 0.06), 0 8px 24px rgba(23, 58, 46, 0.06);
  --shadow-lg: 0 12px 40px rgba(23, 58, 46, 0.16);

  --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--canvas);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background:
    linear-gradient(180deg, var(--pine) 0%, var(--pine-700) 100%);
  color: #d6e4db;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgba(0, 0, 0, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 11px;
}
.brand-text strong {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  color: #fff;
  letter-spacing: 0.2px;
}
.brand-text span {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8fae9c;
}

.nav { padding: 8px 12px 16px; flex: 1; }
.nav-group {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #6f9281;
  margin: 18px 12px 6px;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: #c4d6cb;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active {
  background: var(--leaf);
  color: #06210f;
  box-shadow: inset 3px 0 0 #9be0b3;
}
.nav-ico { width: 18px; text-align: center; font-size: 13px; opacity: 0.85; }

.sidebar-foot {
  padding: 14px 20px;
  font-size: 12px;
  color: #7c9c8a;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex; align-items: center; gap: 8px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--leaf); box-shadow: 0 0 0 3px rgba(63,166,106,0.25); }

/* ---------- Main / Topbar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px;
  background: rgba(246, 245, 239, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.menu-btn {
  display: none;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); width: 38px; height: 38px; font-size: 16px; cursor: pointer;
}
.topbar-title .eyebrow { margin: 0; }
.topbar-title h1 {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -0.01em;
}
.topbar-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.canvas { padding: 26px 28px 60px; outline: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 15px;
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.06s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--leaf); border-color: var(--leaf-deep); color: #06210f;
  box-shadow: 0 2px 0 var(--leaf-deep);
}
.btn-primary:hover { background: var(--leaf-deep); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--leaf-soft); color: var(--pine); }
.btn-danger { color: var(--tomato); border-color: #eccdd3; background: #fbeef0; }
.btn-danger:hover { background: var(--tomato); color: #fff; border-color: var(--tomato); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-head h2 { margin: 0; font-family: var(--font-display); font-size: 18px; font-weight: 600; }

.grid { display: grid; gap: 18px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.span-2 { grid-column: span 2; }

/* ---------- KPI crate-label cards (signature) ---------- */
.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.kpi::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: var(--leaf);
}
.kpi.k-carrot::before { background: var(--carrot); }
.kpi.k-gold::before { background: var(--gold); }
.kpi.k-tomato::before { background: var(--tomato); }
.kpi.k-teal::before { background: var(--teal); }
.kpi .kpi-label {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-faint);
}
.kpi .kpi-value {
  font-family: var(--font-display);
  font-size: 38px; font-weight: 600; line-height: 1.05;
  margin: 10px 0 2px;
  letter-spacing: -0.02em;
}
.kpi .kpi-sub { font-size: 12.5px; color: var(--ink-soft); }
.kpi .kpi-sub b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
table.data th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-faint);
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
table.data td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background 0.12s; }
table.data tbody tr:hover { background: var(--leaf-soft); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.cell-strong { font-weight: 600; }
.cell-id { font-family: var(--font-mono); color: var(--ink-faint); font-size: 12.5px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Badges (price-tag style) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px; font-weight: 500;
  padding: 3px 9px; border-radius: 999px;
  background: var(--leaf-soft); color: var(--leaf-deep);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.b-plain::before { display: none; }
.badge.b-in    { background: var(--leaf-soft); color: var(--leaf-deep); }
.badge.b-low   { background: #faf0d7; color: #9a7414; }
.badge.b-out   { background: #fbe4e8; color: var(--tomato); }
.badge.b-carrot{ background: #fbe9da; color: #b85e1f; }
.badge.b-gold  { background: #faf0d7; color: #9a7414; }
.badge.b-teal  { background: #dcf0f3; color: #1f6675; }
.badge.b-leaf  { background: var(--leaf-soft); color: var(--leaf-deep); }
.badge.b-muted { background: #ececec; color: #6b6b6b; }
.badge.b-berry { background: #efe8f7; color: var(--berry); }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft);
  margin-bottom: 6px;
}
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-family: inherit; font-size: 14px; color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--leaf);
  box-shadow: 0 0 0 3px rgba(63, 166, 106, 0.18);
}
.textarea { resize: vertical; min-height: 72px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 16px; height: 16px; accent-color: var(--leaf); }
.hint { font-size: 12px; color: var(--ink-faint); margin-top: 5px; }
.err-text { color: var(--tomato); font-size: 12.5px; margin-top: 5px; }

/* ---------- Toolbar / filters ---------- */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 18px;
}
.toolbar .input, .toolbar .select { width: auto; }
.search { min-width: 240px; }
.spacer { flex: 1; }

/* ---------- States ---------- */
.state {
  text-align: center; padding: 56px 24px; color: var(--ink-soft);
}
.state .state-ico { font-size: 34px; }
.state h3 { margin: 14px 0 4px; font-family: var(--font-display); color: var(--ink); font-weight: 600; }
.state p { margin: 0 auto; max-width: 360px; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); padding: 40px; justify-content: center; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--leaf);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Charts ---------- */
.chart svg { display: block; width: 100%; height: auto; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 64px; align-items: center; gap: 12px; margin-bottom: 10px; }
.bar-row .bar-label { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--leaf-soft); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--leaf), var(--leaf-deep)); border-radius: 999px; }
.bar-row .bar-val { font-family: var(--font-mono); font-size: 12.5px; text-align: right; color: var(--ink); }

/* ---------- Modal ---------- */
.modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(20, 36, 29, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 20px; pointer-events: auto;
  animation: fade 0.18s ease;
}
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  width: 100%; max-width: 560px; box-shadow: var(--shadow-lg);
  animation: pop 0.2s ease; max-height: 88vh; overflow-y: auto;
}
.modal.modal-wide { max-width: 880px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.icon-btn { background: none; border: none; font-size: 22px; color: var(--ink-faint); cursor: pointer; line-height: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed; right: 22px; bottom: 22px; z-index: 80;
  display: flex; flex-direction: column; gap: 10px; max-width: 360px;
}
.toast {
  background: var(--pine); color: #eafff1;
  padding: 13px 16px; border-radius: var(--r);
  box-shadow: var(--shadow-lg); font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start;
  animation: slidein 0.22s ease;
  border-left: 4px solid var(--leaf);
}
.toast.t-error { border-left-color: var(--tomato); }
.toast.t-warn { border-left-color: var(--gold); }
.toast b { display: block; font-size: 13px; }
@keyframes slidein { from { opacity: 0; transform: translateX(20px); } }

/* ---------- Misc ---------- */
.section-title { font-family: var(--font-display); font-size: 19px; font-weight: 600; margin: 6px 0 14px; }
.muted { color: var(--ink-soft); }
.mono { font-family: var(--font-mono); }
.flex { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.tag-pill { display:inline-block; padding:2px 8px; border-radius:6px; background:var(--leaf-soft); color:var(--leaf-deep); font-size:12px; font-family:var(--font-mono); }
.profile-grid { display:grid; grid-template-columns: 160px 1fr; gap:10px 20px; }
.profile-grid dt { color: var(--ink-faint); font-size: 13px; }
.profile-grid dd { margin: 0; font-weight: 500; }
.pos-line { display:grid; grid-template-columns: 1fr 80px 90px 36px; gap:10px; align-items:center; padding:8px 0; border-bottom:1px dashed var(--line); }
.pos-total { display:flex; justify-content:space-between; align-items:baseline; padding-top:14px; }
.pos-total .big { font-family:var(--font-display); font-size:30px; font-weight:600; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .span-2 { grid-column: span 2; }
}
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50;
    transform: translateX(-100%); transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .cols-3 { grid-template-columns: 1fr; }
  .cols-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}
@media (max-width: 560px) {
  .cols-4 { grid-template-columns: 1fr; }
  .canvas { padding: 18px 16px 50px; }
  .topbar { padding: 14px 16px; }
  .field-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

:focus-visible { outline: 2px solid var(--leaf); outline-offset: 2px; border-radius: 4px; }
