/* =============================================================================
   EV Compartido — design system
   -----------------------------------------------------------------------------
   Tokens lifted from wallbox.com's own stylesheet: navy #142641, green #009B86,
   deep green #085D52, mint #B4E5DD, ink #202124, muted #626467, canvas #F0EEEE,
   line #E5E5E5, danger #DD3B3B.

   Their typeface (HeyWallbox) is proprietary, so we ship Inter — the closest
   free grotesk, vendored under /lib/inter (SIL OFL). Nothing here loads from a
   CDN, by design.

   This layers on Bootstrap rather than replacing it: Bootstrap's own CSS
   variables are overridden, so existing markup inherits the brand untouched.
   ========================================================================== */

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/lib/inter/inter-400.woff2') format('woff2');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('/lib/inter/inter-500.woff2') format('woff2');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('/lib/inter/inter-600.woff2') format('woff2');
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('/lib/inter/inter-700.woff2') format('woff2');
}

:root {
    /* Brand */
    --navy: #142641;
    --navy-2: #192538;
    --green: #009B86;
    --green-dark: #085D52;
    --green-soft: #B4E5DD;
    --green-tint: #EAF7F4;

    /* Neutrals */
    --ink: #202124;
    --muted: #626467;
    --faint: #9AA0A6;
    --surface: #FFFFFF;
    --canvas: #F6F5F5;
    --line: #E5E5E5;
    --line-soft: #F0EEEE;

    --danger: #DD3B3B;
    --warn: #C77700;

    /* Shape */
    --r-sm: 8px;
    --r: 12px;
    --r-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(20, 38, 65, .05);
    --shadow: 0 1px 3px rgba(20, 38, 65, .06), 0 8px 24px -12px rgba(20, 38, 65, .12);

    /* Sidebar (navy, as in myWallbox) */
    --side: #142641;
    --side-hover: #1E3253;
    --side-line: #26374F;
    --side-text: #9BA9BC;

    /* Bootstrap inherits the brand from these. */
    --bs-primary: #009B86;
    --bs-primary-rgb: 0, 155, 134;
    --bs-body-color: #202124;
    --bs-body-bg: #F6F5F5;
    --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --bs-body-font-size: .9375rem;
    --bs-border-color: #E5E5E5;
    --bs-link-color: #085D52;
    --bs-link-hover-color: #009B86;
    --bs-border-radius: 12px;
    --bs-danger: #DD3B3B;
}

body {
    font-family: var(--bs-body-font-family);
    font-size: .9375rem;
    color: var(--ink);
    background: var(--canvas);
    -webkit-font-smoothing: antialiased;
    letter-spacing: -.005em;
}

/* Type scale — tight, dense, data-first. */
h1, .h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -.02em; }
h2, .h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -.015em; }
h3, .h3 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -.01em; }
h4, h5, h6, .h4, .h5, .h6 { font-size: .9375rem; font-weight: 600; }

.text-muted { color: var(--muted) !important; }
.small { font-size: .8125rem; }

/* ---------- Buttons ---------- */

.btn {
    --bs-btn-font-weight: 500;
    --bs-btn-font-size: .875rem;
    --bs-btn-border-radius: var(--r-sm);
    --bs-btn-padding-x: 1rem;
    --bs-btn-padding-y: .5rem;
    letter-spacing: -.005em;
}

.btn-sm { --bs-btn-font-size: .8125rem; --bs-btn-padding-y: .35rem; }

.btn-primary, .btn-success {
    --bs-btn-bg: var(--green);
    --bs-btn-border-color: var(--green);
    --bs-btn-hover-bg: var(--green-dark);
    --bs-btn-hover-border-color: var(--green-dark);
    --bs-btn-active-bg: var(--green-dark);
    --bs-btn-active-border-color: var(--green-dark);
    --bs-btn-disabled-bg: var(--green);
    --bs-btn-disabled-border-color: var(--green);
    --bs-btn-color: #fff;
    --bs-btn-hover-color: #fff;
    --bs-btn-active-color: #fff;
    --bs-btn-disabled-color: #fff;
}

.btn-outline-primary, .btn-outline-success {
    --bs-btn-color: var(--green-dark);
    --bs-btn-border-color: var(--green);
    --bs-btn-hover-bg: var(--green);
    --bs-btn-hover-border-color: var(--green);
    --bs-btn-hover-color: #fff;
}

.btn-outline-secondary {
    --bs-btn-color: var(--ink);
    --bs-btn-border-color: var(--line);
    --bs-btn-bg: var(--surface);
    --bs-btn-hover-bg: var(--line-soft);
    --bs-btn-hover-border-color: #D5D5D5;
    --bs-btn-hover-color: var(--ink);
}

