:root {
  --bg: #f4f2ec;
  --surface: #fffdf8;
  --surface-2: #f8f5ee;
  --ink: #1c241f;
  --muted: #6d746f;
  --line: #dedbd2;
  --brand: #203c2c;
  --brand-2: #315941;
  --accent: #d8a94b;
  --danger: #b94b45;
  --warning: #b47a22;
  --success: #3e7c54;
  --shadow: 0 14px 40px rgba(30, 42, 35, 0.08);
  --radius: 20px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(216, 169, 75, 0.10), transparent 30%),
    var(--bg);
  color: var(--ink);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.hidden { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: 40px;
  align-items: center;
  padding: clamp(24px, 7vw, 100px);
}
.auth-brand { display: flex; align-items: center; gap: 22px; }
.auth-brand h1 { font-size: clamp(38px, 6vw, 76px); margin: 4px 0 12px; letter-spacing: -0.055em; }
.auth-brand p:last-child { max-width: 520px; color: var(--muted); font-size: 18px; }
.brand-mark {
  width: 92px; height: 92px; border-radius: 28px;
  display: grid; place-items: center;
  background: var(--brand); color: white;
  font-family: Georgia, serif; font-size: 52px;
  box-shadow: var(--shadow);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 25px; }
.auth-card {
  width: 100%; max-width: 500px; justify-self: end;
  background: rgba(255, 253, 248, 0.94); border: 1px solid rgba(222, 219, 210, 0.8);
  border-radius: 28px; padding: 30px; box-shadow: var(--shadow); backdrop-filter: blur(16px);
}
.setup-warning {
  display: grid; gap: 6px; padding: 14px 16px; margin-bottom: 18px;
  border: 1px solid #e6c989; border-radius: 14px; background: #fff7e4; color: #735214;
}
.setup-warning span { font-size: 13px; line-height: 1.5; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 14px; margin-bottom: 24px; }
.segment { border: 0; background: transparent; padding: 11px 14px; border-radius: 10px; color: var(--muted); font-weight: 700; }
.segment.active { background: white; color: var(--ink); box-shadow: 0 3px 12px rgba(0,0,0,.06); }
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; }
label > span { font-size: 13px; font-weight: 750; color: #4f5752; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: white; color: var(--ink);
  border-radius: 12px; padding: 12px 13px; outline: none; transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(49, 89, 65, 0.12); }
textarea { resize: vertical; }
.checkbox-field { grid-template-columns: auto 1fr; align-items: center; align-content: end; padding: 10px 0; }
.checkbox-field input { width: 18px; height: 18px; accent-color: var(--brand); }
.checkbox-field span { font-size: 14px; }
.form-message { min-height: 20px; font-size: 13px; color: var(--muted); }

.primary-btn, .outline-btn, .ghost-btn, .text-btn, .icon-btn {
  border-radius: 12px; font-weight: 800; transition: transform .15s, opacity .15s, background .15s;
}
.primary-btn:hover, .outline-btn:hover, .action-card:hover, .product-card:hover { transform: translateY(-1px); }
.primary-btn { border: 1px solid var(--brand); background: var(--brand); color: white; padding: 12px 17px; }
.primary-btn.compact { padding: 10px 14px; }
.outline-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 10px 14px; }
.ghost-btn { border: 0; background: transparent; color: var(--muted); padding: 10px 12px; }
.text-btn { border: 0; background: transparent; color: var(--brand-2); padding: 8px 0; }
.icon-btn { border: 0; background: var(--surface-2); color: var(--ink); width: 36px; height: 36px; font-size: 24px; display: grid; place-items: center; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 10;
  display: flex; flex-direction: column; padding: 24px 18px;
  background: #18271f; color: white;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 28px; }
.sidebar-brand div:last-child { display: grid; gap: 2px; }
.sidebar-brand strong { font-size: 16px; }
.sidebar-brand span { color: rgba(255,255,255,.58); font-size: 12px; }
.side-nav { display: grid; gap: 7px; }
.nav-btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 0; background: transparent; color: rgba(255,255,255,.68);
  padding: 12px 13px; border-radius: 12px; text-align: left; font-weight: 700;
}
.nav-btn span { width: 20px; text-align: center; font-size: 18px; }
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.10); color: white; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.1); }
.user-chip { display: flex; gap: 9px; min-width: 0; align-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.12); font-weight: 900; }
.user-chip div:last-child { display: grid; min-width: 0; }
.user-chip strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.user-chip span { color: rgba(255,255,255,.5); font-size: 11px; }
.sidebar-footer .ghost-btn { color: rgba(255,255,255,.72); }

