:root {
    --bg: #f0f3f8;
    --surface: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #2563eb;
    --brand-dark: #1d4ed8;
    --danger: #dc2626;
    --sidebar: #0b1220;
    --sidebar-text: #94a3b8;
    --sidebar-active: #ffffff;
    --ok: #059669;
    --ok-bg: #ecfdf5;
    --warn-bg: #fff7ed;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .04);
    font-family: "Plus Jakarta Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: .75rem; padding: .35rem .5rem; color: #fff; }

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(145deg, #3b82f6, #1e40af);
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #fff;
    font-size: .9rem;
}

.brand strong { display: block; font-size: .95rem; line-height: 1.2; }
.brand span { font-size: .75rem; color: var(--sidebar-text); font-weight: 500; }

.side-nav { display: flex; flex-direction: column; gap: .25rem; }

.side-nav a,
.side-nav button.nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .7rem .85rem;
    border-radius: 10px;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: .92rem;
    border: 0;
    background: transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.side-nav a:hover,
.side-nav button.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }

.side-nav a.active { background: rgba(37,99,235,.22); color: var(--sidebar-active); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.topbar p { margin: .15rem 0 0; color: var(--muted); font-size: .88rem; }

.user-menu { position: relative; }

.user-chip {
    display: flex;
    align-items: center;
    gap: .65rem;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .35rem .75rem .35rem .4rem;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.user-chip:hover { background: #f1f5f9; }

.user-menu-dd {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 180px;
    z-index: 30;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: .35rem;
}

.user-menu-dd a,
.user-menu-dd button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: .65rem .75rem;
    border-radius: 8px;
    font: inherit;
    color: var(--ink);
    text-decoration: none;
}

.user-menu-dd a:hover,
.user-menu-dd button:hover { background: #f8fafc; }

.user-menu-dd button.danger { color: var(--danger); }

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: .8rem;
}

.content { padding: 1.5rem; max-width: 1180px; width: 100%; margin: 0 auto; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem 1.35rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.card-head h2 { margin: 0; font-size: 1.05rem; }
.muted { color: var(--muted); font-size: .92rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }

.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    box-shadow: var(--shadow);
}

.stat label { display: block; color: var(--muted); font-size: .82rem; font-weight: 600; margin-bottom: .35rem; }
.stat strong { font-size: 1.6rem; letter-spacing: -.02em; }

.badge {
    display: inline-flex;
    align-items: center;
    background: #eff6ff;
    color: #1d4ed8;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    margin: .1rem;
}

.badge-muted { background: #f1f5f9; color: #475569; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: #c2410c; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: .65rem 1rem;
    font-weight: 600;
    font-size: .9rem;
    cursor: pointer;
    font-family: inherit;
}

.btn:hover { background: var(--brand-dark); color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: #f8fafc; color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: .4rem .7rem; font-size: .8rem; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: .85rem .6rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    font-size: .92rem;
}
th {
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
}
tr:last-child td { border-bottom: 0; }

.flash {
    background: var(--ok-bg);
    border: 1px solid #a7f3d0;
    color: #065f46;
    padding: .85rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
}

.cred-box {
    background: var(--ok-bg);
    border: 1px solid #a7f3d0;
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
}

.cred-box h2 { margin: 0 0 .35rem; font-size: 1rem; }

.error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: .85rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
}

label { display: block; font-weight: 600; margin-bottom: .4rem; font-size: .9rem; }

input, select, textarea {
    width: 100%;
    padding: .7rem .85rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 1rem;
    background: #fff;
    font: inherit;
    color: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(37,99,235,.25);
    border-color: var(--brand);
}

.field-error { color: var(--danger); margin-top: -.7rem; margin-bottom: 1rem; font-size: .85rem; }
.hint { margin-top: -.55rem; margin-bottom: 1rem; color: var(--muted); font-size: .85rem; }

.checkbox-row { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; font-weight: 500; }
.checkbox-row input { width: auto; margin: 0; }

.dept-dd { position: relative; margin-bottom: 1rem; }

.dept-dd-toggle {
    width: 100%;
    text-align: left;
    padding: .7rem .85rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    font: inherit;
    color: inherit;
    cursor: pointer;
}

.dept-dd-toggle:focus {
    outline: 2px solid rgba(37,99,235,.25);
    border-color: var(--brand);
}

.dept-dd-menu {
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 220px;
    overflow: auto;
    padding: .35rem;
}

.dept-dd-option {
    display: flex;
    width: 100%;
    align-items: center;
    gap: .55rem;
    border: 0;
    background: transparent;
    text-align: left;
    padding: .55rem .65rem;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
}

.dept-dd-option:hover { background: #f8fafc; }
.dept-dd-option.is-selected { background: #eff6ff; color: #1d4ed8; font-weight: 600; }

.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .25rem; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
code { background: #f1f5f9; padding: .1rem .35rem; border-radius: 6px; font-size: .85em; }

.app-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.app-modal[hidden] { display: none !important; }

.app-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(2px);
}

.app-modal-card {
    position: relative;
    width: min(440px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .18);
    padding: 1.35rem 1.4rem;
}

.app-modal-title { margin: 0 0 .75rem; font-size: 1.1rem; }
.app-modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.25rem; flex-wrap: wrap; }

@media (max-width: 900px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; }
    .stats { grid-template-columns: 1fr !important; }
}

body.guest-layout {
    margin: 0;
    min-height: 100vh;
    color: var(--ink, #0f172a);
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(ellipse 80% 60% at 10% 10%, rgba(37,99,235,.18), transparent 55%),
        radial-gradient(ellipse 70% 50% at 90% 90%, rgba(14,165,233,.12), transparent 50%),
        #0b1220;
}

.guest-layout .panel {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 18px;
    padding: 2rem 1.75rem;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
}

.guest-layout .mark {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(145deg, #3b82f6, #1e40af);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    margin-bottom: 1rem;
}

.guest-layout h1 { margin: 0 0 .35rem; font-size: 1.35rem; }
.guest-layout .sub { margin: 0 0 1.5rem; color: var(--muted, #64748b); font-size: .92rem; }

.guest-layout label {
    display: block;
    font-weight: 600;
    margin-bottom: .4rem;
    font-size: .9rem;
}

.guest-layout input {
    width: 100%;
    padding: .75rem .85rem;
    border: 1px solid var(--line, #e2e8f0);
    border-radius: 10px;
    margin-bottom: 1rem;
    font: inherit;
}

.guest-layout input:focus {
    outline: 2px solid rgba(37,99,235,.25);
    border-color: var(--brand, #2563eb);
}

.guest-layout .field-error {
    color: #dc2626;
    margin-top: -.7rem;
    margin-bottom: 1rem;
    font-size: .85rem;
}

.guest-layout .checkbox-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: 1.1rem;
    font-weight: 500;
}

.guest-layout .checkbox-row input { width: auto; margin: 0; }

.guest-layout .btn {
    width: 100%;
    background: var(--brand, #2563eb);
    color: #fff;
    border: 0;
    border-radius: 10px;
    padding: .8rem 1rem;
    font-weight: 700;
    font-size: .95rem;
    cursor: pointer;
    font-family: inherit;
}

.guest-layout .btn:hover { background: #1d4ed8; }

.guest-layout .error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: .75rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}
