/* =====================================================
   INVENTARIO KJAS & STILO — Sistema de diseño
   ===================================================== */

:root {
    /* Superficies */
    --bg:            #0e0e17;
    --surface-1:     #16161f;
    --surface-2:     #1b1b28;
    --surface-3:     #232333;
    --border:        #2a2a3d;
    --border-soft:   #22222f;

    /* Texto */
    --text-1:        #f2f0ea;
    --text-2:        #a9a7ba;
    --text-3:        #6f6d82;

    /* Acento (latón / dorado sobrio) */
    --gold:          #c9a24b;
    --gold-soft:     #8a7238;
    --gold-bg:       rgba(201, 162, 75, 0.12);
    --gold-contrast: #14120a;

    /* Estados */
    --success:       #7fbf9e;
    --success-bg:    #142620;
    --danger:        #e2919c;
    --danger-bg:     #2a1820;
    --warning:       #e3b563;
    --warning-bg:    #2a2115;
    --info:          #7fa6d9;
    --info-bg:       #16202e;

    /* Niveles de ubicacion (para el camino de nodos) */
    --level-piso:    #9b93e8;
    --level-zona:    #5fbfc4;

    /* Radios */
    --r-sm:  8px;
    --r-md:  12px;
    --r-lg:  18px;
    --r-full: 999px;

    /* Sombra */
    --shadow-card: 0 1px 2px rgba(0,0,0,.35), 0 10px 28px -14px rgba(0,0,0,.55);
    --shadow-fab:  0 6px 20px -4px rgba(201, 162, 75, 0.45);

    /* Tipografia */
    --font-display: 'Sora', -apple-system, sans-serif;
    --font-body:    'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-1);
    -webkit-font-smoothing: antialiased;
    padding-bottom: 84px;
}

h1, h2, h3, .font-display {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
}

a { color: inherit; }

button, input, select, textarea { font-family: inherit; }

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* ===================== LAYOUT ===================== */

.app-topbar {
    border-bottom: 1px solid var(--border-soft);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}
.app-topbar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(14,14,23,0.9);
    backdrop-filter: blur(10px);
    border-radius: inherit;
    z-index: -1;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15px;
    color: var(--text-1);
}
.app-brand .mark {
    width: 30px; height: 30px;
    border-radius: var(--r-sm);
    background: var(--gold-bg);
    border: 1px solid rgba(201,162,75,0.35);
    display: flex; align-items: center; justify-content: center;
    color: var(--gold);
}
.app-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.app-brand-sub { display: none; font-family: var(--font-body); font-weight: 500; font-size: 11.5px; color: var(--text-3); }

.app-user {
    font-size: 12px;
    color: var(--text-3);
    text-align: right;
    line-height: 1.5;
}
.app-user-name { color: var(--text-2); font-weight: 600; }
.app-user-line2 {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}
.app-user-role {
    color: var(--gold);
    text-transform: capitalize;
}
.app-user-role::after { content: '\00b7'; margin-left: 4px; color: var(--text-3); }
.app-user-logout {
    color: var(--text-3);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.app-user-logout:hover { color: var(--danger); }

main.app-main {
    padding: 20px 18px 8px;
    max-width: 640px;
    margin: 0 auto;
}

/* Punto de anclaje para volver aqui despues de cambiar de pagina en un paginador,
   sin que el header fijo tape el titulo de la seccion. */
.scroll-target { scroll-margin-top: 100px; }

.app-bottomnav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(17,17,26,0.92);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-soft);
    display: flex;
    justify-content: space-around;
    padding: 8px 2px max(8px, env(safe-area-inset-bottom));
    z-index: 20;
    overflow-x: auto;
    scrollbar-width: none;
}
.app-bottomnav::-webkit-scrollbar { display: none; }
.app-bottomnav a {
    color: var(--text-3);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 8px;
    border-radius: var(--r-md);
    transition: background .15s ease, color .15s ease;
    white-space: nowrap;
    flex-shrink: 0;
}
.app-bottomnav a.active { color: var(--gold); background: var(--gold-bg); }
.app-bottomnav svg { width: 19px; height: 19px; }

