:root {
    --primary: #14b8a6;
    --primary-strong: #0d9488;
    --primary-soft: color-mix(in srgb, var(--primary) 14%, transparent);
    --secondary: #2563eb;
    --secondary-soft: color-mix(in srgb, var(--secondary) 14%, transparent);
    --accent: #f97316;
    --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface2: #eef1f7;
    --text: #131a26;
    --muted: #64748b;
    --border: #dfe4ec;
    --danger: #dc2626;
    --danger-soft: color-mix(in srgb, var(--danger) 12%, transparent);
    --success: #059669;
    --success-soft: color-mix(in srgb, var(--success) 12%, transparent);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(18, 22, 34, .05);
    --shadow-md: 0 10px 26px -12px rgba(18, 22, 34, .22);
    --transition: 160ms ease;
    --space: clamp(12px, 1.6vw, 24px);
    --tap: clamp(40px, 5vw, 46px);
    --nav-w: clamp(228px, 18vw, 280px);
    --bottomnav-h: 62px;
    font-family: Inter, "Plus Jakarta Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="oscuro"] {
    color-scheme: dark;
    --bg: #10141b;
    --surface: #1a2029;
    --surface2: #232a36;
    --text: #f2f5fa;
    --muted: #97a3b6;
    --border: #303a4a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 14px 30px -14px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body { min-width: 320px; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 800; letter-spacing: -.01em; line-height: 1.2; margin: 0; }
h2 { font-size: clamp(18px, 2.2vw, 21px); display: flex; align-items: center; gap: 8px; }
button, input, select { font: inherit; color: inherit; min-width: 0; }
button { cursor: pointer; transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition); }
button:disabled { cursor: not-allowed; opacity: .5; }
button:active:not(:disabled) { transform: scale(.97); }
:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; }
.icon { display: inline-block; width: 1em; height: 1em; flex: none; vertical-align: -0.15em; }
.icon svg { display: block; width: 100%; height: 100%; }

.boot, .loginScreen { min-height: 100vh; display: grid; place-items: center; padding: clamp(8px, 1vw, 16px); }
.loader, .metric, .ticket, .editor, .row, .empty, .productButton, .reportBox {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}
.loader { padding: clamp(18px, 4vw, 28px); display: grid; gap: 6px; width: min(100%, 360px); }
.loader strong, .brand strong { font-size: clamp(24px, 3vw, 30px); color: var(--primary); line-height: 1; }
.loader span, .muted, .topbar span, .brand span, small { color: var(--muted); }
small { font-size: 12px; }

/* App shell */
.appShell {
    min-height: 100vh;
    width: 100%;
    display: grid;
    grid-template-columns: var(--nav-w) minmax(0, 1fr);
}
.sidebarBackdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 18;
    background: rgba(10, 14, 22, .45);
}
.sidebarBackdrop.open { display: block; }
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: var(--space);
    display: grid;
    align-content: start;
    gap: clamp(18px, 2vw, 28px);
    min-width: 0;
}
.brand { display: grid; gap: 4px; min-width: 0; }
.brand span { overflow-wrap: anywhere; }
.nav { display: grid; gap: 4px; }
.nav button {
    min-height: var(--tap);
    border: 0;
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    text-align: left;
    padding: 0 12px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav button svg { flex: none; }
.nav button.active, .nav button:hover { background: var(--surface2); color: var(--secondary); }
.nav button.active { border-left-color: var(--secondary); }

.workspace {
    min-width: 0;
    display: grid;
    grid-template-rows: auto 1fr;
}
.topbar {
    position: sticky;
    top: 0;
    z-index: 4;
    min-height: clamp(50px, 6vw, 60px);
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(12px);
    padding: 6px var(--space);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: clamp(8px, 1.4vw, 16px);
}
.topbar > div:not(.topActions) { min-width: 0; }
.topbar strong { font-size: clamp(17px, 2.2vw, 21px); line-height: 1.2; }
.topbar span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topActions { display: flex; gap: 8px; min-width: 0; }
.iconButton {
    min-width: var(--tap);
    height: var(--tap);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
}
.iconButton:hover { border-color: var(--secondary); color: var(--secondary); }

.content, .saleLayout {
    width: 100%;
    padding: var(--space);
}
.content { display: grid; gap: clamp(14px, 2vw, 22px); align-content: start; }

/* Metrics */
.metricGrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
    gap: clamp(10px, 1.4vw, 14px);
}
.metric { padding: clamp(14px, 2vw, 18px); display: grid; gap: 8px; min-width: 0; }
.metric .metricHead { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; }
.metric strong { font-size: clamp(20px, 3vw, 28px); overflow-wrap: anywhere; }
.good strong { color: var(--success); }
.warn strong { color: var(--accent); }
.good .metricHead .icon { color: var(--success); }
.warn .metricHead .icon { color: var(--accent); }

