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

:root {
  --bg: #1F2326;
  --surface: #262B2E;
  --surface-2: #2E3438;
  --border: #3A4145;
  --olive: #4A5A3A;
  --olive-light: #5C6F49;
  --tan: #C3B58A;
  --gray: #A7A9AC;
  --offwhite: #F2F1EC;
  --danger: #B0473F;
  --danger-light: #D98A83;
  --success: #7FA86B;
  --font-display: 'Rajdhani', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 8px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--offwhite);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand, nav a, .card-label, th {
  font-family: var(--font-display);
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

a { color: inherit; text-decoration: none; }

/* ---------- Layout ---------- */

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: block;
  object-fit: contain;
  image-rendering: auto;
}

.brand-name {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.06em;
  color: var(--offwhite);
}

.brand-sub {
  font-family: var(--font-body);
  font-size: 10px;
  color: var(--tan);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: -4px;
  padding-left: 8px;
}

nav.primary-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

nav.primary-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--gray);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  cursor: pointer;
}

nav.primary-nav a:hover { background: var(--surface); color: var(--offwhite); }

nav.primary-nav a.active {
  background: var(--olive);
  color: var(--offwhite);
}

nav.primary-nav .nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
}
nav.primary-nav .nav-icon svg { width: 100%; height: 100%; }

nav.primary-nav a.nav-more-trigger { display: none; }

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.footer-link, .logout-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--gray);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--radius);
}
.footer-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
}
.footer-icon svg { width: 100%; height: 100%; }
.footer-link:hover { color: var(--tan); background: var(--surface); }
.logout-link:hover { color: var(--danger-light); background: var(--surface); }

.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

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

.topbar h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin: 0;
  text-transform: uppercase;
}

.content {
  padding: 24px 28px 100px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ---------- Section header w/ signature double-rule ---------- */

.section-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tan);
  padding-bottom: 8px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
  position: relative;
}
.section-title::after {
  content: '';
  position: absolute;
  left: 0; bottom: -5px;
  width: 100%;
  height: 1px;
  background: var(--border);
}

/* ---------- Dashboard cards ---------- */

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}

.card-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gray);
  margin-bottom: 10px;
}

.card-value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  color: var(--offwhite);
}

.card-value .unit {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 400;
  color: var(--gray);
  margin-left: 6px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--offwhite);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }

.btn-primary {
  background: var(--olive);
  border-color: var(--olive);
}
.btn-primary:hover { background: var(--olive-light); }

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger-light);
}
.btn-danger:hover { background: rgba(176,71,63,0.15); }

.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-icon { padding: 6px 8px; }

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-row input, .filter-row select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--offwhite);
}

/* ---------- Table (desktop) / Cards (mobile) ---------- */

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.data-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tan);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}

.data-table th:last-child,
.data-table td.action-cell {
  width: 1%;
  white-space: nowrap;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface-2); }

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

.table-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--tan);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-icon { width: 13px; height: 13px; display: inline-flex; }
.link-icon svg { width: 100%; height: 100%; }
.table-link:hover { color: var(--offwhite); }

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--surface-2);
  color: var(--gray);
  border: 1px solid var(--border);
}
.status-pill.owned { background: rgba(127,168,107,0.15); color: var(--success); border-color: transparent; }
.status-pill.sold { background: rgba(176,71,63,0.15); color: var(--danger-light); border-color: transparent; }
.status-pill.on_loan { background: rgba(195,181,138,0.18); color: var(--tan); border-color: transparent; }

.priority-pill.actively_saving { background: rgba(195,181,138,0.18); color: var(--tan); }

/* mobile card list, hidden on desktop */
.card-list { display: none; flex-direction: column; gap: 10px; }
.record-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.record-card .rc-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.record-card .rc-sub { font-size: 13px; color: var(--gray); margin-bottom: 8px; }
.record-card .rc-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--gray); margin-bottom: 10px; }
.record-card .rc-meta span b { color: var(--offwhite); font-weight: 500; }
.record-card .rc-actions { display: flex; gap: 8px; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray);
}
.empty-state .es-title { font-family: var(--font-display); font-size: 18px; color: var(--offwhite); margin-bottom: 6px; }

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

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  padding: 24px;
}

