:root {
  --bg: #15171a;
  --surface: #1f2227;
  --surface-raised: #262a31;
  --line: #2e3238;
  --text: #e8e6e1;
  --text-muted: #8b8f96;
  --accent: #e8a33d;
  --accent-dim: #a97524;
  --success: #5fbf77;
  --danger: #e0574c;
  --warn: #e0a63c;

  --font-display: "Oswald", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

#app { min-height: 100%; }

h1, h2, h3, .display {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin: 0;
}

.mono { font-family: var(--font-mono); }

a { color: inherit; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(232, 163, 61, 0.06), transparent 40%),
    var(--bg);
}

.tag-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 40px 32px 32px;
}

.tag-card::before {
  content: "";
  position: absolute;
  top: 20px;
  left: -9px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
}

.tag-eyebrow {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.tag-card h1 { font-size: 26px; margin-bottom: 24px; }

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 3px;
  font-family: var(--font-body);
  font-size: 14px;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 3px;
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-primary { background: var(--accent); color: #15171a; width: 100%; }
.btn-primary:hover { background: #f0ae4d; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--line);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
}

/* ---------- Shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
}

.sidebar-brand {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.sidebar-brand .display { font-size: 20px; color: var(--accent); }
.sidebar-brand .sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.nav-item {
  display: block;
  padding: 11px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--text); background: var(--surface-raised); }
.nav-item.active {
  color: var(--text);
  border-left-color: var(--accent);
  background: var(--surface-raised);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px 0;
  border-top: 1px solid var(--line);
}

.user-chip { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }

.main { flex: 1; min-width: 0; padding: 32px 40px; }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 { font-size: 24px; }
.page-header .sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ---------- Stat cards ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px 20px;
  border-top: 3px solid var(--accent);
}
.stat-card.stock { border-top-color: var(--text-muted); }
.stat-card.broken { border-top-color: var(--danger); }
.stat-card.maintenance { border-top-color: var(--warn); }

.stat-card .value { font-family: var(--font-mono); font-size: 32px; font-weight: 500; }
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }

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

.toolbar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar input[type="search"] {
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 3px;
}
.toolbar select { background: var(--surface); border: 1px solid var(--line); color: var(--text); padding: 10px 14px; border-radius: 3px; }

.view-toggle { display: flex; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
.view-toggle-btn {
  background: var(--surface); color: var(--text-muted); border: none;
  padding: 0 14px; font-size: 15px; border-right: 1px solid var(--line);
}
.view-toggle-btn:last-child { border-right: none; }
.view-toggle-btn.active { background: var(--accent); color: #15171a; }

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.item-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.item-card:hover { border-color: var(--accent); }
.item-card-photo {
  aspect-ratio: 4 / 3;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.item-card-photo img { width: 100%; height: 100%; object-fit: cover; }
.item-card-noimg { font-family: var(--font-display); font-size: 34px; color: var(--line); }
.item-card-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.item-card-title { font-size: 14px; font-weight: 500; line-height: 1.3; }
.item-card-meta { font-size: 12px; color: var(--text-muted); }

.item-list { border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }

.item-row {
  display: grid;
  grid-template-columns: 90px 1fr 140px 160px 120px;
  gap: 16px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--text);
}
.item-row:last-child { border-bottom: none; }
.item-row:hover { background: var(--surface); }
.item-row.header {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: default;
}
.item-row.header:hover { background: transparent; }

.inv-num { font-family: var(--font-mono); font-size: 13px; color: var(--accent); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  width: fit-content;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-in_use .status-dot { background: var(--accent); }
.status-in_stock .status-dot { background: var(--text-muted); }
.status-broken .status-dot { background: var(--danger); }
.status-maintenance .status-dot { background: var(--warn); }
.status-rented .status-dot { background: #6da8e0; }
.status-written_off .status-dot { background: var(--text-muted); }

/* ---------- Detail / card ---------- */

.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 24px; align-items: start; }
@media (max-width: 860px) { .detail-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 24px;
}

.panel + .panel { margin-top: 16px; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 10px; font-size: 14px; margin-bottom: 8px; }
.kv .k { color: var(--text-muted); }

.timeline-item { padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline-item:last-child { border-bottom: none; }
.timeline-date { font-family: var(--font-mono); color: var(--text-muted); font-size: 12px; }

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

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 28px; width: 100%; max-width: 440px; }
.modal h2 { font-size: 18px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }

.loading { color: var(--text-muted); padding: 20px; font-size: 13px; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 3px; overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-delete-btn {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0,0,0,0.65); color: #fff; border: none; border-radius: 3px;
  width: 22px; height: 22px; font-size: 12px; line-height: 1;
}
.photo-delete-btn:hover { background: var(--danger); }

.doc-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.doc-row:last-child { border-bottom: none; }
.doc-link { color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 10px; }
.doc-link:hover { color: var(--accent); }
.doc-type { font-size: 11px; color: var(--text-muted); border: 1px solid var(--line); border-radius: 10px; padding: 2px 8px; }
.doc-delete-btn { background: transparent; border: none; color: var(--text-muted); font-size: 13px; }
.doc-delete-btn:hover { color: var(--danger); }

.preview-modal { max-width: 900px; width: 92vw; display: flex; flex-direction: column; max-height: 88vh; }
.preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; font-size: 13px; color: var(--text-muted); }
.preview-image { max-width: 100%; max-height: 75vh; object-fit: contain; margin: 0 auto; border-radius: 3px; }
.preview-frame { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 3px; background: #fff; }
