:root {
    /* Marca */
    --blue: #2F6BE0;
    --blue-deep: #1E4FB8;
    --orange: #F2914E;
    --orange-deep: #E5742A;

    /* Pasteles */
    --pastel-blue: #EAF1FE;
    --pastel-orange: #FFF2E6;
    --pastel-green: #E8F6EF;
    --pastel-purple: #F0ECFE;
    --pastel-pink: #FDEEF3;
    --pastel-cyan: #E6F6FA;

    /* Texto */
    --ink: #2A3346;
    --ink-soft: #5B6678;
    --muted: #8A93A6;

    /* Superficies */
    --bg: #F5F7FC;
    --surface: #FFFFFF;
    --line: #EDF1F7;
    --line-soft: #F3F6FB;

    /* Estado */
    --ok: #2BAE76;
    --warn: #E0902C;
    --danger: #E0584F;

    --radius: 18px;
    --radius-sm: 12px;
    --shadow-xs: 0 1px 2px rgba(35,52,90,.05);
    --shadow-sm: 0 4px 16px rgba(35,52,90,.06);
    --shadow: 0 14px 40px rgba(35,52,90,.10);
    --sidebar-w: 248px;
    --topbar-h: 66px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
h1,h2,h3,h4,h5,h6 { color: var(--ink); }

/* ===================== App shell ===================== */
.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w); flex: none; background: var(--surface);
    border-right: 1px solid var(--line); display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px 14px; }
.sidebar .brand img { height: 34px; width: auto; }
.sidebar .brand .txt { font-weight: 800; font-size: 1.05rem; color: var(--ink); letter-spacing:-.2px; }
.sidebar .brand .txt b { color: var(--orange-deep); }
.sidebar .nav-group { padding: 6px 12px; flex: 1; overflow-y: auto; }
.sidebar .nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 14px 12px 6px; font-weight: 700; }
.side-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px;
    color: var(--ink-soft); font-weight: 600; margin-bottom: 2px; transition: all .15s; white-space: nowrap;
}
.side-link svg { width: 19px; height: 19px; flex: none; opacity: .8; }
.side-link:hover { background: var(--line-soft); color: var(--ink); }
.side-link.active { background: var(--pastel-blue); color: var(--blue-deep); }
.side-link.active svg { opacity: 1; }
.sidebar .foot { border-top: 1px solid var(--line); padding: 14px 16px; }
.sidebar .foot .who { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sidebar .foot .who .nm { font-weight: 700; font-size: .85rem; line-height: 1.1; }
.sidebar .foot .who .rl { font-size: .72rem; color: var(--muted); }

/* Main */
.app-main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: var(--topbar-h); background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px; position: sticky; top: 0; z-index: 30;
}
.topbar .title { font-size: 1.15rem; font-weight: 800; letter-spacing: -.3px; }
.content { padding: 26px 28px; flex: 1; }
.content.flush { padding: 16px; }

/* Burger (móvil) */
.burger { display: none; background: none; border: none; font-size: 1.4rem; color: var(--ink); }
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
    .sidebar.open { transform: translateX(0); }
    .app-main { margin-left: 0; }
    .burger { display: block; }
}

