:root {
  --bg: #0f1115;
  --surface: #161a22;
  --surface-2: #1f2532;
  --text: #e7ecf3;
  --muted: #8b94a7;
  --accent: #4f9cff;
  --accent-2: #7ed957;
  --danger: #ef5a5a;
  --border: #2a3142;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0 0 .5em; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  justify-content: space-between;
}

.tabs {
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: .45rem .75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
}
.tab.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}
.tabs.sub { margin: 1rem 0; border-bottom: 1px solid var(--border); padding-bottom: .5rem; }

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

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.row {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
  margin: .5rem 0;
}

.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

button, .btn-like {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: .5rem .85rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  display: inline-block;
}
button:hover, .btn-like:hover { border-color: var(--accent); }
button[disabled] { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .5rem .65rem;
  border-radius: var(--radius);
  font: inherit;
  width: 100%;
  max-width: 100%;
}
textarea { resize: vertical; }

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: .35rem 0;
}
label input, label select, label textarea { margin-top: .25rem; color: var(--text); }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: .75rem 0;
  padding: .75rem;
}
legend { padding: 0 .4rem; color: var(--muted); font-size: 13px; }

.form { display: flex; flex-direction: column; gap: .25rem; }
.form .row label { flex: 1 1 140px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem;
}
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem;
  display: flex;
  flex-direction: column;
}
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 20px; font-weight: 600; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: .5rem;
}
.items-table th, .items-table td {
  padding: .5rem .4rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}
.items-table th { color: var(--muted); font-weight: 500; cursor: pointer; user-select: none; }
.items-table tr.clickable { cursor: pointer; }
.items-table tr.clickable:hover { background: var(--surface-2); }
.items-table img.thumb {
  width: 44px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--surface-2);
}
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
}
.badge.in_stock { border-color: #3a4a66; color: #a9c2ec; }
.badge.listed { border-color: #5a6b2f; color: #c9e084; }
.badge.sold { border-color: #3a5a3a; color: #9ed9a0; }

.capture { display: flex; flex-direction: column; gap: .5rem; }
#video, #canvas { width: 100%; max-width: 480px; border-radius: var(--radius); background: #000; }
.preview-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .5rem;
}
.preview-wrap img {
  width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border);
}
.capture-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.photos {
  display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0;
}
.photos img { max-width: 180px; max-height: 180px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

.toast {
  position: fixed;
  bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: .6rem 1rem;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  max-width: 90vw;
  z-index: 100;
}

body.locked .tabs { display: none; }
body.auth-page main { max-width: 480px; margin: 2rem auto; padding: 1rem; }

.panel.auth { max-width: 420px; margin: 2rem auto; }
.panel.auth h2 { font-size: 18px; }
.error {
  color: var(--danger);
  font-size: 13px;
  background: rgba(239, 90, 90, .08);
  border: 1px solid rgba(239, 90, 90, .35);
  padding: .5rem .65rem;
  border-radius: var(--radius);
}
.flash {
  color: var(--accent-2);
  font-size: 13px;
  background: rgba(126, 217, 87, .08);
  border: 1px solid rgba(126, 217, 87, .35);
  padding: .5rem .65rem;
  border-radius: var(--radius);
}
.inline-form {
  display: flex;
  gap: .35rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
}
.inline-form input, .inline-form select, .inline-form button { width: auto; }

@media (max-width: 600px) {
  h1 { font-size: 16px; }
  .topbar { padding: .5rem .75rem; }
  .tab { padding: .4rem .6rem; font-size: 13px; }
  .items-table th:nth-child(4), .items-table td:nth-child(4),
  .items-table th:nth-child(7), .items-table td:nth-child(7) { display: none; }
}
