:root {
  --ink: #24160d;
  --soft-ink: #5f4939;
  --muted: #80664f;
  --bg: #f6ead8;
  --paper: #fff8ec;
  --paper-strong: #ffffff;
  --rail: #2a1710;
  --line: #dfc7a6;
  --line-dark: #8f6031;
  --copper: #b55f19;
  --copper-dark: #7f3715;
  --gold: #d79730;
  --danger: #b13e28;
  --good: #24784f;
  --blue: #1f5f70;
  --shadow: 0 18px 45px rgba(77, 45, 20, 0.14);
  --soft-shadow: 0 8px 24px rgba(77, 45, 20, 0.1);
  font-family: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(255,255,255,0.68), rgba(246,234,216,0.62)),
    radial-gradient(circle at 84% 10%, rgba(215, 151, 48, 0.26), transparent 28%),
    radial-gradient(circle at 20% 88%, rgba(31, 95, 112, 0.12), transparent 32%),
    repeating-linear-gradient(0deg, rgba(126, 82, 43, 0.04) 0 1px, transparent 1px 38px),
    var(--bg);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

button, input, select { font: inherit; }

.sidebar {
  min-height: 100vh;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(42, 23, 16, 0.98), rgba(67, 35, 17, 0.96)),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.035) 0 1px, transparent 1px 14px);
  border-right: 1px solid rgba(127, 55, 21, 0.5);
  position: sticky;
  top: 0;
  box-shadow: 12px 0 40px rgba(77, 45, 20, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(223, 199, 166, 0.25);
  color: #fff3d7;
}

.brand img {
  width: 74px;
  height: 74px;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.32));
}

.brand strong {
  display: block;
  font-size: 25px;
  line-height: 1;
}

.brand span {
  color: #d9bb8a;
}

.tabs {
  display: grid;
  gap: 9px;
  margin-top: 24px;
}

.tab, .ghost, .primary {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.tab {
  text-align: left;
  padding: 11px 13px;
  color: #fff7e8;
  background: rgba(255, 248, 236, 0.08);
  border-color: rgba(223, 199, 166, 0.22);
}

.tab:hover, .ghost:hover, .primary:hover {
  transform: translateY(-1px);
}

.tab.is-active, .primary {
  color: #fff8ed;
  background: linear-gradient(180deg, #cf7a25, #8b3f17);
  border-color: #e3a04d;
  box-shadow: inset 0 1px rgba(255,255,255,0.32), 0 10px 22px rgba(127, 55, 21, 0.2);
}

.backup {
  display: grid;
  gap: 9px;
  margin-top: 26px;
}

.ghost, .file-button {
  display: grid;
  place-items: center;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff5e4;
}

.file-button input { display: none; }

main {
  min-width: 0;
  padding: 30px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--copper-dark);
  font-weight: 700;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 44px;
  color: #2e1b10;
  text-shadow: 0 2px 0 rgba(255,255,255,0.55);
}

h2 {
  font-size: 23px;
}

.date-picker {
  display: grid;
  gap: 7px;
  min-width: 190px;
}

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  color: var(--soft-ink);
  font-weight: 700;
}

input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: var(--paper-strong);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
}

input:focus, select:focus {
  outline: 3px solid rgba(215, 151, 48, 0.25);
  border-color: var(--gold);
}

.panel { display: none; }
.panel.is-active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.metrics article, .card {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,248,236,0.96)),
    var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.metrics article::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 4px;
  background: linear-gradient(90deg, var(--copper), var(--gold), var(--blue));
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
}

.metrics strong {
  font-size: 32px;
  color: var(--copper-dark);
}

.metrics.compact { margin-top: 16px; }

.two-col, .workbench {
  display: grid;
  grid-template-columns: minmax(280px, 0.78fr) minmax(0, 1.42fr);
  gap: 14px;
  align-items: start;
}

.card {
  padding: 18px;
}

.wide { min-width: 0; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.section-head span, .list small, th {
  color: var(--muted);
}

.section-head input, .section-head select, .section-head label {
  max-width: 250px;
}

.form-card {
  display: grid;
  gap: 14px;
}

.form-grid, .opening-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.opening-tools {
  align-items: end;
  padding: 12px;
  border: 1px solid rgba(215, 151, 48, 0.45);
  border-radius: 8px;
  background: linear-gradient(135deg, #fff9ed, #f7e1bd);
}

.preview {
  min-height: 52px;
  border: 1px dashed #c79b61;
  border-radius: 8px;
  padding: 11px;
  color: var(--soft-ink);
  background: #fffaf1;
}

.stock-sheet {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.sheet-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.sheet-hero p {
  margin: 6px 0 0;
  color: var(--muted);
}

.sheet-actions {
  display: grid;
  grid-template-columns: minmax(130px, auto) minmax(130px, auto);
  gap: 10px;
}

.sheet-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(140px, 0.6fr) minmax(140px, auto);
  gap: 12px;
  align-items: end;
}

.stock-summary, .save-status {
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--soft-ink);
  background: #fff3dd;
  border: 1px solid var(--line);
  font-weight: 700;
}

.save-status {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--good);
}

