:root {
  --bg: #f6f2ea;
  --panel: #fffaf1;
  --ink: #2b2118;
  --muted: #776858;
  --brand: #8b4513;
  --brand-dark: #5d2f12;
  --line: #e7d9c4;
  --green: #1f7a43;
  --yellow: #9a6500;
  --red: #b42318;
  --blue: #2762a6;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff8e8, var(--bg) 34rem);
  color: var(--ink);
}

.hero, main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 38px 0 20px;
}
.eyebrow { margin: 0 0 8px; color: var(--brand); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: .78rem; }
h1 { margin: 0; font-size: clamp(2rem, 4vw, 4rem); line-height: 1; }
.lede { max-width: 680px; color: var(--muted); font-size: 1.08rem; }

button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 750;
}
button:hover { background: var(--brand-dark); }
button.secondary { background: #ead8bd; color: var(--brand-dark); }
button.secondary:hover { background: #dfc59d; }

.app-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
  padding: 10px;
  background: rgba(246, 242, 234, .94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 14px 40px rgba(73, 42, 12, .08);
}
.tab-button {
  background: #ead8bd;
  color: var(--brand-dark);
  border: 2px solid transparent;
  min-height: 48px;
}
.tab-button:hover { background: #dfc59d; }
.tab-button.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand-dark);
  box-shadow: 0 8px 20px rgba(93, 47, 18, .2);
}
.transaction-tab { font-size: 1.02rem; }
.tab-panel { margin-top: 18px; }
.tab-panel[hidden] { display: none !important; }

.notice, .panel, .card {
  background: rgba(255,250,241,.9);
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(73, 42, 12, .07);
}
.notice { border-radius: 16px; padding: 14px 16px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin: 18px 0; }
.card { border-radius: 18px; padding: 16px; }
.card span { display: block; color: var(--muted); font-size: .82rem; }
.card strong { display: block; margin-top: 8px; font-size: 1.55rem; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(340px, .9fr); gap: 18px; align-items: start; }
.panel { border-radius: 20px; padding: 18px; }
.toolbar { display: grid; grid-template-columns: 1.4fr .8fr .8fr; gap: 12px; margin-bottom: 14px; }
label { color: var(--muted); font-size: .82rem; font-weight: 700; }
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  color: var(--ink);
  padding: 10px 11px;
}
textarea { min-height: 96px; resize: vertical; }
.table-wrap { max-height: 650px; overflow: auto; border-radius: 14px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: 12px; border-bottom: 1px solid #f0e5d3; text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #fbf3e5; z-index: 1; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr { cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: #fff4dd; }
.product { font-weight: 800; }
.sku { display: block; color: var(--muted); font-size: .78rem; margin-top: 2px; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; color: white; font-weight: 800; font-size: .76rem; white-space: nowrap; }
.badge.in-stock { background: var(--green); }
.badge.low-stock { background: var(--yellow); }
.badge.out-of-stock { background: var(--red); }
.badge.overstock { background: var(--blue); }

.details-panel { position: sticky; top: 16px; }
.empty { color: var(--muted); margin: 0; }
.details-header { display: flex; justify-content: space-between; gap: 12px; align-items: start; border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.details-header h2 { margin: 0 0 5px; font-size: 1.3rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.detail { background: white; border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.detail span { display: block; color: var(--muted); font-size: .75rem; font-weight: 800; }
.detail strong { display: block; margin-top: 4px; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.controls button { margin-top: 6px; width: 100%; }
.note-actions { display: flex; gap: 8px; margin-top: 8px; }
.note-actions button { flex: 1; }
.help-panel { margin: 18px 0 36px; }
.help-panel h2 { margin-top: 0; }
.help-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.help-grid article { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.help-grid h3 { margin: 0 0 8px; }
.help-grid p { margin: 0; color: var(--muted); }

@media (max-width: 960px) {
  .hero, .workspace { display: block; }
  .hero button { margin-top: 12px; }
  .app-tabs { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .toolbar, .help-grid { grid-template-columns: 1fr; }
  .details-panel { position: static; margin-top: 18px; }
}

@media (max-width: 560px) {
  .app-tabs { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  th:nth-child(2), td:nth-child(2), th:nth-child(5), td:nth-child(5) { display: none; }
}

.add-product-panel, .history-panel { margin: 0 0 18px; }
.add-product-header, .history-header { display: flex; justify-content: space-between; gap: 18px; align-items: start; }
.history-header h2 { margin: 0 0 6px; }
.history-header p { margin: 0; color: var(--muted); max-width: 720px; }
.history-header label { min-width: min(360px, 100%); }
.history-wrap { max-height: 650px; }
.history-wrap tr { cursor: default; }
.empty-state { color: var(--muted); line-height: 1.45; padding: 22px; }
.transaction-id { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; font-size: .78rem; color: var(--muted); }
.qty-positive { color: var(--green); font-weight: 850; }
.qty-negative { color: var(--red); font-weight: 850; }
.qty-neutral { color: var(--muted); font-weight: 850; }
.add-product-header { display: flex; justify-content: space-between; gap: 18px; align-items: start; }
.add-product-header h2 { margin: 0 0 6px; }
.add-product-header p { margin: 0; color: var(--muted); }
.product-form { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; }
.hidden { display: none !important; }
.form-help { background: white; border: 1px solid var(--line); border-radius: 14px; color: var(--muted); padding: 10px 12px; margin-bottom: 12px; }
.sku-row { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 12px; align-items: end; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.form-error { color: var(--red); font-weight: 800; min-height: 1.2em; margin: 10px 0; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; }
button:disabled { cursor: not-allowed; opacity: .65; }

@media (max-width: 960px) {
  .add-product-header, .history-header, .sku-row { display: block; }
  .add-product-header button, .sku-row button { margin-top: 12px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-actions button { width: 100%; }
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin-bottom: 16px;
}
.section-header h2 { margin: 0 0 6px; }
.section-header p { margin: 0; color: var(--muted); max-width: 760px; }
.po-panel h3, .import-export-panel h3 { margin: 18px 0 10px; }
.po-wrap { margin-top: 8px; }
.po-detail-row td {
  background: #fffaf1;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.5;
}
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.row-actions button { padding: 8px 10px; }
.badge.po-draft { background: var(--blue); }
.badge.po-ordered { background: var(--yellow); }
.badge.po-received { background: var(--green); }
.muted-text { color: var(--muted); font-weight: 800; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tool-card { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.tool-card h3 { margin-top: 0; }
.tool-card p { color: var(--muted); }
#importForm { display: grid; gap: 12px; }
.form-error.success { color: var(--green); }

@media (min-width: 961px) {
  .app-tabs { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .section-header, .tool-grid { display: block; }
  .section-header button { margin-top: 12px; }
  .tool-card + .tool-card { margin-top: 14px; }
}
