:root {
    --bg: #f6f8fc;
    --card: #ffffff;
    --ink: #182230;
    --muted: #6b7280;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --orange: #f97316;
    --orange-dark: #c2410c;
    --purple: #7c3aed;
    --green: #16a34a;
    --border: #e5eaf2;
    --border-strong: #d5ddea;
    --shadow-sm: 0 5px 18px rgba(31, 41, 55, 0.05);
    --shadow-md: 0 16px 38px rgba(31, 41, 55, 0.08);
    --danger-bg: #fff1f1;
    --danger: #9f1d1d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.45;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card,
.panel,
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 34px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--blue);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
}

.muted {
    color: var(--muted);
}

label {
    display: block;
    margin: 18px 0 8px;
    font-weight: 700;
}

input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    padding: 12px 14px;
}

button,
a {
    color: inherit;
}

button {
    width: 100%;
    margin-top: 24px;
    border: 0;
    border-radius: 10px;
    background: var(--blue);
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    padding: 13px 16px;
}

.button-secondary {
    background: var(--orange);
}

.button-secondary:hover {
    background: var(--orange-dark);
}

button:hover,
.topbar a:hover {
    background: var(--blue-dark);
}

.alert {
    margin-top: 18px;
    border: 1px solid #f0b6b6;
    border-radius: 10px;
    background: var(--danger-bg);
    color: var(--danger);
    padding: 12px 14px;
}

.topbar {
    display: flex;
    align-items: stretch;
    flex-direction: column;
    gap: 18px;
    height: 100vh;
    justify-content: flex-start;
    left: 0;
    padding: 18px 24px;
    position: fixed;
    top: 0;
    width: 280px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 20;
}

.dashboard-page .topbar {
    background: rgba(255, 255, 255, 0.92);
}

.brand-lockup {
    align-items: center;
    display: flex;
    gap: 12px;
}

.shell-brand {
    flex: 0 0 auto;
}

.shell-page-heading {
    flex: 0 0 auto;
    margin: 0;
}

.shell-page-heading h1 {
    font-size: 1.2rem;
}

.shell-duplicate-brand h1 {
    display: none;
}

.brand-mark {
    align-items: center;
    background: linear-gradient(135deg, var(--blue), var(--purple));
    border-radius: 12px;
    color: #fff;
    display: flex;
    font-size: 0.78rem;
    font-weight: 800;
    height: 40px;
    justify-content: center;
    letter-spacing: 0.04em;
    width: 40px;
}

.brand-mark.has-logo {
    background: #ffffff;
    border-radius: 8px;
    height: 72px;
    width: 220px;
}

.brand-lockup.has-custom-logo > div:last-child {
    display: none;
}

.brand-mark-fallback {
    display: inline-flex;
}

.brand-logo {
    display: block;
    height: 72px;
    max-width: 220px;
    object-fit: contain;
    width: 220px;
}

.user-chip {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
    padding: 0 4px;
}

.topbar nav {
    display: flex;
    align-items: stretch;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 10px;
    justify-content: flex-start;
    min-width: 0;
    overflow-y: auto;
    width: 100%;
}

.topbar a {
    border-radius: 10px;
    background: var(--blue);
    color: #ffffff;
    flex: 0 0 auto;
    font-weight: 700;
    padding: 10px 14px;
    text-decoration: none;
}

.topbar a.active {
    background: var(--orange);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.18);
}

.topbar nav .user-chip {
    margin-top: auto;
}

.topbar nav .shell-logout {
    background: #475569;
}

.mobile-menu-toggle {
    display: none;
}