.modal h2 {
  font-size: 18px;
  margin: 0 0 18px;
  letter-spacing: 0.02em;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gray);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--offwhite);
}
.field textarea { resize: vertical; min-height: 60px; }
.field .checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }
.field .checkbox-group label {
  display: flex; align-items: center; gap: 6px;
  text-transform: none; font-size: 13px; font-weight: 400; color: var(--offwhite);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 999px; cursor: pointer; margin: 0;
}
.field .checkbox-group input { width: auto; }

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

.form-error {
  background: rgba(176,71,63,0.15);
  border: 1px solid var(--danger);
  color: var(--danger-light);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- Ammo adjust control ---------- */

.qty-adjust { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qty-adjust .qty-value { font-family: var(--font-mono); font-size: 15px; min-width: 40px; text-align: center; }
.qty-btn-group { display: flex; gap: 4px; }
.qty-btn-group .btn-icon { padding: 6px 7px; font-size: 12px; }

/* ---------- Photo thumbnails ---------- */

.thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}
.thumb-empty {
  background: var(--surface-2);
  border-style: dashed;
  cursor: default;
}

.rc-photo {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.lightbox-backdrop { align-items: center; justify-content: center; }
.lightbox-img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  cursor: zoom-out;
  display: block;
}

/* ---------- Reports ---------- */

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.report-card .rc-title { font-weight: 600; font-size: 16px; }
.report-card .rc-sub { font-size: 13px; color: var(--gray); margin-bottom: 4px; line-height: 1.4; }
.report-card .btn { align-self: flex-start; }

/* ---------- "More" sheet (mobile overflow menu) ---------- */

.more-sheet { max-width: 360px; }
.more-sheet-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.more-sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--offwhite);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.more-sheet-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-flex;
}
.more-sheet-icon svg { width: 100%; height: 100%; }
.more-sheet-item:hover { background: var(--surface); }
.more-sheet-danger { color: var(--danger-light); border-color: var(--danger); }

.photo-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.photo-preview img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.remove-photo-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  color: var(--gray);
  cursor: pointer;
}
.remove-photo-label input { width: auto; }

/* ---------- Low stock indicators ---------- */

.low-stock-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(176,71,63,0.18);
  color: var(--danger-light);
  vertical-align: middle;
}
.low-stock-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger-light);
  margin-left: 4px;
  vertical-align: middle;
}
.row-low-stock td { background: rgba(176,71,63,0.06); }
.record-card-low-stock { border-color: var(--danger); }

/* ---------- Threshold ("Set minimums") modal ---------- */

.threshold-help { margin-top: -8px; margin-bottom: 16px; font-size: 13px; }
.threshold-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; margin-bottom: 4px; }
.threshold-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.threshold-row:last-child { border-bottom: none; }
.threshold-caliber { font-size: 14px; }
.threshold-input {
  width: 90px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  color: var(--offwhite);
  text-align: right;
}

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

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
}
.login-card .brand { justify-content: center; margin-bottom: 4px; padding: 0; }
.login-card .brand-sub-center {
  text-align: center;
  font-size: 11px;
  color: var(--tan);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 28px;
}
.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 4px; }

/* ---------- Utility ---------- */

.text-muted { color: var(--gray); }
.hidden { display: none !important; }

/* ---------- Responsive: mobile ---------- */

@media (max-width: 780px) {
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    width: 100%;
    height: 64px;
    flex-direction: row;
    align-items: center;
    padding: 0 6px;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 50;
  }
  .sidebar .brand, .sidebar-footer { display: none; }
  nav.primary-nav {
    flex-direction: row;
    width: 100%;
    justify-content: stretch;
  }
  nav.primary-nav a {
    flex: 1 1 0;
    flex-direction: column;
    gap: 3px;
    font-size: 10px;
    padding: 8px 6px;
    letter-spacing: 0;
    text-transform: uppercase;
  }
  nav.primary-nav a.nav-overflow { display: none; }
  nav.primary-nav a.nav-more-trigger { display: flex; }
  .modal-backdrop.more-sheet-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .more-sheet {
    max-width: none;
    border-radius: 14px 14px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .main { padding-bottom: 64px; }
  .content { padding: 18px 16px 90px; }
  .topbar { padding: 16px 16px; flex-wrap: wrap; }
  .topbar-actions { flex-wrap: wrap; }
  .data-table { display: none; }
  .card-list { display: flex; }
  .modal { max-width: 100%; }
  .qty-btn-group .btn-icon { padding: 6px 6px; font-size: 11px; }
}
