:root {
    --navy-dark: #152238;
    --navy: #1e3a5f;
    --navy-light: #2c507e;
    --gold: #c9a227;
    --gold-light: #e8c85a;
    --teal: #1f8a70;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --border: #e1e6ee;
    --text: #1d2733;
    --text-muted: #6b7688;
    --danger: #c0392b;
    --danger-bg: #fdecea;
    --success: #1f8a70;
    --success-bg: #e7f6f1;
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
}

img { max-width: 100%; height: auto; display: block; }

a { color: var(--navy); }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ---------------------------------------------------------------------- */
/* Topbar                                                                  */
/* ---------------------------------------------------------------------- */

.topbar {
    background: var(--navy-dark);
    color: #fff;
    padding: 10px 20px;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

@media (max-width: 560px) {
    .topbar {
        padding: 8px 10px;
    }
    .topbar-left {
        gap: 6px;
    }
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 1400px;
    margin: 0 auto;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #fff;
    min-width: 0;
}

.topbar-logo {
    height: 40px;
    width: 40px;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
    padding: 3px;
    flex-shrink: 0;
}

.topbar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    overflow: hidden;
}

.topbar-brand-text strong {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-brand-text small {
    font-size: 0.72rem;
    color: var(--gold-light);
    letter-spacing: 0.02em;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.topbar-user {
    font-size: 0.85rem;
    color: #cdd6e4;
    display: none;
}

@media (min-width: 560px) {
    .topbar-user { display: inline; }
}

.sidebar-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 34px;
    height: 34px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
}

.sidebar-toggle span {
    display: block;
    height: 2px;
    background: #fff;
    margin: 0 7px;
}

/* ---------------------------------------------------------------------- */
/* Admin shell: sidebar + content                                         */
/* ---------------------------------------------------------------------- */

.admin-shell {
    display: flex;
    align-items: stretch;
    width: 100%;
    min-height: calc(100vh - 60px);
}

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--navy-dark);
    align-self: stretch;
    position: sticky;
    top: 60px;
    min-height: calc(100vh - 60px);
    padding: 18px 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 10px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #c4cede;
    text-decoration: none;
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-icon {
    display: inline-flex;
    width: 18px;
    flex-shrink: 0;
    justify-content: center;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar-link.active {
    background: var(--navy);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--gold);
}

.admin-content {
    flex: 1;
    min-width: 0;
    padding: 24px 24px 48px;
}

