:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --ink: #1e2433;
    --muted: #6b7280;
    --line: #e5e9f2;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --ok: #16a34a;
    --danger: #dc2626;
    --warn: #d97706;
    --info: #2563eb;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .07);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
code { background: #eef1f7; padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.muted { color: var(--muted); }
.num { text-align: right; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 232px;
    background: #171c2e;
    color: #cdd3e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
}
.brand {
    display: flex; gap: 10px; align-items: center;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon { font-size: 26px; }
.brand strong { display: block; color: #fff; font-size: 14px; line-height: 1.25; }
.brand small { color: #8b93ab; font-size: 11px; }
.sidebar nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
    display: flex; align-items: center; gap: 10px;
    color: #b9c0d4; padding: 8px 10px; border-radius: 8px;
    font-size: 13.5px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.nav-icon { width: 20px; text-align: center; }
.sidebar-foot {
    padding: 14px 16px; font-size: 11.5px; color: #8b93ab;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; gap: 7px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }

.main { flex: 1; min-width: 0; }
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 26px 0;
}
.topbar h1 { margin: 0; font-size: 22px; }
.date-chip {
    background: var(--panel); border: 1px solid var(--line);
    padding: 6px 12px; border-radius: 999px; font-size: 12.5px; color: var(--muted);
}
.content { padding: 18px 26px 40px; }

/* ---------- Flash ---------- */
.flash {
    margin: 14px 26px 0; padding: 11px 16px; border-radius: 10px; font-size: 13.5px;
}
.flash-success { background: #ecfdf3; color: #067647; border: 1px solid #a6f4c5; }
.flash-error { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }

/* ---------- Cards & grids ---------- */
.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 15.5px; }
.card-narrow { max-width: 760px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 18px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Stat cards ---------- */
.stat-grid {
    display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 18px;
}
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1200px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 2px;
}
.stat-card .stat-num { font-size: 24px; font-weight: 700; }
.stat-card .stat-label { font-size: 12.5px; color: var(--muted); }
.stat-card small { color: var(--muted); font-size: 11.5px; }
.stat-warn { border-color: #fecdca; background: #fff7f5; }
.stat-warn .stat-num { color: var(--danger); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--line);
}
.table th.num, .table td.num { text-align: right; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover { background: #f8faff; }
.table-plain td { border-bottom: 1px solid var(--line); }
.table-plain td:first-child { color: var(--muted); width: 42%; }
.msg-cell { max-width: 340px; color: var(--muted); font-size: 12.5px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
    background: #eef1f7; color: #3d4663; font-weight: 600; white-space: nowrap;
}
.badge-ok { background: #ecfdf3; color: #067647; }
.badge-danger { background: #fef3f2; color: #b42318; }
.badge-warn { background: #fffaeb; color: #b54708; }
.badge-info { background: #eff4ff; color: #3538cd; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; border: 1px solid var(--line); background: var(--panel);
    color: var(--ink); padding: 7px 14px; border-radius: 8px; font-size: 13px;
    cursor: pointer; text-decoration: none; font-family: inherit; line-height: 1.4;
}
.btn:hover { background: #f2f4fa; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #fecdca; }
.btn-danger:hover { background: #fef3f2; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.actions { white-space: nowrap; }
.actions form { margin: 2px 0; }
.inline { display: inline; }
.inline-select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }

/* ---------- Toolbar / search ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type="text"], .toolbar select {
    padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; min-width: 220px;
}

/* ---------- Forms ---------- */
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: #3d4663; margin-bottom: 12px; }
.form input, .form select, .form textarea {
    padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13.5px;
    font-family: inherit; font-weight: 400; background: #fff; color: var(--ink);
}
.form input:focus, .form select:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .form-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.form-hint { font-size: 12.5px; color: var(--muted); min-height: 16px; margin: -4px 0 10px; }
.form-hint .over { color: var(--danger); font-weight: 600; }

/* Sign-in screen */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; margin-bottom: 0; }

/* Per-user menu permissions on the Users form */
.menu-perms-title { display: block; font-size: 12.5px; font-weight: 600; color: #3d4663; margin: 2px 0 2px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; margin-bottom: 12px; }
.menu-grid .menu-check { display: flex; flex-direction: row; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 500; color: #3d4663; margin-bottom: 0; padding: 3px 0; }
.menu-grid .menu-check input { margin: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
    padding: 8px 16px; border-radius: 8px; font-size: 13px; color: var(--muted);
    background: var(--panel); border: 1px solid var(--line);
}
.tabs a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Dashboard charts ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 14px; height: 210px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar {
    width: 100%; max-width: 56px; background: linear-gradient(180deg, #6366f1, #4f46e5);
    border-radius: 6px 6px 2px 2px;
}
.bar-val { font-size: 12px; font-weight: 700; margin-top: 4px; }
.bar-label { font-size: 11px; color: var(--muted); }

.progress-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.progress-name { width: 110px; font-size: 12.5px; }
.progress { flex: 1; background: #eef1f7; border-radius: 999px; height: 10px; overflow: hidden; }
.progress-fill { background: var(--primary); height: 100%; border-radius: 999px; }
.progress-pct { width: 90px; text-align: right; font-size: 12px; color: var(--muted); }

.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.activity-list li:last-child { border-bottom: 0; }
.activity-badge {
    flex-shrink: 0; width: 42px; height: 22px; display: flex; align-items: center; justify-content: center;
    border-radius: 6px; font-size: 10.5px; font-weight: 700;
}
.activity-issued { background: #eff4ff; color: #3538cd; }
.activity-returned { background: #ecfdf3; color: #067647; }

/* ---------- Digital library card ---------- */
.lib-card {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff; border-radius: 14px; padding: 16px 18px; margin-bottom: 14px;
    max-width: 380px; box-shadow: 0 8px 22px rgba(79, 70, 229, .35);
}
.lib-card-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; margin-bottom: 18px; }
.lib-card-head code { background: rgba(255,255,255,.2); color: #fff; }
.lib-card-body strong { font-size: 17px; }
.lib-card-body span { font-size: 12px; opacity: .85; }

/* ---------- Report ---------- */
.report-head { text-align: center; margin: 6px 0 18px; }
.report-head h1 { margin: 0 0 4px; font-size: 20px; }
.report-head p { margin: 0; color: var(--muted); font-size: 12.5px; }

/* ---------- Topbar icons ---------- */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--panel); cursor: pointer; font-size: 16px; color: var(--ink);
    text-decoration: none; padding: 0;
}
.icon-btn:hover { background: #f2f4fa; }
.icon-badge {
    position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff;
    font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; line-height: 16px;
    border-radius: 999px; text-align: center; padding: 0 4px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Dark mode ---------- */
html.dark {
    --bg: #0f1420;
    --panel: #1a2133;
    --ink: #e6e9f2;
    --muted: #8b93ab;
    --line: #2b3550;
    --shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
html.dark body { background: var(--bg); color: var(--ink); }
html.dark .sidebar { background: #0c101b; }
html.dark code { background: #232c44; color: #dfe4f0; }
html.dark .table tbody tr:hover { background: #1e2740; }
html.dark .btn:hover { background: #232c44; }
html.dark .btn-danger:hover { background: #33191a; }
html.dark .icon-btn:hover { background: #232c44; }
html.dark .toolbar input[type="text"], html.dark .toolbar select,
html.dark .form input, html.dark .form select, html.dark .form textarea {
    background: #121828; color: var(--ink); border-color: var(--line);
}
html.dark .form input:focus, html.dark .form select:focus { outline-color: #4338ca; }
html.dark .badge { background: #232c44; color: #cdd3e1; }
html.dark .badge-ok { background: #12291c; color: #4ade80; }
html.dark .badge-danger { background: #33191a; color: #f87171; }
html.dark .badge-warn { background: #2e2113; color: #fbbf24; }
html.dark .badge-info { background: #1a2340; color: #93c5fd; }
html.dark .progress { background: #232c44; }
html.dark .stat-warn { background: #241417; }
html.dark .bar { background: linear-gradient(180deg, #818cf8, #6366f1); }
html.dark .activity-issued { background: #1a2340; color: #a5b4fc; }
html.dark .activity-returned { background: #12291c; color: #4ade80; }
html.dark .flash-success { background: #12261a; color: #4ade80; border-color: #1d4630; }
html.dark .flash-error { background: #2a1414; color: #f87171; border-color: #582323; }

/* ---------- Print ---------- */
@media print {
    .sidebar, .topbar, .no-print, .flash, .btn, .actions { display: none !important; }
    .main, .content { padding: 0; }
    body { background: #fff; }
    .card { border: none; box-shadow: none; page-break-inside: avoid; }
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .stat-card { border: 1px solid #ccc; }
}
