/* ============================================================
   Consultorio de la Amistad — Tema claro
   ============================================================ */

:root {
    --paper:        #F4F3EE;
    --surface:      #FFFFFF;
    --surface-2:    #FBFAF6;
    --ink:          #1B201D;
    --muted:        #6A716A;
    --faint:        #9AA09A;
    --line:         #E6E4DC;
    --line-strong:  #D7D4CA;
    --pine:         #16574C;
    --pine-2:       #1E6E60;
    --pine-tint:    #E6EFEC;
    --mint:         #3FA189;
    --slate:        #4E6173;
    --slate-tint:   #E9EDF1;
    --amber:        #A9761B;
    --amber-tint:   #F6ECD7;
    --rose:         #A23A33;
    --rose-tint:    #F3E0DD;
    --shadow:       0 1px 2px rgba(27,32,29,.04), 0 6px 18px rgba(27,32,29,.06);
    --r:            10px;
    --r-sm:         7px;
    --sans:         "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono:         "Space Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--sans);
    background: var(--paper);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ============================================================
   APP LAYOUT — sidebar + main
   ============================================================ */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

/* ============================================================
   RAIL (sidebar)
   ============================================================ */
.rail {
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 6px 18px;
}
.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--pine);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 18px;
    flex: 0 0 auto;
}
.brand-text b { font-weight: 700; font-size: 16px; line-height: 1.1; display: block; }
.brand-text span { display: block; font-size: 13px; color: var(--faint); font-weight: 500; margin-top: 1px; }

.rail-doctor {
    margin: 0 2px 16px;
    padding: 12px 14px;
    border-radius: var(--r-sm);
    background: var(--pine);
    color: #fff;
}
.rail-doctor-label {
    display: block;
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255,255,255,.75);
    font-weight: 600;
}
.rail-doctor-name {
    display: block;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.2;
    margin-top: 2px;
    word-break: break-word;
}

.rail-nav { display: flex; flex-direction: column; gap: 2px; }
.rail-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    border-radius: var(--r-sm);
    padding: 11px 12px;
    color: var(--muted);
    font-size: 15px;
    font-weight: 500;
    transition: background .1s, color .1s;
}
.rail-nav a svg { width: 20px; height: 20px; flex: 0 0 auto; stroke: currentColor; fill: none; stroke-width: 1.7; }
.rail-nav a:hover { background: var(--surface-2); color: var(--ink); }
.rail-nav a.active { background: var(--pine-tint); color: var(--pine); font-weight: 600; }
.rail-nav a.active svg { stroke: var(--pine); }
.rail-sep { height: 1px; background: var(--line); margin: 10px 4px; }
.rail-section-label {
    font-size: 12px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--faint);
    padding: 4px 12px 2px;
    font-weight: 600;
}

.rail-user {
    margin-top: auto;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface-2);
}
.rail-user .name { font-weight: 600; font-size: 15px; }
.rail-user .role { font-size: 13px; color: var(--pine); font-weight: 600; margin-top: 1px; }
.rail-user .logout { display: block; font-size: 13px; color: var(--muted); margin-top: 6px; }
.rail-user .logout:hover { color: var(--rose); }

/* ============================================================
   MAIN AREA
   ============================================================ */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 16px 28px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }
.topbar-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.screen { padding: 20px 28px 40px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    border: 1px solid var(--pine);
    background: var(--pine);
    color: #fff;
    border-radius: var(--r-sm);
    padding: 11px 18px;
    font-weight: 600;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background .1s, border-color .1s;
    line-height: 1;
    white-space: nowrap;
}
.btn:hover { background: var(--pine-2); border-color: var(--pine-2); }
.btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; flex: 0 0 auto; }
.btn-ghost {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
}
.btn-ghost:hover { border-color: var(--pine); color: var(--pine); background: var(--surface); }
.btn-danger { background: var(--rose); border-color: var(--rose); }
.btn-danger:hover { background: #8a302a; border-color: #8a302a; }
.btn-sm { padding: 8px 13px; font-size: 13px; }

.iconbtn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    border-radius: var(--r-sm);
    display: grid;
    place-items: center;
    color: var(--muted);
    cursor: pointer;
    transition: border-color .1s, color .1s;
}
.iconbtn:hover { border-color: var(--pine); color: var(--pine); }
.iconbtn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.9; }

