:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --line: #d9ded7;
  --text: #1d2520;
  --muted: #66736b;
  --primary: #21665a;
  --primary-strong: #154c43;
  --accent: #c76d38;
  --danger: #b83232;
  --warning-bg: #fff1df;
  --ok-bg: #e6f4ea;
  --low-bg: #fff7cc;
  --shadow: 0 14px 36px rgba(20, 33, 29, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
.sidebar {
  background: #172820;
  color: #f8fbf8;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 8px;
  background: #e8b264; color: #172820;
  display: grid; place-items: center; font-weight: 800; font-size: 24px;
}
.logo-mark {
  overflow: hidden;
  background: #0d0d0b;
  border: 1px solid rgba(232, 178, 100, 0.45);
}
.logo-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}
.brand h1 { margin: 0; font-size: 19px; letter-spacing: 0; }
.brand p { margin: 3px 0 0; color: #abc0b6; font-size: 13px; }

.nav { display: grid; gap: 8px; }
.nav-item, .ghost-btn, .danger-btn, .primary-btn, .secondary-btn, .icon-btn {
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
}
.nav-item {
  justify-content: flex-start;
  padding: 11px 12px;
  color: #d7e4dd;
  background: transparent;
}
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,0.12); color: #fff; }
.nav-item svg, button svg, .file-label svg, .search-box svg { width: 18px; height: 18px; flex: 0 0 auto; }