/* Lists / rows */
.list { display: grid; gap: 8px; min-width: 0; }
.row {
    min-height: 54px;
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-width: 0;
    transition: border-color var(--transition), transform var(--transition);
}
.row span { display: grid; gap: 2px; min-width: 0; }
.row strong { text-align: right; overflow-wrap: anywhere; }
.row.compact { min-height: 46px; padding: 10px 12px; }
.row.click { cursor: pointer; }
.row.click:hover { border-color: var(--secondary); }
.row.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.row .rowMain { display: flex; align-items: center; gap: 10px; min-width: 0; }
.thumb, .thumbPlaceholder {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    flex: none;
}
.thumb { object-fit: cover; display: block; }
.thumbPlaceholder { display: grid; place-items: center; background: var(--surface2); color: var(--muted); }
.thumbPlaceholder .icon { width: 18px; height: 18px; }
.empty {
    color: var(--muted);
    border-style: dashed;
    box-shadow: none;
    padding: clamp(18px, 3vw, 24px);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    text-align: center;
}
.empty .icon { color: var(--muted); width: 1.3em; height: 1.3em; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: var(--surface2);
    color: var(--muted);
    white-space: nowrap;
}
.badge.good { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--accent-soft); color: var(--accent); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

.split {
    display: grid;
    grid-template-columns: minmax(min(100%, 320px), 0.42fr) minmax(0, 1fr);
    gap: clamp(14px, 2vw, 20px);
    align-items: start;
}
.productModule { gap: 12px; }
.moduleTabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: thin;
}
.moduleTabs button {
    min-height: 42px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    padding: 0 14px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.moduleTabs button.active { color: var(--secondary); border-bottom-color: var(--secondary); }
.productWorkspace {
    display: grid;
    grid-template-columns: minmax(min(100%, 380px), 0.46fr) minmax(0, 1fr);
    gap: clamp(14px, 2vw, 20px);
    align-items: start;
}
.configColumn {
    display: grid;
    gap: clamp(12px, 1.8vw, 18px);
    min-width: 0;
}
.sectionTitle { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.cashPane, .cashHistory { display: grid; gap: clamp(12px, 1.8vw, 18px); min-width: 0; }
.cashRecord {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: clamp(14px, 2vw, 18px);
    display: grid;
    gap: 12px;
    min-width: 0;
}
.cashRecordHead {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    min-width: 0;
}
.cashRecordHead span:first-child { display: grid; gap: 3px; min-width: 0; }
.cashRecordHead strong { overflow-wrap: anywhere; }
.cashTotals {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
    gap: 8px;
}
.cashTotals span {
    background: var(--surface2);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: grid;
    gap: 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}
.cashTotals strong {
    color: var(--text);
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    text-transform: none;
}

.editor { padding: clamp(16px, 2.2vw, 20px); display: grid; gap: 12px; min-width: 0; }
.editor label, .loginPanel label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
}
input, select {
    width: 100%;
    min-height: var(--tap);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    padding: 0 12px;
    transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus { border-color: var(--secondary); box-shadow: 0 0 0 3px var(--secondary-soft); }
.editor .check, .check {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}
.check input { width: auto; min-height: auto; }
.hidden { display: none !important; }
.editorTabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: thin;
}
.editorTabs button {
    min-height: 36px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
    padding: 0 4px 6px;
    white-space: nowrap;
}
.editorTabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabPanel { display: grid; gap: 12px; }
.imageField { display: grid; gap: 10px; }
.imagePreview {
    width: 96px;
    height: 96px;
    border-radius: var(--radius-md);
    border: 1px dashed var(--border);
    background: var(--surface2);
    display: grid;
    place-items: center;
    overflow: hidden;
    color: var(--muted);
}
.imagePreview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.imagePreview .icon { width: 30px; height: 30px; }
.imageActions { display: flex; gap: 8px; flex-wrap: wrap; }
.fileButton { position: relative; overflow: hidden; }
.fileButton input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    min-height: 0;
}
.primaryButton {
    min-height: var(--tap);
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}
.primaryButton:hover:not(:disabled) { background: var(--primary-strong); }
.secondaryButton {
    min-height: var(--tap);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700;
}
.secondaryButton:hover:not(:disabled) { border-color: var(--secondary); color: var(--secondary); }
.danger { color: var(--danger); }
.success { color: var(--success); }

