:root {
    --ink: #26183f;
    --muted: #756987;
    --line: #e6ddf7;
    --panel: #ffffff;
    --bg: #f7f2ff;
    --purple: #7c3aed;
    --purple-dark: #4c1d95;
    --purple-soft: #ede3ff;
    --violet: #a855f7;
    --teal: #14b8a6;
    --sky: #0ea5e9;
    --amber: #f59e0b;
    --rose: #e11d48;
    --green: #16a34a;
    --shadow: 0 18px 42px rgba(76, 29, 149, .14);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(168, 85, 247, .24), transparent 34rem),
        radial-gradient(circle at top right, rgba(20, 184, 166, .14), transparent 28rem),
        linear-gradient(180deg, #fbf8ff 0, var(--bg) 320px);
}
a { color: inherit; }
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 286px minmax(0, 1fr);
}
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    color: #fff;
    background:
        linear-gradient(160deg, rgba(124, 58, 237, .96), rgba(76, 29, 149, .98)),
        var(--purple-dark);
    box-shadow: 16px 0 42px rgba(76, 29, 149, .2);
}
.sidebar-logo {
    padding: 26px 22px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,.16);
}
.logo-mark {
    width: 82px;
    height: 82px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 28px;
    background: linear-gradient(135deg, #ffffff, #dcd0ff);
    color: var(--purple-dark);
    font-size: 30px;
    font-weight: 900;
    box-shadow: 0 16px 34px rgba(31, 11, 82, .22);
}
.app-logo-img {
    width: 92px;
    height: 92px;
    display: block;
    object-fit: contain;
    margin: 0 auto 14px;
    padding: 10px;
    border-radius: 28px;
    background: rgba(255,255,255,.94);
    box-shadow: 0 16px 34px rgba(31, 11, 82, .22);
}
.sidebar-logo strong {
    display: block;
    font-size: 18px;
    line-height: 1.25;
}
.sidebar-logo span {
    display: block;
    margin-top: 8px;
    color: rgba(255,255,255,.78);
    font-size: 13px;
    line-height: 1.35;
}
.side-nav {
    display: grid;
    gap: 8px;
    padding: 18px 14px 24px;
}
.side-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 10px 13px;
    color: rgba(255,255,255,.9);
    text-decoration: none;
    border-radius: 14px;
    font-weight: 700;
    transition: background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.side-nav a:hover { transform: translateX(2px); }
.side-nav a span {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: rgba(255,255,255,.14);
    font-size: 13px;
}
.side-nav a:hover,
.side-nav a.active {
    color: var(--purple-dark);
    background: #fff;
    box-shadow: 0 12px 24px rgba(31, 11, 82, .2);
}
.side-nav a:hover span,
.side-nav a.active span {
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--teal));
}
.main-pane { min-width: 0; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 8;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 14px 24px;
    background: rgba(255,255,255,.84);
    border-bottom: 1px solid rgba(124, 58, 237, .16);
    backdrop-filter: blur(14px);
}
.quick-nav {
    position: sticky;
    top: 73px;
    z-index: 7;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 24px 12px;
    background: rgba(247,242,255,.78);
    border-bottom: 1px solid rgba(124, 58, 237, .13);
    scrollbar-width: thin;
}
.quick-nav a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid #e2d5f7;
    border-radius: 999px;
    color: var(--purple-dark);
    background: rgba(255,255,255,.86);
    text-decoration: none;
    font-weight: 800;
    box-shadow: 0 8px 20px rgba(76, 29, 149, .08);
    transition: background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.quick-nav a:hover { transform: translateY(-1px); }
