:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --ink: #17201e;
  --muted: #63716e;
  --line: #d9e1de;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --warn: #b45309;
  --danger: #b91c1c;
  --notice: #365314;
  --shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px 14px;
  background: rgba(246, 248, 247, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

main {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 16px 16px 32px;
}

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

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

.metrics article {
  padding: 14px;
}

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

.metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.toolbar {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

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

.search-box input,
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
}

.connection-status {
  margin: 0 0 12px;
  color: var(--brand-dark);
  font-size: 13px;
}

.snapshot-note { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }

.pin-panel {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

.pin-panel input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.pin-panel span,
.form-hint { color: var(--muted); }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.tab {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.tab:last-child {
  border-right: 0;
}

.tab.active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.entry-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 16px;
}

.entry-panel h2 {
  font-size: 16px;
}

.entry-panel p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  min-height: 42px;
  padding: 0 16px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.secondary-button {
  min-height: 42px;
  padding: 0 16px;
  background: #eef3f1;
  color: var(--ink);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: #e8f2ef;
  color: var(--brand-dark);
  font-size: 22px;
}

.item-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.item-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
}

.item-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-title h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.barcode {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

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

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

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

.pill.notice {
  background: #ecfccb;
  color: var(--notice);
}

.qty-block {
  min-width: 56px;
  text-align: right;
}

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

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

dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  padding: 0;
  border: 1px solid var(--line);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.dialog-header h2 {
  font-size: 18px;
}

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

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.form-hint { font-size: 12px; line-height: 1.5; }

.form-grid .confirm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

.form-grid .confirm-row input { width: 18px; height: 18px; }

.existing-photos { display: flex; flex-wrap: wrap; gap: 10px; }
.existing-photos a { display: grid; gap: 3px; color: var(--brand-dark); font-size: 12px; text-decoration: none; }
.existing-photos img { width: 68px; height: 68px; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; }

.dialog-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

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

@media (max-width: 700px) {
  .app-header {
    padding: 14px 14px 12px;
  }

  main {
    padding: 12px 12px 28px;
  }

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

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

  .tab:nth-child(2) {
    border-right: 0;
  }

  .tab:nth-child(1),
  .tab:nth-child(2) {
    border-bottom: 1px solid var(--line);
  }

  .entry-panel {
    align-items: stretch;
    flex-direction: column;
  }

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