/* ============================================================
   DATENAV
   ============================================================ */
.datenav { display: flex; align-items: center; gap: 8px; }
.datenav-date { font-family: var(--mono); font-size: 16px; font-weight: 700; padding: 0 6px; }

/* ============================================================
   DOCTOR TABS
   ============================================================ */
.doctabs { display: flex; gap: 3px; position: relative; z-index: 2; }
.doctab {
    border: 1px solid var(--line);
    border-bottom: 0;
    background: var(--surface-2);
    color: var(--muted);
    border-radius: 8px 8px 0 0;
    padding: 11px 20px 12px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    cursor: pointer;
    font-family: inherit;
    transition: color .1s, background .1s;
}
.doctab small { font-weight: 500; font-size: 13px; color: var(--faint); }
.doctab:hover { color: var(--ink); }
.doctab.on { background: var(--surface); color: var(--ink); box-shadow: 0 -2px 0 var(--pine) inset; }
.doctab.on small { color: var(--pine); }

.doctor-select {
    width: 100%;
    max-width: 420px;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    padding: 11px 14px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    background: var(--surface);
    color: var(--ink);
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color .15s;
}
.doctor-select:focus { outline: none; border-color: var(--pine); }

/* ============================================================
   LEDGER
   ============================================================ */
.ledger-wrap {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0 10px 10px 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.lhead, .lrow {
    display: grid;
    grid-template-columns: 100px 64px 1fr 1fr 1.3fr 120px 90px;
    align-items: center;
}
.lhead {
    padding: 0 6px;
    border-bottom: 1.5px solid var(--line-strong);
    background: var(--surface-2);
}
.lhead div {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--faint);
    font-weight: 700;
    padding: 11px 8px;
}
.ledger { display: flex; flex-direction: column; }
.lrow {
    border-left: 3px solid transparent;
    border-top: 1px solid var(--line);
    padding-right: 6px;
    transition: background .08s;
}
.lrow:first-child { border-top: 0; }
.lrow:hover { background: var(--surface-2); }
.lrow.dragging { opacity: .4; }
.lrow.drag-over { box-shadow: inset 0 2px 0 var(--pine); }
.lrow > div { padding: 11px 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.l-hora { font-family: var(--mono); font-weight: 700; font-size: 15px; }
.l-ap { font-weight: 600; font-size: 15px; }
.l-nom { color: var(--muted); font-size: 15px; }
.l-tipos { font-size: 14px; }
.l-acts { display: flex; gap: 4px; padding: 0 2px !important; }

.ib {
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 6px;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background .1s, color .1s;
}
.ib svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.ib:hover { background: var(--pine-tint); color: var(--pine); }
.ib.del:hover { background: var(--rose-tint); color: var(--rose); }
.ib.pri { background: var(--pine); color: #fff; }
.ib.pri:hover { background: var(--pine-2); }
.ib.grip { cursor: grab; }
.l-acts .ib { opacity: .5; }
.lrow:hover .l-acts .ib { opacity: 1; }

/* Tooltip propio para los botones .ib (más rápido que el nativo del navegador,
   usa el mismo atributo title así no hay que duplicar el texto en markup). */
.ib[title] { position: relative; }
.ib[title]::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 7px);
    left: 50%;
    transform: translateX(-50%) translateY(2px);
    background: var(--ink);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    padding: 5px 9px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    z-index: 20;
    transition: opacity .12s, transform .12s;
}
.ib[title]::before {
    content: "";
    position: absolute;
    bottom: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--ink);
    pointer-events: none;
    opacity: 0;
    z-index: 20;
    transition: opacity .12s;
}
.ib[title]:hover::after,
.ib[title]:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.ib[title]:hover::before,
.ib[title]:focus-visible::before { opacity: 1; }

/* estado border */
.r-age  { border-left-color: var(--slate); }
.r-ate  { border-left-color: var(--mint); }
.r-cob  { border-left-color: var(--pine); }
.r-sob  { border-left-color: var(--amber); }
.r-no   { border-left-color: var(--faint); }
.r-no .l-ap { text-decoration: line-through; color: var(--faint); }
.r-baj  { border-left-color: var(--rose); }
.r-baj .l-ap { text-decoration: line-through; color: var(--rose); }

