:root {
    --mp-bg: #eef3f8;
    --mp-sidebar: #fbfcfe;
    --mp-card: #ffffff;
    --mp-text: #111827;
    --mp-muted: #5f6c83;
    --mp-line: #dce4ef;
    --mp-primary: #0f766e;
    --mp-primary-soft: #e4f4f1;
    --mp-blue: #2563eb;
    --mp-green: #16a34a;
    --mp-orange: #ea580c;
    --mp-danger: #dc2626;
    --mp-shadow: 0 1px 2px rgba(15, 23, 42, .08), 0 12px 28px rgba(15, 23, 42, .04);
}

[data-bs-theme="dark"] {
    --mp-bg: #111827;
    --mp-sidebar: #0f172a;
    --mp-card: #182235;
    --mp-text: #e5e7eb;
    --mp-muted: #a8b3c7;
    --mp-line: #2a364a;
    --mp-primary: #2dd4bf;
    --mp-primary-soft: rgba(45, 212, 191, .14);
    --mp-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 28px rgba(0, 0, 0, .18);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--mp-bg);
    color: var(--mp-text);
    font-family: Inter, Arial, Helvetica, sans-serif;
}

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

a:hover {
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 302px;
    padding: 36px 18px 28px;
    background: var(--mp-sidebar);
    border-right: 1px solid var(--mp-line);
    display: flex;
    flex-direction: column;
    gap: 34px;
    z-index: 10;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--mp-text);
}

.brand-link:hover {
    color: var(--mp-text);
}

.brand-mark {
    display: grid;
    width: 50px;
    height: 50px;
    place-items: center;
    border-radius: 9px;
    background: linear-gradient(135deg, #0f766e, #2563eb);
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    box-shadow: 0 12px 24px rgba(15, 118, 110, .2);
}

.brand strong {
    display: block;
    font-size: 16px;
}

.brand small {
    color: var(--mp-muted);
}

.nav {
    display: grid;
    gap: 8px;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    padding: 0 16px;
    border-radius: 8px;
    color: #475569;
    font-size: 18px;
    font-weight: 700;
    text-decoration: none;
}

[data-bs-theme="dark"] .nav a {
    color: #cbd5e1;
}

.nav a i {
    width: 20px;
    font-size: 20px;
}

.nav a:hover {
    background: #eef4fb;
    color: var(--mp-text);
    text-decoration: none;
}

[data-bs-theme="dark"] .nav a:hover {
    background: #1f2937;
    color: #f8fafc;
}

.nav a.active {
    background: var(--mp-primary-soft);
    color: var(--mp-primary);
    text-decoration: none;
}

.nav a.active {
    box-shadow: inset 3px 0 0 var(--mp-primary);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 14px;
}

.theme-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    min-height: 48px;
    border: 1px solid var(--mp-line);
    border-radius: 8px;
    padding: 0 14px;
    background: transparent;
    color: var(--mp-text);
    font-weight: 700;
    cursor: pointer;
}

.theme-toggle:hover {
    background: var(--mp-primary-soft);
    color: var(--mp-primary);
}

.theme-icon-light {
    display: none;
}

[data-bs-theme="dark"] .theme-icon-dark {
    display: none;
}

[data-bs-theme="dark"] .theme-icon-light {
    display: inline-block;
}

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--mp-muted);
    font-size: 14px;
}

