/* ============================================================
   DIMOBI Facturation — design system
   Colors: #301F1E (Cocoa Brown) / #FCF8F7 (Spring Wood)
   Fonts:  Expletus Sans Bold (titles) / Archivo Light (body)
   ============================================================ */

:root {
    --cocoa:       #301F1E;
    --cocoa-90:    #3d2826;
    --cocoa-70:    rgba(48, 31, 30, 0.7);
    --cocoa-50:    rgba(48, 31, 30, 0.5);
    --cocoa-30:    rgba(48, 31, 30, 0.3);
    --cocoa-15:    rgba(48, 31, 30, 0.15);
    --cocoa-08:    rgba(48, 31, 30, 0.08);
    --cocoa-04:    rgba(48, 31, 30, 0.04);

    --cream:       #FCF8F7;
    --cream-dark:  #F4ECEA;
    --white:       #FFFFFF;

    --accent:      #B8704A;   /* warm copper accent for actions */
    --accent-dark: #9C5C3A;

    --success:     #2F6F4A;
    --success-bg:  #E0EDE5;
    --warning:     #8C5A1F;
    --warning-bg:  #F6E9D3;
    --danger:      #8C2A2A;
    --danger-bg:   #F3D9D9;
    --info:        #2A4F8C;
    --info-bg:     #D9E2F3;

    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 10px;

    --sidebar-w:    240px;
    --topbar-h:     56px;

    --font-title: 'Expletus Sans', 'Trebuchet MS', sans-serif;
    --font-body:  'Archivo', 'Segoe UI', sans-serif;

    --shadow-sm: 0 1px 2px rgba(48,31,30,0.06);
    --shadow:    0 2px 6px rgba(48,31,30,0.08);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--cream);
    color: var(--cocoa);
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-title);
    font-weight: 700;
    color: var(--cocoa);
    letter-spacing: -0.01em;
    margin: 0 0 0.5em 0;
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
h5 { font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--cocoa-70); }

p { margin: 0.4em 0; }

a { color: var(--cocoa); text-decoration: none; }
a:hover { color: var(--accent); }

hr {
    border: none;
    border-top: 1px solid var(--cocoa-15);
    margin: 1rem 0;
}

code {
    font-family: 'Consolas', 'Monaco', monospace;
    background: var(--cocoa-08);
    padding: 0.1em 0.35em;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
}

.small {
    font-size: 0.82rem;
    color: var(--cocoa-70);
}

/* ============ Layout: sidebar + main ============ */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--cocoa);
    color: var(--cream);
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-logo {
    display: block;
    padding: 0.5rem 0;
}
.sidebar-logo img {
    width: 100%;
    max-width: 180px;
    height: auto;
    filter: invert(1);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    color: rgba(252, 248, 247, 0.75);
    font-size: 0.9rem;
    border-radius: var(--radius);
    transition: background 0.15s, color 0.15s;
}
.sidebar-nav a:hover {
    background: rgba(252, 248, 247, 0.08);
    color: var(--cream);
}
.sidebar-nav a.active {
    background: rgba(252, 248, 247, 0.12);
    color: var(--cream);
    font-weight: 400;
}
.sidebar-nav .icon {
    width: 16px;
    height: 16px;
    opacity: 0.85;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(252, 248, 247, 0.12);
    font-size: 0.8rem;
}
.sidebar-footer .user {
    color: rgba(252, 248, 247, 0.6);
    margin-bottom: 0.3rem;
}
.sidebar-footer a {
    color: rgba(252, 248, 247, 0.85);
    padding: 0.25rem 0;
    display: inline-block;
}
.sidebar-footer a:hover { color: var(--cream); }

.main {
    padding: 1.5rem 2rem 3rem 2rem;
    min-width: 0;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--cocoa-15);
}
.page-head h2 { margin: 0; }

/* ============ Cards ============ */

.card {
    background: var(--white);
    border: 1px solid var(--cocoa-08);
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}
.card-tight { padding: 0.75rem 0.9rem; }
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    gap: 0.5rem;
}
.card-head h4 { margin: 0; }

/* ============ Buttons ============ */

button, .btn {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 0.875rem;
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    background: var(--cocoa);
    color: var(--cream) !important;
    transition: background 0.15s, transform 0.05s;
    line-height: 1.2;
}
button.outline, .btn.outline,
button.ghost, .btn.ghost {
    color: var(--cocoa) !important;
}
button:hover, .btn:hover {
    background: var(--cocoa-90);
}
button:active, .btn:active { transform: translateY(1px); }

