:root {
    --ink: #16211f;
    --muted: #687774;
    --surface: #ffffff;
    --canvas: #f4f7f6;
    --line: #dfe8e5;
    --brand: #0f766e;
    --brand-dark: #0a4f4b;
    --brand-soft: #dcf5ef;
    --sidebar: #102c2a;
    --danger: #b42318;
    --shadow: 0 18px 50px rgba(18, 57, 52, .09);
}

* { box-sizing: border-box; }

/* Respaldo mínimo cuando Bootstrap aún no ha sido guardado por el Service Worker. */
.d-none { display: none !important; }
.w-100 { width: 100% !important; }
.text-end { text-align: right !important; }
.text-secondary { color: var(--muted) !important; }
.text-success { color: var(--brand) !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-4 { margin-top: 1.5rem !important; }
.form-label { display: inline-block; margin-bottom: .5rem; font-weight: 650; }
.btn { display: inline-block; border: 1px solid transparent; padding: .65rem 1rem; cursor: pointer; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-lg { padding: .8rem 1.1rem; font-size: 1.05rem; }
.btn-sm { padding: .4rem .65rem; font-size: .85rem; }
.btn-outline-light { border-color: rgba(255,255,255,.7); color: #fff; background: transparent; border-radius: .6rem; }
.alert { margin: 1rem 0; border: 1px solid transparent; border-radius: .8rem; padding: .85rem 1rem; }
.alert-danger { color: #7a271a; background: #fef3f2; border-color: #fecdca; }
.alert-warning { color: #7a2e0e; background: #fffaeb; border-color: #fedf89; }
.alert-success { color: #05603a; background: #ecfdf3; border-color: #abefc6; }
.alert-info { color: #1849a9; background: #eff8ff; border-color: #b2ddff; }
.table-responsive { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .85rem .75rem; vertical-align: middle; text-align: left; }
.table .text-end { text-align: right; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--canvas);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 1rem;
}

button, input { font: inherit; }

.connection-pill {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1100;
    border-radius: 999px;
    padding: .5rem .85rem;
    color: #fff;
    background: #5f6c69;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
    font-size: .82rem;
    font-weight: 700;
}

.connection-pill.online { background: var(--brand); }
.connection-pill.offline { background: #a15c08; }

.login-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
}

.brand-panel {
    position: relative;
    isolation: isolate;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    padding: clamp(3rem, 8vw, 8rem);
    color: #fff;
    background: linear-gradient(145deg, #0a4f4b 0%, #0f766e 55%, #1a9a82 100%);
}

.brand-panel::after {
    content: "";
    position: absolute;
    z-index: -1;
    width: 38rem;
    height: 38rem;
    right: -15rem;
    bottom: -17rem;
    border: 7rem solid rgba(255, 255, 255, .07);
    border-radius: 50%;
}

.brand-mark,
.sidebar-logo,
.empty-icon {
    display: grid;
    place-items: center;
    width: 3.6rem;
    height: 3.6rem;
    border-radius: 1rem;
    color: var(--brand);
    background: #fff;
    font-size: 2.3rem;
    font-weight: 300;
    line-height: 1;
}

.brand-panel h1 {
    max-width: 13ch;
    margin: 1rem 0;
    font-size: clamp(2.5rem, 5vw, 5.3rem);
    line-height: .98;
    letter-spacing: -.055em;
}

.brand-copy {
    max-width: 41rem;
    color: rgba(255, 255, 255, .78);
    font-size: 1.1rem;
}

.brand-points {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    margin-top: 2rem;
}

.brand-points span {
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 999px;
    padding: .55rem .85rem;
    background: rgba(255, 255, 255, .07);
    font-size: .88rem;
    font-weight: 700;
}

.login-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2rem;
    padding: clamp(2rem, 7vw, 7rem);
    background: var(--surface);
}

.login-card h2 { margin: 0; font-size: 2.25rem; letter-spacing: -.04em; }
.login-card form { max-width: 32rem; }
.login-note { max-width: 32rem; color: var(--muted); font-size: .88rem; }

.eyebrow {
    margin: 0 0 .45rem;
    color: inherit;
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.form-control {
    display: block;
    width: 100%;
    min-height: 3rem;
    padding: .65rem .8rem;
    border: 1px solid;
    border-color: #cbd7d4;
    border-radius: .8rem;
    background: #fff;
}

.form-control:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 .25rem rgba(15, 118, 110, .14);
}

.btn-success {
    --bs-btn-bg: var(--brand);
    --bs-btn-border-color: var(--brand);
    --bs-btn-hover-bg: var(--brand-dark);
    --bs-btn-hover-border-color: var(--brand-dark);
    border-radius: .8rem;
    font-weight: 700;
}

.app-shell { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    width: 17rem;
    padding: 1.5rem;
    color: #fff;
    background: var(--sidebar);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .9rem;
    margin-bottom: 2.5rem;
    font-size: .95rem;
    line-height: 1.2;
}

.sidebar-logo { width: 2.8rem; height: 2.8rem; border-radius: .8rem; font-size: 1.8rem; }
.sidebar .nav { gap: .4rem; }
.sidebar .nav-link {
    width: 100%;
    border: 0;
    border-radius: .75rem;
    padding: .85rem 1rem;
    color: rgba(255, 255, 255, .67);
    background: transparent;
    text-align: left;
    font-weight: 700;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active { color: #fff; background: rgba(255, 255, 255, .1); }
.sidebar-footer { margin-top: auto; color: rgba(255, 255, 255, .72); }
.sidebar-footer strong { display: block; margin-top: .15rem; color: #fff; }

.workspace { margin-left: 17rem; min-height: 100vh; padding: 2rem clamp(1.25rem, 4vw, 4rem) 4rem; }

.topbar,
.card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
}

.topbar { margin-bottom: 2rem; }
.topbar h1 { margin: 0; font-size: clamp(2rem, 4vw, 3rem); letter-spacing: -.05em; }
.topbar .eyebrow, .card-heading .eyebrow { color: var(--brand); }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.sync-time { color: var(--muted); font-size: .85rem; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.metric-card,
.content-card,
.pharmacy-card {
    border: 1px solid var(--line);
    border-radius: 1.15rem;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric-card { position: relative; overflow: hidden; padding: 1.25rem; }
.metric-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: .3rem; background: var(--accent); }
.metric-card span { color: var(--muted); font-size: .86rem; font-weight: 700; }
.metric-card strong { display: block; margin: .55rem 0 .25rem; font-size: 2.25rem; letter-spacing: -.05em; }
.metric-card small { color: var(--muted); }
.accent-green { --accent: #0f766e; }
.accent-blue { --accent: #2563eb; }
.accent-amber { --accent: #d97706; }
.accent-purple { --accent: #7c3aed; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(18rem, .65fr); gap: 1rem; }
.content-card { padding: 1.35rem; }
.card-heading { margin-bottom: 1.1rem; }
.card-heading h2 { margin: 0; font-size: 1.25rem; letter-spacing: -.025em; }
.status-chip { border-radius: 999px; padding: .4rem .65rem; color: #0a5b4e; background: var(--brand-soft); font-size: .78rem; font-weight: 800; }

.fefo-item,
.meta-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .95rem 0;
    border-top: 1px solid var(--line);
}

.fefo-item:first-child,
.meta-item:first-child { border-top: 0; }
.item-main strong, .item-main span { display: block; }
.item-main span, .item-meta { color: var(--muted); font-size: .84rem; }
.item-meta { text-align: right; }
.empty-copy { padding: 1.5rem 0; color: var(--muted); text-align: center; }

.table-card { padding-bottom: .5rem; }
.table-search { max-width: 20rem; }
.table { margin: 0; }
.table thead th { border-bottom-color: var(--line); color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.table td { border-color: var(--line); }
.sku { display: block; color: var(--brand); font-size: .8rem; font-weight: 800; }

.pharmacy-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.pharmacy-card { padding: 1.3rem; }
.pharmacy-card h2 { margin: 0 0 .35rem; font-size: 1.1rem; }
.pharmacy-card p { margin: .2rem 0; color: var(--muted); }
.pharmacy-code { display: inline-block; margin-bottom: .8rem; color: var(--brand); font-size: .78rem; font-weight: 800; }

.empty-state { max-width: 48rem; padding: 4rem 2rem; text-align: center; margin: 4rem auto; }
.empty-icon { margin: 0 auto 1.3rem; color: #fff; background: var(--brand); }
.empty-state p { max-width: 38rem; margin: .75rem auto 0; color: var(--muted); }

.offline-page { display: grid; place-items: center; padding: 1.5rem; }
.offline-card { max-width: 34rem; padding: 3rem; border-radius: 1.25rem; background: #fff; box-shadow: var(--shadow); text-align: center; }
.offline-card .brand-mark { margin: 0 auto 1rem; color: #fff; background: var(--brand); }
.offline-card button { border: 0; border-radius: .75rem; padding: .75rem 1.2rem; color: #fff; background: var(--brand); font-weight: 700; }

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .pharmacy-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
    .login-layout { grid-template-columns: 1fr; }
    .brand-panel { min-height: 38vh; padding: 4rem 1.5rem 2.5rem; }
    .brand-panel h1 { font-size: 2.8rem; }
    .brand-copy, .brand-points { display: none; }
    .login-card { min-height: 62vh; padding: 2rem 1.5rem; }

    .app-shell { padding-bottom: 5rem; }
    .sidebar {
        position: fixed;
        inset: auto 0 0;
        width: auto;
        height: 4.6rem;
        padding: .55rem;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, .12);
    }
    .sidebar-brand, .sidebar-footer { display: none; }
    .sidebar .nav { flex-direction: row !important; justify-content: space-around; }
    .sidebar .nav-link { width: auto; padding: .75rem .6rem; text-align: center; font-size: .78rem; }
    .workspace { margin-left: 0; padding: 1.25rem 1rem 2rem; }
    .topbar { align-items: flex-start; }
    .topbar-actions { flex-direction: column-reverse; align-items: flex-end; gap: .35rem; }
    .content-grid, .pharmacy-grid { grid-template-columns: 1fr; }
    .table-search { max-width: 13rem; }
}

@media (max-width: 520px) {
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .metric-card { padding: 1rem; }
    .metric-card strong { font-size: 1.75rem; }
    .metric-card small { display: none; }
    .topbar h1 { font-size: 2rem; }
    .sync-time { max-width: 8rem; text-align: right; }
    .card-heading { align-items: flex-start; }
    .table-search { width: 10rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