.quick-nav a span {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--teal));
    font-size: 11px;
}
.quick-nav a.active {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--purple), var(--violet));
}
.quick-nav a.active span {
    color: var(--purple-dark);
    background: #fff;
}
.menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--violet));
    font-size: 24px;
    cursor: pointer;
}
.page-title {
    display: grid;
    gap: 2px;
}
.page-title strong {
    font-size: 21px;
}
.page-title span {
    color: var(--muted);
    font-size: 13px;
}
.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(76, 29, 149, .08);
}
.user-chip span {
    padding: 5px 9px;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--teal), var(--sky));
    font-size: 12px;
    font-weight: 800;
}
.container {
    max-width: 1220px;
    margin: 0 auto;
    padding: 28px 22px 60px;
}
h1 { font-size: 30px; margin: 0 0 18px; letter-spacing: 0; }
h2 { font-size: 20px; margin: 0 0 12px; }
.panel {
    background: rgba(255,255,255,.94);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.panel:hover {
    transform: translateY(-1px);
    box-shadow: 0 22px 46px rgba(76, 29, 149, .16);
}
.narrow { max-width: 430px; }
.grid { display: grid; gap: 16px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.full { grid-column: 1 / -1; }
.form label, .filters label {
    display: grid;
    gap: 7px;
    color: #4b3a68;
    font-weight: 700;
}
input, textarea, select {
    width: 100%;
    border: 1px solid #ddd0f4;
    border-radius: 13px;
    padding: 12px 13px;
    font: inherit;
    color: var(--ink);
    background: #fff;
    transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--purple);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, .16);
}
textarea { min-height: 90px; resize: vertical; }
.short-textarea { min-height: 76px; }
.filters {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto auto;
    align-items: end;
    gap: 11px;
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255,255,255,.82);
    box-shadow: 0 12px 30px rgba(76, 29, 149, .08);
}
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    border: 1px solid #d9c9f2;
    border-radius: 13px;
    background: #fff;
    color: var(--purple-dark);
    text-decoration: none;
    cursor: pointer;
    font-weight: 800;
    white-space: nowrap;
    transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(76, 29, 149, .16); }