button.outline, .btn.outline {
    background: transparent;
    color: var(--cocoa);
    border-color: var(--cocoa-30);
}
button.outline:hover, .btn.outline:hover {
    background: var(--cocoa-04);
    border-color: var(--cocoa);
}

button.ghost, .btn.ghost {
    background: transparent;
    color: var(--cocoa-70);
    border-color: transparent;
}
button.ghost:hover, .btn.ghost:hover {
    background: var(--cocoa-04);
    color: var(--cocoa);
}

button.danger, .btn.danger { background: var(--danger); }
button.danger:hover, .btn.danger:hover { background: #6e2020; }

button.small, .btn.small {
    padding: 0.25rem 0.55rem;
    font-size: 0.78rem;
}
button.icon, .btn.icon {
    padding: 0.25rem 0.45rem;
    line-height: 1;
}

.button-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ============ Forms ============ */

label {
    font-size: 0.82rem;
    color: var(--cocoa-70);
    font-weight: 400;
    margin: 0;
}

input[type=text],
input[type=number],
input[type=date],
input[type=email],
input[type=password],
select,
textarea {
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 0.875rem;
    color: var(--cocoa);
    background: var(--white);
    border: 1px solid var(--cocoa-15);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.55rem;
    width: 100%;
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--cocoa);
    box-shadow: 0 0 0 2px var(--cocoa-15);
}
input[type=date] {
    padding: 0.3rem 0.4rem;
}
textarea {
    line-height: 1.4;
    resize: vertical;
}

input[type=radio], input[type=checkbox] {
    width: auto;
    accent-color: var(--cocoa);
}

output {
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--cocoa);
}

/* Compact form-row used in invoice detail: label left, control right */
.form-row {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 0.4rem;
    min-height: 28px;
}
.form-row label {
    text-align: right;
    font-size: 0.82rem;
}
.form-row .form-cost {
    display: inline-block;
    margin-left: 0.6rem;
    font-size: 0.82rem;
    color: var(--cocoa-70);
}

/* Stacked form rows for login etc. */
.form-stack label {
    display: block;
    margin-bottom: 0.3rem;
    text-align: left;
    font-size: 0.82rem;
}
.form-stack label > span { display: block; margin-bottom: 0.25rem; }
.form-stack .form-row {
    grid-template-columns: 1fr;
    gap: 0.25rem;
}
.form-stack .form-row label { text-align: left; }

/* ============ Tables ============ */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--cocoa-08);
}
thead {
    background: var(--cream-dark);
}
th {
    text-align: left;
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--cocoa-70);
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--cocoa-15);
}
td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--cocoa-08);
    vertical-align: middle;
    font-size: 0.875rem;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--cocoa-04); }
td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.actions-cell {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    align-items: center;
}

/* ============ Badges ============ */

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    line-height: 1.5;
}
.badge.draft   { background: var(--warning-bg); color: var(--warning); }
.badge.edited  { background: var(--info-bg);    color: var(--info); }
.badge.sent,
.badge.sent_with_sepa { background: var(--success-bg); color: var(--success); }
.badge.archived { background: var(--cocoa-08); color: var(--cocoa-70); }
.badge.failed,
.badge.sepa_failed,
.badge.mollie_pending { background: var(--danger-bg);  color: var(--danger); }

/* ============ Invoice detail layout ============ */

.grid-edit {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: flex-start;
}
.grid-edit > div { min-width: 0; }

iframe.pdf {
    width: 100%;
    height: calc(100vh - 110px);
    border: 1px solid var(--cocoa-15);
    border-radius: var(--radius-lg);
    background: var(--white);
    box-shadow: var(--shadow);
}

.section {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed var(--cocoa-15);
}
.section:last-of-type { border-bottom: none; }
.section-title {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--cocoa-70);
    margin: 0 0 0.5rem 0;
}

.totals {
    background: var(--cream-dark);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    margin-top: 0.8rem;
}
.totals .row {
    display: flex;
    justify-content: space-between;
    padding: 0.18rem 0;
    font-size: 0.875rem;
}
.totals .row > span:last-child { font-variant-numeric: tabular-nums; }
.totals .ttc {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 1rem;
    border-top: 1px solid var(--cocoa-30);
    padding-top: 0.4rem;
    margin-top: 0.35rem;
}

.remise-block {
    background: var(--warning-bg);
    border-radius: var(--radius);
    padding: 0.7rem 0.9rem;
    margin: 0.8rem 0;
}
.remise-block h5 { color: var(--warning); margin-top: 0; }

.adhoc-line {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: 0.4rem;
    margin-bottom: 0.3rem;
    align-items: center;
}