@media (max-width: 860px) {
    .sidebar-toggle { display: flex; }

    .admin-shell { position: relative; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 60px;
        height: calc(100vh - 60px);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 39;
        box-shadow: 2px 0 10px rgba(0,0,0,0.25);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .admin-content {
        padding: 18px 14px 40px;
    }
}

/* ---------------------------------------------------------------------- */
/* Collapsible sidebar (desktop): icons-only, expands on hover             */
/* ---------------------------------------------------------------------- */

@media (min-width: 861px) {
    .sidebar {
        width: 72px;
        overflow: hidden;
        transition: width 0.25s ease;
    }

    .sidebar:hover {
        width: 230px;
    }

    .sidebar-label {
        opacity: 0;
        white-space: nowrap;
        transition: opacity 0.2s ease;
    }

    .sidebar:hover .sidebar-label {
        opacity: 1;
        transition-delay: 0.08s;
    }
}


/* ---------------------------------------------------------------------- */
/* Public pages                                                            */
/* ---------------------------------------------------------------------- */

.page-public {
    padding: 28px 16px 40px;
    min-height: calc(100vh - 140px);
}

.footer {
    padding: 18px 0 28px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.82rem;
}

/* ---------------------------------------------------------------------- */
/* Cards / layout primitives                                               */
/* ---------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    overflow-wrap: break-word;
    box-shadow: 0 1px 2px rgba(20,30,50,0.03);
}

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

.card-head h3 { margin: 0; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.page-head h2 { margin: 0 0 4px; }

.muted { color: var(--text-muted); font-size: 0.92rem; margin: 0; }

h1, h2, h3 { line-height: 1.3; color: var(--navy-dark); margin-top: 0; }

.form-card { max-width: 900px; margin: 0 auto; }

.section-header {
    background: var(--navy);
    color: #fff;
    padding: 9px 14px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.92rem;
    margin: 22px 0 14px;
    letter-spacing: 0.01em;
}

/* ---------------------------------------------------------------------- */
/* Stat cards                                                              */
/* ---------------------------------------------------------------------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 1px 2px rgba(20,30,50,0.03);
}

.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
    color: #fff;
}

.stat-icon-navy { background: var(--navy); }
.stat-icon-gold { background: var(--gold); }
.stat-icon-teal { background: var(--teal); }

.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--navy-dark); line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: 0.82rem; margin-top: 2px; }

.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

/* ---------------------------------------------------------------------- */
/* Forms                                                                    */
/* ---------------------------------------------------------------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 18px;
}

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
}

.form-group { display: flex; flex-direction: column; }
.form-group.full { grid-column: 1 / -1; }
.form-group.grow { flex: 1; }

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--navy-dark);
    margin-bottom: 6px;
}

.field-hint {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 4px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    font-family: inherit;
    font-size: 0.95rem;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    width: 100%;
    min-height: 42px;
}

input[type="file"] {
    font-size: 0.88rem;
    padding: 8px 0;
}

textarea { min-height: 80px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--navy-light);
    box-shadow: 0 0 0 3px rgba(30,58,95,0.12);
}

.form-actions { margin-top: 24px; }

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.filters .form-group { min-width: 180px; }
.filter-btn { min-width: unset; }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                  */
/* ---------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 11px 20px;
    font-size: 0.92rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    min-height: 42px;
    transition: filter 0.15s, background 0.15s;
}

.btn-primary {
    background: var(--navy);
    color: #fff;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
    background: #fff;
    color: var(--navy);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }

.btn-ghost {
    background: transparent;
    color: #fff;
    border-color: rgba(255,255,255,0.4);
}
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-danger {
    background: #fff;
    color: var(--danger);
    border-color: #f0c4bd;
}
.btn-danger:hover { background: var(--danger-bg); }

.btn-block { width: 100%; }

.btn-small {
    padding: 7px 12px;
    font-size: 0.82rem;
    min-height: 34px;
}

/* ---------------------------------------------------------------------- */
/* Tables                                                                    */
/* ---------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 640px;
}

.data-table th {
    text-align: left;
    background: var(--bg);
    color: var(--navy-dark);
    padding: 10px 12px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; }

.detail-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 4px;
    font-size: 0.92rem;
}

.detail-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
}

.detail-table .label {
    font-weight: 600;
    color: var(--navy-dark);
    width: 220px;
}

/* ---------------------------------------------------------------------- */
/* Profile / documents                                                     */
/* ---------------------------------------------------------------------- */

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.btn-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.profile-grid {
    display: flex;
    gap: 22px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.profile-photo {
    width: 130px;
    height: 150px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
    flex-shrink: 0;
}

.profile-photo img { width: 100%; height: 100%; object-fit: cover; }

.detail-table { flex: 1; min-width: 260px; }

.doc-links { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------------- */
/* Auth pages                                                               */
/* ---------------------------------------------------------------------- */

.auth-wrap {
    display: flex;
    justify-content: center;
    padding-top: 20px;
}

.auth-card { width: 100%; max-width: 420px; }

.auth-title { text-align: center; margin-bottom: 4px; }
.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 18px;
}

.auth-links {
    text-align: right;
    margin: 6px 0 18px;
    font-size: 0.85rem;
}

.auth-links a { text-decoration: none; color: var(--navy); font-weight: 600; }

.center-link {
    text-align: center;
    margin-top: 18px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.center-link a { color: var(--navy); font-weight: 600; text-decoration: none; }

/* ---------------------------------------------------------------------- */
/* Alerts                                                                    */
/* ---------------------------------------------------------------------- */

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-info { background: #eaf1fb; color: var(--navy); }
.alert-warning { background: #fff7e0; color: #8a6d00; }

/* Django form field errors render as <ul> */
.form-group ul, .card ul.errorlist {
    color: var(--danger);
    font-size: 0.8rem;
    margin: 4px 0 0;
    padding-left: 18px;
}