.ledger-addrow {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 0;
    background: var(--surface-2);
    color: var(--muted);
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 600;
    border-top: 1px solid var(--line);
    cursor: pointer;
    font-family: inherit;
    transition: background .1s, color .1s;
}
.ledger-addrow:hover { background: var(--pine-tint); color: var(--pine); }
.ledger-addrow svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

.ledger-hint { font-size: 13px; color: var(--faint); margin: 10px 2px 0; }

/* ============================================================
   CHIPS
   ============================================================ */
.chip {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.chip-cob  { background: var(--pine-tint); color: var(--pine); }
.chip-no   { background: #EEEDE8; color: var(--faint); }
.chip-baj  { background: var(--rose-tint); color: var(--rose); }
.chip-ate  { background: rgba(63,161,137,.15); color: var(--mint); }
.chip-sob  { background: var(--amber-tint); color: var(--amber); }
.chip-age  { background: var(--slate-tint); color: var(--slate); }
.price-tag { font-family: var(--mono); font-weight: 700; font-size: 12.5px; }

/* ============================================================
   TOTBAR
   ============================================================ */
.totbar {
    margin-top: 14px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 26px;
    flex-wrap: wrap;
    box-shadow: var(--shadow);
}
.totbar-date { font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--muted); }
.totbar-item { display: flex; flex-direction: column; line-height: 1.1; }
.totbar-item small {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--faint);
    font-weight: 600;
    margin-bottom: 3px;
}
.totbar-item b { font-family: var(--mono); font-size: 19px; font-weight: 700; }
.totbar-item.grow { margin-left: auto; }
.totbar-item.green b { color: var(--pine); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow);
}
.card-head {
    padding: 15px 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 10px;
}
.card-head h3 { font-size: 14px; font-weight: 700; }
.card-head .hint { font-size: 12px; color: var(--muted); }
.card-body { padding: 6px 18px 14px; }

/* ============================================================
   KPIs
   ============================================================ */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.kpi {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 15px 16px;
    box-shadow: var(--shadow);
}
.kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.kpi-value { font-family: var(--mono); font-size: 22px; font-weight: 700; letter-spacing: -1px; margin-top: 8px; }
.kpi-value.pos { color: var(--pine); }
.kpi-value.neg { color: var(--rose); }
.kpi-detail { font-size: 11.5px; margin-top: 3px; color: var(--faint); }

/* ============================================================
   SPLIT (totales)
   ============================================================ */
.split {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 9px 15px;
    margin-bottom: 12px;
}
.split-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 15px;
}
.split-row .k { color: var(--muted); }
.split-row .v { font-family: var(--mono); font-weight: 700; }
.split-row.big { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 9px; }
.split-row.big .k { color: var(--ink); font-weight: 700; }
.split-row.big .v { font-size: 16px; }

/* ============================================================
   GRID
   ============================================================ */
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }

/* ============================================================
   TABLES
   ============================================================ */
table { width: 100%; border-collapse: collapse; }
th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--faint);
    font-weight: 600;
    text-align: left;
    padding: 13px 10px 10px;
}
td { padding: 13px 10px; border-top: 1px solid var(--line); font-size: 15px; }
td.num, th.num { text-align: right; font-family: var(--mono); font-weight: 700; }
tr:hover td { background: var(--surface-2); }
.totrow td { border-top: 2px solid var(--line-strong); font-weight: 700; background: var(--surface-2); }

/* ============================================================
   MODAL
   ============================================================ */
.scrim {
    position: fixed;
    inset: 0;
    background: rgba(20,24,21,.42);
    backdrop-filter: blur(2px);
    display: none;
    z-index: 30;
    align-items: center;
    justify-content: center;
    padding: 24px 18px;
}
.scrim.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: 14px;
    width: 100%;
    max-width: 470px;
    max-height: calc(100vh - 48px);
    box-shadow: 0 24px 60px rgba(20,24,21,.28);
    overflow: hidden;
    animation: pop .16s ease-out;
    display: flex;
    flex-direction: column;
}
@keyframes pop {
    from { transform: translateY(8px) scale(.99); opacity: 0; }
    to   { transform: none; opacity: 1; }
}
.modal-head {
    padding: 13px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}
