:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --border: #d9dfe8;
  --text: #1a2233;
  --muted: #5a6578;
  --primary: #1f6feb;
  --primary-dark: #1a5fd0;
  --navy: #1f3a5f;
  --green: #1a7f37;
  --green-bg: #e6f4ea;
  --amber: #9a6700;
  --amber-bg: #fff3d6;
  --red: #c62828;
  --red-bg: #fdecea;
  --gray-bg: #eceff3;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--red); font-size: 13px; margin: 6px 0; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: linear-gradient(160deg, var(--navy), #2c5382);
}
.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 32px 28px;
  width: 100%; max-width: 380px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p { margin: 0 0 20px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  position: sticky; top: 0; z-index: 50;
  flex-wrap: wrap;
}
.brand { font-size: 18px; font-weight: 700; padding: 12px 0; white-space: nowrap; }
#main-nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.nav-btn {
  background: none; border: none; color: #c9d6e8;
  padding: 14px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap;
}
.nav-btn.active { color: #fff; border-bottom-color: #6aa5ff; }
.nav-btn:hover { color: #fff; }
.user-menu { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.ghost-btn {
  background: rgba(255,255,255,0.12); border: none; color: #fff;
  padding: 7px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { background: rgba(255,255,255,0.22); }

main { max-width: 1100px; margin: 0 auto; padding: 18px 14px 60px; }

/* ---------- Common ---------- */
h2 { font-size: 20px; margin: 6px 0 14px; }
h3 { font-size: 16px; margin: 18px 0 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #a8c7fa; border-color: var(--primary); }
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 10px; }
.btn {
  background: var(--gray-bg); color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 7px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(0.96); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }
.row > .btn { flex: 0 0 auto; min-width: auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Pills / badges ---------- */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.pill.pending { background: var(--amber-bg); color: var(--amber); }
.pill.approved { background: var(--green-bg); color: var(--green); }
.pill.denied, .pill.overdue { background: var(--red-bg); color: var(--red); }
.pill.cancelled, .pill.returned { background: var(--gray-bg); color: var(--muted); }
.pill.maintenance { background: #ede7f6; color: #5e35b1; }
.pill.available { background: var(--green-bg); color: var(--green); }
.pill.checked_out { background: var(--amber-bg); color: var(--amber); }

/* ---------- Category chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  background: var(--surface); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer; color: var(--muted);
}
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }

/* ---------- Item grid ---------- */
.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.item-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow); transition: transform 0.1s;
  display: flex; flex-direction: column;
}
.item-card:hover { transform: translateY(-2px); }
.item-card .thumb {
  height: 110px; background: var(--gray-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; overflow: hidden;
}
.item-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-card .body { padding: 10px 12px; flex: 1; }
.item-card .name { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.item-card .meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

/* ---------- Reservation cards ---------- */
.res-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.res-card.overdue-card { border-left: 4px solid var(--red); }
.res-card .thumb {
  width: 64px; height: 64px; border-radius: 8px; background: var(--gray-bg);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
  overflow: hidden; flex-shrink: 0;
}
.res-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.res-card .info { flex: 1; min-width: 0; }
.res-card .title { font-weight: 700; }
.res-card .dates { font-size: 13px; color: var(--muted); margin: 3px 0; }
.conflict-warn {
  background: var(--red-bg); color: var(--red);
  border-radius: 7px; padding: 8px 10px; font-size: 13px; margin-top: 8px;
}
.ok-note {
  background: var(--green-bg); color: var(--green);
  border-radius: 7px; padding: 8px 10px; font-size: 13px; margin-top: 8px;
}

/* ---------- Calendar ---------- */
.cal-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cal-toolbar .title { font-weight: 700; font-size: 17px; flex: 1; min-width: 150px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button {
  background: var(--surface); border: none; padding: 7px 13px;
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted);
}
.seg button.active { background: var(--navy); color: #fff; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: var(--border); gap: 1px;
}
.cal-head {
  background: var(--gray-bg); padding: 6px 4px; text-align: center;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.cal-cell {
  background: var(--surface); min-height: 86px; padding: 4px;
  font-size: 12px; cursor: pointer; overflow: hidden;
}
.cal-cell:hover { background: #f6f9ff; }
.cal-cell .daynum { font-weight: 700; margin-bottom: 3px; }
.cal-cell.other { background: #fafbfd; color: #b3bcc9; }
.cal-cell.today .daynum {
  background: var(--primary); color: #fff; border-radius: 999px;
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center;
}
.cal-event {
  border-radius: 5px; padding: 2px 6px; margin-bottom: 2px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; color: #fff;
}
.cal-event.maint { background: #7e57c2 !important; }
.cal-event.overdue { outline: 2px solid var(--red); }
.cal-more { font-size: 11px; color: var(--primary); font-weight: 700; }
.day-list .res-card { margin-bottom: 8px; }

/* ---------- Admin ---------- */
.subtabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 2px solid var(--border); }
.subtab {
  background: none; border: none; padding: 9px 13px;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.subtab.active { color: var(--primary); border-bottom-color: var(--primary); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 2px solid var(--border);
}
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table-wrap { overflow-x: auto; }
.bar-track { background: var(--gray-bg); border-radius: 5px; height: 10px; min-width: 80px; }
.bar-fill { background: var(--primary); border-radius: 5px; height: 10px; }
.cat-checks { display: flex; gap: 10px; flex-wrap: wrap; }
.cat-checks label {
  display: inline-flex; align-items: center; gap: 5px; margin: 0;
  font-weight: 500; font-size: 13px; color: var(--text);
}
.cat-checks input { width: auto; margin: 0; }
.thumb-mini {
  width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
  background: var(--gray-bg); display: block;
}
.select-check { width: 18px; height: 18px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 18, 34, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 14px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  padding: 22px;
}
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal .close-x {
  float: right; background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--muted); line-height: 1;
}

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; width: max-content; max-width: 92vw; }
.toast {
  background: var(--navy); color: #fff; padding: 11px 18px;
  border-radius: 8px; margin-top: 8px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  animation: toast-in 0.2s ease;
}
.toast.error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .topbar { padding: 0 8px; }
  .brand-name { display: none; }
  .nav-btn { padding: 13px 10px; font-size: 13px; }
  .user-menu .ghost-btn { padding: 6px 9px; font-size: 12px; }
  .cal-cell { min-height: 60px; font-size: 11px; }
  .cal-event { font-size: 9px; padding: 1px 3px; }
  main { padding: 12px 8px 50px; }
  .item-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