.btn-dark {
    --bs-btn-bg: var(--navy);
    --bs-btn-border-color: var(--navy);
    --bs-btn-hover-bg: var(--navy-2);
    --bs-btn-hover-border-color: var(--navy-2);
}

.btn-outline-danger { --bs-btn-color: var(--danger); --bs-btn-border-color: #F0C4C4; }

.btn-link {
    --bs-btn-color: var(--green-dark);
    --bs-btn-hover-color: var(--green);
    --bs-btn-font-weight: 500;
    text-decoration: none;
}

/* ---------- Surfaces ---------- */

.card {
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow-sm);
    background: var(--surface);
}

.card-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    font-size: .9375rem;
    padding: .85rem 1.15rem;
    border-radius: var(--r) var(--r) 0 0 !important;
}

.card-body { padding: 1.15rem; }

/* ---------- Tables: quiet lines, loud numbers ---------- */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table {
    --bs-table-bg: var(--surface);
    --bs-table-border-color: var(--line);
    margin-bottom: 0;
    font-size: .875rem;
}

.table > thead { background: var(--line-soft); }

.table > thead th {
    color: var(--muted);
    font-weight: 500;
    font-size: .75rem;
    letter-spacing: .03em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
    padding: .7rem 1rem;
    white-space: nowrap;
}

.table > tbody td {
    border-color: var(--line-soft);
    padding: .8rem 1rem;
    vertical-align: middle;
}