@media (max-width: 400px) {
    .app-bottomnav a { padding: 6px 6px; font-size: 9.5px; }
    .app-bottomnav svg { width: 18px; height: 18px; }
}

.fab {
    position: fixed;
    bottom: 78px; right: 18px;
    width: 54px; height: 54px;
    border-radius: 50%;
    background: var(--gold);
    color: var(--gold-contrast);
    display: flex; align-items: center; justify-content: center;
    text-decoration: none;
    box-shadow: var(--shadow-fab);
    z-index: 20;
    transition: transform .15s ease;
}
.fab:active { transform: scale(0.94); }
.fab svg { width: 24px; height: 24px; }

/* Grid de resultados del buscador: 1 columna en movil, 2 en escritorio (override en @media 900px mas abajo) */
.search-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ===================== ESCRITORIO ===================== */
@media (min-width: 900px) {
    body { padding-bottom: 0; }

    main.app-main {
        max-width: 1040px;
        padding: 40px 32px 40px;
        margin-top: 66px; /* compensa el header fixed, que ya no reserva espacio en el flujo normal */
    }

    /* El header pasa a ser una sola tarjeta flotante: marca + nav + usuario en una fila.
       Se usa position:fixed (en vez de sticky) para que quede realmente quieto arriba
       sin el parpadeo que puede dar sticky + backdrop-filter al hacer scroll rapido.
       top:0 y sin espacio libre arriba: asi no hay ningun hueco por donde se pueda
       colar contenido al hacer scroll (esa era la causa del bug anterior). */
    .app-topbar {
        position: fixed;
        top: 0;
        left: 32px;
        right: 32px;
        margin: 0;
        border: 1px solid var(--border);
        border-top: none;
        border-radius: 0 0 var(--r-lg) var(--r-lg);
        padding: 12px 22px;
        gap: 12px;
        will-change: transform;
    }
    .app-topbar::before {
        background: rgba(22,22,31,0.85);
    }

    .app-brand-sub { display: block; }

    /* El nav deja de ser una barra fija aparte y pasa a vivir dentro de la
       misma fila del header, entre la marca y el usuario. */
    .app-bottomnav {
        position: static;
        display: flex;
        flex: 1;
        background: transparent;
        border: none;
        padding: 0;
        margin: 0 12px;
        justify-content: flex-start;
        align-items: center;
        gap: 30px;
        overflow: visible;
    }
    .app-bottomnav a {
        position: relative;
        flex-direction: row;
        flex-shrink: 0;
        font-size: 13.5px;
        font-weight: 600;
        padding: 6px 2px;
        gap: 8px;
        border-radius: 0;
    }
    .app-bottomnav a:hover { color: var(--text-1); background: transparent; }
    .app-bottomnav a.active { color: var(--gold); background: transparent; }
    .app-bottomnav a.active::after {
        content: '';
        position: absolute;
        left: 50%;
        bottom: -19px;
        transform: translateX(-50%);
        width: 20px;
        height: 3px;
        border-radius: 2px;
        background: var(--gold);
    }
    .app-bottomnav svg { width: 17px; height: 17px; }

    .app-user-role::after { content: none; }
    .app-user-line2 { flex-direction: column; align-items: flex-end; gap: 2px; }

    .fab { bottom: 32px; right: 32px; }

    /* Grillas de 2 columnas para pantallas anchas (las tarjetas que antes eran una sola columna) */
    .grid-desktop-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }

    .search-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
}

/* ===================== COMPONENTES ===================== */

.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    box-shadow: var(--shadow-card);
}

