@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --black: #000;
  --white: #fff;
  --gray: #f0f0f0;
  --mid: #d0d0d0;
  --border: 2px solid #000;
  --shadow: 4px 4px 0 #000;
  --shadow-sm: 2px 2px 0 #000;
  --radius: 0;
  --font: 'Space Grotesk', sans-serif;
  --mono: 'Space Mono', monospace;
}

body {
  font-family: var(--font);
  background: var(--white);
  color: var(--black);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── HEADER ─────────────────────────────────── */
#app-header {
  border-bottom: var(--border);
  background: var(--black);
  color: var(--white);
  display: flex;
  align-items: stretch;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  background: var(--white);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-right: 3px solid var(--black);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-logo-img {
  height: 30px;
  width: auto;
  display: block;
}

.header-logo-tag {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--black);
  padding: 0.15rem 0.4rem;
  border: 1.5px solid var(--black);
  line-height: 1.4;
}

.header-tabs {
  display: flex;
  flex: 1;
  overflow-x: auto;
}

.tab-btn {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #999;
  background: none;
  border: none;
  border-right: 1px solid #222;
  padding: 0 1.5rem;
  height: 52px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--white); background: #111; }
.tab-btn.active { color: var(--black); background: var(--white); border-color: var(--black); }

/* ── MAIN CONTENT ────────────────────────────── */
#app-content { flex: 1; }

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

/* ── TOOLBAR ─────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: var(--border);
  flex-wrap: wrap;
}

.toolbar-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-right: auto;
}

/* ── INPUTS ─────────────────────────────────── */
input[type=text],
input[type=search],
input[type=number],
input[type=date],
input[type=email],
select,
textarea {
  font-family: var(--font);
  font-size: 0.875rem;
  background: var(--white);
  border: var(--border);
  padding: 0.5rem 0.75rem;
  outline: none;
  color: var(--black);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  box-shadow: var(--shadow-sm);
}

textarea { resize: vertical; min-height: 80px; }

.search-box {
  position: relative;
  min-width: 200px;
  max-width: 320px;
  flex: 1;
}

.search-box input { padding-left: 2.25rem; }

.search-box::before {
  content: '⌕';
  position: absolute;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: #666;
  pointer-events: none;
}

select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%23000'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

/* ── BUTTONS ─────────────────────────────────── */
.btn {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: var(--border);
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  background: var(--white);
  color: var(--black);
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s, box-shadow 0.1s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:hover { transform: translate(-1px,-1px); box-shadow: 3px 3px 0 var(--black); }
.btn:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--black); }

