:root {
  --bg: #f4f6f1;
  --surface: #ffffff;
  --ink: #17201b;
  --muted: #667166;
  --line: #dce2d8;
  --primary: #1f6b4d;
  --primary-dark: #154f39;
  --accent: #d98b2b;
  --danger: #b53d35;
  --shadow: 0 16px 42px rgba(25, 39, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #edf2eb 0%, #f8faf6 100%);
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #14251d;
  color: #eef5ee;
  padding: 24px 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand.compact {
  margin-bottom: 8px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #1c160e;
  font-size: 22px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin-top: 3px;
  color: #aebbad;
  font-size: 13px;
}

.login-card .brand p {
  color: var(--muted);
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dfe9de;
  text-align: left;
  padding: 0 12px;
}

.nav-item:hover,
.nav-item.active {
  background: #244233;
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 30px;
}

.toolbar,
.action-row,
.row-actions,
.panel-title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar {
  justify-content: flex-end;
}

.action-row {
  justify-content: flex-end;
  margin: 12px 0 14px;
}

.compact-actions {
  justify-content: flex-start;
  margin: 0;
}

.panel-title-row {
  justify-content: space-between;
}

.inline-note {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: min(320px, 100%);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.inline-note input {
  min-height: 34px;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.ghost-button.warn {
  color: var(--danger);
  border-color: #efc4bf;
}

.danger-button {
  background: #fff6f5;
  border-color: #efc4bf;
  color: var(--danger);
}

.user-badge {
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.metrics article,
.panel,
.view {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 16px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.view {
  display: none;
  padding: 18px;
}

.view.active {
  display: block;
}

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

.section-head h3,
.panel h3 {
  font-size: 18px;
}

.muted-count {
  margin-left: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.section-head p,
.hint {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.search-input {
  width: min(360px, 100%);
}

.stock-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}

.summary-card {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 12px;
}

.summary-card.total {
  background: #eef7f1;
  border-color: #b9d8c4;
}

.summary-card span,
.summary-card small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-card strong {
  display: block;
  margin: 7px 0 4px;
  font-size: 22px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 9px 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.check-line {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 8px;
}

.check-line input {
  width: auto;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
}

.upload-panel {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 14px;
}

.scanner-panel {
  margin-bottom: 14px;
}

.history-filters {
  display: grid;
  grid-template-columns: minmax(120px, 160px) repeat(2, minmax(150px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.range-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.history-table-wrap {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow: auto;
}

.history-summary-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.history-summary-card:hover {
  border-color: #b7c9bd;
  background: #f4f8f3;
}

.history-summary-card strong {
  font-size: 15px;
}

.history-summary-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.history-section {
  display: grid;
  gap: 8px;
}

.history-section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  color: var(--ink);
}

.history-section-title span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.history-pivot-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.history-pivot-table th,
.history-pivot-table td {
  border: 1px solid var(--line);
  padding: 7px 8px;
  background: #fff;
  white-space: nowrap;
}

.history-pivot-table th {
  background: #edf2eb;
}

.history-pivot-table .product-col {
  min-width: 220px;
  text-align: left;
}

.history-pivot-table .num {
  text-align: right;
}

.history-pivot-table .total-col,
.history-pivot-table tfoot td {
  font-weight: 800;
  background: #f7faf8;
}

.scanner-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
}

.scanner-video {
  width: min(520px, 100%);
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  object-fit: cover;
}

.stock-available {
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2eb;
  color: var(--primary-dark);
  padding: 0 12px;
  font-weight: 800;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-button input {
  display: none;
}

.inline-form {
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  align-items: end;
  margin-bottom: 14px;
}

.inline-form h3 {
  grid-column: 1 / -1;
}

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

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  background: #ffffff;
}

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

th {
  background: #edf2eb;
  color: #445044;
  font-size: 13px;
}

.sort-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  font-weight: 800;
}

.num .sort-button {
  text-align: right;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.grid-table td {
  padding: 4px;
}

.grid-table input {
  min-height: 36px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.grid-table input:focus {
  outline: 2px solid rgba(31, 107, 77, 0.25);
  background: #fff;
}

.num {
  text-align: right;
}

.row-actions {
  justify-content: flex-end;
}

.small-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 0 10px;
}

.small-button.warn {
  color: var(--danger);
  border-color: #efc4bf;
}

.mini-list {
  display: grid;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
}

.shortage-summary {
  display: grid;
  gap: 8px;
  border: 1px solid #efc4bf;
  border-radius: 8px;
  background: #fff6f5;
  color: var(--danger);
  padding: 12px;
}

.shortage-summary strong {
  color: var(--danger);
}

.shortage-summary div {
  display: grid;
  gap: 4px;
  color: #6f2d28;
  font-size: 13px;
}

.scanner-panel .mini-list {
  margin-top: 10px;
}

.mini-list.tall {
  max-height: 520px;
}

.mini-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.mini-item strong,
.mini-item span {
  display: block;
}

.mini-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.history-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  overflow: hidden;
}

.history-group summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  cursor: pointer;
}

.history-group summary strong,
.history-group summary span {
  display: block;
}

.history-group summary span {
  color: var(--muted);
  font-size: 12px;
}

.history-detail-list {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px;
}

.history-detail {
  background: #ffffff;
}

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(380px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #14251d;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 16px;
  }

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

  .main {
    padding: 16px;
  }

  .metrics,
  .two-column,
  .inline-form,
  .upload-panel,
  .scanner-grid {
    grid-template-columns: 1fr;
  }

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

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