/* =========================================================================
   Ferredata — Sistema de diseño
   Estética industrial limpia · azul marino + amarillo construcción · iconos outline
   ========================================================================= */

:root {
    --bg:          #f2f4f8;
    --surface:     #ffffff;
    --surface-2:   #f8fafc;
    --ink:         #101a30;
    --ink-2:       #3a465e;
    --ink-soft:    #6a7690;
    --line:        #e3e7ee;
    --line-strong: #cfd6e2;

    --brand:       #fbbe2c;   /* amarillo construcción */
    --brand-dark:  #e8a900;   /* hover de botones */
    --brand-ink:   #8a5b00;   /* texto/iconos de marca sobre fondo claro */
    --brand-soft:  #fff6dd;
    --brand-2:     #ffd25e;   /* amarillo claro sobre azul marino */
    --on-brand:    #0b1330;   /* texto sobre amarillo */

    --steel:       #0a1129;   /* azul marino: sidebar / hero */
    --steel-2:     #131d3d;
    --steel-line:  #212e53;
    --steel-ink:   #97a5c2;

    --success:  #12805c;
    --success-soft: #e5f4ee;
    --danger:   #c0392b;
    --danger-soft:  #fbeceb;
    --warn:     #b45309;
    --warn-soft:    #fdeee0;
    --info:     #2563eb;
    --info-soft:    #e8effd;

    --radius:   10px;
    --radius-sm: 7px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
    --shadow:    0 4px 14px rgba(16,24,40,.08);
    --shadow-lg: 0 12px 34px rgba(16,24,40,.14);

    --sidebar-w: 246px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
p { margin: 0; }
img { max-width: 100%; display: block; }
.ic { flex: 0 0 auto; vertical-align: middle; }

/* ---------- Utilidades ---------- */
.muted { color: var(--ink-soft); }
.small { font-size: 12.5px; }
.strong { font-weight: 700; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.flex { display: flex; }
.between { justify-content: space-between; }
.items-center { align-items: center; }
.gap-1 { gap: 6px; }
.gap-2 { gap: 12px; }
.gap-3 { gap: 20px; }
.mt-1{margin-top:8px}.mt-2{margin-top:16px}.mt-3{margin-top:24px}
.mb-1{margin-bottom:8px}.mb-2{margin-bottom:16px}.mb-3{margin-bottom:24px}
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* =========================================================================
   Botones
   ========================================================================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: inherit; font-weight: 600; font-size: 14px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    border: 1px solid transparent; cursor: pointer;
    background: var(--surface); color: var(--ink);
    transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-navy { background: var(--steel); color: #fff; }
.btn-navy:hover { background: var(--steel-2); }
.btn-outline { background: var(--surface); border-color: var(--line-strong); color: var(--ink-2); }
.btn-outline:hover { border-color: var(--ink-soft); background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* =========================================================================
   Formularios
   ========================================================================= */
.field { margin-bottom: 16px; }
.label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--ink-2); }
.input, .select, textarea.input {
    width: 100%; font: inherit; font-size: 14.5px;
    padding: 10px 12px; border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, textarea.input:focus {
    outline: none; border-color: var(--brand-dark);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.input::placeholder { color: #a2abb8; }
.hint { font-size: 12px; color: var(--ink-soft); margin-top: 5px; }
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon {
    display: inline-flex; align-items: center; padding: 0 12px;
    border: 1px solid var(--line-strong); border-left: 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: var(--surface-2); color: var(--ink-soft); font-size: 13px;
}
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 640px){ .grid-2,.grid-3 { grid-template-columns: 1fr; } }

/* =========================================================================
   Cards
   ========================================================================= */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
    padding: 16px 20px; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-head h3 { font-size: 15px; }
.card-body { padding: 20px; }

/* =========================================================================
   Badges / píldoras
   ========================================================================= */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 100px;
    background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }
.badge-warn    { background: var(--warn-soft);    color: var(--warn);    border-color: transparent; }
.badge-info    { background: var(--info-soft);    color: var(--info);    border-color: transparent; }
.badge-brand   { background: var(--brand-soft);   color: var(--brand-ink); border-color: transparent; }

/* =========================================================================
   Tablas
   ========================================================================= */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th {
    text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
    text-transform: uppercase; color: var(--ink-soft);
    padding: 11px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
table.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: 0; }

/* =========================================================================
   Alertas / flash
   ========================================================================= */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px; border-radius: var(--radius-sm);
    font-size: 14px; margin-bottom: 18px; border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: #0c5c42; border-color: #bfe3d5; }
.alert-error   { background: var(--danger-soft);  color: #93261b; border-color: #f0c7c2; }
.alert-info    { background: var(--info-soft);    color: #1746a8; border-color: #c7d8fb; }

/* =========================================================================
   App shell (sidebar + contenido)
   ========================================================================= */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    background: var(--steel); color: var(--steel-ink);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 11px;
    padding: 18px 20px; border-bottom: 1px solid var(--steel-line); color: #fff;
}
.sidebar-brand .logo {
    width: 34px; height: 34px; border-radius: 8px; flex: 0 0 34px;
    background: var(--brand); display: grid; place-items: center; color: var(--on-brand);
    font-weight: 800;
}
.logo.logo-img { background: #fff; overflow: hidden; padding: 0; }
.logo.logo-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sidebar-brand b { font-size: 16px; letter-spacing: -.01em; }
.sidebar-brand .sub { font-size: 11px; color: var(--steel-ink); font-weight: 500; }
.nav { padding: 12px 12px; overflow-y: auto; flex: 1; scrollbar-width: none; -ms-overflow-style: none; }
.nav::-webkit-scrollbar { width: 0; height: 0; display: none; }
.nav-label {
    font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
    color: #64719a; padding: 14px 12px 6px;
}
.nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; border-radius: 8px; color: var(--steel-ink);
    font-size: 14px; font-weight: 500; margin-bottom: 2px; transition: background .12s, color .12s;
}
.nav a:hover { background: var(--steel-2); color: #e8edf3; }
.nav a.active { background: var(--brand); color: var(--on-brand); font-weight: 600; }
.nav a.active .ic { color: var(--on-brand); }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--steel-line); }
.sidebar-foot a { color: var(--steel-ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 62px; background: var(--surface); border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; }
.topbar .user {
    display: flex; align-items: center; gap: 10px; font-size: 13.5px;
    font-family: inherit; background: transparent; border: 0; cursor: pointer;
    padding: 5px 8px; border-radius: var(--radius-sm); transition: background .12s;
}
.topbar .user:hover { background: var(--surface-2); }
.topbar .user .right { text-align: right; }
.topbar .user .caret { color: var(--ink-soft); display: inline-flex; transition: transform .15s; }
.user-menu { position: relative; }
.user-menu.open .caret { transform: rotate(180deg); }
.user-menu.open .user { background: var(--surface-2); }
.user-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0; min-width: 190px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 6px; z-index: 40;
    opacity: 0; visibility: hidden; transform: translateY(-4px);
    transition: opacity .14s, transform .14s, visibility .14s;
}
.user-menu.open .user-dropdown { opacity: 1; visibility: visible; transform: translateY(0); }
.user-dropdown a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px;
    border-radius: var(--radius-sm); color: var(--ink-2); font-size: 14px; font-weight: 500;
}
.user-dropdown a:hover { background: var(--surface-2); }
.user-dropdown a.danger { color: var(--danger); }
.user-dropdown a.danger:hover { background: var(--danger-soft); }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft);
    color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.content { padding: 26px; flex: 1; max-width: 1760px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--ink-soft); font-size: 14px; margin-top: 3px; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 900px){ .stats { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 520px){ .stats { grid-template-columns: 1fr; } }
.stat {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow-sm); position: relative;
}
.stat .stat-ic {
    width: 40px; height: 40px; border-radius: 9px; display: grid; place-items: center;
    background: var(--steel); color: var(--brand); margin-bottom: 14px;
}
.stat .stat-ic.g { background: var(--success-soft); color: var(--success); }
.stat .stat-ic.b { background: var(--info-soft); color: var(--info); }
.stat .stat-ic.w { background: var(--warn-soft); color: var(--warn); }
.stat .stat-val { font-size: 25px; font-weight: 800; letter-spacing: -.02em; }
.stat .stat-lbl { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

.mobile-toggle { display: none; }
@media (max-width: 860px){
    .sidebar { position: fixed; left: -100%; z-index: 60; transition: left .2s; box-shadow: var(--shadow-lg); }
    .sidebar.open { left: 0; }
    .mobile-toggle { display: inline-flex; }
    .scrim { display:none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 55; }
    .scrim.show { display: block; }
}

/* =========================================================================
   Páginas de acceso (login / instalador)
   ========================================================================= */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
@media (max-width: 860px){ .auth-wrap { grid-template-columns: 1fr; } }
.auth-side {
    background: var(--steel); color: #fff; padding: 54px 48px;
    display: flex; flex-direction: column; justify-content: space-between;
    background-image: radial-gradient(1200px 400px at 100% 0, rgba(251,190,44,.20), transparent 60%);
}
.auth-side .brand-row { display: flex; align-items: center; gap: 12px; }
.auth-side .logo { width: 42px; height: 42px; border-radius: 10px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.auth-side h2 { color: #fff; font-size: 30px; line-height: 1.2; margin-top: 8px; letter-spacing: -.02em; }
.auth-side .feat { display: flex; align-items: center; gap: 12px; margin-top: 16px; color: #c4cdd8; font-size: 14.5px; }
.auth-side .feat .ic { color: var(--brand-2); }
.auth-main { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card .lead { color: var(--ink-soft); margin-bottom: 26px; }

/* Login: tarjeta centrada sobre fondo con degradado suave (mismos colores) */
.login-page {
    min-height: 100vh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 18px; padding: 32px 20px;
    background:
        radial-gradient(900px 500px at 15% 0, var(--brand-soft), transparent 55%),
        radial-gradient(1100px 600px at 100% 100%, rgba(10,17,41,.09), transparent 55%),
        linear-gradient(160deg, #ffffff 0%, var(--bg) 55%, #e7ebf3 100%);
}
.login-card {
    width: 100%; max-width: 400px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); padding: 34px 32px 30px;
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 24px; }
.login-logo {
    width: 46px; height: 46px; border-radius: 12px; flex: 0 0 46px;
    background: var(--brand); color: var(--on-brand); display: grid; place-items: center;
    font-weight: 800; font-size: 22px; box-shadow: 0 4px 12px rgba(251,190,44,.45);
}
.login-logo-img { background: #fff; overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.login-logo-img img { width: 100%; height: 100%; object-fit: contain; }
.login-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.login-brand-text b { font-size: 18px; letter-spacing: -.01em; }
.login-brand-text span { font-size: 12.5px; color: var(--ink-soft); }
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card .lead { color: var(--ink-soft); margin-bottom: 24px; }
.login-foot { font-size: 12.5px; color: var(--ink-soft); }
.cred-hint {
    margin-top: 18px; padding: 12px 14px; background: var(--surface-2);
    border: 1px dashed var(--line-strong); border-radius: var(--radius-sm);
    font-size: 12.5px; color: var(--ink-soft);
}
.cred-hint code { background: #e9edf4; padding: 1px 6px; border-radius: 5px; color: var(--ink-2); font-weight: 600; }

/* =========================================================================
   Catálogo / inventario
   ========================================================================= */
.thumb {
    width: 40px; height: 40px; border-radius: 8px; flex: 0 0 40px;
    background: var(--surface-2); border: 1px solid var(--line);
    display: grid; place-items: center; color: var(--ink-soft); overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Subida de imagen */
.img-drop {
    width: 100%; aspect-ratio: 1/1; max-width: 220px; margin: 0 auto;
    border: 1px dashed var(--line-strong); border-radius: var(--radius);
    background: var(--surface-2); display: grid; place-items: center; overflow: hidden;
}
.img-drop img { width: 100%; height: 100%; object-fit: cover; }
.img-ph { display: flex; flex-direction: column; align-items: center; color: var(--ink-soft); }

/* Filas de conversión de unidades */
.conv-head, .conv-row {
    display: grid; grid-template-columns: 44px 1.3fr 110px 110px 1fr 44px;
    gap: 8px; align-items: center;
}
.conv-head { padding: 0 2px 8px; font-size: 11.5px; font-weight: 700; letter-spacing: .03em;
    text-transform: uppercase; color: var(--ink-soft); }
.conv-row { padding: 7px 0; border-top: 1px solid var(--line); }
.conv-row .input, .conv-row .select { padding: 8px 10px; font-size: 13.5px; }
.conv-def { display: grid; place-items: center; }
.conv-def input { width: 17px; height: 17px; accent-color: var(--brand); }
.conv-base { background: var(--brand-soft); border-radius: var(--radius-sm); padding-left: 4px; padding-right: 4px; border-top: 0; }
@media (max-width: 720px){
    .conv-head { display: none; }
    .conv-row { grid-template-columns: 1fr 1fr; gap: 6px; }
}

/* Vista previa del ticket (configuración) */
.ticket-prev {
    width: 250px; max-width: 100%; background: #fff; color: #000;
    border: 1px solid var(--line); border-radius: 4px; padding: 14px 12px;
    font-family: "Segoe UI", Tahoma, monospace; font-size: 12px; line-height: 1.4;
    box-shadow: var(--shadow-sm); text-align: center;
}
.ticket-prev img { max-width: 60%; max-height: 70px; margin: 0 auto 6px; display: block; }
.ticket-prev .pv-name { font-size: 15px; font-weight: 800; }
.ticket-prev .pv-line { font-size: 11px; color: #333; }
.ticket-prev .pv-sep { color: #999; margin: 5px 0; overflow: hidden; }
.ticket-prev .pv-row, .ticket-prev .pv-item { display: flex; justify-content: space-between; text-align: left; }
.ticket-prev .pv-total { font-size: 15px; font-weight: 800; margin-top: 2px; }
.ticket-prev .pv-foot { margin-top: 8px; font-size: 11px; color: #333; }

/* ---- Matriz de permisos por rol ---- */
.perm-row {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 9px 0; border-bottom: 1px dashed var(--line);
}
.perm-row:last-child { border-bottom: 0; }
.perm-mod {
    display: flex; align-items: center; gap: 7px; width: 200px; flex: 0 0 200px;
    font-weight: 600; font-size: 14px; color: var(--ink);
}
.perm-mod .ic { color: var(--ink-soft); }
.perm-acts { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 auto; }
.perm-chk {
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
    padding: 5px 10px; border: 1px solid var(--line); border-radius: 100px;
    font-size: 12.5px; color: var(--ink-2); background: var(--surface);
}
.perm-chk:hover { border-color: var(--line-strong); }
.perm-chk input { width: 15px; height: 15px; accent-color: var(--brand); margin: 0; }
.perm-chk:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.perm-chk.is-view { border-style: solid; }
@media (max-width: 700px) {
    .perm-mod { width: 100%; flex: 1 1 100%; }
}

/* Columna lateral fija (ficha de cliente, etc.). Se fija la columna entera,
   no una tarjeta suelta, para que no se encime con las de abajo. */
.side-sticky { display: flex; flex-direction: column; gap: 16px; align-self: start; }
@media (min-width: 901px) {
    .side-sticky { position: sticky; top: 88px; }
}