.btn-primary { background: var(--black); color: var(--white); }
.btn-primary:hover { box-shadow: 3px 3px 0 #444; }
.btn-primary:active { box-shadow: 1px 1px 0 #444; }

.btn-danger { background: var(--black); color: var(--white); border-color: var(--black); }
.btn-sm { font-size: 0.65rem; padding: 0.3rem 0.75rem; box-shadow: 2px 2px 0 #000; }
.btn-sm:hover { box-shadow: 3px 3px 0 #000; }

.btn-icon {
  padding: 0.4rem;
  min-width: 32px;
  justify-content: center;
}

/* ── TABLE ─────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-top: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--black);
  color: var(--white);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.65rem 0.875rem;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  border-right: 1px solid #333;
}

thead th:last-child { border-right: none; }
thead th:hover { background: #222; }
thead th.sorted-asc::after { content: ' ↑'; }
thead th.sorted-desc::after { content: ' ↓'; }

tbody tr {
  border-bottom: 1px solid var(--mid);
  transition: background 0.1s;
}

tbody tr.inv-row { cursor: pointer; }
tbody tr:hover { background: var(--gray); }

tbody td {
  padding: 0.6rem 0.875rem;
  vertical-align: middle;
  border-right: 1px solid #eee;
}

tbody td:last-child { border-right: none; }

.td-id {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
}

.td-thumb { padding: 0.35rem 0.875rem; }

.thumb-strip {
  display: flex;
  gap: 2px;
  align-items: center;
  max-width: 240px;
  overflow-x: auto;
}

.thumb-strip img {
  width: 44px;
  height: 33px;
  object-fit: cover;
  border: 1px solid var(--mid);
  border-radius: 1px;
  flex-shrink: 0;
  display: block;
}

.thumb-strip .no-img {
  width: 44px;
  height: 33px;
  background: var(--gray);
  border: 1px solid var(--mid);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.td-actions { display: flex; gap: 0.4rem; white-space: nowrap; }

/* ── BADGES ─────────────────────────────────── */
.badge {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--black);
  display: inline-block;
}

.badge-ok       { background: var(--black); color: var(--white); }
.badge-out      { background: var(--white); color: var(--black); border-width: 2px; }
.badge-planned  { background: var(--gray); color: var(--black); }
.badge-active   { background: var(--black); color: var(--white); }
.badge-returned { background: var(--gray); color: #666; }

/* ── MODAL ─────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border: var(--border);
  box-shadow: 8px 8px 0 var(--black);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-lg { max-width: 900px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: var(--border);
  background: var(--black);
  color: var(--white);
}

.modal-header h2 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.modal-close {
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 0.25rem;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ── FORM GRID ─────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .full { grid-column: 1 / -1; }

.form-group label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

/* ── SCANNER TAB ─────────────────────────────── */
#tab-scanner {
  display: none;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 52px);
}

#tab-scanner.active { display: grid; }

.scanner-left {
  border-right: var(--border);
  display: flex;
  flex-direction: column;
}

.scanner-right {
  overflow-y: auto;
}

.drop-zone {
  flex: 1;
  border: 3px dashed var(--black);
  margin: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  cursor: pointer;
  transition: background 0.15s;
  padding: 2rem;
  text-align: center;
}

.drop-zone:hover, .drop-zone.dragover { background: var(--gray); }

.drop-zone-icon { font-size: 3rem; line-height: 1; }

.drop-zone p {
  font-size: 0.8rem;
  color: #555;
  font-weight: 500;
}

.drop-zone strong { font-size: 0.9rem; color: var(--black); }

.photo-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 1.5rem 1rem;
  min-height: 0;
}

.photo-thumb {
  position: relative;
  width: 80px;
  height: 60px;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 2px solid var(--black);
  display: block;
}

.photo-thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: var(--black);
  color: var(--white);
  border: none;
  font-size: 0.6rem;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  border-radius: 50%;
}

.scanner-actions {
  padding: 0 1.5rem 1.5rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.scanner-form { padding: 1.5rem; }

.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 3rem;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--mid);
  border-top-color: var(--black);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── EVENTS TAB ─────────────────────────────── */
.events-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0;
  padding: 0;
}

.event-card {
  border-bottom: var(--border);
  border-right: var(--border);
  padding: 1.25rem;
  cursor: pointer;
  transition: background 0.1s;
}

.event-card:hover { background: var(--gray); }

.event-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.event-card-id {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: #666;
}

.event-card-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.event-card-meta {
  font-size: 0.75rem;
  color: #555;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.event-card-items {
  font-size: 0.75rem;
  color: #555;
  margin-top: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── EVENT FORM ─────────────────────────────── */
.toggle-type {
  display: flex;
  border: var(--border);
  overflow: hidden;
  width: fit-content;
}

.toggle-type button {
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.5rem 1.5rem;
  border: none;
  cursor: pointer;
  background: var(--white);
  color: #888;
  border-right: var(--border);
  transition: background 0.15s, color 0.15s;
}

.toggle-type button:last-child { border-right: none; }
.toggle-type button.active { background: var(--black); color: var(--white); }

.item-selector {
  border: var(--border);
  max-height: 250px;
  overflow-y: auto;
}

.item-selector-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--mid);
  cursor: pointer;
  transition: background 0.1s;
}

.item-selector-row:last-child { border-bottom: none; }
.item-selector-row:hover { background: var(--gray); }
.item-selector-row.selected { background: var(--gray); }