/* ============ Login page ============ */

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: var(--cream);
}
.login-card {
    background: var(--white);
    border: 1px solid var(--cocoa-08);
    border-radius: var(--radius-lg);
    padding: 2rem 2rem 1.75rem;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow);
}
.login-card .logo {
    display: block;
    margin: 0 auto 1.5rem;
    width: 200px;
    max-width: 100%;
    height: auto;
}
.login-card h1 {
    text-align: center;
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--cocoa-70);
    margin-bottom: 1.25rem;
}

.alert {
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}
.alert.error { background: var(--danger-bg); color: var(--danger); }

/* ============ Misc helpers ============ */

.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-sm { gap: 0.4rem; }
.gap { gap: 0.75rem; }
.items-center { align-items: center; }
.between { justify-content: space-between; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.text-muted { color: var(--cocoa-70); }
.text-right { text-align: right; }
.tabular { font-variant-numeric: tabular-nums; }

/* ============ Fixed-layout list table ============ */

table.grid-table { table-layout: fixed; }
table.grid-table th,
table.grid-table td { overflow: hidden; }

.ellipsis {
    display: block;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-strong {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
}
.cell-strong .ellipsis { flex: 0 1 auto; }
.cell-strong .badge { flex: 0 0 auto; }

/* ============ Modal ============ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(48, 31, 30, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1000;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--cream);
    color: var(--cocoa);
    border: 1px solid var(--cocoa-15);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 10px 40px rgba(48, 31, 30, 0.3);
}
.modal h4 { margin: 0 0 0.75rem 0; }
.modal p { font-size: 0.9rem; line-height: 1.5; margin: 0.4rem 0; }
.modal-warning {
    background: var(--warning-bg);
    color: var(--warning);
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius);
    font-size: 0.82rem;
}
.modal-warning[hidden] { display: none; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

/* ============ Archive tree-table (client > année > factures) ============ */

.tree-table .tr-client > td,
.tree-table .tr-year > td { padding: 0; }

.tree-bar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}
.tree-name {
    flex: 0 1 auto;
    min-width: 0;
}
.tree-recap {
    margin-left: auto;
    padding-left: 1rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.caret {
    flex: 0 0 auto;
    font-size: 0.62rem;
    transition: transform 0.18s ease;
}
.tree-table .open .caret { transform: rotate(90deg); }

/* --- Niveau client : barre cocoa pleine, texte crème --- */
.tree-table .tr-client { cursor: pointer; }
.tree-table .tr-client > td {
    background: var(--cocoa);
    transition: background 0.15s;
}
.tree-table .tr-client:hover > td { background: var(--cocoa-90); }
.tree-table .tr-client .tree-bar { padding: 0.7rem 0.95rem; }
.tree-table .tr-client .tree-name {
    font-family: var(--font-title);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--cream);
}
.tree-table .tr-client .caret { color: rgba(252, 248, 247, 0.65); }
.tree-table .tr-client .tree-recap {
    font-size: 0.8rem;
    color: rgba(252, 248, 247, 0.72);
}

/* --- Niveau année : teinte intermédiaire, en retrait, rail cuivré --- */
.tree-table .tr-year { cursor: pointer; }
.tree-table .tr-year > td {
    background: var(--cream-dark);
    box-shadow: inset 3px 0 0 var(--accent);
    transition: background 0.15s;
}
.tree-table .tr-year:hover > td { background: var(--cocoa-08); }
.tree-table .tr-year .tree-bar { padding: 0.5rem 0.95rem 0.5rem 2.1rem; }
.tree-table .tr-year .tree-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--cocoa);
}
.tree-table .tr-year .caret { color: var(--accent); }
.tree-table .tr-year .tree-recap {
    font-size: 0.78rem;
    color: var(--cocoa-70);
}

/* --- Niveau facture : blanc, double retrait, rail de liaison --- */
.tree-table .tr-fact > td { background: var(--white); }
.tree-table .tr-fact > td:first-child {
    padding-left: 3.4rem;
    box-shadow: inset 3px 0 0 var(--cocoa-08);
}
.tree-table .tr-fact:last-child > td { border-bottom: none; }

/* Responsive */
@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: relative;
        height: auto;
        flex-direction: row;
        padding: 0.75rem 1rem;
        align-items: center;
        gap: 1rem;
    }
    .sidebar-logo img { max-width: 100px; }
    .sidebar-nav { flex-direction: row; gap: 0.25rem; flex: 1; }
    .sidebar-footer { margin: 0; border: none; padding: 0; }
    .grid-edit { grid-template-columns: 1fr; }
    iframe.pdf { height: 70vh; }
}
