:root {
  --green: #17473f;
  --green-2: #0f6b5d;
  --paper: #fffdf2;
  --ink: #14201d;
  --muted: #6b756f;
  --line: #d8d0b4;
  --line-dark: #a7a083;
  --cell-w: 72px;
  --product-w: 154px;
  --topbar-h: 67px;
  --controls-h: 96px;
  --hint-h: 52px;
  --header-h: 92px;
  --header-top: 215px;
  --content-top: 307px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: system-ui, -apple-system, Segoe UI, sans-serif; background: #edf1ed; color: var(--ink); }
body { padding-top: var(--content-top); }
body.auth-locked { padding-top: 0; overflow: hidden; }
body.auth-locked .topbar,
body.auth-locked .controls,
body.auth-locked .hint,
body.auth-locked .floating-header,
body.auth-locked main { display: none; }
.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 120; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; background: var(--green); color: white; box-shadow: 0 2px 10px rgba(0,0,0,.16); }
.topbar > div:first-child { min-width: 0; flex: 1 1 auto; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 0 1 auto; min-width: 0; }
.top-actions button { white-space: nowrap; }
h1 { font-size: 1.15rem; margin: 0; letter-spacing: .01em; }
#status { margin: 2px 0 0; font-size: .78rem; opacity: .84; }
button, input, select { font: inherit; }
.primary { background: #f1c15b; color: #1b1b10; border: 0; border-radius: 12px; padding: 10px 12px; font-weight: 750; }
.secondary { background: #dce9e5; color: #14342d; border: 0; border-radius: 12px; padding: 10px 12px; font-weight: 750; }
.login-modal, .confirm-modal, .history-modal, .export-modal, .warehouse-admin-modal { position: fixed; top: 0; left: 0; right: auto; bottom: auto; width: 100vw; height: 100dvh; z-index: 300; display: none; align-items: center; justify-content: center; padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom)); overflow: auto; background: radial-gradient(circle at top, #2e7b6d 0, var(--green) 42%, #09231f 100%); }
body.modal-open { overflow: hidden; }
body.auth-locked .login-modal, .confirm-modal:not([hidden]), .history-modal:not([hidden]), .export-modal:not([hidden]), .warehouse-admin-modal:not([hidden]) { display: flex; }
.login-card, .confirm-card, .history-card, .export-card, .warehouse-admin-card { width: min(92vw, 390px); display: grid; gap: 13px; background: #fffdf2; color: var(--ink); border-radius: 24px; padding: 24px; box-shadow: 0 28px 90px rgba(0,0,0,.42); border: 1px solid rgba(255,255,255,.35); }
.login-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: var(--green); color: #f1c15b; font-weight: 900; font-size: 1.4rem; }
.login-card h2, .confirm-card h2, .history-card h2, .export-card h2, .warehouse-admin-card h2 { margin: 0; color: var(--green); }
.login-card p, .confirm-card p, .history-card p, .export-card p, .warehouse-admin-card p { margin: -4px 0 4px; color: var(--muted); line-height: 1.35; }
.login-card label, .export-card label { display: grid; gap: 5px; color: var(--muted); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.login-card input, .export-card input { width: 100%; border: 1px solid #cbd2cc; border-radius: 14px; padding: 13px 12px; background: #fafffb; }
.login-error { min-height: 1.2em; color: #9b2517; font-weight: 800; font-size: .88rem; }
.connecting-overlay { position: fixed; inset: 0; z-index: 330; display: none; align-items: center; justify-content: center; padding: 18px; background: rgba(9, 35, 31, .64); backdrop-filter: blur(3px); }
.connecting-overlay:not([hidden]) { display: flex; }
.connecting-card { width: min(88vw, 340px); display: grid; justify-items: center; gap: 12px; text-align: center; background: #fffdf2; color: var(--ink); border-radius: 22px; padding: 24px; box-shadow: 0 24px 80px rgba(0,0,0,.38); }
.connecting-card h2 { margin: 0; color: var(--green); }
.connecting-card p { margin: 0; color: var(--muted); line-height: 1.35; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid #dce9e5; border-top-color: #f1c15b; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.confirm-actions, .export-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.confirm-actions button, .export-actions button { min-width: 116px; }
.history-modal { z-index: 340; background: rgba(9,35,31,.74); backdrop-filter: blur(3px); }
.history-card { width: min(94vw, 560px); max-height: 86vh; overflow: hidden; padding: 18px; }
.history-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.history-head > div { display: grid; gap: 8px; }
.history-body { display: grid; gap: 10px; overflow: auto; padding-right: 4px; }
.history-entry { border: 1px solid #d8d0b4; border-radius: 16px; padding: 12px; background: #fffaf0; }
.history-entry.history-diff { border-color: #d35a39; background: #fff0e8; box-shadow: inset 4px 0 0 #d35a39; }
.history-entry-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.history-entry-top span, .history-time { color: var(--muted); font-size: .78rem; font-weight: 750; }
.history-metrics { margin-top: 6px; color: var(--green-2); font-weight: 800; font-size: .78rem; line-height: 1.35; }
.warehouse-admin-modal { z-index: 345; background: rgba(9,35,31,.78); backdrop-filter: blur(3px); }
.warehouse-admin-card { width: min(94vw, 560px); max-height: 88dvh; overflow: hidden; padding: 18px; }
.warehouse-admin-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.warehouse-admin-head > div { display: grid; gap: 8px; }
.warehouse-admin-list { display: grid; gap: 9px; overflow-y: auto; padding: 2px 4px 2px 2px; }
.warehouse-admin-row { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 15px; background: #fffaf0; }
.warehouse-admin-row.inactive { opacity: .66; background: #eee9df; }
.warehouse-admin-copy { min-width: 0; flex: 1; display: grid; gap: 3px; }
.warehouse-admin-name { color: var(--green); font-weight: 850; line-height: 1.15; overflow-wrap: anywhere; }
.warehouse-admin-status { color: var(--muted); font-size: .78rem; font-weight: 700; }
.warehouse-toggle { position: relative; flex: 0 0 auto; width: 52px; height: 30px; }
.warehouse-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.warehouse-toggle-track { display: block; width: 52px; height: 30px; border-radius: 999px; background: #a8b0ac; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); transition: background .18s ease; }
.warehouse-toggle-track::after { content: ''; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: transform .18s ease; }
.warehouse-toggle input:checked + .warehouse-toggle-track { background: var(--green-2); }
.warehouse-toggle input:checked + .warehouse-toggle-track::after { transform: translateX(22px); }
.warehouse-toggle input:focus-visible + .warehouse-toggle-track { outline: 3px solid #f1c15b; outline-offset: 2px; }
.warehouse-toggle input:disabled + .warehouse-toggle-track { cursor: not-allowed; opacity: .55; }
.controls { position: fixed; top: var(--topbar-h); left: 0; right: 0; z-index: 115; display: flex; gap: 10px; padding: 10px; background: white; border-bottom: 1px solid #dfe3df; box-shadow: 0 1px 8px rgba(0,0,0,.06); }
.controls label, .warehouse { display: grid; gap: 4px; font-size: .72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.search { flex: 1; }
.search input, .warehouse select, .days select, dialog input { width: 100%; border: 1px solid #cbd2cc; border-radius: 12px; padding: 11px 12px; background: #fafffb; }
.warehouse { width: min(34vw, 230px); }
.warehouse select { min-width: 0; font-weight: 800; color: var(--green); }
.warehouse-select-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.warehouse-admin-btn { min-width: 70px; padding: 8px; border: 1px solid #cbd2cc; font-size: .78rem; }
.days { width: 82px; }
.hint { position: fixed; top: calc(var(--topbar-h) + var(--controls-h)); left: 0; right: 0; z-index: 110; margin: 0; padding: 10px; min-height: var(--hint-h); display: flex; align-items: center; font-size: .84rem; color: var(--muted); background: #edf1ed; border-bottom: 1px solid #dfe3df; }
main { padding: 0 0 72px; }
.grid-wrap { overflow-x: auto; overflow-y: visible; width: 100%; padding-left: 8px; padding-bottom: 16px; -webkit-overflow-scrolling: touch; direction: rtl; }
.stock-grid, .header-grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; direction: ltr; background: var(--paper); min-width: calc(var(--product-w) + var(--cell-w) * 14); margin-left: auto; }
.stock-grid { box-shadow: 0 2px 18px rgba(0,0,0,.10); }
.floating-header { position: fixed; top: var(--header-top); left: 0; right: 0; height: var(--header-h); z-index: 105; overflow: hidden; padding-left: 8px; direction: rtl; background: #edf1ed; box-shadow: 0 4px 12px rgba(0,0,0,.14); }
th, td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); height: 68px; padding: 0; }
th { color: #26342f; font-size: .75rem; font-weight: 800; }
.date-head { width: var(--cell-w); min-width: var(--cell-w); max-width: var(--cell-w); writing-mode: vertical-rl; transform: rotate(180deg); text-align: left; height: var(--header-h); padding: 8px 0; border-top: 2px solid var(--line-dark); background: #f7efc9; }
.date-head.locked { background: #ffd1c7; color: #631b12; }
.lock-icon { display: inline-block; transform: rotate(180deg); margin-block-end: 3px; }
.stock-input.locked, .stock-input:disabled { color: #777; background: #eee6df; }
.product-head, .product-cell { position: sticky; right: 0; width: var(--product-w); min-width: var(--product-w); max-width: var(--product-w); border-left: 2px solid var(--line-dark); direction: ltr; }
.product-head { background: #e3ecd3; height: var(--header-h); padding: 8px; text-align: left; z-index: 130; box-shadow: -3px 0 0 var(--line-dark); }
.product-cell { background: #fffaf0; padding: 5px 8px; vertical-align: middle; z-index: 12; }
.product-name { display: block; font-weight: 760; font-size: .86rem; line-height: 1.08; white-space: normal; }
.product-meta { display: block; color: var(--green-2); font-weight: 800; font-size: .64rem; line-height: 1.12; margin-top: 4px; }
.stock-cell { width: var(--cell-w); min-width: var(--cell-w); max-width: var(--cell-w); background: linear-gradient(90deg, transparent calc(100% - 1px), rgba(19,60,52,.05)); vertical-align: middle; }
.stock-cell.stock-diff { background: linear-gradient(180deg, #fff0e8 0, #fffaf0 100%); box-shadow: inset 0 0 0 2px #d35a39; }
.stock-entry { height: 67px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.entry-user-badge { display: block; width: 100%; color: var(--green-2); font-weight: 800; font-size: .64rem; line-height: 1.12; text-align: center; pointer-events: none; margin-top: -2px; }
.cell-history-btn { width: 22px; height: 16px; border: 0; border-radius: 8px; margin-top: -1px; background: #dce9e5; color: var(--green); font-weight: 900; font-size: .68rem; line-height: 1; padding: 0; }
.stock-diff .cell-history-btn { background: #d35a39; color: white; }
.stock-input { width: 100%; height: 32px; border: 0; background: transparent; text-align: center; font-size: 1rem; font-weight: 700; color: #1f2b27; padding: 0 3px; line-height: 32px; }
.stock-input:focus { outline: 3px solid #f1c15b; background: #fff8ce; }
.stock-input.saved { animation: flash .55s ease; }
@keyframes flash { from { background: #c8ffd9; } to { background: transparent; } }
.empty { text-align: center; padding: 32px 14px; color: var(--muted); direction: ltr; }
.fab { position: fixed; right: 16px; bottom: 16px; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--green); color: white; font-size: 2rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 140; }
dialog { border: 0; border-radius: 18px; padding: 18px; width: min(92vw, 420px); box-shadow: 0 20px 80px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin-top: 0; }
dialog form { display: grid; gap: 12px; }
menu { display: flex; justify-content: flex-end; gap: 10px; padding: 0; margin: 6px 0 0; }
@media (max-width: 480px) {
  :root { --cell-w: 62px; --product-w: 138px; }
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 10px; }
  .topbar h1 { font-size: 1.02rem; line-height: 1.05; }
  .top-actions { width: auto; display: grid; grid-template-columns: repeat(2, minmax(74px, max-content)); justify-content: end; gap: 6px; }
  .top-actions button { min-width: 0; padding: 8px 8px; border-radius: 11px; font-size: .78rem; line-height: 1.05; }
  #syncBtn { grid-column: 1 / -1; justify-self: stretch; }
  #status { font-size: .70rem; white-space: normal; line-height: 1.15; }
  .controls { display: grid; grid-template-columns: minmax(0, 1fr) 82px; gap: 8px; }
  .search { grid-column: 1 / -1; }
  .warehouse { width: auto; min-width: 0; }
  .days { width: auto; }
  .export-modal { align-items: center; justify-content: center; }
  .export-card { width: min(92vw, 360px); margin: auto; padding: 22px; gap: 12px; }
  .export-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .export-actions button { min-width: 0; width: 100%; }
  .product-name { font-size: .80rem; }
}