.btn.primary {
    border-color: transparent;
    background: linear-gradient(135deg, var(--purple), var(--violet));
    color: #fff;
}
.btn.danger {
    border-color: transparent;
    background: linear-gradient(135deg, var(--rose), #fb7185);
    color: #fff;
}
.btn.ghost { background: rgba(255,255,255,.52); }
.btn.small { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.alert {
    padding: 13px 15px;
    border-radius: 16px;
    margin-bottom: 16px;
    border: 1px solid rgba(20, 184, 166, .24);
    background: #e9fffb;
    color: #0f766e;
    box-shadow: 0 10px 24px rgba(20, 184, 166, .12);
    font-weight: 700;
}
.alert.danger { background: #fff1f4; color: #9f1239; border-color: #fecdd3; }
.alert.warning { background: #fff7db; color: #8a5400; border-color: #fde68a; }
.import-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid #e6d8fb;
    border-radius: 16px;
    background: linear-gradient(135deg, #fbf7ff, #eefcff);
}
.import-actions h2,
.import-actions p { margin: 0; }
.import-actions p { margin-top: 4px; }
.branding-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    border: 1px solid #e6d8fb;
    border-radius: 16px;
    background: #fbf7ff;
}
.branding-preview span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    color: var(--purple-dark);
    background: #fff;
    font-weight: 900;
}
.branding-preview img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 8px;
}
.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stats div {
    position: relative;
    overflow: hidden;
    padding: 18px;
    border-radius: 18px;
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--violet));
    box-shadow: var(--shadow);
}
.stats div:nth-child(2) { background: linear-gradient(135deg, var(--teal), #22c55e); }
.stats div:nth-child(3) { background: linear-gradient(135deg, var(--sky), #6366f1); }
.stats div:nth-child(4) { background: linear-gradient(135deg, var(--amber), #f97316); }
.stats div::after {
    content: "";
    position: absolute;
    width: 82px;
    height: 82px;
    right: -22px;
    top: -22px;
    border-radius: 999px;
    background: rgba(255,255,255,.22);
}
.stats strong { display: block; font-size: 34px; line-height: 1; }
.stats span { display: block; margin-top: 8px; color: rgba(255,255,255,.88); font-weight: 700; }
.muted { color: var(--muted); }
.danger-zone { border-color: #fecdd3; }
.table-wrap {
    max-height: 68vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow);
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 840px;
}
.edit-table table { min-width: 1180px; }
.edit-table input { min-width: 150px; padding: 9px 10px; }
.edit-table td:nth-child(2) input,
.edit-table td:nth-child(4) input { min-width: 250px; }
.user-manager-hero {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background:
        linear-gradient(135deg, rgba(124, 58, 237, .12), rgba(20, 184, 166, .1)),
        rgba(255,255,255,.9);
    box-shadow: var(--shadow);
}
.user-manager-hero h2 { margin-bottom: 6px; }
.access-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(104px, 1fr));
    gap: 10px;
    min-width: 340px;
}
.access-summary span {
    display: grid;
    place-items: center;
    min-height: 68px;
    padding: 10px;
    border-radius: 16px;
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--violet));
    font-weight: 900;
    text-align: center;
    box-shadow: 0 12px 28px rgba(76, 29, 149, .16);
}
.access-summary span:nth-child(2) { background: linear-gradient(135deg, var(--teal), #22c55e); }
.access-summary span:nth-child(3) { background: linear-gradient(135deg, var(--sky), #6366f1); }
.user-manager-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, .6fr);
    gap: 16px;
}
.form-grid.compact {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.permission-box {
    max-height: 214px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    background: linear-gradient(180deg, #fff, #fbf7ff);
}
.permission-box legend {
    padding: 0 8px;
    color: var(--purple-dark);
    font-weight: 900;
}
.permission-box label,
.permission-checks label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 4px 7px 4px 0;
    padding: 7px 10px;
    border: 1px solid #e6d8fb;
    border-radius: 999px;
    background: #f7f0ff;
    color: #4b267c;
    font-weight: 800;
    white-space: nowrap;
}
.menu-permission-box label,
.menu-checks label {
    background: #eefcff;
    border-color: #c9eef3;
    color: #155e75;
}
.menu-permission-box label span,
.menu-checks label span {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--teal));
    font-size: 11px;
}
.permission-box input,
.permission-checks input {
    width: auto;
    min-width: 0;
    accent-color: var(--purple);
}
.permission-checks {
    min-width: 360px;
    max-width: 560px;
    max-height: 190px;
    overflow: auto;
}
.menu-checks { min-width: 440px; }
.user-manager-table table { min-width: 1550px; }
.user-manager-table td:nth-child(1) input,
.user-manager-table td:nth-child(2) input { min-width: 210px; }
.user-manager-table select { min-width: 190px; }
.user-manager-table td:last-child {
    min-width: 180px;
}
.access-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 11px;
    border-radius: 999px;
    font-weight: 900;
    white-space: nowrap;
}
.all-access {
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--teal));
}
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0 10px;
    padding: 0 2px;
}
.table-toolbar strong {
    color: var(--purple-dark);
    font-size: 18px;
}
.table-toolbar span {
    color: var(--muted);
    font-weight: 700;
}
.recommendation-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}
.recommendation-list span {
    padding: 10px 12px;
    border-radius: 14px;
    color: var(--purple-dark);
    background: #f4edff;
    font-weight: 800;
}
.fixed-access {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    margin: 4px 7px 4px 0;
    padding: 7px 11px;
    border-radius: 999px;
    color: #6d3d00;
    background: #fff7db;
    border: 1px solid #fde68a;
    font-weight: 900;
    white-space: nowrap;
}
.account-hero {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    padding: 20px;
    border: 1px solid rgba(124, 58, 237, .18);
    border-radius: 22px;
    color: #fff;
    background:
        linear-gradient(135deg, rgba(124, 58, 237, .95), rgba(168, 85, 247, .9)),
        var(--purple);
    box-shadow: 0 22px 48px rgba(76, 29, 149, .22);
}
.account-hero h1 {
    margin: 0 0 4px;
    color: #fff;
}
.account-hero p {
    margin: 0;
    color: rgba(255,255,255,.82);
    font-weight: 800;
}
.profile-orb {
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 24px;
    color: var(--purple-dark);
    background: linear-gradient(135deg, #fff, #e9ddff);
    font-size: 30px;
    font-weight: 900;
    box-shadow: 0 16px 32px rgba(31, 11, 82, .22);
}
.account-status {
    margin-left: auto;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.26);
    font-weight: 900;
}
.account-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(330px, .95fr);
    gap: 16px;
}
.account-card h2,
.security-card h2 { margin-top: 0; }
.profile-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}
.profile-facts div {
    padding: 13px;
    border: 1px solid #eadffc;
    border-radius: 16px;
    background: #fbf7ff;
}
.profile-facts span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}
.profile-facts strong {
    display: block;
    margin-top: 5px;
    overflow-wrap: anywhere;
}
.pill-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 16px;
}
.pill-cloud span {
    padding: 8px 11px;
    border-radius: 999px;
    color: #4b267c;
    background: #f4edff;
    border: 1px solid #e6d8fb;
    font-weight: 900;
}
.pill-cloud.soft span {
    color: #155e75;
    background: #eefcff;
    border-color: #c9eef3;
}
.security-card {
    position: relative;
    overflow: hidden;
}
.security-card::after {
    content: "";
    position: absolute;
    width: 150px;
    height: 150px;
    right: -66px;
    top: -66px;
    border-radius: 50%;
    background: rgba(124, 58, 237, .12);
}
.security-heading {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    gap: 14px;
}
.security-heading p { margin-top: 4px; }
.security-heading > span {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 18px;
    color: #fff;
    background: linear-gradient(135deg, var(--purple), var(--teal));
    font-size: 12px;
    font-weight: 900;
}
.password-form {
    position: relative;
    z-index: 1;
    gap: 12px;
}
.district-box {
    max-height: 190px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
}
.district-box label,
.district-checks label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 4px 8px 4px 0;
    padding: 6px 9px;
    border-radius: 999px;
    background: #f4edff;
    font-weight: 700;
    white-space: nowrap;
}
.district-box input,
.district-checks input {
    width: auto;
    min-width: 0;
}
.district-checks {
    min-width: 320px;
    max-width: 520px;
}
th, td {
    padding: 12px 14px;
    border-bottom: 1px solid #f0e9fb;
    text-align: left;
    vertical-align: top;
}
th {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #f4edff, #ecfeff);
    color: var(--purple-dark);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}
