:root {
  --bg: #12151c;
  --panel: #1b1f2a;
  --panel-2: #232837;
  --border: #2d3346;
  --text: #e6e9f0;
  --text-dim: #9aa3b8;
  --accent: #4f8cff;
  --ok: #2fb872;
  --bad: #e5484d;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

/* --- Login --- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
}

.login-card h1 {
  font-size: 1.2rem;
  margin: 0 0 20px;
  text-align: center;
}

/* --- Topbar --- */

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

.topbar h1 { font-size: 1.1rem; margin: 0; }

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

#search-box {
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  min-width: 220px;
}

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

/* --- Shelf grid --- */

.shelf-grid {
  display: grid;
  gap: 10px;
}

.shelf-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.shelf-tile:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.shelf-tile-filled { border-color: #35405c; background: var(--panel-2); }
.shelf-tile-issue { border-color: var(--bad); }
.shelf-tile-merged {
  background: linear-gradient(135deg, var(--panel-2), #2a3350);
  border-color: var(--accent);
}

.shelf-label { font-size: 1.1rem; font-weight: 700; }
.shelf-count { font-size: 0.75rem; color: var(--text-dim); margin-top: 4px; }
.shelf-issue { font-size: 0.7rem; color: var(--bad); margin-top: 2px; }

/* --- Search results --- */

.search-results {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}

.hidden { display: none !important; }

/* --- Modals --- */

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

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-header h2 { margin: 0; font-size: 1.1rem; }

/* --- Item list --- */

.item-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.item-row {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-row:hover { border-color: var(--accent); }

.item-row-main { display: flex; align-items: center; gap: 10px; }
.item-row-sub { color: var(--text-dim); font-size: 0.85rem; }
.item-row-serials { display: flex; gap: 14px; font-size: 0.8rem; color: var(--text-dim); }

.empty-state { color: var(--text-dim); font-style: italic; }

.badge {
  align-self: flex-start;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
}

.badge-ok { background: rgba(47,184,114,0.15); color: var(--ok); }
.badge-bad { background: rgba(229,72,77,0.15); color: var(--bad); }

/* --- Forms --- */

form { display: flex; flex-direction: column; gap: 12px; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

input[type="text"], input[type="search"], input[type="password"], textarea {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-danger { background: transparent; border-color: var(--bad); color: var(--bad); margin-right: auto; }
.btn-ghost { background: transparent; }

.error { color: var(--bad); font-size: 0.85rem; min-height: 1.2em; }

.hint-text { color: var(--text-dim); font-size: 0.85rem; margin: 0 0 12px; }

.input-with-scan {
  display: flex;
  gap: 8px;
}

.input-with-scan input { flex: 1; }

.scan-btn {
  white-space: nowrap;
  padding: 9px 12px;
}

#scan-reader {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: black;
  min-height: 200px;
}

h3 {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin: 20px 0 8px;
}

/* --- Photos --- */

.photos-section label { margin-bottom: 6px; }

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.photo-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-thumb-delete {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.65);
  color: white;
  font-size: 0.7rem;
  cursor: pointer;
  line-height: 1;
}

.item-row-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .shelf-label { font-size: 0.95rem; }
  #search-box { min-width: 0; flex: 1; }
}