.modal-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--pine-tint);
    color: var(--pine);
    display: grid;
    place-items: center;
    font-weight: 700;
    flex: 0 0 auto;
    font-size: 16px;
}
.modal-icon svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }
.modal-title { font-weight: 700; font-size: 18px; }
.modal-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.modal-close {
    margin-left: auto;
    width: 30px; height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    display: grid;
    place-items: center;
}
.modal-close:hover { border-color: var(--rose); color: var(--rose); }
.modal-body { padding: 12px 20px 14px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-foot {
    padding: 11px 20px;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
    background: var(--surface-2);
}
.modal-foot .btn { flex: 1; justify-content: center; }

/* ============================================================
   FORM FIELDS (modal)
   ============================================================ */
.field { margin-bottom: 11px; }
.lbl {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--faint);
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
}
.field input, .field select, .field textarea {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    padding: 12px 14px;
    font-family: inherit;
    font-size: 15px;
    background: var(--surface);
    color: var(--ink);
    transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--pine);
}
.field textarea { resize: vertical; min-height: 70px; }
.hint-line { font-size: 11.5px; color: var(--faint); margin-top: 6px; }
.frow { display: flex; gap: 10px; }
.frow .field { flex: 1; }

/* tipo atención checkboxes */
.ttip-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.ttip {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1.5px solid var(--line);
    background: var(--surface);
    border-radius: var(--r-sm);
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    width: 100%;
    font-family: inherit;
    transition: border-color .1s, background .1s;
}
.ttip-name { font-weight: 600; font-size: 15px; }
.ttip-price { margin-left: auto; font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--muted); }
.ttip-box {
    width: 18px; height: 18px;
    border: 1.5px solid var(--line-strong);
    border-radius: 5px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 12px;
    flex: 0 0 auto;
}
.ttip.on { border-color: var(--pine); background: var(--pine-tint); }
.ttip.on .ttip-box { background: var(--pine); border-color: var(--pine); }
.ttip.on .ttip-price { color: var(--pine); }

.tt-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 11px 14px;
    font-size: 13px;
}
.tt-total b { font-family: var(--mono); font-size: 16px; }

/* cobro presets */
.presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-bottom: 12px; }
.preset {
    border: 1.5px solid var(--line);
    background: var(--surface);
    border-radius: var(--r-sm);
    padding: 8px 12px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    transition: border-color .1s, background .1s;
}
.preset:hover { border-color: var(--line-strong); }
.preset.on { border-color: var(--pine); background: var(--pine-tint); }
.preset-title { font-weight: 700; font-size: 15px; }
.preset-sub { font-size: 13px; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.preset.on .preset-sub { color: var(--pine); }

/* medio pago */
.pay-row { display: flex; gap: 8px; }
.pay-btn {
    flex: 1;
    border: 1.5px solid var(--line);
    background: var(--surface);
    border-radius: var(--r-sm);
    padding: 10px;
    font-weight: 600;
    font-size: 15px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: border-color .1s, background .1s, color .1s;
}
.pay-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.pay-btn.on { border-color: var(--pine); background: var(--pine-tint); color: var(--pine); }

/* items list */
.items-list {
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    overflow: hidden;
    margin-bottom: 12px;
}
.item-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
}
.item-row:last-child { border-bottom: 0; }
.item-name { font-weight: 600; font-size: 15px; }
.item-desc { font-size: 13px; color: var(--muted); }
.item-price { margin-left: auto; font-family: var(--mono); font-weight: 700; font-size: 15px; }

/* ============================================================
   ALERTS / FLASH
   ============================================================ */