.table > tbody tr:last-child td { border-bottom: 0; }
.table > tbody tr:hover td { background: #FBFBFB; }

/* Numbers line up when they share a width. */
.num { font-variant-numeric: tabular-nums; }

/* Bootstrap has no min-width utility, and without it text-truncate cannot shrink inside a flex row. */
.min-w-0 { min-width: 0; }

/* ---------- Chips ---------- */

.badge {
    font-weight: 500;
    font-size: .75rem;
    letter-spacing: 0;
    padding: .32em .7em;
    border-radius: 999px;
    border: 1px solid transparent;
}

.badge.bg-success { background: var(--green-tint) !important; color: var(--green-dark) !important; border-color: var(--green-soft); }
.badge.bg-primary { background: #E7EDF6 !important; color: var(--navy) !important; border-color: #CBD8E8; }
.badge.bg-info { background: #E7EDF6 !important; color: var(--navy) !important; border-color: #CBD8E8; }
.badge.bg-warning { background: #FDF3E4 !important; color: var(--warn) !important; border-color: #F5DFB8; }
.badge.bg-danger { background: #FBEAEA !important; color: var(--danger) !important; border-color: #F2C9C9; }
.badge.bg-secondary { background: var(--line-soft) !important; color: var(--muted) !important; border-color: var(--line); }
.badge.bg-light { background: var(--line-soft) !important; color: var(--muted) !important; border-color: var(--line); }

/* ---------- Forms ---------- */

.form-label {
    font-weight: 500;
    font-size: .8125rem;
    color: var(--ink);
    margin-bottom: .3rem;
}

.form-control, .form-select {
    border-color: var(--line);
    border-radius: var(--r-sm);
    font-size: .875rem;
    padding: .5rem .75rem;
    background-color: var(--surface);
}

.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(0, 155, 134, .12);
}

.form-check-input:checked { background-color: var(--green); border-color: var(--green); }
.form-text { font-size: .8125rem; color: var(--muted); }

.alert { border-radius: var(--r-sm); border: 1px solid var(--line); font-size: .875rem; padding: .75rem 1rem; }
.alert-success { background: var(--green-tint); border-color: var(--green-soft); color: var(--green-dark); }
.alert-danger { background: #FBEAEA; border-color: #F2C9C9; color: #A82A2A; }
.alert-warning { background: #FDF3E4; border-color: #F5DFB8; color: var(--warn); }

/* ---------- Shell ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    flex: 0 0 248px;
    background: var(--side);
    color: var(--side-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: 1.15rem 1.25rem;
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -.02em;
    text-decoration: none;
}

.sidebar-brand:hover { color: #fff; }

.sidebar-mark {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--green);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: .7rem;
    flex: none;
}

/* The scope switcher, as in myWallbox: which copropiedad am I looking at. */
.sidebar-scope-box {
    margin: 0 .85rem 1rem;
    padding: .55rem .7rem;
    border: 1px solid var(--side-line);
    border-radius: var(--r-sm);
    color: #fff;
    font-size: .8125rem;
    font-weight: 500;
    line-height: 1.3;
}

.sidebar-scope-box small { display: block; color: var(--side-text); font-weight: 400; font-size: .7rem; }

.sidebar-role {
    padding: .35rem 1.4rem .3rem;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #6D7C90;
}

.sidebar-nav { list-style: none; padding: 0 .6rem; margin: 0 0 .4rem; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem .75rem;
    margin-bottom: .1rem;
    border-radius: var(--r-sm);
    color: var(--side-text);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 450;
    line-height: 1.3;
}

.sidebar-nav a:hover { background: var(--side-hover); color: #fff; }

.sidebar-nav a.active {
    background: var(--side-hover);
    color: #fff;
    font-weight: 500;
    box-shadow: inset 3px 0 0 var(--green);
}

.sidebar-nav svg { width: 17px; height: 17px; flex: none; opacity: .9; }

.sidebar-spacer { flex: 1; }

.sidebar-foot {
    border-top: 1px solid var(--side-line);
    padding: .85rem 1rem;
    display: flex;
    align-items: center;
    gap: .6rem;
}

.sidebar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--side-hover);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: .75rem;
    font-weight: 600;
    flex: none;
}

.sidebar-user { color: #fff; font-size: .8125rem; font-weight: 500; line-height: 1.2; }
.sidebar-mail { color: var(--side-text); font-size: .72rem; }

.sidebar-signout {
    background: none;
    border: 0;
    color: var(--side-text);
    padding: .2rem;
    display: grid;
    place-items: center;
}

.sidebar-signout:hover { color: #fff; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: .8rem 1.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.crumbs { font-size: .8125rem; color: var(--faint); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--green-dark); }

.topbar h1 { font-size: 1.125rem; margin: 0; font-weight: 600; }

.topbar-bell {
    position: relative;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--muted);
    background: var(--line-soft);
}

.topbar-bell:hover { color: var(--navy); background: var(--line); }

.topbar-bell-count {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: .65rem;
    font-weight: 600;
    line-height: 17px;
    text-align: center;
    border: 2px solid var(--surface);
    box-sizing: content-box;
}

/* Charger tabs on the resident calendar. */
.nav-pills {
    --bs-nav-pills-link-active-bg: var(--navy);
    --bs-nav-link-color: var(--muted);
    --bs-nav-link-hover-color: var(--navy);
    --bs-nav-pills-border-radius: var(--r-sm);
    --bs-nav-link-font-size: .875rem;
    --bs-nav-link-font-weight: 500;
    --bs-nav-link-padding-y: .45rem;
    gap: .35rem;
}

.page { padding: 1.5rem 1.75rem; flex: 1; }
.page-lead { color: var(--muted); font-size: .875rem; margin-top: -.25rem; }

.section-title {
    font-size: .8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin-bottom: .75rem;
}

/* ---------- KPI tiles ---------- */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: .9rem;
}

.tile {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    gap: .2rem;
}

.tile-value {
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
    color: var(--navy);
}

.tile-label { font-size: .8125rem; color: var(--muted); }
.tile-accent .tile-value { color: var(--green-dark); }
.tile-warn .tile-value { color: var(--warn); }

/* A bar chart of plain divs — no charting library, nothing extra to load. */
.chart { display: flex; align-items: flex-end; gap: .45rem; height: 180px; margin-top: 1.25rem; }
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .4rem; height: 100%; }
.chart-bar { width: 100%; max-width: 30px; background: var(--green); border-radius: 4px 4px 0 0; min-height: 3px; }
.chart-bar.is-empty { background: var(--line); }
.chart-label { font-size: .7rem; color: var(--faint); }

/* ---------- Entity header + tabs (detail pages) ---------- */

.entity-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.nav-tabs {
    --bs-nav-tabs-border-color: var(--line);
    --bs-nav-tabs-link-active-color: var(--navy);
    --bs-nav-tabs-link-active-border-color: transparent transparent var(--green);
    --bs-nav-tabs-link-active-bg: transparent;
    --bs-nav-tabs-border-width: 2px;
    --bs-nav-tabs-border-radius: 0;
    --bs-nav-link-color: var(--muted);
    --bs-nav-link-hover-color: var(--navy);
    --bs-nav-link-font-size: .9375rem;
    --bs-nav-link-font-weight: 500;
    --bs-nav-link-padding-x: .1rem;
    gap: 1.5rem;
}

.nav-tabs .nav-link { border-top: 0; border-left: 0; border-right: 0; margin-bottom: -2px; }
.nav-tabs .nav-link:hover { border-color: transparent transparent var(--line); }

/* A key/value list that keeps its labels quiet and its values aligned. */
.kv { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1.5rem; margin: 0; }
.kv dt { font-weight: 400; color: var(--muted); font-size: .875rem; }
.kv dd { margin: 0; font-weight: 500; font-size: .875rem; text-align: right; }

/* A lifecycle read left to right: Borrador → Emitido → Firmado → Pagado. */
.steps {
    display: flex;
    align-items: center;
    gap: .4rem;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: .75rem;
    color: var(--faint);
}

.steps li { display: flex; align-items: center; gap: .4rem; }

.steps li::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--line);
    flex: none;
}

.steps li + li::after {
    content: "";
    order: -1;
    width: 14px;
    height: 1px;
    background: var(--line);
}

.steps li.is-done { color: var(--green-dark); font-weight: 500; }
.steps li.is-done::before { background: var(--green); }
.steps li.is-done + li.is-done::after { background: var(--green-soft); }

/* The opening values, read as a line of facts rather than a form. */
.summary-chips { display: flex; flex-wrap: wrap; gap: .4rem .5rem; font-size: .8125rem; color: var(--muted); }

.summary-chips > span {
    background: var(--line-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: .2rem .6rem;
}

.summary-chips .num { color: var(--ink); font-weight: 600; }

/* A deactivated row is still readable, just clearly out of service. */
.is-muted-row td { opacity: .55; }

.modal-card-footer {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--line);
}

/* ---------- Meter (utilization) ---------- */

.meter {
    flex: 1;
    min-width: 5rem;
    height: 6px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}

.meter-fill { height: 100%; border-radius: 999px; background: var(--green); }
.meter-fill.is-mid { background: #E0A100; }
.meter-fill.is-high { background: var(--danger); }

/* ---------- Empty states ---------- */

.empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: var(--r);
}

.empty-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--green-tint);
    color: var(--green-dark);
    display: grid;
    place-items: center;
    margin: 0 auto .75rem;
}

