:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --text: #1b2b44;
    --muted: #5f6f86;
    --primary: #0c4a7e;
    --primary-soft: #dceaf7;
    --accent: #00838f;
    --danger: #a3172a;
    --ok: #126e3a;
    --border: #d8e2ef;
    --shadow: 0 12px 30px rgba(16, 44, 76, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background: radial-gradient(circle at 10% 10%, #eaf2fb 0%, var(--bg) 35%, #eef3f8 100%);
    color: var(--text);
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

a {
    color: var(--primary);
}

.login-body {
    min-height: 100vh;
    overflow-x: hidden;
}

.bg-shape {
    position: fixed;
    border-radius: 999px;
    filter: blur(2px);
    opacity: 0.45;
    z-index: 0;
}

.bg-a {
    width: 380px;
    height: 380px;
    background: #d5e9ff;
    top: -120px;
    left: -120px;
}

.bg-b {
    width: 460px;
    height: 460px;
    background: #d2f0f2;
    bottom: -180px;
    right: -160px;
}

.login-layout {
    position: relative;
    z-index: 2;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 2rem;
    padding: 3rem;
    align-items: center;
}

.brand-panel h1 {
    font-size: clamp(1.7rem, 2.7vw, 2.6rem);
    max-width: 680px;
}

.brand-panel p {
    max-width: 560px;
    line-height: 1.6;
    color: var(--muted);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.78rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.4rem;
    box-shadow: var(--shadow);
}

.login-card {
    max-width: 440px;
    width: 100%;
}

label {
    display: block;
    margin: 0.9rem 0 0.35rem;
    font-weight: 600;
    color: #354964;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #c5d3e2;
    border-radius: 10px;
    padding: 0.72rem 0.82rem;
    font-size: 0.96rem;
    background: #fbfdff;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #abd2ff;
    border-color: #8cbcff;
}

button,
.btn-link {
    display: inline-block;
    margin-top: 1rem;
    border: 0;
    border-radius: 10px;
    padding: 0.72rem 1rem;
    background: linear-gradient(125deg, var(--primary), #105d9d);
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.btn-link {
    margin-top: 0;
}

.btn-secondary {
    background: #f2f7fd;
    color: #164872;
    border: 1px solid #c2d7ec;
}

.hint {
    margin-top: 0.9rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.small-hint {
    margin-top: 0.45rem;
    margin-bottom: 0.35rem;
    font-size: 0.82rem;
}

.alert {
    background: #ffe8ec;
    border: 1px solid #f4bcc7;
    color: var(--danger);
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
}

.ok {
    background: #e8f7ed;
    border: 1px solid #b4e1c3;
    color: var(--ok);
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    margin-bottom: 0;
    font-size: 1.25rem;
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.pill {
    background: var(--primary-soft);
    border: 1px solid #bfd9ef;
    color: #194b73;
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.88rem;
}

.ingest-widget {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid #c2d7ec;
    border-radius: 999px;
    background: #f4f9ff;
    padding: 0.3rem 0.45rem 0.3rem 0.6rem;
}

.ingest-main {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    text-decoration: none;
    color: #194b73;
}

.ingest-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #9cb2c8;
}

.ingest-label {
    font-size: 0.82rem;
    font-weight: 700;
}

.ingest-state {
    font-size: 0.74rem;
    border-radius: 999px;
    border: 1px solid #c7d8ea;
    background: #eff4fb;
    padding: 0.08rem 0.42rem;
    font-weight: 700;
}

.ingest-info {
    font-size: 0.74rem;
    color: #4d6682;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ingest-audio-btn {
    margin-top: 0;
    border-radius: 999px;
    padding: 0.34rem 0.6rem;
    font-size: 0.72rem;
    background: #e8f0fa;
    color: #1f4f79;
    border: 1px solid #bdd2e6;
}

.ingest-widget.status-ok .ingest-dot { background: #2f7f5d; }

.ingest-widget.status-alert {
    border-color: #efb9c4;
    background: #fff1f4;
}

.ingest-widget.status-alert .ingest-dot { background: #a3172a; }

.ingest-widget.status-offline {
    border-color: #d6dfea;
    background: #f5f8fc;
}

.ingest-widget.blink {
    animation: ingest-blink 1s infinite;
}

@keyframes ingest-blink {
    0%, 100% { box-shadow: 0 0 0 0 rgba(163, 23, 42, 0); }
    50% { box-shadow: 0 0 0 5px rgba(163, 23, 42, 0.22); }
}

.dashboard-grid,
.setup-layout {
    max-width: 1200px;
    margin: 1.2rem auto;
    padding: 0 1rem 1.8rem;
    display: grid;
    gap: 1rem;
}

.metrics {
    margin: 0;
    padding-left: 1rem;
}

.metrics li {
    margin: 0.48rem 0;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
}

th,
td {
    border-bottom: 1px solid #ebf0f6;
    padding: 0.6rem;
    text-align: left;
    white-space: nowrap;
}

th {
    color: #456282;
    font-size: 0.82rem;
    text-transform: uppercase;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

.full-width {
    grid-column: 1 / -1;
}

.check-row label {
    margin: 0.2rem 0;
    font-weight: 600;
}

.check-row input[type="checkbox"] {
    width: auto;
    margin-right: 0.4rem;
}

.search-row {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 0.9rem;
}

.search-row input {
    max-width: 420px;
}

textarea {
    resize: vertical;
    min-height: 96px;
}

.action-row {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
}

.action-links {
    display: flex;
    gap: 0.5rem;
}

.compact-list {
    column-gap: 1rem;
}

.clinical-layout {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 1rem;
    align-items: start;
}

.stack-cards {
    display: grid;
    gap: 1rem;
}

.mini-form label {
    margin-top: 0.55rem;
    font-size: 0.86rem;
    color: #3a5777;
}

.mini-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

.mini-grid input {
    padding: 0.55rem 0.65rem;
}

.notes-feed {
    display: grid;
    gap: 0.6rem;
}

.note-item {
    background: #f7fbff;
    border: 1px solid #d9e8f5;
    border-radius: 10px;
    padding: 0.65rem;
}

.note-item p {
    margin: 0.3rem 0;
}

.patient-photo-preview {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid #d5e2ef;
    display: block;
    margin-bottom: 0.6rem;
}

.patient-photo-thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #d5e2ef;
    display: block;
}

.permission-block {
    border: 1px dashed #c7d8ea;
    border-radius: 10px;
    padding: 0.65rem;
    background: #f8fbff;
}

.perm-check {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-right: 0.8rem;
    font-weight: 600;
    color: #355678;
}

.status-pill {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    border: 1px solid #c7d8ea;
    background: #eff4fb;
    color: #365473;
    text-transform: uppercase;
}

.status-programada { background: #ecf3ff; border-color: #c9daf6; color: #2d5f97; }
.status-en_espera { background: #fff5e8; border-color: #f0d8b5; color: #8b5a19; }
.status-en_atencion { background: #e9f7f0; border-color: #b9dfcb; color: #1f6e45; }
.status-finalizada { background: #edf2f7; border-color: #cfd8e4; color: #425a74; }
.status-cancelada { background: #ffecef; border-color: #f0c2cd; color: #8f2637; }

.inline-form {
    display: inline;
}

.link-btn {
    border: 0;
    background: transparent;
    color: var(--primary);
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    margin: 0;
}

.control-hero {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    background: linear-gradient(140deg, #edf5ff 0%, #f8fcff 60%, #e9f9f7 100%);
}

.control-hero h2 {
    margin-bottom: 0.45rem;
}

.hero-metrics {
    display: flex;
    gap: 0.8rem;
}

.hero-metrics article {
    min-width: 120px;
    background: #fff;
    border: 1px solid #d8e6f4;
    border-radius: 12px;
    padding: 0.8rem;
    text-align: center;
}

.hero-metrics strong {
    display: block;
    font-size: 1.4rem;
    color: #124a7b;
}

.hero-metrics span {
    color: #4a6484;
    font-size: 0.84rem;
}

.control-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.control-card {
    border-left: 5px solid #7ea6ca;
}

.control-card h3 {
    margin-bottom: 0.4rem;
}

.control-card p {
    color: #526981;
    margin-bottom: 0.85rem;
    min-height: 48px;
}

.accent-blue { border-left-color: #2e6ea8; }
.accent-green { border-left-color: #2f7f5d; }
.accent-slate { border-left-color: #4c647d; }
.accent-teal { border-left-color: #1f7f8f; }

.device-hero {
    background: linear-gradient(140deg, #edf6ff 0%, #f8fcff 55%, #edf9f5 100%);
}

.device-controls-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr 1.2fr 0.8fr;
    align-items: end;
}

.device-kpi {
    background: #f8fbff;
    border: 1px solid #d8e6f4;
    border-radius: 12px;
    padding: 0.7rem;
}

.device-global-alert {
    margin-top: 1rem;
}

.device-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.timeline-filter-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr 1fr 0.9fr;
    align-items: end;
    margin-bottom: 0.9rem;
}

.timeline-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.timeline-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
}

.timeline-card {
    background: #fbfdff;
}

.timeline-canvas {
    width: 100%;
    height: 180px;
    border: 1px solid #d9e6f3;
    border-radius: 10px;
    background: #fff;
}

.device-card {
    border-left: 5px solid #9bb4cd;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.device-card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.device-status[data-status="ok"] {
    background: #e9f7f0;
    border-color: #b9dfcb;
    color: #1f6e45;
}

.device-status[data-status="warn"] {
    background: #fff5e8;
    border-color: #f0d8b5;
    color: #8b5a19;
}

.device-status[data-status="alert"] {
    background: #ffecef;
    border-color: #f0c2cd;
    color: #8f2637;
}

.device-card.device-ok {
    border-left-color: #2f7f5d;
}

.device-card.device-warn {
    border-left-color: #bf8a2d;
}

.device-card.device-alert {
    border-left-color: #a3172a;
    box-shadow: 0 0 0 2px rgba(163, 23, 42, 0.15);
}

.alarm-active .topbar {
    border-bottom-color: #f0c2cd;
}

.alarm-active .device-global-alert {
    animation: pulse-alert 1.2s infinite;
}

@keyframes pulse-alert {
    0% { box-shadow: 0 0 0 0 rgba(163, 23, 42, 0.35); }
    70% { box-shadow: 0 0 0 14px rgba(163, 23, 42, 0); }
    100% { box-shadow: 0 0 0 0 rgba(163, 23, 42, 0); }
}

@media (max-width: 900px) {
    .login-layout {
        grid-template-columns: 1fr;
        padding: 1rem;
        gap: 1rem;
    }

    .login-card {
        max-width: 100%;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.7rem;
    }

    .ingest-widget {
        width: 100%;
    }

    .ingest-info {
        max-width: none;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .search-row {
        flex-direction: column;
        align-items: stretch;
    }

    .clinical-layout {
        grid-template-columns: 1fr;
    }

    .mini-grid {
        grid-template-columns: 1fr;
    }

    .control-hero {
        flex-direction: column;
        align-items: flex-start;
    }

    .hero-metrics {
        width: 100%;
    }

    .hero-metrics article {
        flex: 1;
    }

    .control-grid {
        grid-template-columns: 1fr;
    }

    .device-controls-grid {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .device-grid {
        grid-template-columns: 1fr;
    }

    .timeline-filter-grid {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
}
