:root {
  --forest: #142414;
  --forest-2: #1c3320;
  --leaf: #5f9a32;
  --leaf-2: #7cb342;
  --ink: #1c2618;
  --muted: #5d6a58;
  --line: #dbe5d2;
  --paper: #f3f6ee;
  --card: #fffcf7;
  --gold: #c4a035;
  --gold-2: #efe0a8;
  --ok: #157347;
  --danger: #b42318;
  --warn: #b45309;
  --shadow: 0 18px 40px rgba(20, 36, 20, 0.14);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", "Source Sans 3", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at -10% -20%, rgba(124, 179, 66, 0.18), transparent 50%),
    var(--paper);
}

button, input, select, textarea { font: inherit; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 4;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  background:
    linear-gradient(160deg, #132313 0%, #1e3a22 45%, #243f1c 100%);
}

.login-card {
  width: min(440px, 100%);
  margin: auto;
  flex-shrink: 0;
  background: var(--card);
  border-radius: 24px;
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo {
  width: 120px;
  max-width: 80%;
  height: auto;
  margin: 0 auto 8px;
  display: block;
}

.login-card h1 {
  margin: 8px 0 0;
  font-size: 28px;
  letter-spacing: 0.02em;
}

.login-card > p {
  color: var(--muted);
  margin: 6px 0 22px;
}

.login-card form {
  display: grid;
  gap: 12px;
  text-align: left;
}

.login-card label, .form-grid label, .modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.login-error {
  color: var(--danger);
  font-weight: 700;
  margin: 0;
}

.app {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: linear-gradient(180deg, var(--forest) 0%, #0d1a10 100%);
  color: #f4f8ee;
  padding: 16px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  z-index: 5;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 8px 12px;
  border-bottom: 1px solid rgba(124, 179, 66, 0.25);
  flex-shrink: 0;
}

.brand-logo {
  width: 62px;
  height: 62px;
  object-fit: contain;
  background: #fff;
  border-radius: 14px;
  padding: 4px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
}

.brand p {
  margin: 2px 0 0;
  color: var(--leaf-2);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.user-chip {
  background: rgba(124, 179, 66, 0.14);
  border: 1px solid rgba(124, 179, 66, 0.28);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  flex-shrink: 0;
}

.user-chip strong { display: block; }
.user-chip span { color: #b7c9a8; font-size: 12px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(196, 160, 53, 0.7) transparent;
}

.nav::-webkit-scrollbar { width: 8px; }
.nav::-webkit-scrollbar-thumb {
  background: rgba(196, 160, 53, 0.7);
  border-radius: 8px;
}

.nav button {
  text-align: left;
  border: 0;
  background: transparent;
  color: #d5e4cc;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

.nav button.active,
.nav button:hover {
  background: rgba(124, 179, 66, 0.2);
  color: #fff;
}

body.menu-locked .nav button,
body.menu-locked .btn-side {
  pointer-events: none;
}

body.menu-locked .sidebar {
  filter: brightness(0.42);
  pointer-events: none;
}

.sidebar-foot {
  margin-top: 0;
  font-size: 12px;
  color: #93aa88;
  padding: 8px 8px 4px;
  display: grid;
  gap: 10px;
  flex-shrink: 0;
  border-top: 1px solid rgba(124, 179, 66, 0.25);
}

.btn-side {
  color: #e8f3dc !important;
  border-color: rgba(255,255,255,0.18) !important;
}

.main {
  padding: 24px 28px 48px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head h2 {
  margin: 0;
  font-size: 30px;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.card, .stat, .table-wrap, .modal, .chart-card, .login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.stat, .table-wrap, .modal, .chart-card { padding: 18px; }

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.stat.warn strong { color: var(--warn); }
.stat.ok strong { color: var(--ok); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  background: #eef6e3;
  color: #34551c;
}

.badge i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--leaf));
  display: inline-block;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #cfd9c4;
  background: #fff;
  border-radius: 12px;
  padding: 11px 13px;
}

textarea { min-height: 78px; resize: vertical; }

.btn, .btn-ghost, .btn-danger, .btn-gold {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

.btn { background: var(--leaf); color: #fff; }
.btn:hover { background: #4e8624; }
.btn-gold { background: var(--gold); color: #1c2618; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn-danger { background: #fde8e6; color: var(--danger); }

.table-wrap {
  overflow: auto;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f4f8ee;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.low { color: var(--danger); font-weight: 800; }

.menu-blocker {
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 12, 0.55);
  z-index: 25;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
}

.modal {
  width: min(860px, 100%);
  margin: auto;
  flex-shrink: 0;
  max-height: none;
  overflow: visible;
  position: relative;
  z-index: 31;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.modal-head h3 { margin: 0; font-size: 24px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.form-grid.full { grid-template-columns: 1fr; }

.lines {
  display: grid;
  gap: 8px;
  margin: 8px 0 14px;
}

.line-row {
  display: grid;
  grid-template-columns: 1.6fr 0.7fr 0.7fr auto;
  gap: 8px;
  align-items: center;
}

.line-row.no-price { grid-template-columns: 1.8fr 0.8fr auto; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.chart-card { min-height: 380px; }
.chart-card canvas { max-height: 310px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--ok);
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  z-index: 50;
  font-weight: 700;
}

.notify-pop {
  position: fixed;
  right: 24px;
  top: 24px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--leaf);
  border-left: 6px solid var(--leaf);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  z-index: 60;
}

.notify-pop h4 { margin: 0 0 8px; }
.notify-pop ul { margin: 0; padding-left: 18px; }
.notify-pop li { margin: 4px 0; }

.empty { color: var(--muted); padding: 18px; }

.readonly-banner {
  background: #fff6df;
  border: 1px solid #ead38a;
  color: #6a5210;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-weight: 600;
}

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.login-screen,
.main,
.nav,
.overlay,
.table-wrap,
.notify-pop {
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 154, 50, 0.8) transparent;
}

.login-screen::-webkit-scrollbar,
.main::-webkit-scrollbar,
.overlay::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar,
.notify-pop::-webkit-scrollbar { width: 10px; height: 10px; }

.login-screen::-webkit-scrollbar-thumb,
.main::-webkit-scrollbar-thumb,
.overlay::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb,
.notify-pop::-webkit-scrollbar-thumb {
  background: rgba(95, 154, 50, 0.75);
  border-radius: 8px;
}

@media (max-width: 1100px) {
  .stats, .form-grid, .split, .line-row, .line-row.no-price {
    grid-template-columns: 1fr;
  }
}

@media print {
  html, body {
    overflow: visible;
    height: auto;
  }
  .sidebar, .toolbar, .btn, .btn-ghost, .btn-danger, .btn-gold, .no-print, .notify-pop, .toast {
    display: none !important;
  }
  .app { display: block; height: auto; overflow: visible; }
  .main { padding: 0; height: auto; overflow: visible; }
  .card, .table-wrap, .modal { box-shadow: none; border: 0; }
}