.flash-container { padding: 0 28px; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 13px 16px; border-radius: var(--r-sm); font-size: 15px; font-weight: 500; }
.flash-success { background: var(--pine-tint); color: var(--pine); border: 1px solid #b8d9d2; }
.flash-error   { background: var(--rose-tint); color: var(--rose); border: 1px solid #e8c0bc; }
.flash-info    { background: var(--slate-tint); color: var(--slate); border: 1px solid #c8d4de; }
.flash-warn    { background: var(--amber-tint); color: var(--amber); border: 1px solid #e6d3a3; }

/* ============================================================
   FORMS (pages)
   ============================================================ */
.page-form {
    max-width: 640px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 24px;
    box-shadow: var(--shadow);
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem 1rem; }
.form-group { display: flex; flex-direction: column; gap: .2rem; margin-bottom: 14px; }
.form-group label {
    font-size: 12px;
    font-weight: 700;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: .06em;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    padding: 12px 14px;
    font-family: inherit;
    font-size: 15px;
    background: var(--surface);
    color: var(--ink);
    box-sizing: border-box;
    transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--pine); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group small { font-size: 11.5px; color: var(--faint); }
.form-optional { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--faint); }
.form-actions { display: flex; gap: .75rem; margin-top: 20px; }

/* pac search */
.pac-search-wrap { position: relative; }
.pac-search-results {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
    background: var(--surface);
    border: 1.5px solid var(--pine);
    border-radius: var(--r-sm);
    margin-top: 2px;
    max-height: 320px; overflow-y: auto; display: none;
    box-shadow: var(--shadow);
}
.pac-search-results.open { display: block; }
.pac-result-item {
    padding: .75rem 1rem; cursor: pointer; font-size: 15px;
    border-bottom: 1px solid var(--line);
    transition: background .1s;
}
.pac-result-item:hover { background: var(--pine-tint); color: var(--pine); }
.pac-result-item:last-child { border-bottom: none; }

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 16px;
}
.page-header h1 { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.page-header p { font-size: 15px; color: var(--muted); margin-top: 4px; }

/* ============================================================
   FILTER BAR
   ============================================================ */
.filter-bar {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}
.filter-input {
    flex: 1;
    min-width: 180px;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    padding: 12px 15px;
    font-family: inherit;
    font-size: 18px;
    background: var(--surface);
    color: var(--ink);
    transition: border-color .15s;
}
.filter-input:focus { outline: none; border-color: var(--pine); }
.hist-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 5px;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    padding: .75rem 0 .25rem;
}
.pagination-current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 .6rem;
    background: var(--pine);
    color: #fff;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 700;
}
.pagination-ellipsis { color: var(--muted); padding: 0 .25rem; font-size: 13px; }

/* ============================================================
   DETALLE DL
   ============================================================ */
.detalle-grid { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
.detalle-dl { display: flex; flex-direction: column; }
.detalle-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.detalle-row:last-child { border-bottom: 0; }
.detalle-row dt { color: var(--muted); font-weight: 500; white-space: nowrap; }
.detalle-row dd { font-weight: 600; text-align: right; word-break: break-all; }

/* Datos del afiliado en columnas horizontales (etiqueta arriba, valor abajo) */
.datos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 28px; }
.datos-field { display: flex; flex-direction: column; gap: 3px; padding: .4rem 0; border-bottom: 1px solid var(--line); min-width: 0; }
.datos-field dt { color: var(--muted); font-weight: 500; font-size: 13px; }
.datos-field dd { font-weight: 600; font-size: 16px; word-break: break-word; }

/* Edición inline de datos de contacto */
.campo-edit {
    display: none; width: 100%; box-sizing: border-box;
    border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
    padding: 7px 10px; font-family: inherit; font-size: 15px;
    background: var(--surface); color: var(--ink);
}
.campo-edit:focus { outline: none; border-color: var(--pine); }
.chip-manual {
    font-size: 10px; font-weight: 700; color: var(--pine); background: var(--pine-tint);
    padding: 1px 6px; border-radius: 6px; margin-left: 5px; vertical-align: middle;
    cursor: help;
}
.chip-ex {
    font-size: 12px; font-weight: 700; color: var(--amber); background: var(--amber-tint);
    padding: 2px 9px; border-radius: 6px; margin-left: 8px; vertical-align: middle;
    text-transform: uppercase; cursor: help;
}
#formDatos.editando .campo-view { display: none; }
#formDatos.editando .campo-edit { display: block; }

/* Tablas de órdenes y recetas dentro del detalle del paciente: letra más grande */
.detalle-grid .admin-table td { font-size: 16px; }
.detalle-grid .admin-table th { font-size: 13px; }

/* Altura fija para que los botones de paginación no salten al cambiar de página.
   Si una página tiene filas más altas (práctica larga), scrollea dentro. */
.tabla-scroll { height: 22rem; overflow-y: auto; margin-bottom: 12px; }
.tabla-scroll .admin-table thead th {
    position: sticky; top: 0; background: var(--surface); z-index: 1;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-icon { font-size: 2.5rem; margin-bottom: 1rem; }

/* ============================================================
   ADMIN TABLE (pacientes lista etc)
   ============================================================ */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--faint);
    font-weight: 600;
    text-align: left;
    padding: 13px 10px 10px;
}
.admin-table td { padding: 13px 10px; border-top: 1px solid var(--line); font-size: 15px; }
.admin-table th.num { text-align: right; }

