/* =====================================================================
   Celeste Portal — diseño según mockup aprobado (agosto 2026).
   Paleta de Celeste: navy #083556, verde acción #10AC84,
   degradado de marca #133EB1 → #66DE9C.
   ===================================================================== */

:root {
    --ground: #f2f7f5;
    --card: #ffffff;
    --ink: #0d2b40;
    --ink-soft: #47606e;
    --muted: #6e8391;
    --line: #d9e4e0;
    --accent: #10ac84;
    --accent-ink: #0b7d61;
    --accent-soft: #e2f5ee;
    --navy: #083556;
    --navy-2: #0d4a75;
    --mint: #64dc9a;
    --danger: #c9504e;
    --chip-ground: #e9f0ed;
    --shadow: 0 1px 2px rgba(8, 53, 86, .06), 0 8px 24px rgba(8, 53, 86, .07);
    --sans: "Segoe UI Variable Text", "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
    --display: "Segoe UI Variable Display", "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); }

.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* ---------- marca ---------- */
.wordmark { display: flex; align-items: center; gap: 10px; }
.cel-logo { flex: none; display: block; }
.cel-word {
    font-family: var(--display);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .28em;
    color: #fff;
    font-size: 19px;
}
.portal-tag {
    font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
    background: rgba(100, 220, 154, .18); color: var(--mint);
    border: 1px solid rgba(100, 220, 154, .4);
    padding: 2px 8px; border-radius: 4px;
}

/* ---------- botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: 600 14px var(--sans); border-radius: 8px; cursor: pointer;
    padding: 10px 18px; border: 1px solid transparent; text-decoration: none;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); }
.btn-ghost { background: var(--card); border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { border-color: var(--muted); color: var(--ink); }
.btn-block { width: 100%; margin-top: 16px; }

/* ---------- login / invitación ---------- */
.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-split {
    display: grid;
    grid-template-columns: 5fr 6fr;
    min-height: 560px;
    max-width: 980px;
    width: 100%;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
    background: var(--card);
}

.login-brand {
    background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 70%, #0f5c8c 100%);
    color: #eaf4f0;
    padding: 44px 40px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}
.login-brand::after {
    content: "";
    position: absolute; right: -80px; bottom: -110px;
    width: 320px; height: 320px; border-radius: 50%;
    background: radial-gradient(circle, rgba(100, 220, 154, .28), transparent 65%);
}
.login-brand h3 {
    font-family: var(--display); font-weight: 600; font-size: 24px; line-height: 1.3;
    margin: auto 0 12px; max-width: 15ch; letter-spacing: -.01em;
}
.login-brand p { margin: 0; color: #b8d2c9; font-size: 13.5px; max-width: 34ch; }
.brand-foot { margin-top: auto; padding-top: 32px; font-size: 12px; color: #8fb0a5; }

.login-form { padding: 48px 48px 32px; display: flex; flex-direction: column; }
.login-form h4 { font-family: var(--display); font-size: 19px; margin: 0 0 4px; }
.login-form .sub { color: var(--muted); font-size: 13.5px; margin: 0 0 26px; }

.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.input {
    width: 100%; border: 1px solid var(--line); border-radius: 8px;
    background: var(--ground); color: var(--ink);
    font: 14px var(--sans); padding: 10px 12px;
}
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input[readonly] { color: var(--muted); }

.login-error {
    margin-top: 12px; font-size: 13px; color: var(--danger);
    background: #fdf1f1; border: 1px solid #f0d4d3; border-radius: 8px; padding: 8px 12px;
}
.status-ok {
    margin: 10px 0; font-size: 13px; color: var(--accent-ink);
    background: var(--accent-soft); border-radius: 8px; padding: 8px 12px;
}

.auth-step {
    margin-top: 26px; border: 1px dashed var(--line); border-radius: 10px;
    padding: 18px; display: flex; gap: 14px; align-items: center;
}
.auth-step iframe { width: 100%; background: #fff; border-radius: 6px; }
.auth-step .icon {
    width: 42px; height: 42px; border-radius: 10px; flex: none;
    background: var(--accent-soft); color: var(--accent-ink);
    display: grid; place-items: center;
}
.auth-step b { display: block; font-size: 13.5px; }
.auth-step span { font-size: 12.5px; color: var(--muted); }

.login-copy { margin-top: auto; padding-top: 28px; font-size: 12px; color: var(--muted); text-align: center; }

.iframe-error-body { background: #fff; display: grid; place-items: center; min-height: 90vh; }
.iframe-error { text-align: center; font-size: 13.5px; color: var(--ink-soft); padding: 16px; }
.iframe-error b { color: var(--danger); display: block; margin-bottom: 6px; }

/* ---------- paso Buypass: iframe con fallback y velo de popup/redirect ---------- */
.auth-step-frame { flex-direction: column; gap: 6px; }
.auth-fallback {
    display: block; text-align: center;
    font-size: 12.5px; color: var(--muted); text-decoration: underline;
}
.auth-fallback:hover { color: var(--accent-ink); }
.auth-overlay {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(8, 53, 86, .45);
    display: flex; align-items: center; justify-content: center;
}
.auth-overlay-card {
    background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
    padding: 28px 32px; max-width: 340px; text-align: center;
}
.auth-overlay-card p { margin: 14px 0 4px; font-size: 14px; color: var(--ink-soft); }
.auth-spinner {
    width: 34px; height: 34px; margin: 0 auto; border-radius: 50%;
    border: 3px solid var(--accent-soft); border-top-color: var(--accent);
    animation: auth-spin .8s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }
.btn-link {
    background: none; border: none; cursor: pointer; margin-top: 10px;
    font-size: 13px; color: var(--muted); text-decoration: underline;
}
.btn-link:hover { color: var(--accent-ink); }

/* ---------- barra de aplicación ---------- */
/* La app ocupa el alto completo: la barra queda fija y el contenido scrollea adentro. */
body:has(.appbar) {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.appbar {
    display: flex; align-items: center; gap: 18px;
    background: var(--navy); color: #dcebe4;
    padding: 10px 24px;
    flex: none;
    z-index: 100;
}
.appbar .cel-word { font-size: 13px; letter-spacing: .24em; }
.appbar .portal-tag { font-size: 9.5px; padding: 1px 6px; }
.appbar nav { display: flex; gap: 4px; margin-left: 12px; }
.appbar nav a {
    font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 6px;
    color: #a9c4ba; text-decoration: none;
}
.appbar nav a.on { background: rgba(255, 255, 255, .12); color: #fff; }
.appbar .user { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.appbar .avatar {
    width: 28px; height: 28px; border-radius: 50%; background: var(--mint); color: var(--navy);
    display: grid; place-items: center; font-size: 11.5px; font-weight: 700;
}
.appbar .logout { color: #a9c4ba; text-decoration: none; }
.appbar .logout:hover { color: #fff; }

/* ---------- página ---------- */
.page {
    padding: 22px 24px 24px;
    max-width: 1280px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.page h1 { font-family: var(--display); font-size: 20px; margin: 0; letter-spacing: -.01em; }
.page h1:focus { outline: none; }

/* Bandeja: el encabezado con filtros queda fijo y solo la grilla scrollea. */
.inbox-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}
.inbox-shell .table-wrap {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}
.inbox-shell .refs thead th {
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 2;
}

.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.count-pill {
    font-size: 12px; font-weight: 700; color: var(--accent-ink);
    background: var(--accent-soft); border-radius: 999px; padding: 2px 10px;
}
.page-head .search {
    margin-left: auto;
    border: 1px solid var(--line); border-radius: 8px; background: var(--card);
    padding: 7px 12px; color: var(--ink); font: 13px var(--sans); min-width: 220px;
}

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
    font: 600 13px var(--sans); padding: 6px 14px; color: var(--muted);
    background: var(--card); border: none; cursor: pointer;
}
.seg button.on { background: var(--accent-soft); color: var(--accent-ink); }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.toggle i {
    width: 32px; height: 18px; border-radius: 999px; background: var(--line);
    position: relative; display: block; transition: background .15s;
}
.toggle i::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
    border-radius: 50%; background: #fff; transition: transform .15s;
}
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(14px); }
.toggle input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- tabla de henvisninger ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table.refs { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.refs th {
    text-align: left; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.refs td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.refs tbody tr:last-child td { border-bottom: none; }
.refs .rowlink { cursor: pointer; }
.refs .rowlink:hover td { background: var(--ground); }
.refs tr.unread td { background: color-mix(in srgb, var(--accent-soft) 45%, var(--card)); }
.refs tr.unread .patient { font-weight: 700; }

.pt { display: flex; align-items: center; gap: 9px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.dot.off { background: transparent; }

.badge {
    display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 9px;
    border-radius: 999px; white-space: nowrap;
}
.b-new { background: var(--accent-soft); color: var(--accent-ink); }
.b-read { background: var(--chip-ground); color: var(--ink-soft); }
.b-sent { background: transparent; color: var(--navy-2); border: 1px solid var(--line); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
    width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line);
    background: var(--card); color: var(--ink-soft);
    display: grid; place-items: center; cursor: pointer; text-decoration: none;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent-ink); }

.subrow td { background: var(--ground); padding: 12px 12px 12px 44px; }
.sub-title {
    font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 6px;
}
.epk-item { display: flex; gap: 14px; align-items: baseline; font-size: 13px; padding: 4px 0; flex-wrap: wrap; }
.epk-item .num { min-width: 120px; color: var(--ink-soft); }
.epk-item .epk-text { white-space: pre-wrap; flex: 1; min-width: 200px; }
.epk-item .files { color: var(--accent-ink); font-size: 12.5px; }

/* ---------- detalle ---------- */
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.crumb a { text-decoration: none; }
.crumb b { color: var(--ink); font-weight: 600; }

.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-head h1 { font-size: 19px; }
.detail-head .sub { font-size: 12.5px; color: var(--muted); }
.detail-head .avatar-lg {
    width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink);
    display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.detail-actions { margin-left: auto; }

.detail-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

.card {
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px;
}
.card h6 {
    font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
    margin: 0 0 14px; font-weight: 700;
}
.card .prev-title { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 14px; font-size: 13.5px; margin: 0 0 14px; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; }

.free-text { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; margin: 0 0 14px; }
.free-text .lbl {
    font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.free-text p { margin: 4px 0 0; font-size: 13.5px; color: var(--ink-soft); font-style: italic; white-space: pre-wrap; }

.textarea {
    width: 100%; border: 1px solid var(--line); border-radius: 8px;
    background: var(--ground); color: var(--ink); font: 13.5px var(--sans);
    padding: 10px 12px; resize: vertical;
}
.textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.char-hint { font-size: 12px; color: var(--muted); text-align: right; margin-top: 4px; font-variant-numeric: tabular-nums; }

.dropzone {
    display: block;
    border: 1.5px dashed var(--line); border-radius: 10px; padding: 16px;
    text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0 10px;
    cursor: pointer;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone b { color: var(--accent-ink); }

.file-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.file-chip {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 12.5px; background: var(--chip-ground); border: 1px solid var(--line);
    border-radius: 999px; padding: 4px 12px; color: var(--ink-soft);
}
.file-chip .x {
    color: var(--muted); font-weight: 700; cursor: pointer;
    background: none; border: none; font-size: 12px; padding: 0;
}
.file-chip .x:hover { color: var(--danger); }

.actions-row { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- notificación ---------- */
.refresh-btn { width: 34px; height: 34px; }

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 500;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    background: var(--navy);
    color: #eaf4f0;
    border-left: 4px solid var(--mint);
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: 0 6px 24px rgba(8, 53, 86, .35);
    max-width: 360px;
}
.toast-body { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.toast-body b { font-size: 14px; }
.toast-body span { color: #b8d2c9; }
.toast-close {
    background: none; border: none; color: #b8d2c9; cursor: pointer;
    font-size: 13px; padding: 2px 4px; border-radius: 4px;
}
.toast-close:hover { color: #fff; }
.toast-close:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
    .login-split { grid-template-columns: 1fr; }
    .login-brand { min-height: 180px; }
    .login-form { padding: 32px 24px 24px; }
    .detail-cols { grid-template-columns: 1fr; }
    .refs .hide-sm { display: none; }
    .page { padding: 16px 12px 32px; }
    .page-head .search { min-width: 100%; margin-left: 0; }
}
