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

:root {
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --green: #059669;
  --green-light: #d1fae5;
  --blue: #2563eb;
  --blue-light: #dbeafe;
  --orange: #d97706;
  --orange-light: #fef3c7;
  --red: #dc2626;
  --sidebar-w: 230px;
  --topbar-h: 64px;
  --bg: #f8f7fc;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  z-index: 50;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.logo-icon { font-size: 1.8rem; }
.logo-text { font-size: 1rem; font-weight: 800; color: var(--purple); line-height: 1.2; }
.logo-sub  { font-size: 0.7rem; color: var(--muted); }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.25rem; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--purple-light); color: var(--purple); }
.nav-item.active { background: var(--purple-light); color: var(--purple); font-weight: 600; }
.nav-icon { font-size: 1.1rem; }

/* ── Main ── */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 40;
}

.page-title { font-size: 1.3rem; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.topbar-date { color: var(--muted); font-size: 0.9rem; }

.avatar {
  width: 36px; height: 36px;
  background: var(--purple);
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
}

/* ── Pages ── */
.page { display: none; padding: 2rem; }
.page.active { display: block; }

.loading { text-align: center; color: var(--muted); padding: 2rem; font-size: 0.9rem; }

/* ── Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
}

.stat-card.purple::before { background: var(--purple); }
.stat-card.green::before  { background: var(--green); }
.stat-card.blue::before   { background: var(--blue); }
.stat-card.orange::before { background: var(--orange); }

.stat-label { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.stat-num   { font-size: 2.5rem; font-weight: 900; line-height: 1; }
.stat-card.purple .stat-num { color: var(--purple); }
.stat-card.green  .stat-num { color: var(--green); }
.stat-card.blue   .stat-num { color: var(--blue); }
.stat-card.orange .stat-num { color: var(--orange); }

.stat-icon { position: absolute; bottom: 1rem; right: 1.25rem; font-size: 2rem; opacity: 0.15; }

/* ── Dashboard bottom ── */
.dashboard-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ── Card ── */
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 1.25rem; color: var(--text); }

/* ── Category list ── */
.category-list { display: flex; flex-direction: column; gap: 0.75rem; }

.category-row { display: flex; align-items: center; gap: 0.75rem; }
.category-name { width: 110px; font-size: 0.9rem; color: var(--muted); }
.category-bar-wrap { flex: 1; background: var(--bg); border-radius: 50px; height: 8px; overflow: hidden; }
.category-bar { height: 100%; background: var(--purple); border-radius: 50px; transition: width 0.5s ease; }
.category-count { font-size: 0.85rem; font-weight: 600; color: var(--text); width: 24px; text-align: right; }

/* ── Recent list ── */
.recent-list { display: flex; flex-direction: column; gap: 0.75rem; }

.recent-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.recent-item:last-child { border-bottom: none; }

.recent-icon {
  width: 36px; height: 36px;
  background: var(--purple-light);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.recent-info { flex: 1; }
.recent-name { font-size: 0.9rem; font-weight: 600; }
.recent-sub  { font-size: 0.78rem; color: var(--muted); }

/* ── Toolbar ── */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; gap: 1rem; }
.toolbar-left { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.search-input {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  width: 260px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: var(--purple); }

.filter-select {
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  cursor: pointer;
  outline: none;
}

/* ── Buttons ── */
.btn {
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: #6d28d9; }
.btn-primary:disabled { background: #a78bfa; cursor: not-allowed; }

.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; border-radius: 6px; }

/* ── Table ── */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.table th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #faf9ff; }

.table-empty { text-align: center; padding: 3rem; color: var(--muted); font-size: 0.95rem; }

/* ── Status badges ── */
.badge {
  display: inline-block;
  padding: 0.25rem 0.7rem;
  border-radius: 50px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-使用中 { background: var(--green-light);  color: var(--green); }
.badge-閒置   { background: var(--blue-light);   color: var(--blue); }
.badge-維修中 { background: var(--orange-light); color: var(--orange); }
.badge-報廢   { background: #f3f4f6;             color: #9ca3af; }
.badge-借用中 { background: #fce7f3;             color: #be185d; }
.badge-已歸還 { background: var(--green-light);  color: var(--green); }

/* ── Action buttons ── */
.action-btns { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.btn-edit   { background: var(--blue-light);   color: var(--blue); }
.btn-edit:hover   { background: #bfdbfe; }

.btn-del    { background: #fee2e2; color: var(--red); }
.btn-del:hover    { background: #fecaca; }

.btn-return { background: var(--green-light); color: var(--green); }
.btn-return:hover { background: #a7f3d0; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-sm { max-width: 400px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.1rem; font-weight: 700; }

.modal-close {
  background: none; border: none; font-size: 1.1rem;
  cursor: pointer; color: var(--muted); padding: 0.25rem 0.5rem; border-radius: 6px;
}

.modal-close:hover { background: var(--bg); }
.modal-body { padding: 1.5rem; }
.modal-body > p { color: var(--muted); font-size: 0.95rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── Form ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: var(--text); }

.form-group input,
.form-group select,
.form-group textarea {
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: #fff;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--purple); }

.form-group textarea { resize: vertical; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #1f2937;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
