/* Ilaro — hoja de estilos principal. Sin dependencias externas. */

:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --border: #dfe4e8;
    --border-strong: #c7ced5;
    --text: #1b2733;
    --text-2: #52606d;
    --text-3: #7b8794;
    --primary: #0b6e8a;
    --primary-hover: #095a71;
    --primary-soft: #e3f2f6;
    --on-primary: #ffffff;
    --danger: #c0392b;
    --danger-soft: #fdecea;
    --ok: #1e7d4f;
    --ok-soft: #e4f4ec;
    --warn: #9a6200;
    --warn-soft: #fff4dc;
    --info: #2458b3;
    --info-soft: #e7eefb;
    --muted-soft: #eceff2;
    --sidebar: #102a36;
    --sidebar-text: #c9d6dd;
    --sidebar-active: #1c4252;
    --shadow: 0 1px 2px rgba(16, 42, 54, .06), 0 2px 8px rgba(16, 42, 54, .05);
    --radius: 10px;
    --radius-sm: 6px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e161c;
        --surface: #152029;
        --surface-2: #1a2731;
        --border: #263641;
        --border-strong: #34495a;
        --text: #e3eaef;
        --text-2: #a9b7c2;
        --text-3: #7f909d;
        --primary: #3aa7c7;
        --primary-hover: #5bbad6;
        --primary-soft: #16323d;
        --on-primary: #06202a;
        --danger: #ef6b5b;
        --danger-soft: #3a1c19;
        --ok: #53c28b;
        --ok-soft: #14301f;
        --warn: #e8b04b;
        --warn-soft: #33280f;
        --info: #7aa7f0;
        --info-soft: #172640;
        --muted-soft: #1f2c36;
        --sidebar: #0a1217;
        --sidebar-text: #aab9c3;
        --sidebar-active: #173340;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 14px/1.5 var(--font);
    color: var(--text);
    background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.1rem; color: #fff; }
