:root {
  --bg: #f5f2ec;
  --surface: #ffffff;
  --border: #e0dbd0;
  --text: #2b2620;
  --text-muted: #8a8272;
  --accent: #3f7d58;
  --accent-hover: #336347;
  --danger: #b5453a;
  --warn: #c98a2c;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b18;
    --surface: #26241f;
    --border: #3a3730;
    --text: #ece7dd;
    --text-muted: #9a9384;
    --accent: #5fae7f;
    --accent-hover: #4c9268;
    --danger: #e0685a;
    --warn: #e3a94a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  padding: 16px 20px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  margin: 0 0 12px;
  font-size: 1.4rem;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 0.95rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

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

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

.toolbar input[type="search"],
.toolbar input[type="text"] {
  flex: 1 1 200px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  padding: 0;
}

.badge.low-stock {
  background: rgba(181, 69, 58, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}

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

.inline-field input {
  flex: 1;
  margin-top: 0 !important;
}

.scan-status {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 10px;
}

.scan-video-wrap {
  position: relative;
  line-height: 0;
}

.scan-video {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  display: block;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.lookup-status {
  margin: -6px 0 10px;
  font-size: 0.8rem;
}

.lookup-status.hidden {
  display: none;
}

.lookup-status.looking {
  color: var(--text-muted);
}

.lookup-status.found {
  color: var(--accent);
}

.lookup-status.not-found {
  color: var(--warn);
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

button {
  cursor: pointer;
  background: var(--surface);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

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

button.icon-btn {
  padding: 6px 10px;
  border-radius: 8px;
}

.group-heading {
  margin: 24px 0 8px;
  font-size: 1.05rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.group-heading:first-child { margin-top: 0; }

.item-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.item-info { flex: 1; min-width: 0; }

.item-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge.expiring {
  background: rgba(201, 138, 44, 0.15);
  border-color: var(--warn);
  color: var(--warn);
}

.badge.expired {
  background: rgba(181, 69, 58, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-controls button {
  width: 30px;
  height: 30px;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
}

.qty-value {
  min-width: 32px;
  text-align: center;
  font-weight: 600;
}

.item-actions {
  display: flex;
  gap: 6px;
}

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

.manage-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.manage-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h2 { margin-top: 0; }

#item-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

#item-form input,
#item-form select,
#item-form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
}

#item-form .row {
  display: flex;
  gap: 10px;
}

#item-form .row label { flex: 1; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 480px) {
  #item-form .row { flex-direction: column; }
  .item-card { flex-wrap: wrap; }
}