.main-content { margin-left: 260px; padding: 28px 34px 50px; max-width: 1700px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.topbar h2 { margin: 2px 0 0; font-size: clamp(26px, 3vw, 38px); letter-spacing: -0.035em; }
.topbar-actions { display: flex; gap: 10px; }
.eyebrow { margin: 0; color: var(--brand-2); letter-spacing: .14em; font-size: 10px; font-weight: 900; }
.muted { color: var(--muted); margin: 5px 0 0; font-size: 14px; line-height: 1.5; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.summary-card {
  min-height: 142px; display: flex; flex-direction: column; justify-content: space-between;
  padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 6px 20px rgba(30,42,35,.04);
}
.summary-card strong { font-size: 42px; line-height: 1; letter-spacing: -.05em; }
.summary-card small { color: var(--muted); }
.summary-label { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; }
.summary-card.danger { border-top: 4px solid var(--danger); }
.summary-card.warning { border-top: 4px solid var(--warning); }
.summary-card.success { border-top: 4px solid var(--success); }
.summary-card.neutral { border-top: 4px solid var(--brand); }

.dashboard-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: 18px; margin-bottom: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: 0 8px 26px rgba(30,42,35,.04); }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.panel-header h3 { margin: 3px 0 0; font-size: 21px; letter-spacing: -.02em; }
.panel-header.responsive { align-items: end; }
.list-stack { display: grid; gap: 10px; }
.empty-state { padding: 28px 18px; text-align: center; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); }
.replenishment-item, .history-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 13px 14px; border: 1px solid var(--line); border-radius: 14px; background: white;
}
.replenishment-item strong { display: block; margin-bottom: 3px; }
.replenishment-item span { color: var(--muted); font-size: 12px; }
.quantity-badge { min-width: 54px; text-align: center; padding: 8px 10px; border-radius: 10px; background: #fff1ee; color: var(--danger); font-weight: 900; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.action-card { min-height: 104px; text-align: left; border: 1px solid var(--line); border-radius: 15px; padding: 15px; background: white; transition: transform .15s, border-color .15s; }
.action-card:hover { border-color: #a8b5ac; }
.action-card strong { display: block; color: var(--ink); margin-bottom: 7px; }
.action-card span { color: var(--muted); font-size: 12px; line-height: 1.45; }

.location-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.location-grid.large { grid-template-columns: repeat(3, minmax(0,1fr)); }
.location-card { padding: 16px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.location-card .location-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.location-card h4 { margin: 0; font-size: 15px; }
.location-card p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.location-card .status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(62,124,84,.1); }
.location-card .status-dot.alert { background: var(--danger); box-shadow: 0 0 0 4px rgba(185,75,69,.1); }
.location-metrics { display: flex; gap: 16px; margin-top: 17px; padding-top: 12px; border-top: 1px solid var(--line); }
.location-metrics span { display: grid; gap: 2px; color: var(--muted); font-size: 11px; }
.location-metrics strong { color: var(--ink); font-size: 17px; }
.card-actions { display: flex; gap: 7px; margin-top: 14px; }
.card-actions button { flex: 1; }

.inline-field { min-width: 240px; }
.inventory-table { display: grid; gap: 9px; }
.inventory-row {
  display: grid; grid-template-columns: minmax(180px, 1.4fr) minmax(110px, .7fr) repeat(3, minmax(82px, .45fr));
  gap: 12px; align-items: center; padding: 13px 14px; border: 1px solid var(--line); border-radius: 14px; background: white;
}
.inventory-row.header { background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .05em; }
.inventory-row .product-cell strong { display: block; }
.inventory-row .product-cell span { color: var(--muted); font-size: 12px; }
.inventory-row input { padding: 9px 10px; }
.stock-status { display: inline-flex; width: fit-content; padding: 6px 8px; border-radius: 9px; font-size: 11px; font-weight: 900; }
.stock-status.low { background: #fff0ee; color: var(--danger); }
.stock-status.near { background: #fff6e5; color: var(--warning); }
.stock-status.ok { background: #ebf6ee; color: var(--success); }
.form-footer { display: flex; justify-content: flex-end; margin-top: 18px; }

.toolbar { display: grid; grid-template-columns: 1fr 180px; gap: 10px; margin-bottom: 16px; }
.product-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.product-card { border: 1px solid var(--line); border-radius: 16px; background: white; padding: 16px; transition: transform .15s, border-color .15s; }
.product-card:hover { border-color: #a8b5ac; }
.product-card.inactive { opacity: .66; }
.product-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.product-card h4 { margin: 0 0 5px; }
.product-card p { margin: 0; color: var(--muted); font-size: 12px; }
.tag { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 900; text-transform: uppercase; }
.product-locations { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0; }
.product-location-chip { border: 1px solid var(--line); padding: 6px 8px; border-radius: 9px; font-size: 11px; color: var(--muted); }
.product-card-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.product-card-footer span { font-size: 11px; color: var(--muted); }

.timeline { display: grid; gap: 11px; }
.history-item { grid-template-columns: auto minmax(0,1fr) auto; }
.history-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); font-weight: 900; }
.history-main strong { display: block; }
.history-main p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.history-time { text-align: right; font-size: 11px; color: var(--muted); }

.modal { width: min(94vw, 620px); max-height: 90vh; padding: 0; border: 0; border-radius: 22px; background: transparent; }
.modal::backdrop { background: rgba(16, 24, 19, .52); backdrop-filter: blur(4px); }
.modal-card { display: grid; gap: 16px; max-height: 90vh; overflow-y: auto; background: var(--surface); padding: 23px; border-radius: 22px; box-shadow: 0 24px 80px rgba(0,0,0,.22); }
.modal-card.wide { width: min(94vw, 860px); }
#productDialog { width: min(94vw, 860px); }
.modal-header { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.modal-header h3 { margin: 3px 0 0; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1.2fr 1fr .8fr; gap: 12px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.subsection-header { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 16px; }
.subsection-header div { display: grid; gap: 3px; }
.subsection-header span { color: var(--muted); font-size: 12px; }
.location-stock-editor { display: grid; gap: 8px; }
.stock-editor-row { display: grid; grid-template-columns: minmax(180px,1.2fr) repeat(3,minmax(90px,.55fr)); gap: 9px; align-items: center; padding: 11px; border: 1px solid var(--line); border-radius: 13px; background: white; }
.stock-editor-name { display: flex; align-items: center; gap: 9px; }
.stock-editor-name input { width: 18px; height: 18px; accent-color: var(--brand); }
.stock-editor-row label span { font-size: 10px; }
.stock-editor-row input[type="number"] { padding: 9px; }
.stock-editor-row.disabled { opacity: .5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 6px; }
.install-steps { display: grid; gap: 12px; margin: 0; padding-left: 22px; color: var(--muted); line-height: 1.5; }

.toast {
  position: fixed; top: 20px; right: 20px; z-index: 100;
  max-width: min(380px, calc(100vw - 40px));
  padding: 12px 15px; border-radius: 12px; background: #17251d; color: white;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(-10px); pointer-events: none; transition: .22s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.loading-card { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 140px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.spinner { width: 22px; height: 22px; border: 3px solid #d9ddd9; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.mobile-nav { display: none; }

@media (max-width: 1180px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .location-grid, .location-grid.large { grid-template-columns: repeat(2, 1fr); }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; padding: 28px 18px; align-content: center; }
  .auth-brand { align-items: flex-start; }
  .brand-mark { width: 66px; height: 66px; border-radius: 20px; font-size: 38px; flex: none; }
  .auth-card { justify-self: stretch; max-width: none; }
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 20px 14px calc(90px + var(--safe-bottom)); }
  .topbar { align-items: flex-start; }
  .topbar-actions .outline-btn { display: none; }
  .mobile-nav {
    position: fixed; display: grid; grid-template-columns: repeat(5, 1fr); z-index: 20;
    inset: auto 0 0; padding: 8px 8px calc(8px + var(--safe-bottom));
    background: rgba(255,253,248,.96); border-top: 1px solid var(--line); backdrop-filter: blur(16px);
  }
  .mobile-nav-btn { display: grid; gap: 2px; place-items: center; border: 0; background: transparent; color: var(--muted); padding: 6px 2px; border-radius: 10px; }
  .mobile-nav-btn span { font-size: 19px; }
  .mobile-nav-btn small { font-size: 9px; font-weight: 800; }
  .mobile-nav-btn.active { color: var(--brand); background: #eef2ee; }
  .inventory-row { grid-template-columns: minmax(150px, 1.3fr) repeat(3, minmax(76px,.55fr)); overflow-x: auto; }
  .inventory-row > :nth-child(2) { display: none; }
  .inventory-row.header > :nth-child(2) { display: none; }
}

@media (max-width: 620px) {
  .topbar h2 { font-size: 27px; }
  .topbar-actions { align-self: center; }
  .summary-grid { gap: 10px; }
  .summary-card { min-height: 125px; padding: 15px; }
  .summary-card strong { font-size: 34px; }
  .summary-card small { font-size: 10px; }
  .panel { padding: 16px; border-radius: 17px; }
  .panel-header.responsive { display: grid; align-items: stretch; }
  .inline-field { min-width: 0; }
  .action-grid, .location-grid, .location-grid.large, .product-grid { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr; }
  .inventory-table { overflow-x: auto; padding-bottom: 4px; }
  .inventory-row { min-width: 570px; }
  .form-grid, .form-grid.two { grid-template-columns: 1fr; }
  .stock-editor-row { grid-template-columns: 1fr 1fr 1fr; }
  .stock-editor-name { grid-column: 1 / -1; }
  .modal { width: 96vw; }
  .modal-card, .modal-card.wide { width: 96vw; padding: 18px; border-radius: 18px; }
  .history-item { grid-template-columns: auto 1fr; }
  .history-time { grid-column: 2; text-align: left; }
  .auth-brand h1 { font-size: 38px; }
  .auth-brand p:last-child { font-size: 15px; }
}
