:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --surface: #ffffff;
  --surface-2: #eef4f1;
  --ink: #17211f;
  --muted: #69716e;
  --line: #d9ddd6;
  --accent: #25635a;
  --accent-2: #b85f35;
  --warn: #b7791f;
  --danger: #b42318;
  --ok: #1f7a4d;
  --shadow: 0 8px 24px rgba(23, 33, 31, .08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 700;
}

button:active {
  transform: translateY(1px);
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.login-screen.hidden {
  display: none;
}

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

.login-panel h1 {
  margin-bottom: 4px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  background: #fbfaf7;
  border-bottom: 1px solid var(--line);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.icon-btn {
  width: 44px;
  min-width: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 24px;
}

.tabs {
  position: sticky;
  top: 70px;
  z-index: 19;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 8px 10px;
  background: #fbfaf7;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 38px;
  padding: 0 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.tab.active {
  background: var(--accent);
  color: white;
}

main {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 14px 12px 32px;
}

#resetBtn {
  display: none;
}

.period-bar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, .72);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.period-bar .search-box {
  margin: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.toolbar.split {
  align-items: end;
}

.search-box {
  flex: 1;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-box.compact {
  flex: 0 0 118px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.summary-grid article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

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

.list.single {
  grid-template-columns: 1fr;
}

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

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.title {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.qty-control {
  display: grid;
  grid-template-columns: 38px 68px 38px;
  gap: 4px;
  align-items: center;
}

.qty-control button {
  min-height: 38px;
  padding: 0;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 20px;
}

.qty-control input {
  min-height: 38px;
  padding: 0 6px;
  text-align: center;
  font-weight: 800;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pill.warn {
  background: #fff4dc;
  color: var(--warn);
}

.pill.danger {
  background: #fee4e2;
  color: var(--danger);
}

.pill.ok {
  background: #dff3e8;
  color: var(--ok);
}

.money {
  color: var(--accent-2);
  font-weight: 800;
}

.grid-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

dialog {
  width: min(560px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .28);
}

dialog::backdrop {
  background: rgba(23, 33, 31, .42);
}

.dialog-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
}

.dialog-panel h2 {
  margin: 0;
  font-size: 18px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions button[value="cancel"],
.danger-btn,
.secondary-btn {
  background: var(--surface-2);
  color: var(--accent);
}

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

.grid-fields label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.grid-fields label.wide {
  grid-column: 1 / -1;
}

.category-block {
  display: grid;
  gap: 10px;
}

.category-title {
  margin: 8px 0 0;
  padding: 8px 2px 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
}

.line-items {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.line-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.line-item:first-child {
  border-top: 0;
}

.line-item strong {
  text-align: right;
}

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

.mini-btn {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.status-select {
  min-height: 36px;
  max-width: 150px;
}

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

.loss-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

.loss-table th,
.loss-table td {
  border: 1px solid #6f7774;
  padding: 6px 7px;
  text-align: right;
  vertical-align: middle;
}

.loss-table th {
  background: #e9f0f7;
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

.loss-table td:nth-child(2),
.loss-table td:nth-child(3),
.loss-table td:nth-child(4) {
  text-align: left;
}

.loss-table input {
  min-height: 32px;
  width: 92px;
  padding: 0 6px;
  text-align: right;
}

.receive-controls {
  display: grid;
  grid-template-columns: minmax(76px, 100px) minmax(110px, 140px);
  gap: 6px;
  justify-items: stretch;
}

.receive-controls .mini-btn {
  grid-column: 1 / -1;
}

.receive-controls input,
.receive-controls select {
  min-height: 36px;
  padding: 0 8px;
}

.order-line-heading {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  border-top: 0;
}

.order-qty-heading {
  align-items: center;
  text-align: center;
}

.notice {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.4;
}

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

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 30;
  display: none;
  background: #17211f;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
}

.toast.show {
  display: block;
}

@media (min-width: 760px) {
  .app-header {
    padding-left: 28px;
    padding-right: 28px;
  }

  .tabs {
    top: 74px;
    width: min(980px, calc(100% - 48px));
    margin: 0 auto;
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 8px 8px;
  }

  main {
    padding-top: 20px;
  }

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

  #mappingList,
  #inventoryList {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .tabs {
    gap: 4px;
    padding-left: 6px;
    padding-right: 6px;
  }

  .tab {
    min-height: 36px;
    padding: 0 3px;
    font-size: 12px;
  }

  .period-bar,
  .toolbar,
  .toolbar.split {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .toolbar {
    gap: 12px;
  }

  .search-box,
  .search-box.compact {
    width: 100%;
    min-width: 0;
    flex: none;
  }

  .toolbar button {
    width: 100%;
  }
}