.topbar + .container {
    margin-left: calc(280px + max(16px, (100% - 280px - 1180px) / 2));
    margin-right: 16px;
    width: min(1180px, calc(100% - 312px));
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 34px auto 56px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.dashboard-page > .container > .grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.card,
.panel {
    padding: 24px;
}

.dashboard-page .panel {
    box-shadow: var(--shadow-sm);
}

.kpi-card {
    border-top: 3px solid var(--blue);
    min-height: 128px;
    position: relative;
}

.kpi-card::after {
    background: currentColor;
    border-radius: 50%;
    content: "";
    height: 8px;
    opacity: 0.55;
    position: absolute;
    right: 22px;
    top: 24px;
    width: 8px;
}

.kpi-card strong {
    color: currentColor;
}

.kpi-blue { border-top-color: var(--blue); color: var(--blue); }
.kpi-green { border-top-color: var(--green); color: var(--green); }
.kpi-purple { border-top-color: var(--purple); color: var(--purple); }
.kpi-danger { border-top-color: var(--danger); color: var(--danger); }
.kpi-neutral { border-top-color: var(--ink); color: var(--ink); }

.card span {
    display: block;
    color: var(--muted);
    font-size: 14px;
}

.card strong {
    display: block;
    margin-top: 10px;
    color: var(--blue);
    font-size: 28px;
}

.panel {
    margin-top: 22px;
}

.section-header {
    align-items: flex-start;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.section-header-compact {
    margin-bottom: 1rem;
}

.section-header .eyebrow {
    margin-bottom: 5px;
}

.button-link {
    background: var(--blue);
    border-radius: 10px;
    color: #fff;
    display: inline-block;
    font-weight: 700;
    padding: 0.75rem 1rem;
    text-decoration: none;
}

.button-link:hover {
    background: var(--blue-dark);
}

.button-link.secondary,
.button-link.preview,
.button-link.edit {
    background: var(--orange);
    color: #fff;
}

.button-link.secondary:hover,
.button-link.preview:hover,
.button-link.edit:hover {
    background: var(--orange-dark);
}

.search-form {
    margin-bottom: 1.5rem;
}

.filters-form {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
}

.filters-form-reports {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
}

.filters-form-financial {
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
}

.filters-form-audit-logs {
    grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
}

.filter-field label {
    margin: 0 0 7px;
}

.filter-field input,
.filter-field select {
    margin: 0;
}

.filters-form .form-actions {
    margin: 0;
}

.filters-form .form-actions button {
    margin-top: 0;
    white-space: nowrap;
    width: auto;
}

.inline-actions {
    align-items: center;
    display: flex;
    gap: 0.75rem;
}

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

table {
    border-collapse: collapse;
    width: 100%;
}

.dashboard-page table tr:last-child td {
    border-bottom: 0;
}

.dashboard-page th,
.dashboard-page td {
    padding: 1rem 0.85rem;
}

.dashboard-page tbody tr:hover {
    background: #fafbff;
}

th,
td {
    border-bottom: 1px solid #e5e7eb;
    padding: 0.85rem;
    text-align: left;
    vertical-align: top;
}

th {
    color: #6b7280;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.badge {
    border-radius: 999px;
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.25rem 0.65rem;
}

.badge.active {
    background: #dcfce7;
    color: #166534;
}

.badge.inactive {
    background: #fee2e2;
    color: #991b1b;
}

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

.actions form {
    margin: 0;
}

.actions button {
    margin-top: 0;
    width: auto;
}

.actions .cancel-form {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.actions .cancel-form input[type="text"] {
    margin: 0;
    width: auto;
    flex: 1 1 200px;
}

.narrow {
    max-width: 760px;
}

textarea,
select {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.75rem;
    color: #111827;
    display: block;
    font: inherit;
    margin: 0.35rem 0 1rem;
    padding: 0.85rem 1rem;
    width: 100%;
}

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

.field-error {
    color: #b91c1c;
    font-size: 0.85rem;
    margin: -0.65rem 0 1rem;
}

.form-actions {
    align-items: center;
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.item-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: 2fr 1fr 1fr;
}

@media (max-width: 820px) {
    .topbar {
        align-items: center;
        flex-direction: row;
        flex-wrap: wrap;
        height: auto;
        min-height: 76px;
        overflow: visible;
        padding: 14px 16px;
        position: relative;
        width: 100%;
    }

    .dashboard-page .topbar {
        position: relative;
    }

    .mobile-menu-toggle {
        align-items: center;
        display: flex;
        height: 44px;
        justify-content: center;
        margin: 0 0 0 auto;
        padding: 8px;
        width: 44px;
    }

    .shell-brand {
        order: 1;
    }

    .mobile-menu-toggle {
        order: 2;
    }

    .shell-page-heading {
        flex-basis: 100%;
        order: 3;
    }

    .brand-mark.has-logo {
        height: 50px;
        width: 150px;
    }

    .brand-logo {
        height: 50px;
        max-width: 150px;
        width: 150px;
    }

    .topbar nav {
        align-items: stretch;
        background: #ffffff;
        border-top: 1px solid var(--border);
        display: none;
        flex: 0 0 auto;
        gap: 10px;
        left: 0;
        padding: 14px 16px 16px;
        position: absolute;
        top: 100%;
        width: 100%;
        z-index: 20;
    }

    .topbar.nav-open nav {
        display: flex;
    }

    .topbar + .container {
        margin-left: auto;
        margin-right: auto;
        width: min(1180px, calc(100% - 32px));
    }

    .topbar nav .user-chip {
        margin-top: 0;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .dashboard-page > .container > .grid,
    .filters-form {
        grid-template-columns: 1fr;
    }

    .filter-field-wide {
        grid-column: auto;
    }

    .item-grid {
        display: block;
    }
}

@media (min-width: 821px) and (max-width: 1100px) {
    .dashboard-page > .container > .grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