/* ===================== Componentes ===================== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 22px 24px; }
.section-title { font-weight: 800; color: var(--ink); letter-spacing: -.2px; }

/* Botones */
.btn { border-radius: 11px; font-weight: 600; padding: .5rem 1rem; border: 1px solid transparent; }
.btn-sm { border-radius: 9px; padding: .35rem .7rem; font-size: .82rem; }
.btn-primary { background: var(--blue); border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-deep); border-color: var(--blue-deep); }
.btn-orange { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-orange:hover { background: var(--orange-deep); border-color: var(--orange-deep); color: #fff; }
.btn-outline-primary { color: var(--blue); border-color: #CFE0FB; background: #fff; }
.btn-outline-primary:hover { background: var(--pastel-blue); border-color: var(--blue); color: var(--blue-deep); }
.btn-outline-secondary { color: var(--ink-soft); border-color: var(--line); background: #fff; }
.btn-outline-secondary:hover { background: var(--line-soft); color: var(--ink); }
.btn-light-soft { background: var(--line-soft); color: var(--ink-soft); }

/* Stat cards */
.stat { display: flex; align-items: center; gap: 16px; padding: 20px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.stat .ico { width: 50px; height: 50px; border-radius: 14px; display: flex; align-items: center; justify-content: center; flex: none; }
.stat .ico svg { width: 24px; height: 24px; }
.stat .num { font-size: 1.9rem; font-weight: 800; line-height: 1; color: var(--ink); }
.stat .lbl { color: var(--muted); font-size: .8rem; font-weight: 600; margin-top: 4px; }
.tint-blue { background: var(--pastel-blue); color: var(--blue-deep); }
.tint-orange { background: var(--pastel-orange); color: var(--orange-deep); }
.tint-green { background: var(--pastel-green); color: var(--ok); }
.tint-purple { background: var(--pastel-purple); color: #6D45D9; }

/* Badges */
.badge { font-weight: 600; padding: .38em .7em; border-radius: 999px; font-size: .74rem; }
.badge-soft { background: var(--line-soft); color: var(--ink-soft); }
.badge-abierta { background: var(--pastel-green); color: var(--ok); }
.badge-nuevo { background: var(--pastel-orange); color: var(--orange-deep); }
.badge-pendiente { background: #FCF1DD; color: var(--warn); }
.badge-cerrada { background: var(--line-soft); color: var(--muted); }
.chip-status { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: .76rem; padding: .3em .7em; border-radius: 999px; }
.chip-status .dot { width: 8px; height: 8px; border-radius: 50%; }

/* Avatares */
.avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: .92rem; }
.avatar.sm { width: 34px; height: 34px; font-size: .78rem; }
.avatar.c1 { background: linear-gradient(135deg,#5B8DEF,#2F6BE0);} .avatar.c2 { background: linear-gradient(135deg,#F7A86A,#E5742A);}
.avatar.c3 { background: linear-gradient(135deg,#56C596,#2BAE76);} .avatar.c4 { background: linear-gradient(135deg,#A78BFA,#7C5CE0);}
.avatar.c5 { background: linear-gradient(135deg,#56C3D6,#2C9CB5);}

/* Tablas */
.table { margin: 0; }
.table thead th { background: transparent; color: var(--muted); font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--line); padding: 12px 16px; }
.table tbody td { padding: 13px 16px; border-top: 1px solid var(--line-soft); color: var(--ink-soft); vertical-align: middle; }
.table tbody tr:hover td { background: var(--line-soft); }
.table.rows-clickable tbody tr { cursor: pointer; }

/* Formularios */
.form-label { font-weight: 600; color: var(--ink-soft); margin-bottom: .3rem; font-size: .85rem; }
.form-control, .form-select { border-radius: 11px; border-color: #DEE6F2; padding: .55rem .85rem; color: var(--ink); background: #FCFDFF; }
.form-control:focus, .form-select:focus { border-color: var(--blue); box-shadow: 0 0 0 .2rem rgba(47,107,224,.12); background: #fff; }
.form-control-sm, .form-select-sm { border-radius: 9px; }
.form-switch .form-check-input:checked { background-color: var(--ok); border-color: var(--ok); }

/* ===================== Login ===================== */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg,#EAF1FE 0%, #F5F7FC 45%, #FFF2E6 100%); padding: 20px; }
.login-card { width: 100%; max-width: 410px; background: var(--surface); border-radius: 24px; padding: 42px 38px; box-shadow: 0 30px 80px rgba(35,52,90,.16); border: 1px solid var(--line); }

/* ===================== Chat ===================== */
.chat-shell { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - var(--topbar-h) - 32px); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); background: var(--surface); }
.inbox-panel { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.inbox-head { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.inbox-search { position: relative; margin-top: 10px; }
.inbox-search input { width: 100%; border: 1px solid var(--line); background: var(--line-soft); border-radius: 999px; padding: 8px 32px 8px 34px; font-size: .85rem; color: var(--ink); outline: none; transition: border-color .12s, background .12s; }
.inbox-search input:focus { border-color: var(--blue); background: #fff; }
.inbox-search input::placeholder { color: var(--muted); }
.inbox-search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .9rem; pointer-events: none; }
.inbox-search .clear { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); border: none; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0; display: none; }
.inbox-search .clear:hover { color: var(--ink); }
.conv-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.conv-filters select { font-size: .78rem; }
.conv-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; align-items: center; }
.conv-tag { font-size: .66rem; font-weight: 700; border-radius: 999px; padding: 1px 8px; background: var(--line-soft); color: var(--ink-soft); white-space: nowrap; }
.conv-tag.muted { background: transparent; color: var(--muted); font-weight: 600; padding: 1px 4px; }
.conv-tag.st-0 { background: #FFF2E6; color: #b4690e; }   /* Pendiente */
.conv-tag.st-1 { background: var(--pastel-blue); color: var(--blue-deep); } /* Abierta */
.conv-tag.st-2 { background: var(--line-soft); color: var(--muted); }       /* Cerrada */
.conv-tag.st-3 { background: var(--pastel-purple); color: #6D45D9; }        /* En bot */
.conv-tag.st-4 { background: var(--pastel-green); color: #157a3c; }         /* Vendida */
.inbox-list { flex: 1; overflow-y: auto; }
.inbox-section { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; background: var(--line-soft); color: var(--muted); font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; position: sticky; top: 0; z-index: 1; }
.inbox-section span { background: #fff; color: var(--ink-soft); border-radius: 999px; padding: 0 7px; font-size: .68rem; }
.inbox-item { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); cursor: pointer; transition: background .12s; }
.inbox-item:hover { background: var(--line-soft); }
.inbox-item.active { background: var(--pastel-blue); }
.inbox-item .body { min-width: 0; flex: 1; }
.inbox-item .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.inbox-item .name { font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item .time { font-size: .7rem; color: var(--muted); flex: none; }
.inbox-item .preview { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item .unread { background: var(--orange); color: #fff; border-radius: 999px; padding: 1px 7px; font-size: .7rem; font-weight: 700; min-width: 19px; text-align: center; }

.chat-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #F7F9FC; position: relative; }

/* Panel lateral de venta que se antepone al chat */
.sale-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: #fff; border-left: 1px solid var(--line); box-shadow: -10px 0 28px rgba(21,32,56,.14); transform: translateX(105%); transition: transform .25s ease; z-index: 30; display: flex; flex-direction: column; }
.sale-panel.open { transform: translateX(0); }
.sale-panel .sale-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.sale-panel .sale-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px 18px; }
.sale-panel .sale-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.sale-panel .sale-section { font-size: .72rem; font-weight: 700; text-transform: uppercase; color: var(--muted); margin: 16px 0 6px; padding-top: 12px; border-top: 1px dashed var(--line); }
.sale-panel .form-label { font-size: .8rem; font-weight: 600; }

/* Drawer lateral genérico (monitoreo) */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(21,32,56,.35); opacity: 0; visibility: hidden; transition: opacity .2s; z-index: 1040; }
.drawer-backdrop.open { opacity: 1; visibility: visible; }
.side-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: #fff; box-shadow: -10px 0 28px rgba(21,32,56,.18); transform: translateX(105%); transition: transform .25s ease; z-index: 1050; display: flex; flex-direction: column; }
.side-drawer.open { transform: translateX(0); }
.side-drawer .sd-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side-drawer .sd-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px; background: #F7F9FC; }
.chat-header { padding: 13px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; background: var(--surface); gap: 12px; flex: none; }
.chat-header .who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 22px 9%; }
.chat-footer { flex: none; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface); }
.chat-footer .form-control { border-radius: 22px; background: var(--line-soft); border-color: transparent; padding: .6rem 1.1rem; }
.chat-footer .form-control:focus { background: #fff; }
.chat-footer .btn { border-radius: 50%; width: 44px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; }
.chat-footer { position: relative; }
.chat-tool { width: 40px; height: 40px; flex: none; border: none; background: var(--line-soft); border-radius: 50%; font-size: 1.1rem; display: flex; align-items: center; justify-content: center; transition: background .15s; }
.chat-tool:hover { background: var(--pastel-blue); }
.chat-pop { position: absolute; bottom: 64px; left: 16px; right: 16px; max-height: 280px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; z-index: 20; }
.quick-item { padding: 9px 12px; border-radius: 10px; cursor: pointer; border-bottom: 1px solid var(--line-soft); }
.quick-item:hover { background: var(--pastel-blue); }
.quick-item .q-title { font-weight: 700; font-size: .82rem; color: var(--blue-deep); }
.quick-item .q-text { font-size: .82rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emoji-pop { display: flex; flex-wrap: wrap; gap: 2px; left: auto; right: 16px; width: 280px; }
.emoji-pop span { font-size: 1.3rem; padding: 4px 6px; cursor: pointer; border-radius: 8px; }
.emoji-pop span:hover { background: var(--line-soft); }
.msg img.media { max-width: 220px; border-radius: 10px; display: block; cursor: pointer; }

.day-sep { text-align: center; margin: 6px 0 14px; }
.day-sep span { background: #fff; color: var(--muted); font-size: .7rem; font-weight: 600; padding: 3px 12px; border-radius: 999px; box-shadow: var(--shadow-xs); }

.msg { max-width: 64%; padding: 8px 12px 5px; border-radius: 14px; margin-bottom: 8px; font-size: .9rem; position: relative; word-wrap: break-word; box-shadow: var(--shadow-xs); clear: both; line-height: 1.4; }
.msg.in { background: #fff; float: left; border-bottom-left-radius: 4px; color: var(--ink); }
.msg.out { background: var(--pastel-blue); float: right; border-bottom-right-radius: 4px; color: #16356f; }
.msg .meta { font-size: .64rem; color: var(--muted); margin-top: 3px; text-align: right; display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.msg .ack { font-weight: 700; }
.msg .ack.read { color: var(--blue); }
.chat-body::after { content: ""; display: block; clear: both; }
.empty-chat { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--muted); text-align: center; padding: 20px; }
