:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --primary: #4f7cff;
    --primary-2: #3b63d9;
    --green: #2bb673; --green-bg: rgba(43,182,115,.15);
    --amber: #e0a83a; --amber-bg: rgba(224,168,58,.15);
    --red: #e0524a;   --red-bg: rgba(224,82,74,.15);
    --blue: #4f8cff;  --blue-bg: rgba(79,140,255,.15);
    --purple:#9b6cff;  --purple-bg: rgba(155,108,255,.15);
    --teal: #2bc4c4;   --teal-bg: rgba(43,196,196,.15);
    --gray: #8a93a3;   --gray-bg: rgba(138,147,163,.15);
    --radius: 12px;
    --shadow: 0 6px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; flex-shrink: 0; background: var(--surface);
    border-right: 1px solid var(--border); display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { padding: 20px 18px; font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg,var(--primary),var(--purple)); display:flex; align-items:center; justify-content:center; font-weight:800; color:#fff; }
.brand small { display:block; font-weight: 400; font-size: 11px; color: var(--muted); }
.nav { padding: 10px; flex: 1; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 12px 6px; }
.nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
    color: var(--muted); font-weight: 500; margin-bottom: 2px; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary); color: #fff; }
.nav a .ic { width: 18px; text-align: center; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 60px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
    justify-content: space-between; padding: 0 24px; background: var(--surface);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; }
.topbar .user { display: flex; align-items: center; gap: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); display:flex; align-items:center; justify-content:center; font-weight:600; }
.content { padding: 24px; flex: 1; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card-head { display:flex; align-items:center; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { margin: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px){ .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; } .sidebar{ display:none; } }

/* ---------- Stat tiles ---------- */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat .ic { float:right; width: 40px; height: 40px; border-radius: 10px; display:flex; align-items:center; justify-content:center; font-size: 18px; background: var(--surface-2); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer; font-size: 13px; transition: .15s; }
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-danger { background: var(--red-bg); border-color: transparent; color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }

/* ---------- Tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.tbl tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* DataTables overrides */
.dataTables_wrapper { color: var(--muted); }
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 10px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button { color: var(--muted) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { background: var(--primary) !important; color: #fff !important; border-radius: 6px; border: none; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-teal { background: var(--teal-bg); color: var(--teal); }
.badge-gray { background: var(--gray-bg); color: var(--gray); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control, select.form-control, textarea.form-control {
    width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 560px; box-shadow: var(--shadow); }
.modal.lg { max-width: 800px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; }

/* ---------- Misc ---------- */
.flash { padding: 12px 16px; border-radius: 9px; margin-bottom: 16px; font-weight: 500; }
.flash.success { background: var(--green-bg); color: var(--green); }
.flash.error { background: var(--red-bg); color: var(--red); }
.flash.info { background: var(--blue-bg); color: var(--blue); }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap { gap: 10px; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* timeline */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content:''; position:absolute; left: 9px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline .tl-item { position: relative; padding-bottom: 22px; }
.timeline .tl-item::before { content:''; position:absolute; left: -23px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }
.timeline .tl-time { color: var(--muted); font-size: 12px; }
.tl-photos { display:flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tl-photos img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* auth */
.auth-wrap { min-height: 100vh; display:flex; align-items:center; justify-content:center; padding: 20px; background: radial-gradient(1200px 600px at 50% -10%, rgba(79,124,255,.18), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.auth-card .brand { border: none; padding: 0 0 8px; justify-content: center; }
.auth-card h2 { text-align: center; margin: 8px 0 4px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin: 0 0 22px; }

.demo-login { margin-top: 20px; padding-top: 18px; border-top: 1px dashed var(--border); }
.demo-login-title { text-align: center; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin: 0 0 10px; }
.demo-accounts { display: flex; flex-direction: column; gap: 6px; }
.demo-account { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 12px; cursor: pointer; transition: border-color .15s, background .15s; text-align: left; }
.demo-account:hover { border-color: var(--primary); background: rgba(79,124,255,.08); }
.demo-account .demo-role { font-weight: 600; color: var(--primary); min-width: 58px; }
.demo-account .demo-cred { color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-account .demo-pass { color: var(--muted); font-size: 11px; flex-shrink: 0; }

/* portal (public) — lighter */
body.portal { background: #f4f6fb; color: #1c2230; }
.portal-header { background: #fff; border-bottom: 1px solid #e6e9f0; padding: 18px 24px; }
.portal-container { max-width: 760px; margin: 0 auto; padding: 24px 16px; }
.portal .card { background: #fff; border-color: #e6e9f0; color: #1c2230; }
.portal .timeline::before { background: #e0e4ee; }
.portal .timeline .tl-item::before { border-color: #fff; }
.portal .muted { color: #6b7280; }