.item-selector-row input[type=checkbox] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--black);
  flex-shrink: 0;
}

.item-selector-thumb {
  width: 36px;
  height: 28px;
  object-fit: cover;
  border: 1px solid var(--mid);
  flex-shrink: 0;
}

.item-selector-info { flex: 1; min-width: 0; }
.item-selector-info strong { font-size: 0.8rem; display: block; }
.item-selector-info span { font-size: 0.7rem; color: #666; font-family: var(--mono); }

.item-selector-qty {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.item-selector-qty input {
  width: 50px;
  text-align: center;
  padding: 0.25rem;
  font-size: 0.75rem;
}

.selected-items-summary {
  background: var(--gray);
  border: var(--border);
  padding: 0.75rem;
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

/* ── GALLERY TAB ─────────────────────────────── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0;
}

.gallery-card {
  border-right: var(--border);
  border-bottom: var(--border);
  cursor: pointer;
  transition: background 0.1s;
  overflow: hidden;
}

.gallery-card:hover { background: var(--gray); }

.gallery-img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
  border-bottom: var(--border);
}

.gallery-no-img {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--gray);
  border-bottom: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.gallery-card-body { padding: 0.75rem; }

.gallery-card-id {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  color: #666;
  margin-bottom: 0.15rem;
}

.gallery-card-name {
  font-weight: 700;
  font-size: 0.8rem;
  line-height: 1.3;
  margin-bottom: 0.25rem;
}

.gallery-card-cat {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #666;
}

/* ── ITEM DETAIL MODAL ─────────────────────── */
.item-detail-images {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 1.25rem;
}

.item-detail-images img {
  height: 180px;
  width: auto;
  object-fit: cover;
  border: 2px solid var(--black);
  cursor: zoom-in;
  flex-shrink: 0;
}

.item-detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.detail-field label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #666;
  display: block;
  margin-bottom: 0.2rem;
}

.detail-field p {
  font-size: 0.875rem;
  font-weight: 500;
}

.detail-field .mono { font-family: var(--mono); font-size: 0.8rem; }

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.detail-tag {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--black);
  background: var(--white);
}

/* ── LIGHTBOX ─────────────────────────────── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.lightbox.open { display: flex; }
.lightbox img { max-width: 92vw; max-height: 90vh; object-fit: contain; border: 3px solid #fff; }
.lightbox-close {
  position: absolute;
  top: 1rem; right: 1.5rem;
  color: var(--white);
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
}

/* ── TOAST ───────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border: var(--border);
  box-shadow: var(--shadow);
  background: var(--black);
  color: var(--white);
  min-width: 200px;
  animation: toastIn 0.2s ease;
}

.toast.toast-error { background: var(--white); color: var(--black); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── EMPTY STATE ─────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: #888;
  text-align: center;
  gap: 0.75rem;
}

.empty-state-icon { font-size: 3rem; line-height: 1; }
.empty-state p { font-size: 0.875rem; }

/* ── DIVIDER ─────────────────────────────── */
.section-divider {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 0.5rem 0;
  border-bottom: var(--border);
  margin-bottom: 1rem;
  color: #666;
}

/* ── RESPONSIVE ─────────────────────────── */
@media (max-width: 768px) {
  #tab-scanner.active { display: flex; flex-direction: column; height: auto; }
  .scanner-left { border-right: none; border-bottom: var(--border); }
  .form-grid { grid-template-columns: 1fr; }
  .item-detail-grid { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .events-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; }
  .header-logo { padding: 0 0.75rem; font-size: 0.75rem; }
  .tab-btn { padding: 0 0.875rem; }
}

/* ── MISC ─────────────────────────────────── */
.qty-chip {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-block;
}

.qty-chip.unavailable { text-decoration: line-through; color: #999; }

hr { border: none; border-top: var(--border); margin: 1.25rem 0; }

.text-mono { font-family: var(--mono); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.7rem; }
.text-muted { color: #666; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.d-flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; }
