/* Tokens portados de legacy/lib/core/theme/app_theme.dart. Todo color sale de
   un token: ninguna regla de abajo escribe un valor a mano, así el tema oscuro
   es un solo bloque y no una segunda hoja de estilos. */

:root {
    --primary: #3D6B50;
    --page: #F6F4F1;
    --surface: #FFFFFF;
    --border: #E4E0DB;
    --ink: #1A1917;
    --muted: #7A746D;
    --tinted: #F0EDE8;

    --income: #3D6B50;
    --expense: #9E4A40;
    --pending: #9A7B2D;
    --info: #4A7B8C;
    --movement: #7B6B8A;

    --stock-ok: #3D6B50;
    --stock-low: #9A7B2D;
    --stock-out: #9E4A40;

    --radius: 10px;
    --radius-chip: 8px;
    --radius-dialog: 14px;
    --control-height: 52px;
}

:root[data-theme="dark"] {
    --primary: #6DA67E;
    --page: #1A1917;
    --surface: #252420;
    --border: #3A3833;
    --ink: #F6F4F1;
    --muted: #9E9890;
    --tinted: #2E2D28;

    --income: #6DA67E;
    --expense: #CF7A70;
    --pending: #CDB05A;
    --info: #7CB5C8;
    --movement: #AA9ABB;

    --stock-ok: #6DA67E;
    --stock-low: #CDB05A;
    --stock-out: #CF7A70;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--page);
    color: var(--ink);
    font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
}

/* Las siete escalas de texto del tema Flutter, fijadas acá en lugar de dejarlas
   caer en los valores por omisión del navegador. */
.t-display { font: 700 28px/1.25 inherit; letter-spacing: -0.5px; }
.t-title   { font: 600 22px/1.3 inherit; letter-spacing: -0.3px; }
.t-section { font: 600 18px/1.35 inherit; }
.t-body-em { font: 500 16px/1.5 inherit; }
.t-body    { font: 400 16px/1.4 inherit; }
.t-small   { font: 400 14px/1.4 inherit; }
.t-label   { font: 600 14px/1.45 inherit; }

.muted { color: var(--muted); }

/* Sin sombras en ninguna parte: una tarjeta es un borde de 1px. */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

label {
    display: block;
    margin-bottom: 14px;
}

label > span {
    display: block;
    margin-bottom: 6px;
    font: 600 14px/1.45 inherit;
}

input {
    display: block;
    width: 100%;
    height: var(--control-height);
    padding: 0 14px;
    background: var(--page);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
}

input:focus {
    outline: none;
    border: 1.5px solid var(--primary);
}

button {
    width: 100%;
    height: var(--control-height);
    border: 0;
    border-radius: var(--radius);
    background: var(--primary);
    color: #FFFFFF;
    font: 600 16px/1 inherit;
    cursor: pointer;
}

button:disabled {
    opacity: 0.6;
    cursor: default;
}

button.ghost {
    background: none;
    color: var(--primary);
    border: 1px solid var(--border);
}

.screen-login {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 20px;
    max-width: 420px;
    margin: 0 auto;
    padding: 24px;
}

.brand {
    text-align: center;
    margin-bottom: 4px;
}

.brand .mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-dialog);
    background: var(--tinted);
    color: var(--primary);
    margin-bottom: 12px;
}

.error {
    background: var(--tinted);
    border: 1px solid var(--expense);
    color: var(--expense);
    border-radius: var(--radius-chip);
    padding: 10px 12px;
    font: 400 14px/1.45 inherit;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar button {
    width: auto;
    height: auto;
    padding: 8px 12px;
    background: none;
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-chip);
    font: 600 14px/1 inherit;
}

main.home {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px 16px 60px;
    display: grid;
    gap: 16px;
}

.pending {
    border-left: 3px solid var(--pending);
    padding-left: 12px;
}

/* ---- Chrome: barra inferior, FAB, aviso ---------------------------------- */

.ic { width: 20px; height: 20px; flex: none; }
.ic.big { width: 32px; height: 32px; }

.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.view {
    flex: 1;
    padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
}

.view[hidden] { display: none !important; }

/* La barra se apoya en una línea de 1px, sin sombra, igual que el tema Flutter. */
.bottombar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

.bottombar button {
    flex: 1;
    width: auto;
    height: 60px;
    border: 0;
    border-radius: 0;
    background: none;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font: 600 12px/1 inherit;
}

.bottombar button .pill {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 28px;
    border-radius: 14px;
}

.bottombar button[aria-current] { color: var(--primary); }
.bottombar button[aria-current] .pill { background: color-mix(in srgb, var(--primary) 14%, transparent); }

.bottombar .badge-dot {
    position: absolute;
    transform: translate(14px, -12px);
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    background: var(--pending);
    color: var(--surface);
    font: 600 10px/16px inherit;
    text-align: center;
}

/* El FAB del tema Flutter es un cuadrado redondeado de 16px, no un círculo. */
.fab {
    position: fixed;
    right: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    z-index: 21;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--primary);
    color: #fff;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab .ic { width: 28px; height: 28px; }

.toast {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    z-index: 40;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-radius: var(--radius-chip);
    background: var(--ink);
    color: var(--page);
}

