/* ===== Base / theme ===== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1c2435;
  --muted: #687087;
  --border: #e4e8f0;
  --primary: #3a6df0;
  --primary-dark: #2f59c9;

  --available: #1f9d6b;
  --available-bg: #e3f6ee;
  --checkedout: #c47d12;
  --checkedout-bg: #fbf0db;
  --testing: #6c5ce7;
  --testing-bg: #ece9fb;
  --returned: #6b7280;
  --returned-bg: #eef0f4;
  --danger: #d64545;
  --danger-bg: #fbe4e4;

  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

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

/* The hidden attribute must always win, even over display:flex/grid rules below */
[hidden] { display: none !important; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

/* ===== Top bar ===== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  font-size: 1.8rem;
  color: var(--primary);
  line-height: 1;
}

.brand h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.subtitle { font-size: 0.78rem; color: var(--muted); }

.topbar-right { display: flex; align-items: center; gap: 16px; }

.role-switch { display: flex; align-items: center; gap: 8px; }
.role-label { font-size: 0.82rem; color: var(--muted); }

#roleSelect {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}

.who {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  background: #eef3fe;
  padding: 6px 12px;
  border-radius: 999px;
}

/* ===== Layout ===== */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Summary cards ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-left: 4px solid var(--primary);
}

.card-available { border-left-color: var(--available); }
.card-checkedout { border-left-color: var(--checkedout); }
.card-testing { border-left-color: var(--testing); }
.card-pending { border-left-color: var(--danger); }

.card-num { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }
.card-label { font-size: 0.8rem; color: var(--muted); font-weight: 500; }

/* ===== Panels ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

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

.panel-head h2 { font-size: 1.05rem; font-weight: 700; }

.badge-count {
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 999px;
}

/* ===== Buttons ===== */
.btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #eef0f4; }

.btn-sm { padding: 6px 12px; font-size: 0.82rem; }

.btn-success { background: var(--available); color: #fff; }
.btn-success:hover { filter: brightness(0.94); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search {
  flex: 1;
  min-width: 220px;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}
.search:focus { outline: none; border-color: var(--primary); background: #fff; }

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

.chip {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }

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

.table thead th {
  text-align: left;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover { background: var(--surface-2); }

.table .mono { font-variant-numeric: tabular-nums; font-weight: 600; }
.table .muted-cell { color: var(--muted); }

.col-actions { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ===== Status badges ===== */
.status {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-Available { background: var(--available-bg); color: var(--available); }
.status-Checked-out { background: var(--checkedout-bg); color: var(--checkedout); }
.status-In-testing { background: var(--testing-bg); color: var(--testing); }
.status-Returned { background: var(--returned-bg); color: var(--returned); }

.empty { text-align: center; color: var(--muted); padding: 30px; font-style: italic; }

/* ===== Approvals ===== */
.approvals { border-left: 4px solid var(--danger); }
.approvals-list { display: flex; flex-direction: column; gap: 10px; }

.approval-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-wrap: wrap;
}

.approval-info { font-size: 0.9rem; }
.approval-info strong { font-weight: 700; }
.approval-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.approval-actions { display: flex; gap: 8px; }

.approvals-empty { color: var(--muted); font-style: italic; }

/* ===== Activity log ===== */
.log { list-style: none; display: flex; flex-direction: column; gap: 0; }

.log li {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.86rem;
}
.log li:last-child { border-bottom: none; }

.log-time { color: var(--muted); font-size: 0.78rem; white-space: nowrap; min-width: 130px; }
.log-action { font-weight: 600; }
.log-detail { color: var(--muted); }
.log-empty { color: var(--muted); font-style: italic; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 620px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.25);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-sm { max-width: 440px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-form { padding: 22px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.modal-form label.full { grid-column: 1 / -1; }

.modal-form input,
.modal-form select,
.modal-form textarea {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 400;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  width: 100%;
}
.modal-form input:focus,
.modal-form select:focus,
.modal-form textarea:focus { outline: none; border-color: var(--primary); background: #fff; }

.prompt-msg { font-size: 0.92rem; margin-bottom: 14px; }

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

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 60;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== Responsive ===== */
@media (max-width: 1000px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 720px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; }
  .subtitle { display: none; }
}