.stat-card {
    flex: 1;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.stat-card .stat-icon {
    width: 32px; height: 32px;
    border-radius: var(--r-sm);
    background: var(--gold-bg);
    color: var(--gold);
    display: flex; align-items: center; justify-content: center;
}
.stat-card .stat-icon svg { width: 17px; height: 17px; }
.stat-card .stat-value {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
}
.stat-card .stat-label { font-size: 12px; color: var(--text-3); }
.stat-card.alert .stat-value { color: var(--warning); }

.quick-action {
    flex: 1;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 14px;
    text-decoration: none;
    color: var(--text-1);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    transition: border-color .15s ease, transform .1s ease;
}
.quick-action:active { transform: scale(0.98); }
.quick-action .qa-icon {
    width: 34px; height: 34px;
    border-radius: var(--r-sm);
    background: var(--gold-bg);
    color: var(--gold);
    display: flex; align-items: center; justify-content: center;
}
.quick-action .qa-icon svg { width: 18px; height: 18px; }
.quick-action .qa-label { font-size: 13.5px; font-weight: 600; }

/* Ruta de ubicacion — elemento firma de la app: camino de nodos de color */
.location-trail {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 6px;
    font-size: 12.5px;
    color: var(--text-2);
}
.location-trail .seg {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.location-trail .dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.04);
}
.location-trail .connector {
    width: 16px; height: 2px;
    margin: 0 6px;
    border-radius: 2px;
    flex-shrink: 0;
    opacity: 0.8;
}
.location-trail .seg.current { color: var(--gold); font-weight: 600; }
.location-trail .seg.current .dot {
    width: 8px; height: 8px;
    box-shadow: 0 0 0 4px var(--gold-bg);
}
.location-trail.empty { color: var(--text-3); font-style: italic; }

.location-trail.lg { font-size: 14.5px; }
.location-trail.lg .dot { width: 7px; height: 7px; }
.location-trail.lg .seg.current .dot { width: 10px; height: 10px; }
.location-trail.lg .connector { width: 22px; margin: 0 7px; }

/* Linea de tiempo (historial de movimientos) */
.timeline-item { display: flex; gap: 12px; }
.timeline-rail { display: flex; flex-direction: column; align-items: center; width: 10px; flex-shrink: 0; }
.timeline-dot {
    width: 11px; height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
    box-shadow: 0 0 0 4px var(--bg);
}
.timeline-line { flex: 1; width: 2px; background: var(--border); margin-top: 4px; min-height: 16px; }
.timeline-content { flex: 1; min-width: 0; padding-bottom: 16px; }

/* Tarjeta de item (busqueda) */
.item-row {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 13px;
    display: flex;
    gap: 12px;
    align-items: center;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s ease;
}
.item-row:active { border-color: var(--gold-soft); }
.item-row .thumb {
    width: 52px; height: 52px;
    object-fit: cover;
    border-radius: var(--r-md);
    background: var(--surface-3);
    flex-shrink: 0;
}
.item-row .thumb-icon {
    width: 52px; height: 52px;
    border-radius: var(--r-md);
    background: var(--surface-3);
    color: var(--text-3);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.item-row .thumb-icon svg { width: 22px; height: 22px; }
.item-row .info { flex: 1; min-width: 0; }
.item-row .nombre { font-weight: 600; font-size: 14.5px; }
.item-row .meta { color: var(--text-3); font-size: 11px; margin-top: 3px; }

/* Tarjeta de resultado del buscador (estilo "Calculadora de Costos" del cliente) */
.search-card {
    display: block;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s ease;
}
.search-card:active { border-color: var(--gold-soft); }
.search-card-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-1);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
}
.search-card-tags {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    row-gap: 6px;
    column-gap: 12px;
    margin-bottom: 12px;
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    color: var(--text-3);
}
.tag-chip svg { flex-shrink: 0; }
.search-card-stats { display: flex; gap: 8px; }
.stat-pill {
    flex: 1;
    min-width: 0;
    background: var(--surface-3);
    border-radius: var(--r-md);
    padding: 8px 10px;
}
.stat-pill-value {
    font-weight: 700;
    font-size: 13.5px;
    color: var(--gold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat-pill-label {
    font-size: 10px;
    color: var(--text-3);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Paginador del buscador */
.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 18px;
}
.pager-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface-1);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.pager-btn:hover { border-color: var(--gold-soft); color: var(--text-1); }
.pager-btn.active { background: var(--gold-bg); border-color: var(--gold); color: var(--gold); }
.pager-btn:disabled, .pager-btn.disabled { opacity: .35; cursor: default; pointer-events: none; }
.pager-btn:disabled:hover, .pager-btn.disabled:hover { border-color: var(--border); color: var(--text-2); }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
label.field-label {
    font-size: 12.5px; font-weight: 600; color: var(--text-2);
    display: flex; align-items: center; gap: 5px;
}
.input, select.input, textarea.input {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-1);
    font-size: 15px;
    font-family: var(--font-body);
    appearance: none;
}
select.input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a9a7ba' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 38px;
}
.input:focus, select.input:focus { outline: none; border-color: var(--gold-soft); background: var(--surface-3); }
.input::placeholder { color: var(--text-3); }
.input-file {
    display: flex; align-items: center; gap: 10px;
    border: 1px dashed var(--border);
    border-radius: var(--r-md);
    padding: 12px 14px;
    color: var(--text-3);
    font-size: 13px;
    cursor: pointer;
    background: var(--surface-2);
}
.hint { font-size: 11.5px; color: var(--text-3); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 12px 16px;
    border-radius: var(--r-md);
    border: none;
    font-size: 14.5px;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    text-decoration: none;
    transition: opacity .15s ease, transform .1s ease;
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--gold); color: var(--gold-contrast); width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--text-1); border: 1px solid var(--border); }
.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid rgba(226,145,156,0.3); }
.btn-sm { padding: 8px 12px; font-size: 13px; }
.btn-icon {
    width: 34px; height: 34px; padding: 0;
    background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
    border-radius: var(--r-sm);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-2);
    border-radius: var(--r-full);
    padding: 6px 12px;
    font-size: 12px;
}
.chip b { color: var(--gold); font-weight: 600; }
.chip svg { width: 12px; height: 12px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: var(--r-full);
    font-size: 11px;
    font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: var(--surface-3); color: var(--text-3); }