.card { overflow: hidden; }
.admin-table tr:hover td { background: var(--surface-2); }
.text-muted { color: var(--muted); }
.action-btns { display: flex; gap: .4rem; flex-wrap: wrap; }

.copy-btn {
    border: none; background: transparent; cursor: pointer;
    line-height: 0; padding: 4px; border-radius: 5px;
    vertical-align: middle; margin-left: 5px; color: var(--faint);
    transition: color .1s, background .1s;
}
.copy-btn svg { width: 15px; height: 15px; display: block; }
.copy-btn:hover { color: var(--pine); background: var(--pine-tint); }
.copy-btn.copied { color: var(--pine); background: var(--pine-tint); }

.qr-btn {
    border: none; background: transparent; cursor: pointer;
    line-height: 0; padding: 4px; border-radius: 5px;
    vertical-align: middle; margin-left: 3px; color: var(--faint);
    transition: color .1s, background .1s;
}
.qr-btn svg { width: 16px; height: 16px; display: block; }
.qr-btn:hover { color: var(--pine); background: var(--pine-tint); }

.qr-modal-body { text-align: center; }
.qr-modal-img {
    width: 320px; height: 320px; max-width: 100%;
    image-rendering: pixelated;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
    padding: 8px;
}
.qr-modal-name { margin-top: 12px; font-weight: 700; font-size: 16px; }
.qr-modal-code { margin-top: 2px; font-family: var(--mono); font-size: 13px; color: var(--muted); }

.chip-reciente {
    font-size: 13px; font-weight: 700; color: var(--amber); background: var(--amber-tint);
    padding: 3px 10px; border-radius: 6px; margin-left: 6px; white-space: nowrap;
    vertical-align: middle; text-transform: uppercase;
}

.row-reciente { background: var(--amber-tint); }
.row-reciente:hover { background: var(--amber-tint); filter: brightness(0.97); }

.historia-list { display: flex; flex-direction: column; gap: 7px; }
.historia-entry {
    border: 1px solid var(--line); border-left: 3px solid var(--mint);
    border-radius: 8px; overflow: hidden; background: var(--surface);
}
.historia-entry.abierto { border-left-color: var(--pine); }