/* Sale screen */
.saleLayout {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(320px, clamp(340px, 34vw, 520px));
    gap: clamp(14px, 2vw, 22px);
    align-items: start;
}
.saleProducts { display: grid; grid-template-rows: auto 1fr; gap: clamp(10px, 1.5vw, 14px); min-width: 0; }
.searchBox {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    min-height: var(--tap);
    color: var(--muted);
}
.searchBox input { border: 0; outline: 0; min-height: 36px; padding: 0; background: transparent; }
.productGrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, clamp(150px, 22vw, 230px)), 1fr));
    gap: clamp(10px, 1.3vw, 14px);
    align-content: start;
}
.productButton {
    min-height: clamp(96px, 12vw, 118px);
    color: var(--text);
    padding: clamp(12px, 1.6vw, 16px);
    display: grid;
    gap: 6px;
    text-align: left;
    min-width: 0;
    align-content: start;
}
.productButton:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.productButton:active { transform: translateY(0) scale(.97); }
.productButton span { overflow-wrap: anywhere; font-weight: 600; }
.productButton strong { color: var(--primary); font-size: 17px; }
.ticket {
    padding: clamp(16px, 2.2vw, 24px);
    display: grid;
    gap: clamp(12px, 1.8vw, 18px);
    align-content: start;
    position: sticky;
    top: calc(clamp(50px, 6vw, 60px) + var(--space));
    min-width: 0;
}
.ticket h2 { font-size: clamp(20px, 3vw, 24px); display: flex; align-items: center; gap: 8px; }
.ticketItem {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(58px, 8vw, 78px) clamp(86px, 12vw, 112px) 34px;
    align-items: center;
    gap: 8px;
}
.ticketItem span { overflow-wrap: anywhere; font-weight: 600; }
.ticketItem button { border: 0; background: var(--surface2); border-radius: var(--radius-sm); height: 34px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.ticketItem button:hover { background: var(--danger-soft); color: var(--danger); }
.cashShortcut {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface2);
}
.cashShortcut p { margin: 0; display: flex; align-items: center; gap: 8px; }
.cashShortcut label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
}
.totalLine { border-top: 1px solid var(--border); padding-top: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.totalLine strong { font-size: clamp(24px, 4vw, 32px); color: var(--primary); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* Login */
.loginScreen { background: var(--bg); padding: 0; }
.loginSplit {
    width: min(100%, 920px);
    min-height: min(600px, 92vh);
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin: var(--space);
}
.loginBrand {
    background: linear-gradient(155deg, var(--primary), var(--secondary));
    color: #fff;
    padding: clamp(28px, 4vw, 48px);
    display: grid;
    align-content: center;
    gap: 14px;
}
.loginBrand strong { font-size: clamp(28px, 3.6vw, 36px); }
.loginBrand p { margin: 0; color: rgba(255, 255, 255, .88); line-height: 1.6; max-width: 32ch; }
.loginBrand ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.loginBrand li { display: flex; align-items: center; gap: 10px; color: rgba(255, 255, 255, .92); font-weight: 600; font-size: 14px; }
.loginPanel { background: var(--surface); width: 100%; padding: clamp(24px, 5vw, 44px); display: grid; gap: 14px; align-content: center; box-shadow: none; border: 0; border-radius: 0; }
.reportBox { padding: 16px; overflow: auto; white-space: pre-wrap; color: var(--muted); }
.health { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface2); color: var(--muted); overflow-wrap: anywhere; font-size: 13px; }
.stockColumns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
    gap: clamp(14px, 2vw, 20px);
    align-items: start;
}
.stockColumns > div { display: grid; gap: 10px; min-width: 0; }