.toast.show { display: flex; }
.toast.tone-error { background: var(--expense); color: #fff; }
.toast .linkbtn { margin-left: auto; }

/* ---- Hojas modales ------------------------------------------------------- */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--ink) 45%, transparent);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

body.modal-open { overflow: hidden; }

/* 16px arriba y nada abajo: la hoja sale del borde de la pantalla. */
.sheet {
    background: var(--surface);
    width: 100%;
    max-width: 560px;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
}

.sheet.small { max-height: 60dvh; }
.sheet.full { height: 100dvh; max-height: 100dvh; border-radius: 0; }

.sheet-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 8px;
}

.sheet-body {
    padding: 8px 16px 16px;
    overflow-y: auto;
    flex: 1;
}

/* Pegado al final del scroll, no a la ventana: con el teclado abierto en
   Android una barra fija a la ventana queda tapada. */
.sheet-foot {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 12px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.sheet-foot button { flex: 1; }

.icon-btn {
    width: 44px;
    height: 44px;
    min-height: 44px;
    border: 0;
    border-radius: var(--radius-chip);
    background: none;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---- Filas, tarjetas, vacíos -------------------------------------------- */

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 64px;
    padding: 10px 0;
    border: 0;
    border-top: 1px solid var(--border);
    border-radius: 0;
    background: none;
    color: var(--ink);
    text-align: left;
    font: inherit;
    height: auto;
}

.row:first-of-type { border-top: 0; }
button.row:active { background: var(--tinted); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { display: flex; align-items: center; gap: 6px; }
.row-sub { color: var(--muted); }
.row-trail { text-align: right; white-space: nowrap; }

.row-lead {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background: var(--tinted);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

.day-head { margin: 20px 0 4px; color: var(--primary); }

.metric { display: flex; flex-direction: column; gap: 6px; padding: 16px; }
.metric-head { display: flex; align-items: center; gap: 6px; }
.metric-value { font-variant-numeric: tabular-nums; }
.metric.income .metric-value { color: var(--income); }
.metric.expense .metric-value { color: var(--expense); }
.metric.info .metric-value { color: var(--info); }
.metric.pending .metric-value { color: var(--pending); }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.empty .ic { color: var(--border); }

.skeleton { display: grid; gap: 10px; padding: 8px 0; }
.sk-line { height: 14px; border-radius: 7px; background: var(--tinted); }
.sk-line:nth-child(2) { width: 70%; }
.sk-line:nth-child(3) { width: 45%; }

.note { display: flex; align-items: center; gap: 8px; color: var(--muted); margin: 8px 0; }

/* ---- Chips, badges, estados de stock ------------------------------------ */

.chiprow { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; scrollbar-width: none; }
.chiprow::-webkit-scrollbar { display: none; }

.chip {
    width: auto;
    height: auto;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-chip);
    background: var(--surface);
    color: var(--muted);
    font: 400 14px/1 inherit;
    white-space: nowrap;
}

.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.badge {
    padding: 2px 8px;
    border-radius: var(--radius-chip);
    background: var(--tinted);
    color: var(--muted);
}

.pending-badge { background: color-mix(in srgb, var(--pending) 18%, transparent); color: var(--pending); }

.stock-ok { color: var(--stock-ok); }
.stock-low { color: var(--stock-low); }
.stock-out { color: var(--stock-out); }

.linkbtn {
    width: auto;
    height: auto;
    min-height: 0;
    padding: 4px 2px;
    background: none;
    border: 0;
    color: var(--primary);
    font: 600 14px/1.2 inherit;
    text-decoration: underline;
}

button.danger { background: var(--expense); }

/* ---- Carrito de Nueva venta --------------------------------------------- */

.cart-strip { background: var(--tinted); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; }
.cart-line { display: flex; gap: 8px; align-items: baseline; }
.cart-line .qty { font-weight: 600; }
.cart-line .name { flex: 1; min-width: 0; }

.stepper { display: flex; align-items: center; gap: 2px; }
.stepper button { width: 40px; height: 40px; min-height: 40px; padding: 0; background: none; border: 0; color: var(--primary); }
.stepper .n { min-width: 28px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.total-bar { display: flex; align-items: center; gap: 12px; }
.total-bar .sum { flex: 1; display: flex; flex-direction: column; }
.total-bar .sum strong { font: 700 22px/1.2 inherit; font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---- Barra superior y contenedor de pantallas ---------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 8px;
}

.topbar-actions { display: flex; gap: 2px; align-items: center; }

#screens { display: block; }

/* El tono de la burbuja de una fila sigue el significado de la acción. */
.row-lead.income { color: var(--income); background: color-mix(in srgb, var(--income) 14%, transparent); }
.row-lead.expense { color: var(--expense); background: color-mix(in srgb, var(--expense) 14%, transparent); }
.row-lead.info { color: var(--info); background: color-mix(in srgb, var(--info) 14%, transparent); }
.row-lead.pending { color: var(--pending); background: color-mix(in srgb, var(--pending) 14%, transparent); }
.row-lead.movement { color: var(--movement); background: color-mix(in srgb, var(--movement) 14%, transparent); }

a.row { text-decoration: none; }
a.row:active { background: var(--tinted); }
