:root {
  --bg: #f3efe6;
  --bg-deep: #e8e1d3;
  --ink: #1a1c19;
  --muted: #5c6158;
  --card: #fffcf6;
  --line: #d9d1c2;
  --accent: #c45c16;
  --accent-soft: #f6e4d4;
  --green: #1f5c45;
  --green-soft: #dcebe3;
  --red: #b42318;
  --red-soft: #f8e4e1;
  --amber: #9a6700;
  --amber-soft: #f7ebc8;
  --sidebar: #1a1c19;
  --sidebar-text: #efe8db;
  --shadow: 0 10px 30px rgba(26, 28, 25, 0.08);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar-h: calc(64px + var(--safe-b));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Barlow, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

h1,
h2,
h3,
.brand h1,
.stat-value,
.page-kicker,
.brand-kicker {
  font-family: "Barlow Condensed", Barlow, sans-serif;
  letter-spacing: 0.02em;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.app {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.sidebar {
  display: none;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 28px 20px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  margin-bottom: 28px;
  text-decoration: none;
  color: inherit;
}

.brand-logo {
  width: 100%;
  background: #fff;
  border-radius: 16px;
  padding: 14px 12px 10px;
  display: block;
}

.brand-kicker,
.page-kicker,
.sidebar-foot {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  font-weight: 700;
  color: #b7b09f;
}

.brand .brand-kicker {
  text-align: center;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-nav a,
.tabbar a {
  text-decoration: none;
  border-radius: 12px;
  color: inherit;
}

.side-nav a {
  padding: 12px 14px;
  color: #d8d2c4;
}

.side-nav a.active,
.side-nav a:hover {
  background: #2a2d27;
  color: #fff;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 24px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px 8px;
}

.mobile-banner {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 8px;
}

.mobile-banner img {
  height: 64px;
  width: auto;
  max-width: min(200px, 68vw);
  object-fit: contain;
}

.report-head {
  text-align: center;
}

.report-logo,
.modal-logo {
  display: block;
  width: min(220px, 70%);
  margin: 0 auto 12px;
}

.topbar h2 {
  margin: 2px 0 0;
  font-size: 32px;
  line-height: 1;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 8px 16px calc(24px + var(--tabbar-h));
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--tabbar-h);
  padding: 8px 8px var(--safe-b);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: #fffdf8;
  border-top: 1px solid var(--line);
  z-index: 20;
}

.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  min-height: 48px;
}

.tabbar a.active {
  color: var(--accent);
}

.tabbar svg {
  width: 22px;
  height: 22px;
}

.grid {
  display: grid;
  gap: 12px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.stat-value {
  margin: 6px 0 0;
  font-size: 28px;
}

.stat-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.alert {
  border-left: 4px solid var(--amber);
  background: var(--amber-soft);
}

.row-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg-deep);
}

.badge.in {
  background: var(--green-soft);
  color: var(--green);
}

.badge.out {
  background: var(--red-soft);
  color: var(--red);
}

.badge.low {
  background: var(--amber-soft);
  color: var(--amber);
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.search,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 48px;
  font-size: 16px;
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.btn,
.ghost-btn,
.danger-btn {
  border: 0;
  border-radius: 12px;
  min-height: 48px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

.btn {
  background: var(--ink);
  color: #fff;
}

.btn.accent {
  background: var(--accent);
}

.btn.green {
  background: var(--green);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.danger-btn {
  background: var(--red-soft);
  color: var(--red);
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn-row > * {
  flex: 1;
}

.part-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.qty-big {
  font-family: "Barlow Condensed", sans-serif;
  font-size: 28px;
  text-align: right;
  line-height: 1;
}

.empty {
  text-align: center;
  padding: 28px 12px;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 12px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  z-index: 40;
  max-width: calc(100% - 32px);
}

.modal-root {
  position: fixed;
  inset: 0;
  background: rgba(26, 28, 25, 0.45);
  display: grid;
  place-items: end center;
  z-index: 50;
}

.modal-root[hidden],
#modal-root[hidden] {
  display: none !important;
  pointer-events: none !important;
}

.sheet {
  width: min(560px, 100%);
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + var(--safe-b));
}

.suggest {
  position: relative;
}

.suggest-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  max-height: 220px;
  overflow: auto;
  z-index: 8;
}

.suggest-list button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    grid-column: 1;
    grid-row: 1 / -1;
  }

  .topbar {
    grid-column: 2;
    grid-row: 1;
    padding: 24px 28px 8px;
  }

  .content {
    grid-column: 2;
    grid-row: 2;
    padding: 8px 28px 32px;
  }

  .tabbar {
    display: none;
  }

  .mobile-banner {
    display: none;
  }

  .stats {
    grid-template-columns: repeat(4, 1fr);
  }

  .form-grid.two {
    grid-template-columns: 1fr 1fr;
  }

  .modal-root {
    place-items: center;
  }

  .sheet {
    border-radius: 20px;
    padding: 24px;
  }
}

@media print {
  .sidebar,
  .tabbar,
  .topbar .ghost-btn,
  .mobile-banner,
  .toolbar .ghost-btn,
  .btn-row {
    display: none !important;
  }

  .content {
    padding: 0;
  }

  .app {
    display: block;
  }
}
