:root {
  --accent:      #1a73e8;
  --accent-dark: #1558b0;
  --danger:      #d32f2f;
  --warn:        #f59e0b;
  --ok:          #16a34a;
  --bg:          #f8f9fa;
  --surface:     #ffffff;
  --border:      #dee2e6;
  --text:        #212529;
  --text-muted:  #6c757d;
  --sidebar-w:   220px;
}

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

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: #1e293b;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}

.nav-brand {
  padding: 20px 16px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #334155;
}

.nav-list { list-style: none; padding: 8px 0; }

.nav-link {
  display: block;
  padding: 10px 16px;
  color: #94a3b8;
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 8px;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover { background: #334155; color: #e2e8f0; }
.nav-link.active { background: var(--accent); color: #fff; }

/* ── Content ─────────────────────────────────────────────────────────────── */

.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1300px;
}

.page { display: none; }
.page.active { display: block; }

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

h1 { font-size: 22px; font-weight: 600; margin-bottom: 20px; }
h2 { font-size: 15px; font-weight: 600; margin: 24px 0 12px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-primary, .btn-secondary, .btn-sm, .btn-danger {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #ced4da; }
.btn-sm        { padding: 4px 10px; font-size: 12px; background: var(--border); color: var(--text); }
.btn-sm:hover  { background: #ced4da; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b71c1c; }

/* ── Tables ─────────────────────────────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.data-table th {
  background: #f1f5f9;
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
}

.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table th.num { text-align: right; }

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8f9fa; }

tr.overdue-mid  td { background: #fffbeb; }
tr.overdue-high td { background: #fef2f2; }

/* ── Badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-in_stock { background: #dcfce7; color: #166534; }
.badge-loaned   { background: #dbeafe; color: #1e40af; }
.badge-empty    { background: #f3f4f6; color: #6b7280; }
.badge-sold     { background: #fef9c3; color: #854d0e; }
.badge-retired  { background: #fee2e2; color: #991b1b; }

/* Loan day-status badges */
.days-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.days-badge.free { background: #dcfce7; color: #166534; }
.days-badge.warn { background: #fef9c3; color: #854d0e; }
.days-badge.paid { background: #fee2e2; color: #991b1b; }

/* ── Filter bar ─────────────────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar select, .filter-bar input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
}

/* ── Forms ───────────────────────────────────────────────────────────────── */

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

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
}

label input, label select, label textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

label textarea { min-height: 60px; resize: vertical; }

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

/* Inline select + button row */
.ref-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ref-row select { flex: 1; }

/* ── Modal ───────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: 10px;
  width: 500px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.modal-header h2 { font-size: 16px; margin: 0; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
}

#modal-body { padding: 20px; }

/* ── Dashboard stats ────────────────────────────────────────────────────── */

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

.stat-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.stat-card.stat-warning { border-left: 3px solid var(--warn); }
.stat-card.stat-warning .stat-value { color: var(--danger); }
.stat-card.stat-accent  { border-left: 3px solid var(--accent); }
.stat-card.stat-accent  .stat-value { color: var(--accent); }
.stat-card.stat-warn    { border-left: 3px solid #f59e0b; }
.stat-card.stat-warn    .stat-value { color: #d97706; }

/* ── Settings ────────────────────────────────────────────────────────────── */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 8px;
}

.settings-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 20px 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.settings-card h2 { margin: 0 0 16px; font-size: 14px; font-weight: 600; }

.input-suffix {
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-suffix input { flex: 1; }
.input-suffix span { color: var(--text-muted); font-size: 13px; white-space: nowrap; }

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

.toast.hidden { display: none; }
.toast-ok    { background: var(--ok); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* ── Loan section in modal ───────────────────────────────────────────────── */

.loan-section {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8f9fa;
  display: none;
}

.loan-section.visible { display: block; }

.loan-section .loan-checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-weight: 600;
}

.loan-section .loan-checkbox input[type=checkbox] { width: 16px; height: 16px; }

/* ── Login ───────────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed; inset: 0;
  background: #1e293b;
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
}

.login-overlay.hidden { display: none; }

.login-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  max-width: 92vw;
  box-shadow: 0 16px 48px rgba(0,0,0,.4);
}

.login-logo     { font-size: 24px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }
.login-error    { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 4px; }

/* ── Sidebar footer ──────────────────────────────────────────────────────── */

.nav-footer { margin-top: auto; padding: 12px 8px; border-top: 1px solid #334155; }

.btn-logout {
  display: block; width: 100%;
  padding: 8px 12px;
  background: none; border: 1px solid #334155; border-radius: 6px;
  color: #94a3b8; font-size: 12px; cursor: pointer; text-align: left;
}

.btn-logout:hover { background: #334155; color: #e2e8f0; }

/* ── Rental form helpers ─────────────────────────────────────────────────── */

/* ── Bulk selection toolbar ──────────────────────────────────────────────── */

.bulk-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 6px;
}

.bulk-toolbar.hidden { display: none; }

.bulk-count { font-size: 13px; font-weight: 600; color: var(--accent); }

.cb-col { width: 36px !important; padding-left: 10px !important; text-align: center !important; }

tr.row-fee td { background: #dcfce7 !important; }
tr.row-selected td { background: #eff6ff !important; }

.fa-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; color: #166534; cursor: pointer;
}
.fa-toggle input { cursor: pointer; }

/* ── Rental form helpers ─────────────────────────────────────────────────── */

.rental-info-box, .rental-calc-box {
  display: flex; gap: 16px; flex-wrap: wrap;
  background: #f1f5f9; border-radius: 6px; padding: 8px 12px;
  font-size: 13px;
}

.rental-info-box { color: var(--accent); }
.rental-calc-box { color: var(--text); border: 1px solid var(--border); }

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .sidebar { width: 60px; }
  .nav-brand { display: none; }
  .content { margin-left: 60px; padding: 16px; }
}