.side-actions { margin-top: auto; display: grid; gap: 8px; }
.ghost-btn, .danger-btn { padding: 0 12px; color: #fff; background: rgba(255,255,255,0.1); }
.danger-btn { background: rgba(184,50,50,0.18); color: #ffe5e5; }
.danger-btn:hover { background: rgba(184,50,50,0.28); }
.danger-icon {
  background: #b91c1c;
  color: #fff;
}
.danger-icon:hover { background: #7f1111; }
.file-label input { display: none; }

.main { min-width: 0; padding: 24px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.eyebrow { margin: 0 0 4px; text-transform: uppercase; color: var(--muted); font-size: 12px; font-weight: 700; }
.topbar h2 { margin: 0; font-size: 28px; letter-spacing: 0; }
.topbar-actions { display: flex; align-items: end; gap: 10px; }
.sync-status {
  align-self: end;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.sync-status.online { color: #1f6a45; background: var(--ok-bg); border-color: #b8dfc4; }
.sync-status.offline { color: #8a5b00; background: var(--low-bg); border-color: #ead47a; }
.admin-only.hidden { display: none; }
.manager-only.hidden { display: none; }
.hidden { display: none !important; }
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 243, 0.94);
  padding: 24px;
}
.auth-gate.hidden { display: none; }
.auth-box {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-box h2 { margin: 0 0 8px; }
.auth-box p { color: var(--muted); margin: 0 0 18px; }
.auth-box a { text-decoration: none; }
.login-form { display: grid; gap: 12px; text-align: left; }
.login-form .primary-btn { width: 100%; margin-top: 4px; text-decoration: none; }
.user-form { grid-template-columns: 1fr 1fr 0.8fr 1fr 160px; margin-bottom: 14px; }
.date-control { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }

input, select {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid rgba(33,102,90,0.22); border-color: var(--primary); }
.primary-btn { background: var(--primary); color: #fff; padding: 0 14px; }
.primary-btn:hover { background: var(--primary-strong); }
.secondary-btn { background: #e4ebe6; color: var(--primary-strong); padding: 0 12px; }
.icon-btn { width: 38px; height: 38px; background: #eef3ef; color: var(--primary-strong); }
.small { min-height: 34px; font-size: 13px; }
.wide { width: 100%; margin-top: 12px; }

.view { display: none; }
.view.active { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 14px; }
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 8px; font-size: 28px; }
.category-value-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.category-card {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.category-card span { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.category-card strong { display: block; margin-top: 6px; font-size: 20px; }
.category-card small { display: block; margin-top: 3px; color: var(--muted); }

.split-layout, .two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.two-column { grid-template-columns: minmax(300px, 0.8fr) minmax(420px, 1.2fr); }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-head h3 { margin: 0; font-size: 16px; }
.panel-head.sub { margin-top: 18px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.search-box {
  height: 40px; border: 1px solid var(--line); border-radius: 8px;
  display: flex; align-items: center; gap: 8px; padding: 0 10px; background: #fff; min-width: 260px;
}
.search-box input { border: 0; padding: 0; height: 36px; flex: 1; }
.search-box input:focus { outline: 0; }
.search-box.full { width: 100%; min-width: 0; margin-bottom: 12px; }

.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.panel .table-wrap { border-radius: 6px; box-shadow: none; }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
.compact table { min-width: 0; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #edf3ef; color: #415149; font-size: 12px; text-transform: uppercase; white-space: nowrap; }
td { font-size: 14px; }
tr:hover td { background: #f8faf8; }
.stock-row.ok td { background: #f0f9f2; }
.stock-row.low td { background: #fff4dc; }
.stock-row.empty td, .stock-row.negative td { background: #fde8e8; }
.stock-row.ok:hover td { background: #e5f4e8; }
.stock-row.low:hover td { background: #ffe9bd; }
.stock-row.empty:hover td, .stock-row.negative:hover td { background: #fbd6d6; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pill { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: #d5f2dd; color: #1f6a45; }
.pill.empty { background: #fbd2d2; color: #9d2020; }
.pill.low { background: #ffe3ad; color: #885700; }
.pill.negative { background: #fbd2d2; color: #9d2020; }

.bar-chart { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.6fr) 70px; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; border-radius: 999px; background: #e8eee9; overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, #21665a, #d99a3d); }
.bar-value { text-align: right; color: var(--muted); font-size: 12px; font-weight: 700; }

.list { display: grid; gap: 8px; max-height: 660px; overflow: auto; padding-right: 4px; }
.list-item {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  text-align: left;
  display: grid;
  gap: 4px;
}
.list-item.active { border-color: var(--primary); background: #f0f7f4; }
.list-item strong { font-size: 14px; }
.list-item span { color: var(--muted); font-size: 12px; }
.editor-panel { min-height: 620px; }
.form-grid { display: grid; grid-template-columns: 1.2fr 1fr 0.8fr 0.8fr; gap: 10px; align-items: end; }
label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.readonly-box { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #f7faf8; }
.readonly-box span { color: var(--muted); font-size: 12px; font-weight: 700; }
.readonly-box strong { display: block; margin-top: 5px; }
.compact-readonly { min-height: 40px; padding: 6px 10px; }
.compact-readonly strong { margin-top: 2px; font-size: 14px; }
.ingredient-editor { display: grid; gap: 8px; }
.ingredient-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px 44px 96px 38px;
  gap: 8px;
  align-items: center;
  overflow: hidden;
}
.ingredient-row select,
.ingredient-row input { width: 100%; min-width: 0; }
.ingredient-row .line-unit {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}
.ingredient-row .line-total {
  color: var(--muted);
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.movement-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.movement-form { display: grid; gap: 10px; align-content: start; }
.movement-form h3 { margin: 0 0 4px; }
.timeline { display: grid; gap: 10px; }
.timeline-item { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.timeline-item strong { display: block; }
.timeline-item span { color: var(--muted); font-size: 12px; }
.backup-policy {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.archive-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  margin-bottom: 12px;
  border: 1px solid #f1c9c9;
  border-radius: 8px;
  background: #fff7f7;
}

dialog { border: 0; border-radius: 10px; padding: 0; box-shadow: 0 24px 80px rgba(0,0,0,0.24); }
dialog::backdrop { background: rgba(17, 28, 23, 0.45); }
.dialog-card { width: min(460px, calc(100vw - 32px)); padding: 18px; display: grid; gap: 12px; }
.developer-card { width: min(640px, calc(100vw - 32px)); }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 8px; }
.dev-paths { display: grid; gap: 10px; }
.dev-paths p {
  margin: 0;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f7faf8;
}
.dev-paths strong { color: var(--primary-strong); }
.dev-paths span {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.danger-copy { margin: 0; color: #8f1f1f; line-height: 1.4; }
.supplier-layout { grid-template-columns: minmax(280px, 0.7fr) minmax(520px, 1.3fr); }
.supplier-create { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.supplier-form { grid-template-columns: 1fr 1fr 1fr 1.2fr auto; margin-bottom: 14px; }
.supplier-products { display: grid; gap: 8px; }
.category-manager { margin-top: 16px; }
.category-edit { margin: 0; }
.category-edit input { width: 100%; }
.action-cell { display: flex; gap: 8px; align-items: center; justify-content: flex-start; white-space: nowrap; }
.success-icon {
  background: #e4f3ea;
  color: #0f6b3b;
}
.success-icon:hover { background: #cde9d8; }
#toast {
  position: fixed; right: 20px; bottom: 20px;
  background: #172820; color: #fff;
  padding: 12px 14px; border-radius: 8px;
  opacity: 0; transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  pointer-events: none; box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1020px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(2, 1fr); }
  .side-actions { grid-template-columns: repeat(3, 1fr); }
  .split-layout, .two-column, .movement-grid, .kpi-grid, .category-value-grid, .supplier-layout { grid-template-columns: 1fr; }
  .backup-policy, .archive-form { grid-template-columns: 1fr; }
  .form-grid, .supplier-form, .supplier-create { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .main { padding: 16px; }
  .topbar, .topbar-actions, .toolbar { align-items: stretch; flex-direction: column; }
  .nav, .side-actions { grid-template-columns: 1fr; }
  .search-box { min-width: 0; width: 100%; }
  .ingredient-row { grid-template-columns: 1fr; }
}
