:root {
    --bg: #f3f6fb;
    --panel: #ffffff;
    --text: #14213d;
    --muted: #68758a;
    --line: #dbe4f0;
    --brand: #0b4ea2;
    --brand-dark: #083b7a;
    --brand-soft: #e8f1ff;
    --accent: #e7f0ff;
    --danger: #d62828;
    --danger-dark: #a4161a;
    --sidebar-width: 250px;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    padding: 22px 16px;
    background: #0a2a55;
    color: #e8f1ff;
    border-right: 4px solid var(--danger);
    transition: width 0.22s ease, padding 0.22s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 34px;
    font-size: 22px;
    font-weight: 800;
    min-height: 42px;
}

.brand-mark {
    display: inline-grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 8px;
    background: var(--danger);
    color: #fff;
    font-weight: 900;
    flex: 0 0 auto;
}

.brand-text,
.nav-label {
    white-space: nowrap;
    transition: opacity 0.15s ease;
}

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

nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #d9e8ff;
    font-weight: 700;
    transition: background 0.18s ease, color 0.18s ease;
}

nav a:hover,
nav a.is-active {
    background: #ffffff;
    color: var(--brand);
}

.nav-icon {
    display: inline-grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    flex: 0 0 auto;
}

nav a.is-active .nav-icon,
nav a:hover .nav-icon {
    background: var(--danger);
    color: #fff;
}

.main {
    margin-left: var(--sidebar-width);
    padding: 28px;
    transition: margin-left 0.22s ease;
}

body.sidebar-reduced {
    --sidebar-width: 82px;
}

body.sidebar-reduced .sidebar {
    padding-inline: 14px;
}

body.sidebar-reduced .brand {
    justify-content: center;
}

body.sidebar-reduced .brand-text,
body.sidebar-reduced .nav-label {
    width: 0;
    opacity: 0;
    overflow: hidden;
}

body.sidebar-reduced nav a {
    justify-content: center;
    padding-inline: 8px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

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

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
}

h1 {
    font-size: 30px;
}

h2 {
    margin-bottom: 18px;
    font-size: 18px;
}

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

.stats-grid article,
.panel,
.install-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 14px 36px rgba(20, 33, 61, 0.08);
}

.stats-grid article {
    padding: 22px;
}

.stats-grid strong {
    display: block;
    margin-bottom: 6px;
    font-size: 34px;
}

.stats-grid span {
    color: var(--muted);
    font-weight: 700;
}

.panel {
    padding: 22px;
    min-width: 0;
}

.content-stack {
    display: grid;
    gap: 18px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.panel-header h2 {
    margin-bottom: 0;
}

.split {
    display: grid;
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.form-panel {
    display: grid;
    gap: 14px;
}

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

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 28px;
}

.modal.is-open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 25, 49, 0.62);
    backdrop-filter: blur(3px);
}

.modal-dialog {
    position: relative;
    z-index: 1;
    width: min(720px, 100%);
    max-height: min(86vh, 860px);
    overflow: auto;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 28px 80px rgba(7, 24, 48, 0.28);
}

.modal-wide .modal-dialog {
    width: min(900px, 100%);
}

.modal .form-panel {
    padding: 24px;
}

.modal-header,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.modal-header {
    margin-bottom: 18px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 16px;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 4px;
    border-top: 1px solid var(--line);
    padding-top: 16px;
}

.modal-close {
    display: inline-grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: #ffe3e3;
    color: var(--danger);
    cursor: pointer;
    font-size: 18px;
    font-weight: 900;
}

.modal-close:hover {
    background: var(--danger);
    color: #fff;
}

.line-items {
    display: grid;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #f8fbff;
}

.line-items-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.line-items-header h3 {
    margin: 0;
    font-size: 15px;
}

.line-items-table {
    display: grid;
    gap: 8px;
    overflow-x: auto;
}

.line-item-row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) 90px 110px 130px 110px 92px;
    gap: 8px;
    min-width: 780px;
    align-items: end;
}

.line-item-head {
    align-items: center;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

body.modal-open {
    overflow: hidden;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    color: var(--text);
    font: inherit;
    background: #fff;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    outline: 3px solid var(--brand-soft);
}

textarea {
    resize: vertical;
}

.button,
.icon-button,
.small-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 0 16px;
    cursor: pointer;
    font-weight: 800;
}

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

.button.primary:hover {
    background: var(--brand-dark);
}

.button.ghost {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--brand);
}

.menu-toggle[aria-pressed="true"] {
    border-color: var(--danger);
    color: var(--danger);
    background: #fff5f5;
}

.icon-button {
    min-height: 34px;
    background: #ffe3e3;
    color: var(--danger);
}

.icon-button:hover {
    background: var(--danger);
    color: #fff;
}

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

.small-button {
    min-height: 34px;
    padding: 0 12px;
    font-size: 13px;
}

.small-button.secondary {
    border: 1px solid var(--line);
    background: var(--brand-soft);
    color: var(--brand);
}

.small-button.secondary:hover {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.small-button.danger {
    background: #ffe3e3;
    color: var(--danger);
}

.small-button.danger:hover {
    background: var(--danger);
    color: #fff;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.projects-table {
    min-width: 1180px;
}

.devis-table {
    min-width: 1220px;
}

.depenses-table {
    min-width: 1080px;
}

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.status {
    display: inline-flex;
    border-radius: 999px;
    padding: 5px 9px;
    background: var(--accent);
    color: var(--brand);
    font-size: 12px;
    font-weight: 800;
}

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

.install-page {
    display: grid;
    place-items: center;
    padding: 20px;
}

.install-box {
    width: min(520px, 100%);
    padding: 28px;
}

.install-box p {
    color: var(--muted);
}

.notice {
    margin: 18px 0;
    border-radius: 8px;
    padding: 12px;
    font-weight: 700;
}

.notice.success {
    background: var(--brand-soft);
    color: var(--brand);
}

.notice.danger {
    background: #ffe3e3;
    color: var(--danger);
}

@media (max-width: 900px) {
    body,
    body.sidebar-reduced {
        --sidebar-width: 0px;
    }

    .sidebar {
        position: static;
        width: auto;
        border-right: 0;
        border-bottom: 4px solid var(--danger);
    }

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

    .topbar,
    .split {
        grid-template-columns: 1fr;
    }

    .topbar {
        display: grid;
    }

    .menu-toggle {
        display: none;
    }

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

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

    .modal {
        align-items: flex-end;
        padding: 12px;
    }

    .modal-dialog {
        max-height: 92vh;
        width: 100%;
    }
}

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

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

    .panel-header,
    .modal-header,
    .modal-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .panel-header .button,
    .modal-actions .button {
        width: 100%;
    }
}