/* Fila colapsada: una sola línea clickeable */
.historia-entry-row {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer;
    transition: background .1s;
}
.historia-entry-row:hover { background: var(--surface-2); }
.hc-row-arrow { color: var(--faint); font-size: 12px; transition: transform .12s; flex-shrink: 0; }
.historia-entry.abierto .hc-row-arrow { transform: rotate(90deg); }
.hc-row-fecha {
    color: var(--pine); font-weight: 600; font-size: 13px; white-space: nowrap; flex-shrink: 0;
    background: var(--pine-tint); padding: 3px 9px; border-radius: 20px; font-variant-numeric: tabular-nums;
}
.hc-row-resumen {
    flex: 1; min-width: 0; font-size: 15px; color: var(--ink);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hc-row-clip { flex-shrink: 0; font-size: 13px; }
.hc-row-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* Vista expandida: cada campo con su etiqueta de color */
.historia-entry-vista { padding: 8px 14px 14px; }
.hc-vista-field { margin-bottom: 11px; }
.hc-vista-field:last-child { margin-bottom: 0; }
.hc-tag {
    display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .04em; padding: 2px 8px; border-radius: 5px; margin-bottom: 4px;
}
.hc-tag-motivo { background: var(--slate-tint); color: var(--slate); }
.hc-tag-examen { background: var(--pine-tint);  color: var(--pine); }
.hc-tag-dx     { background: var(--rose-tint);  color: var(--rose); }
.hc-tag-tto    { background: var(--amber-tint); color: var(--amber); }
.hc-tag-obs    { background: var(--surface-2);  color: var(--muted); border: 1px solid var(--line); }
.hc-vista-field p { font-size: 15px; white-space: pre-wrap; color: var(--ink); }

/* Formulario: una sola columna ancha; fecha angosta */
.historia-entry-edit { margin: 0 14px 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.hc-stack { display: flex; flex-direction: column; gap: 11px; }
.hc-field { min-width: 0; }
.hc-field-fecha .hc-input { max-width: 240px; }
.hc-field-label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 0 4px; }

.hc-input {
    display: block; width: 100%; border: 1.5px solid var(--line); border-radius: var(--r-sm);
    padding: 8px 11px; font-family: inherit; font-size: 16px; background: var(--surface);
    color: var(--ink); transition: border-color .15s, box-shadow .15s; resize: vertical; line-height: 1.45;
}
.hc-input:focus { outline: none; border-color: var(--pine); box-shadow: 0 0 0 3px var(--pine-tint); }

/* Progressive disclosure: "+ Más campos" */
.hc-more { display: none; flex-direction: column; gap: 11px; }
.hc-more.abierto { display: flex; }
.hc-more-toggle {
    align-self: flex-start; background: none; border: none; color: var(--pine);
    font-weight: 600; font-size: 14px; padding: 2px 0; cursor: pointer;
}
.hc-more-toggle:hover { color: var(--pine-2); text-decoration: underline; }

/* Resumen del año en curso */
.resumen-anual-box {
    border: 1.5px solid var(--line); border-radius: var(--r-sm);
    background: var(--surface-2); padding: 14px 16px; margin-bottom: 16px;
}
.resumen-anual-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; flex-wrap: wrap; margin-bottom: 8px;
}
.resumen-anual-texto { line-height: 1.55; font-size: 15px; background: var(--surface); }

.historia-adjuntos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip-adjunto {
    display: inline-flex; align-items: center; gap: 4px; font-size: 13px;
    background: var(--surface-2); border-radius: 6px; padding: 3px 4px 3px 8px;
}
.chip-adjunto a { color: var(--pine); text-decoration: none; }
.chip-adjunto a:hover { text-decoration: underline; }
.chip-adjunto-borrar {
    border: none; background: transparent; cursor: pointer; color: var(--faint);
    padding: 2px 4px; border-radius: 4px; line-height: 1;
}
.chip-adjunto-borrar:hover { color: var(--pine); background: var(--pine-tint); }

.file-upload-btn {
    position: relative; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
    padding: 8px 14px; font-size: 14px; font-weight: 600; color: var(--ink);
    transition: background .1s, border-color .1s;
}
.file-upload-btn:hover { background: var(--pine-tint); border-color: var(--pine); }
.file-upload-btn input[type="file"] {
    position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none;
}

.ficha-fisica-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px;
}
.ficha-fisica-item { position: relative; }
.ficha-fisica-thumb {
    display: flex; align-items: center; justify-content: center; aspect-ratio: 1;
    border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden;
    background: var(--surface-2);
}
.ficha-fisica-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ficha-fisica-pdf { font-size: 34px; color: var(--rose); }
.ficha-fisica-borrar {
    position: absolute; top: 4px; right: 4px; border: none; border-radius: 50%;
    width: 22px; height: 22px; background: rgba(27,32,29,.55); color: #fff;
    cursor: pointer; line-height: 1; font-size: 13px;
}
.ficha-fisica-borrar:hover { background: var(--rose); }

#hcToggle:hover h2 { color: var(--pine); }
.hc-toggle-arrow { font-size: 20px; color: var(--muted); transition: color .1s; }
#hcToggle:hover .hc-toggle-arrow { color: var(--pine); }

.link-primary { color: var(--pine); font-weight: 600; }
.link-primary:hover { color: var(--pine-2); }
.link-wa { color: var(--mint); font-weight: 600; }
.link-wa:hover { color: var(--pine); }