.brand img { width: 34px; height: 34px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.brand strong { display: block; font-size: 1rem; }
.brand small { display: block; font-size: .72rem; color: var(--sidebar-text); line-height: 1.2; }
.nav { list-style: none; margin: 0; padding: .25rem .6rem 1rem; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #7b95a3; padding: .9rem .6rem .3rem; }
.nav a {
    display: flex; align-items: center; gap: .65rem; padding: .5rem .6rem; border-radius: var(--radius-sm);
    color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #3aa7c7; }
.nav .count { margin-left: auto; background: #c0392b; color: #fff; font-size: .7rem; padding: 0 .45rem; border-radius: 999px; }
.sidebar-footer { margin-top: auto; padding: .8rem 1.1rem 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .82rem; }
.sidebar-footer .who { color: #fff; font-weight: 600; }
.sidebar-footer .role { color: #7b95a3; font-size: .75rem; }
.sidebar-footer .links { display: flex; gap: .8rem; margin-top: .5rem; flex-wrap: wrap; }
.sidebar-footer a, .sidebar-footer button { color: var(--sidebar-text); background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.sidebar-footer a:hover, .sidebar-footer button:hover { color: #fff; text-decoration: underline; }

.main { min-width: 0; padding: 1.4rem 1.8rem 3rem; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.page-head .sub { color: var(--text-2); margin-top: .15rem; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { font-size: .82rem; color: var(--text-3); margin-bottom: .3rem; }
.breadcrumb a { color: var(--text-2); }

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
    .nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
    .topbar {
        display: flex; align-items: center; gap: .75rem; position: sticky; top: 0; z-index: 40;
        background: var(--sidebar); color: #fff; padding: .6rem 1rem;
    }
    .topbar button { background: none; border: 0; color: #fff; padding: .25rem; cursor: pointer; }
    .main { padding: 1rem 1rem 3rem; }
}

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 1.1rem 1.2rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .85rem 1.2rem; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; font-size: 1rem; }
.card + .card, .stack > * + * { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-main { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.kpi { padding: 1rem 1.1rem; display: block; color: inherit; }
a.kpi:hover { text-decoration: none; border-color: var(--primary); }
.kpi .label { color: var(--text-2); font-size: .8rem; font-weight: 500; }
.kpi .value { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; margin: .15rem 0; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--text-3); font-size: .78rem; }
.kpi.danger .value { color: var(--danger); }
.kpi.warn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
    padding: .5rem .9rem; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
    background: var(--surface); color: var(--text); font: 500 .88rem/1.2 var(--font); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-icon { padding: .35rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.1rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 700px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } }
.field label, .label { display: block; font-weight: 600; font-size: .84rem; margin-bottom: .3rem; }
.field .req { color: var(--danger); }
.field .help { font-size: .78rem; color: var(--text-3); margin: .25rem 0 0; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date], input:not([type]), select, textarea {
    width: 100%; padding: .5rem .65rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: 14px/1.4 var(--font);
}
textarea { min-height: 84px; resize: vertical; }
input[type=file] { font: inherit; max-width: 100%; }
.check { display: flex; align-items: flex-start; gap: .5rem; font-weight: 500; cursor: pointer; }
.check input { margin-top: .2rem; width: 16px; height: 16px; accent-color: var(--primary); }
.checks { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.field-error { color: var(--danger); font-size: .8rem; margin: .25rem 0 0; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.form-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem 1rem; margin: 0; }
legend { font-weight: 650; padding: 0 .35rem; }
.signature { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); border-radius: var(--radius); padding: .9rem 1rem; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 150px; flex: 1 1 150px; }
.filters .field.grow { flex: 3 1 260px; }
.filters label { font-size: .75rem; color: var(--text-2); font-weight: 600; margin-bottom: .2rem; display: block; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chip { padding: .3rem .75rem; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-2); background: var(--surface); font-size: .82rem; font-weight: 500; }
.chip:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chip .n { font-variant-numeric: tabular-nums; opacity: .8; margin-left: .2rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); font-weight: 650; background: var(--surface-2); }
.table th, .table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .muted, .muted { color: var(--text-3); }
.table .row-link { font-weight: 600; }
.table .actions { text-align: right; white-space: nowrap; }
.table-meta { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; padding: .6rem 1.2rem; border-top: 1px solid var(--border); color: var(--text-2); font-size: .82rem; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-3); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted, .badge-neutral { background: var(--muted-soft); color: var(--text-2); }
.crit { display: inline-flex; gap: 2px; vertical-align: middle; }
.crit i { width: 6px; height: 12px; border-radius: 2px; background: var(--border-strong); }
.crit.c1 i:nth-child(-n+1), .crit.c2 i:nth-child(-n+2), .crit.c3 i:nth-child(-n+3) { background: var(--warn); }
.crit.c3 i { background: var(--danger) !important; }

/* ---------- Flash ---------- */
.flash { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: .75rem; border: 1px solid transparent; }
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash-warning { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.flash-info { background: var(--info-soft); color: var(--info); }
.flash .close { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; font-size: 1.1rem; line-height: 1; }

/* ---------- Details / definition lists ---------- */
dl.details { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; margin: 0; }
dl.details dt { color: var(--text-2); font-size: .84rem; padding: .4rem 0; border-bottom: 1px dashed var(--border); }
dl.details dd { margin: 0; padding: .4rem 0 .4rem .6rem; border-bottom: 1px dashed var(--border); font-weight: 500; overflow-wrap: anywhere; }
dl.details dt:last-of-type, dl.details dd:last-of-type { border-bottom: 0; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }

.equipment-hero { display: grid; grid-template-columns: 180px 1fr 140px; gap: 1.2rem; align-items: start; }
.equipment-hero .photo { width: 180px; height: 150px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); object-fit: cover; display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.equipment-hero .qr { width: 140px; text-align: center; font-size: .75rem; color: var(--text-3); }
.equipment-hero .qr svg { width: 130px; height: 130px; background: #fff; border-radius: 6px; padding: 4px; }
.equipment-hero .code { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; color: var(--primary); }
.tags { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
@media (max-width: 800px) { .equipment-hero { grid-template-columns: 1fr; } .equipment-hero .qr { display: none; } }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.4rem; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: -6px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline .meta { font-size: .78rem; color: var(--text-3); }
.timeline .body { margin-top: .15rem; }

/* ---------- Files ---------- */
.files { list-style: none; margin: 0; padding: 0; }
.files li { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.files li:last-child { border-bottom: 0; }
.files .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .meta { color: var(--text-3); font-size: .78rem; white-space: nowrap; }

/* ---------- Gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .6rem; }
.gallery figure { margin: 0; position: relative; }
.gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; background: var(--surface-2); }
.gallery form { position: absolute; top: 4px; right: 4px; }
.gallery .link-btn { background: var(--surface); border-radius: 50%; padding: 3px; display: flex; box-shadow: var(--shadow); }

/* ---------- Signature dialog ---------- */
.sign-dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.3rem 1.4rem; width: min(380px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.sign-dialog::backdrop { background: rgba(10, 20, 26, .55); }
.sign-dialog h2 { margin-bottom: .25rem; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: .25rem; flex-wrap: wrap; }
.pagination a, .pagination span { min-width: 32px; text-align: center; padding: .25rem .55rem; border-radius: var(--radius-sm); border: 1px solid var(--border); color: var(--text-2); font-size: .82rem; }
.pagination a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pagination .current { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.pagination .gap { border: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--text-2); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Charts (CSS bars) ---------- */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: .35rem; align-items: end; height: 170px; padding-top: .5rem; }
.bars .col { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-end; gap: 2px; height: 100%; position: relative; }
.bars .bar { border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .pair { display: flex; gap: 2px; align-items: flex-end; height: 100%; }
.bars .pair .bar { flex: 1; }
.bars .opened { background: var(--primary); }
.bars .closed { background: var(--ok); opacity: .75; }
.bars-labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: .35rem; font-size: .7rem; color: var(--text-3); text-align: center; margin-top: .3rem; }
.legend { display: flex; gap: 1rem; font-size: .78rem; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 40%) 1fr 36px; gap: .6rem; align-items: center; font-size: .84rem; padding: .3rem 0; }
.hbar .track { display: block; background: var(--muted-soft); border-radius: 4px; height: 10px; overflow: hidden; }
.hbar .fill { display: block; background: var(--primary); height: 100%; border-radius: 4px; }
.meter { height: 8px; background: var(--muted-soft); border-radius: 4px; overflow: hidden; margin-top: .45rem; }
.meter > span { display: block; height: 100%; background: var(--ok); }

/* ---------- Guest (login) ---------- */
.guest { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, var(--sidebar) 0%, #164355 100%); }
.guest-card { width: 100%; max-width: 400px; }
.guest-card .card-body { padding: 1.8rem; }
.guest-brand { text-align: center; margin-bottom: 1.2rem; }
.guest-brand img { max-height: 70px; max-width: 220px; margin-bottom: .6rem; }
.guest-brand h1 { margin: 0; }
.guest-brand p { color: var(--text-2); margin: .2rem 0 0; font-size: .88rem; }
.guest-foot { text-align: center; color: #9fb6c2; font-size: .78rem; margin-top: 1rem; }
.guest-foot a { color: #cfe3ec; }

/* ---------- Utilities ---------- */
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.right { text-align: right; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 1rem; }
.small { font-size: .82rem; }
.strong { font-weight: 650; }
.hidden { display: none !important; }
.inline { display: inline; }
.text-danger { color: var(--danger); } .text-ok { color: var(--ok); } .text-warn { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media print {
    .sidebar, .topbar, .page-head .actions, .no-print, .form-actions, .filters { display: none !important; }
    .app { display: block; }
    .main { padding: 0; }
    .card { box-shadow: none; border-color: #bbb; }
    body { background: #fff; }
}