tbody tr:hover td { background: #fbf7ff; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
tr.unsolved td {
    background: #fff2a8;
    color: #5d4200;
}

.print-page { background: #e8ecf3; }
.letter {
    width: 210mm;
    min-height: 297mm;
    margin: 16px auto;
    padding: 18mm 20mm;
    background: #fff;
    color: #111827;
    font-size: 12pt;
    line-height: 1.5;
}
.letterhead {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 14px;
    align-items: center;
    text-align: center;
    border-bottom: 3px double #111827;
    padding-bottom: 12px;
}
.letterhead img { max-width: 76px; max-height: 76px; }
.letterhead h1 { margin: 0; font-size: 18pt; }
.letterhead p { margin: 2px 0; }
.letter-meta { margin-top: 20px; }
.letter-meta p { margin: 4px 0; }
.letter h2 {
    margin: 26px 0 20px;
    text-align: center;
    text-decoration: underline;
    font-size: 15pt;
    line-height: 1.35;
    white-space: normal;
}
.plain { min-width: auto; margin: 8px 0 18px; }
.plain td { border: 0; padding: 3px 8px 3px 0; }
.plain td:first-child { width: 160px; }
.signature {
    margin-top: 46px;
    margin-left: auto;
    width: 260px;
    text-align: left;
}
.signature strong {
    display: block;
    margin-top: 70px;
    text-decoration: underline;
}
.print-actions {
    width: 210mm;
    margin: 0 auto 18px;
    text-align: right;
}
@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 20;
        width: min(84vw, 310px);
        transform: translateX(-105%);
        transition: transform .2s ease;
    }
    .nav-open .sidebar { transform: translateX(0); }
    .menu-toggle { display: inline-grid; place-items: center; }
    .topbar { padding: 12px 14px; }
    .quick-nav { top: 69px; padding: 9px 14px 11px; }
    .container { padding: 20px 14px 48px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .user-manager-hero,
    .table-toolbar { flex-direction: column; align-items: stretch; }
    .access-summary { min-width: 0; }
    .user-manager-grid { grid-template-columns: 1fr; }
    .account-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .page-title strong { font-size: 18px; }
    .user-chip { display: none; }
    h1 { font-size: 24px; }
    .two, .filters { grid-template-columns: 1fr; }
    .stats { grid-template-columns: 1fr; }
    .panel { padding: 15px; border-radius: 16px; }
    .btn { width: 100%; }
    .import-actions { align-items: stretch; flex-direction: column; }
    .table-wrap { border-radius: 14px; }
    .quick-nav a { min-height: 36px; padding: 7px 10px; font-size: 13px; }
    table { min-width: 760px; }
    th, td { padding: 10px 11px; }
    .form-grid.compact,
    .access-summary { grid-template-columns: 1fr; }
    .permission-checks,
    .menu-checks { min-width: 320px; }
    .user-manager-table table { min-width: 1360px; }
    .account-hero { align-items: flex-start; flex-direction: column; }
    .account-status { margin-left: 0; }
    .profile-facts { grid-template-columns: 1fr; }
}
@media print {
    body { background: #fff; }
    .app-shell { display: block; }
    .sidebar, .topbar, .quick-nav, .print-actions { display: none; }
    .letter { margin: 0; box-shadow: none; width: auto; min-height: auto; }
}