/* ============================================================
   ALERTS (inline)
   ============================================================ */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
}
.alert-success { background: var(--pine-tint); color: var(--pine); border: 1px solid #b8d9d2; }
.alert-error   { background: var(--rose-tint); color: var(--rose); border: 1px solid #e8c0bc; }

/* ============================================================
   MOBILE (hamburger replaced by simplified rail)
   ============================================================ */
@media (max-width: 880px) {
    .app { grid-template-columns: 1fr; }
    .rail {
        position: static;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 10px 14px;
    }
    .rail-user { display: none; }
    .rail-nav { flex-direction: row; flex-wrap: wrap; }
    .rail-sep, .rail-section-label { display: none; }
    .brand { padding: 0 10px 0 0; border-right: 1px solid var(--line); margin-right: 6px; }
    .kpis { grid-template-columns: repeat(2, 1fr); }
    .grid2 { grid-template-columns: 1fr; }
    .detalle-grid { grid-template-columns: 1fr; }
    .lhead, .lrow { grid-template-columns: 90px 56px 1fr .9fr 1.1fr 90px 80px; }
    .screen { padding: 16px 16px 40px; }
    .topbar { padding: 12px 16px; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
}

@media (max-width: 640px) {
    .kpis { grid-template-columns: 1fr 1fr; }
    .doctabs { overflow-x: auto; }
}

/* ============================================================
   MULTI-SELECT (especialidades médico)
   ============================================================ */
.ms-container {
    position: relative;
    user-select: none;
}
.ms-display {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    padding: 8px 12px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color .15s;
}
.ms-container.ms-open .ms-display,
.ms-display:hover { border-color: var(--pine); }
.ms-tags { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.ms-placeholder { color: var(--faint); font-size: 15px; }
.ms-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--pine-tint);
    color: var(--pine);
    border-radius: 20px;
    padding: 3px 10px 3px 12px;
    font-size: 13px;
    font-weight: 600;
}
.ms-tag-remove {
    border: none;
    background: none;
    color: var(--pine);
    cursor: pointer;
    font-size: 13px;
    padding: 0;
    line-height: 1;
    opacity: .7;
}
.ms-tag-remove:hover { opacity: 1; }
.ms-arrow { color: var(--faint); font-size: 12px; flex: 0 0 auto; }

.ms-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--surface);
    border: 1.5px solid var(--pine);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow);
    z-index: 20;
    overflow: hidden;
}
.ms-container.ms-open .ms-dropdown { display: block; }
.ms-search {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--line);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    background: var(--surface-2);
    color: var(--ink);
    outline: none;
}
.ms-options {
    list-style: none;
    max-height: 220px;
    overflow-y: auto;
}
.ms-option {
    padding: 11px 14px;
    font-size: 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
    transition: background .1s;
}
.ms-option:last-child { border-bottom: 0; }
.ms-option:hover { background: var(--surface-2); }
.ms-option.ms-selected { background: var(--pine-tint); color: var(--pine); font-weight: 600; }
.ms-option.ms-option-ecografo { font-weight: 700; }
.ms-option.ms-hidden { display: none; }

/* bottom sheet (mobile) */
.ss-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 100;
}
.ss-backdrop.ss-active { display: block; }
.ss-sheet {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-radius: 18px 18px 0 0;
    z-index: 101;
    transform: translateY(100%);
    transition: transform .25s ease;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}
.ss-sheet.ss-active { transform: translateY(0); }
.ss-sheet-handle {
    width: 40px; height: 4px;
    background: var(--line-strong);
    border-radius: 2px;
    margin: 12px auto 0;
    flex: 0 0 auto;
}
.ss-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    flex: 0 0 auto;
}
.ss-sheet-title { font-weight: 700; font-size: 16px; }
.ss-sheet-close {
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 8px;
    width: 32px; height: 32px;
    font-size: 14px;
    cursor: pointer;
    display: grid;
    place-items: center;
    color: var(--muted);
}
.ss-sheet-search-wrap { padding: 10px 14px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.ss-sheet-search {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 15px;
    background: var(--surface);
    color: var(--ink);
    outline: none;
}
.ss-sheet-search:focus { border-color: var(--pine); }
.ss-sheet-list { list-style: none; overflow-y: auto; flex: 1; }
.ss-sheet-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    font-size: 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--line);
}
.ss-sheet-option:hover { background: var(--surface-2); }
.ss-sheet-option.ss-sheet-selected { color: var(--pine); font-weight: 600; }
.ss-sheet-check { color: var(--pine); font-weight: 700; visibility: hidden; }
.ss-sheet-option.ss-sheet-selected .ss-sheet-check { visibility: visible; }
.ss-sheet-option.ss-sheet-hidden { display: none; }