.reportSummary { display: grid; gap: 10px; }
.reportSummary .row strong { font-variant-numeric: tabular-nums; }

/* Bottom nav (mobile/tablet) */
.bottomNav {
    display: none;
    position: fixed;
    z-index: 15;
    inset: auto 0 0 0;
    height: var(--bottomnav-h);
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    grid-template-columns: repeat(5, 1fr);
}
.bottomNav button {
    border: 0;
    background: transparent;
    color: var(--muted);
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 700;
    height: 100%;
}
.bottomNav button.active { color: var(--secondary); }
.bottomNav button svg { width: 20px; height: 20px; }

@media (min-width: 1180px) {
    .sidebarSheetClose { display: none; }
}

@media (max-width: 1179px) {
    .appShell { grid-template-columns: 1fr; }
    .bottomNav { display: grid; }
    .content, .saleLayout { padding-bottom: calc(var(--bottomnav-h) + var(--space) + env(safe-area-inset-bottom, 0)); }
    .sidebar {
        position: fixed;
        z-index: 20;
        inset: auto 0 0 0;
        max-height: 82vh;
        border-right: 0;
        border-top: 1px solid var(--border);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
        transition: transform .2s ease;
        box-shadow: 0 -18px 40px rgba(0, 0, 0, .22);
        overflow-y: auto;
        padding-bottom: calc(var(--space) + env(safe-area-inset-bottom, 0));
    }
    .sidebar.open { transform: translateY(0); }
    .nav button { border-left: 0; border-radius: var(--radius-sm); }
    .nav button.active { background: var(--secondary-soft); }
    .saleLayout { grid-template-columns: minmax(260px, 0.95fr) minmax(300px, 1.05fr); }
}

@media (max-width: 900px) {
    .loginSplit { grid-template-columns: 1fr; min-height: auto; }
    .loginBrand { display: none; }
}

@media (max-width: 760px) {
    .topActions { gap: 6px; }
    .topActions .iconButton { width: auto; min-width: var(--tap); padding: 0 9px; }
    .saleLayout, .split, .productWorkspace { grid-template-columns: 1fr; }
    .ticket { position: static; min-height: auto; }
    .productGrid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 165px), 1fr)); }
}

@media (max-width: 520px) {
    :root { --space: 12px; }
    .metricGrid, .productGrid { grid-template-columns: 1fr; }
    .row { align-items: stretch; flex-direction: column; }
    .row strong { text-align: left; }
    .ticketItem { grid-template-columns: minmax(0, 1fr) 66px 34px; }
    .ticketItem strong { grid-column: 1 / -1; }
    .bottomNav button span { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        transition-duration: .001ms !important;
    }
}