.quick-grid {
  display: grid;
  gap: 8px;
}

.quick-header, .quick-row {
  display: grid;
  grid-template-columns: minmax(210px, 1.7fr) repeat(6, minmax(82px, 0.65fr)) minmax(92px, 0.75fr);
  gap: 8px;
  align-items: center;
}

.quick-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 12px;
  color: #fff8ed;
  background: linear-gradient(180deg, #814018, #4d2816);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  font-size: 13px;
  font-weight: 700;
}

.quick-body {
  display: grid;
  gap: 8px;
}

.quick-row {
  padding: 10px 12px;
  border: 1px solid rgba(223, 199, 166, 0.95);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--soft-shadow);
}

.quick-item {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.quick-item strong {
  overflow-wrap: anywhere;
}

.quick-item small, .quick-result small {
  color: var(--muted);
}

.quick-input {
  gap: 4px;
}

.quick-input span {
  display: none;
}

.quick-input input {
  min-height: 38px;
  padding: 7px 8px;
  text-align: center;
}

.quick-result {
  display: grid;
  gap: 2px;
  min-height: 44px;
  align-content: center;
  padding: 6px 8px;
  border-radius: 8px;
  background: #fff3dd;
  border: 1px solid rgba(215, 151, 48, 0.42);
}

.quick-result strong {
  color: var(--copper-dark);
}

.quick-result.has-danger {
  background: #fff0ea;
  border-color: rgba(177, 62, 40, 0.35);
}

.quick-result.has-danger strong,
.quick-result.has-danger small {
  color: var(--danger);
}

.quick-result.has-good {
  background: #edf8f0;
  border-color: rgba(36, 120, 79, 0.3);
}

.quick-result.has-good strong,
.quick-result.has-good small {
  color: var(--good);
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid rgba(223, 199, 166, 0.9);
  border-radius: 8px;
  background: rgba(255,255,255,0.68);
  box-shadow: var(--soft-shadow);
}

.list-item strong {
  color: var(--copper-dark);
}

.line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.danger { color: var(--danger); }
.good { color: var(--good); }
.gold { color: var(--copper-dark); font-weight: 700; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.58);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
}

th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid rgba(223, 199, 166, 0.86);
  white-space: nowrap;
}

th {
  background: #fff0d6;
  font-weight: 700;
}

tbody tr:hover {
  background: rgba(215, 151, 48, 0.1);
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.item-card {
  display: grid;
  gap: 9px;
  border: 1px solid rgba(223, 199, 166, 0.95);
  border-radius: 8px;
  padding: 13px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.82), rgba(255,248,236,0.95));
  box-shadow: var(--soft-shadow);
}

.item-card input {
  min-height: 38px;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.empty {
  padding: 18px;
  color: var(--muted);
  border: 1px dashed var(--line-dark);
  border-radius: 8px;
  text-align: center;
  background: rgba(255,255,255,0.44);
}

.sync-panel {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid rgba(215, 151, 48, 0.42);
  border-radius: 8px;
  background: linear-gradient(135deg, #fff9ed, #f7e1bd);
}

.sync-panel strong {
  color: var(--copper-dark);
  font-size: 19px;
}

.sync-panel span {
  color: var(--soft-ink);
}

.global-sync {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid rgba(223, 199, 166, 0.26);
  border-radius: 8px;
  color: #fff3d7;
  background: rgba(255, 248, 236, 0.08);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.global-sync.sync-error {
  color: #ffe1d8;
  border-color: rgba(255, 180, 160, 0.45);
  background: rgba(177, 62, 40, 0.22);
}

@media (max-width: 1080px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: static;
    padding-bottom: 16px;
  }

  .brand {
    align-items: center;
  }

  .tabs {
    grid-template-columns: repeat(6, minmax(112px, 1fr));
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .tab {
    text-align: center;
  }

  .backup {
    grid-template-columns: 1fr 1fr;
  }

  .metrics, .two-col, .workbench {
    grid-template-columns: 1fr;
  }

  .quick-header {
    display: none;
  }

  .quick-row {
    grid-template-columns: minmax(180px, 1.4fr) repeat(3, minmax(82px, 1fr));
  }

  .quick-item {
    grid-column: 1 / -1;
  }

  .quick-input span {
    display: block;
  }
}

@media (max-width: 720px) {
  main, .sidebar {
    padding: 16px;
  }

  .topbar, .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 34px;
  }

  h2 {
    font-size: 21px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tabs {
    grid-template-columns: repeat(3, minmax(105px, 1fr));
  }

  .form-grid, .opening-tools, .mini-grid, .backup {
    grid-template-columns: 1fr;
  }

  .sheet-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .sheet-actions, .sheet-controls {
    grid-template-columns: 1fr;
  }

  .quick-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quick-result {
    grid-column: 1 / -1;
  }

  .inventory-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .metrics {
    grid-template-columns: 1fr;
  }

  .brand img {
    width: 62px;
    height: 62px;
  }
}