/* ---------- Slot grid (resident calendar) ---------- */

.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: .5rem; }

.slot {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: .55rem .7rem;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    text-align: left;
    font-size: .8125rem;
}

.slot-time { font-weight: 600; font-variant-numeric: tabular-nums; }
.slot-state { font-size: .72rem; opacity: .9; }

.slot-free { background: var(--green-tint); border-color: var(--green-soft); color: var(--green-dark); cursor: pointer; }
.slot-free:hover { background: var(--green-soft); border-color: var(--green); }
.slot-mine { background: var(--green); border-color: var(--green-dark); color: #fff; }
.slot-taken { background: #FBEAEA; border-color: #F2C9C9; color: #A82A2A; }
.slot-outside { background: var(--line-soft); border-color: var(--line); color: var(--muted); }
.slot-past { background: #FAFAFA; border-color: var(--line-soft); color: var(--faint); }

.slot-legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .8125rem; color: var(--muted); }
.legend-box { display: inline-block; width: .8rem; height: .8rem; border-radius: .2rem; margin-right: .3rem; vertical-align: -1px; }

/* ---------- Confirm dialog (Alpine owns open/closed, htmx owns the contents) ---------- */

.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: rgba(20, 38, 65, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1050;
}

.modal-card {
    background: var(--surface);
    border-radius: var(--r-lg);
    width: 100%;
    max-width: 32rem;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 1.5rem 3rem rgba(20, 38, 65, .28);
}

.modal-card-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.modal-card-body { padding: 1.25rem; }

[x-cloak] { display: none !important; }

/* ---------- Mobile: the sidebar becomes a drawer ---------- */

.sidebar-toggle { display: none; }

@media (max-width: 991.98px) {
    .sidebar { position: fixed; z-index: 1050; transform: translateX(-100%); transition: transform .2s ease; }
    .sidebar.open { transform: translateX(0); }

    .sidebar-toggle {
        display: inline-flex;
        border: 1px solid var(--line);
        background: var(--surface);
        border-radius: var(--r-sm);
        padding: .35rem .55rem;
    }

    .scrim { position: fixed; inset: 0; background: rgba(20, 38, 65, .45); z-index: 1040; }
    .page { padding: 1rem; }
    .topbar { padding: .75rem 1rem; }
}

/* ---------- Print: the statement leaves as a sign-ready sheet ---------- */

@media print {
    .no-print, .sidebar, .topbar, .btn, .scrim { display: none !important; }

    body, .page { background: #fff !important; padding: 0 !important; }

    .app { display: block; }

    .printable .table,
    .printable .table th,
    .printable .table td { border-color: #000 !important; color: #000 !important; background: #fff !important; }

    .printable .table > thead { background: #fff !important; }

    .printable .badge { border: 1px solid #000; color: #000 !important; background: #fff !important; }

    a[href]::after { content: ""; }
}
