:root {
  --ink: #26312d;
  --muted: #6d7772;
  --cream: #f6f2ea;
  --paper: #fffdf8;
  --green: #355e50;
  --green-dark: #24483d;
  --sage: #dce7df;
  --terracotta: #bd6c4c;
  --gold: #d5a957;
  --danger: #a3473c;
  --line: #e5e0d6;
  --shadow: 0 16px 45px rgba(36, 57, 50, .08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--cream); color: var(--ink); }
a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--green-dark); color: #fff; padding: 28px 20px 20px; display: flex; flex-direction: column; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--terracotta); color: #fff; font-family: Georgia, serif; font-size: 24px; }
.brand div { display: flex; flex-direction: column; }
.brand strong { font-family: Georgia, serif; font-size: 21px; font-weight: 500; letter-spacing: .02em; }
.brand small { opacity: .65; margin-top: 2px; }
.sidebar nav { margin-top: 42px; display: grid; gap: 7px; }
.nav-link { color: rgba(255,255,255,.7); padding: 12px 14px; border-radius: 12px; display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 14px; }
.nav-link:hover, .nav-link.active { color: #fff; background: rgba(255,255,255,.1); }
.nav-link.active { box-shadow: inset 3px 0 0 var(--gold); }
.nav-icon { width: 17px; height: 17px; border: 1.7px solid currentColor; border-radius: 5px; opacity: .9; }
.nav-icon[data-icon="chart"] { border-radius: 50%; border-right-color: transparent; }
.nav-icon[data-icon="truck"] { border-radius: 3px; width: 19px; height: 13px; }
.nav-icon[data-icon="tag"] { transform: rotate(45deg); border-radius: 3px; width: 14px; height: 14px; }
.nav-icon[data-icon="shield"] { border-radius: 8px 8px 10px 10px; }
.sidebar-footer { margin-top: auto; padding-top: 20px; border-top: 1px solid rgba(255,255,255,.12); }
.user-chip { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.user-chip > span { width: 34px; height: 34px; display: grid; place-items: center; background: var(--sage); color: var(--green-dark); border-radius: 50%; font-weight: 800; }
.user-chip div { display: flex; flex-direction: column; min-width: 0; }
.user-chip strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip small { font-size: 11px; opacity: .6; }
.link-button { border: 0; padding: 4px 0; background: transparent; color: rgba(255,255,255,.65); cursor: pointer; font-size: 12px; }

.main { min-width: 0; }
.topbar { min-height: 105px; padding: 24px 38px 20px; display: flex; align-items: center; gap: 18px; border-bottom: 1px solid rgba(53,94,80,.09); }
.topbar h1 { font-family: Georgia, serif; font-weight: 500; font-size: clamp(25px, 3vw, 34px); margin: 2px 0 0; }
.topbar-date { margin-left: auto; color: var(--muted); font-size: 13px; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .16em; color: var(--terracotta); font-size: 10px; font-weight: 800; }
.menu-button { display: none; border: 0; background: transparent; font-size: 24px; }
.page-content { padding: 30px 38px 60px; max-width: 1520px; margin: 0 auto; }

.hero-panel { border-radius: 24px; padding: 30px 34px; background: linear-gradient(120deg, var(--green), var(--green-dark)); color: white; display: flex; align-items: center; justify-content: space-between; gap: 30px; box-shadow: var(--shadow); overflow: hidden; position: relative; }
.hero-panel::after { content: ""; width: 240px; height: 240px; border: 42px solid rgba(255,255,255,.05); border-radius: 50%; position: absolute; right: 8%; top: -110px; }
.hero-panel h2 { font-family: Georgia, serif; font-weight: 500; font-size: 29px; margin: 7px 0; }
.hero-panel p:not(.eyebrow) { margin: 0; opacity: .75; max-width: 640px; }
.hero-panel .eyebrow { color: #efc991; }
.hero-panel > * { position: relative; z-index: 1; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; margin: 22px 0; }
.kpi { background: var(--paper); border: 1px solid var(--line); padding: 20px; border-radius: var(--radius); box-shadow: 0 8px 24px rgba(36,57,50,.04); display: flex; flex-direction: column; min-height: 128px; }
.kpi span { color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi strong { font-family: Georgia, serif; font-size: 28px; font-weight: 500; margin: 10px 0 6px; }
.kpi small { color: var(--muted); margin-top: auto; }
.kpi.attention { border-top: 3px solid var(--gold); }
.kpi.danger { border-top: 3px solid var(--danger); }

.split-grid { display: grid; grid-template-columns: minmax(0,1.35fr) minmax(320px,.65fr); gap: 20px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 25px rgba(36,57,50,.04); overflow: hidden; margin-bottom: 20px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px 16px; }
.panel-heading h2 { font-family: Georgia, serif; font-weight: 500; font-size: 20px; margin: 4px 0 0; }
.panel-heading > a { font-size: 12px; font-weight: 700; }
.form-panel { overflow: visible; }
.narrow-panel { max-width: 980px; }
.compact-panel { padding: 20px 22px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.compact-panel p { margin: 4px 0 0; }
.hint { font-size: 11px; color: var(--muted); }
.empty-state { min-height: 190px; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 30px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 16px; color: var(--muted); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; background: #faf7f1; white-space: nowrap; }
td { padding: 14px 16px; border-top: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
td strong { font-weight: 700; }
td small { display: block; color: var(--muted); margin-top: 3px; font-size: 11px; }
tbody tr:hover { background: rgba(220,231,223,.18); }
.number { font-variant-numeric: tabular-nums; font-weight: 800; }
.positive-text { color: var(--green); }
.negative-text { color: var(--danger); }
code { font-size: 11px; background: #f1eee7; padding: 4px 7px; border-radius: 6px; }
.table-search { width: min(240px, 45vw); border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px 12px; outline: none; }
.table-search:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(53,94,80,.1); }

.pill { display: inline-flex; align-items: center; min-height: 24px; padding: 4px 9px; border-radius: 999px; background: #eeece5; color: var(--muted); font-size: 10px; font-weight: 800; white-space: nowrap; }
.pill.success, .status-received { background: var(--sage); color: var(--green-dark); }
.pill.warning, .status-partial { background: #f6e8c9; color: #855b18; }
.pill.bundle, .status-draft { background: #e7e5ee; color: #58506e; }
.status-ordered { background: #dfeaf0; color: #35586a; }
.status-cancelled { background: #f0ded9; color: var(--danger); }
.muted-pill { opacity: .65; }

.activity-list { padding: 0 20px 10px; }
.activity { display: grid; grid-template-columns: 10px minmax(0,1fr) auto; gap: 11px; align-items: center; border-top: 1px solid var(--line); padding: 13px 0; }
.activity-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.activity-dot.positive { background: var(--green); }
.activity-dot.negative { background: var(--terracotta); }
.activity div { display: flex; flex-direction: column; min-width: 0; }
.activity strong { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.activity b { font-size: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 15px 18px; padding: 4px 22px 24px; }
.movement-form { grid-template-columns: repeat(3,minmax(0,1fr)); }
.form-grid label, .form-stack label { display: flex; flex-direction: column; gap: 7px; font-size: 11px; color: var(--muted); font-weight: 800; }
input, select { width: 100%; min-height: 43px; border: 1px solid #dcd6ca; border-radius: 10px; padding: 9px 11px; background: #fff; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(53,94,80,.1); }
.span-2 { grid-column: span 2; }
.checkbox { flex-direction: row !important; align-items: center; }
.checkbox input { width: 18px; min-height: 18px; accent-color: var(--green); }
.form-action { display: flex; align-items: flex-end; justify-content: flex-end; }
.button { min-height: 41px; border: 1px solid transparent; border-radius: 11px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; cursor: pointer; white-space: nowrap; }
.button:disabled { opacity: .6; cursor: wait; }
.button.primary { background: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: transparent; color: var(--green); border-color: #cfd9d2; }
.button.light { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.25); }
.button.small { min-height: 32px; padding: 6px 10px; background: var(--sage); color: var(--green-dark); }
.button.wide { width: 100%; }
.inline-form { display: flex; align-items: center; gap: 10px; padding: 4px 22px 24px; }
.inline-form select { min-width: 220px; }
.inline-form input { max-width: 180px; }
.receive-form { display: flex; align-items: center; gap: 7px; }
.receive-form input { width: 85px; min-height: 32px; padding: 5px 7px; }
.component-list { padding: 0 22px 14px; display: grid; gap: 8px; }
.component-list > div { display: flex; justify-content: space-between; padding: 12px; background: #faf7f1; border-radius: 10px; }
.component-list span { color: var(--muted); font-size: 12px; }
.page-actions { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 20px; }
.page-actions p { margin: 0; color: var(--muted); }
.page-actions > div { display: flex; align-items: center; gap: 12px; }
.explanation { border: 1px solid #d7e1da; background: var(--sage); border-radius: 15px; padding: 17px 20px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.explanation p { margin: 3px 0 0; font-size: 12px; color: #52655d; }
.muted { color: var(--muted); }
.alert { margin: 18px 38px -10px; border-radius: 12px; padding: 12px 16px; font-size: 13px; font-weight: 700; }
.alert.success { background: var(--sage); color: var(--green-dark); }
.alert.error { background: #f3dfdb; color: var(--danger); }
.alert.info { background: #e4ebef; color: #38596a; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 85% 15%, #d9e4dc 0, transparent 28%), var(--cream); }
.login-card { width: min(440px, 100%); background: var(--paper); border: 1px solid var(--line); border-radius: 24px; padding: 34px; box-shadow: var(--shadow); }
.login-brand { color: var(--green-dark); margin-bottom: 42px; }
.login-card h1 { font-family: Georgia, serif; font-size: 30px; font-weight: 500; margin: 8px 0; }
.login-card .muted { font-size: 13px; margin: 0 0 25px; }
.form-stack { display: grid; gap: 16px; }
.login-card .alert { margin: 0 0 18px; }
.login-security { text-align: center; color: var(--muted); font-size: 10px; margin: 22px 0 0; }

@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .split-grid { grid-template-columns: 1fr; }
  .movement-form { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -280px; width: 260px; transition: left .2s ease; box-shadow: 14px 0 40px rgba(0,0,0,.2); }
  .sidebar.open { left: 0; }
  .menu-button { display: block; }
  .topbar { min-height: 84px; padding: 18px 18px 14px; }
  .topbar-date { display: none; }
  .page-content { padding: 20px 14px 50px; }
  .alert { margin: 14px 14px -6px; }
  .hero-panel { align-items: flex-start; flex-direction: column; padding: 24px; }
  .hero-panel h2 { font-size: 25px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { min-height: 115px; padding: 15px; }
  .kpi strong { font-size: 23px; }
  .form-grid, .movement-form { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form select, .inline-form input { min-width: 0; max-width: none; }
  .compact-panel, .page-actions, .explanation { align-items: flex-start; flex-direction: column; }
  .panel-heading { align-items: flex-start; }
  .table-search { width: 150px; }
}

@media (max-width: 430px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .table-search { display: none; }
  .login-card { padding: 26px 22px; }
}