.sidebar-user span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-shell {
    margin-left: 302px;
    padding: 34px 34px 48px;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-card,
.panel,
.kpi {
    background: var(--mp-card);
    border: 1px solid var(--mp-line);
    border-radius: 8px;
    box-shadow: var(--mp-shadow);
}

.auth-card {
    width: min(420px, 100%);
    padding: 28px;
}

.auth-card .brand-mark {
    margin-bottom: 16px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 28px;
    padding: 26px;
    background: var(--mp-card);
    border: 1px solid var(--mp-line);
    border-radius: 8px;
    box-shadow: var(--mp-shadow);
}

.topbar-filter {
    display: flex;
    align-items: end;
    gap: 16px;
}

.topbar h1,
.auth-card h1 {
    margin: 0 0 8px;
    font-size: 34px;
    font-weight: 800;
    letter-spacing: 0;
}

.auth-card h1 {
    font-size: 28px;
}

.topbar p,
.auth-card p,
.muted {
    margin: 0;
    color: var(--mp-muted);
    font-size: 17px;
}

.panel {
    padding: 20px;
    margin-bottom: 20px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.panel-head h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
}

.panel.narrow {
    max-width: 860px;
}

.import-form {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) auto auto;
    align-items: end;
    gap: 12px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi {
    min-height: 132px;
    padding: 20px;
    border-top: 4px solid var(--mp-primary);
}

.kpi:nth-child(2n) {
    border-top-color: var(--mp-blue);
}

.kpi:nth-child(3n) {
    border-top-color: var(--mp-green);
}

.kpi:nth-child(4n) {
    border-top-color: var(--mp-orange);
}

.kpi span {
    display: block;
    min-height: 40px;
    color: var(--mp-muted);
    margin-bottom: 18px;
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.kpi strong {
    display: block;
    font-size: 30px;
    line-height: 1.15;
    font-weight: 800;
}

.form-stack,
.form-grid,
.filters {
    display: grid;
    gap: 14px;
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.filters {
    grid-template-columns: 1fr 220px 1fr auto;
    align-items: end;
}

.filters.compact {
    grid-template-columns: 220px auto;
    justify-content: start;
}

label {
    display: grid;
    gap: 7px;
    color: var(--mp-muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

input,
select,
textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid #d6dfec;
    border-radius: 8px;
    padding: 10px 13px;
    color: var(--mp-text);
    font: inherit;
    font-weight: 700;
    background: var(--mp-card);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

[data-bs-theme="dark"] input,
[data-bs-theme="dark"] select,
[data-bs-theme="dark"] textarea {
    border-color: var(--mp-line);
}

input:focus,
select:focus,
textarea:focus {
    outline: 0;
    border-color: var(--mp-primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .14);
}

.full {
    grid-column: 1 / -1;
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.primary-button,
.secondary-button,
.danger-button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 16px;
    font-weight: 800;
    cursor: pointer;
}

.primary-button {
    background: var(--mp-primary);
    border-color: var(--mp-primary);
    color: #fff;
}

.primary-button:hover {
    color: #fff;
    filter: brightness(.95);
}

.secondary-button,
button {
    background: var(--mp-card);
    border-color: var(--mp-line);
    color: var(--mp-text);
}

.secondary-button:hover,
button:hover {
    background: var(--mp-primary-soft);
    color: var(--mp-primary);
}

.danger-button,
.row-actions button {
    background: rgba(220, 38, 38, .08);
    border-color: rgba(220, 38, 38, .2);
    color: var(--mp-danger);
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--mp-line);
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
    margin: 0;
    background: var(--mp-card);
}

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--mp-line);
    text-align: left;
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: 0;
}

th {
    color: var(--mp-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
    background: var(--mp-bg);
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.row-actions form {
    margin: 0;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 800;
}

.status-pill.ok {
    background: rgba(22, 163, 74, .14);
    color: #16a34a;
}

.status-pill.warn {
    background: rgba(234, 88, 12, .14);
    color: #ea580c;
}

.status-pill.danger {
    background: rgba(220, 38, 38, .14);
    color: #dc2626;
}

.dre-table {
    display: grid;
    gap: 8px;
}

.dre-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 14px;
    border: 1px solid var(--mp-line);
    border-radius: 8px;
    background: var(--mp-card);
}

.dre-row.negative strong {
    color: var(--mp-danger);
}

.dre-row.total {
    background: var(--mp-primary-soft);
    border-color: rgba(15, 118, 110, .2);
}

.dre-row.grand-total {
    background: #111827;
    border-color: #111827;
    color: #fff;
}

.muted-cell {
    color: var(--mp-muted);
    text-align: center;
}

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    background: rgba(22, 163, 74, .12);
    border: 1px solid rgba(22, 163, 74, .25);
    color: #15803d;
}

.flash.warn {
    background: rgba(234, 88, 12, .12);
    border-color: rgba(234, 88, 12, .25);
    color: #c2410c;
}

@media (max-width: 1200px) {
    .kpi-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .sidebar {
        position: static;
        width: auto;
        padding: 18px;
    }

    .app-shell {
        margin-left: 0;
        padding: 18px;
    }

    .kpi-grid,
    .form-grid,
    .filters,
    .filters.compact,
    .import-form {
        grid-template-columns: 1fr;
    }

    .topbar,
    .topbar-filter {
        display: grid;
        width: 100%;
    }
}