.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    font-size: 13.5px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.alert svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(127,191,158,0.25); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(226,145,156,0.25); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(227,181,99,0.25); }

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 22px 0 10px;
}
.section-title:first-child { margin-top: 0; }

.empty-state {
    color: var(--text-3);
    font-size: 13px;
    text-align: center;
    padding: 30px 14px;
}

.divider { height: 1px; background: var(--border-soft); border: none; margin: 16px 0; }

.disclosure summary {
    cursor: pointer;
    color: var(--gold);
    font-size: 13.5px;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 0;
}
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary svg { width: 15px; height: 15px; }
.disclosure[open] summary .chev { transform: rotate(90deg); }
.disclosure .chev { transition: transform .15s ease; }

.avatar-thumb {
    border-radius: var(--r-lg);
    background: var(--surface-3);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-3);
    flex-shrink: 0;
    overflow: hidden;
}
.avatar-thumb img { width: 100%; height: 100%; object-fit: cover; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.data-table th {
    text-align: left;
    color: var(--text-3);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
table.data-table td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border-soft);
}

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row .bar-label { width: 92px; font-size: 12px; color: var(--text-2); flex-shrink: 0; }
.bar-row .bar-track { flex: 1; height: 8px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: var(--gold); border-radius: var(--r-full); }
.bar-row .bar-value { width: 30px; text-align: right; font-size: 12px; color: var(--text-2); flex-shrink: 0; }

/* Selector de tipo de item (Inventario vs Herramienta) */
.tipo-toggle { flex: 1; cursor: pointer; }
.tipo-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.tipo-toggle-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
    padding: 14px 10px;
    border-radius: var(--r-md);
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    transition: border-color .15s ease, background .15s ease;
}
.tipo-toggle-box strong { font-size: 13px; color: var(--text-1); }
.tipo-toggle-box small { font-size: 10.5px; color: var(--text-3); line-height: 1.3; }
.tipo-toggle input:checked + .tipo-toggle-box {
    border-color: var(--gold);
    background: var(--gold-bg);
}
.tipo-toggle input:checked + .tipo-toggle-box strong { color: var(--gold); }

/* Chips de filtro (Buscar: Todos / Herramientas / Inventario) */
.filter-chip {
    padding: 8px 14px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.filter-chip.active { border-color: var(--gold); background: var(--gold-bg); color: var(--gold); }