:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #162033;
    --muted: #68758a;
    --line: #dfe5ef;
    --primary: #22577a;
    --primary-2: #38a3a5;
    --success: #13795b;
    --warning: #9a6700;
    --danger: #b42318;
    --info: #1d4ed8;
    --shadow: 0 16px 40px rgba(22, 32, 51, .08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100%;
    background: radial-gradient(circle at top left, rgba(56, 163, 165, .18), transparent 30%), var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 18px;
    align-items: center;
    padding: 14px 22px;
    background: rgba(255, 255, 255, .92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 180px; color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-logo {
    width: 50px;
    height: 50px;
    object-fit: contain;
    border-radius: 14px;
    background: #fff;
    border: 1px solid rgba(223, 229, 239, .9);
    box-shadow: 0 8px 18px rgba(22, 32, 51, .06);
    padding: 4px;
}
.brand-copy strong { display: block; font-size: 18px; letter-spacing: -.01em; }
.brand-mark, .auth-logo {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font-weight: 800;
    letter-spacing: .06em;
}
.brand small, .brand-copy small { display: block; color: var(--muted); }
.nav { display: flex; gap: 7px; flex-wrap: wrap; }
.nav a {
    padding: 8px 10px;
    border-radius: 999px;
    color: var(--text);
    font-size: 14px;
}
.nav a:hover { background: #edf5f7; text-decoration: none; }
.userbox { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }

.container { width: min(1440px, calc(100% - 36px)); margin: 28px auto 64px; }
.auth-container { min-height: calc(100vh - 90px); display: grid; place-items: center; }
.footer {
    width: min(1440px, calc(100% - 36px));
    margin: 0 auto 24px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.footer-brand { display: inline-flex; align-items: center; gap: 8px; }
.footer-brand img { width: 22px; height: 22px; object-fit: contain; }

.card, .metric, .appointment-card, .therapy-card, .message {
    background: var(--card);
    border: 1px solid rgba(223, 229, 239, .9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card { padding: 22px; margin-bottom: 20px; }
.auth-card { width: min(440px, 100%); text-align: center; padding: 34px; }
.auth-card.brand-auth { width: min(520px, 100%); }
.auth-card .auth-logo { margin: 0 auto 12px; width: 62px; height: 62px; border-radius: 20px; }
.auth-logo-img {
    display: block;
    width: min(310px, 84%);
    height: auto;
    margin: -8px auto 16px;
}
.auth-logo-img.compact { width: min(260px, 76%); margin-top: -4px; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; }
h1 { font-size: clamp(26px, 4vw, 42px); }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }

.page-heading {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 22px;
}
.page-heading p { color: var(--muted); margin-top: 8px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.card-title.compact { margin-bottom: 8px; }

.grid { display: grid; gap: 20px; }
.two-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
.cards-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.metric { padding: 20px; }
.metric span { display: block; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.metric strong { font-size: 32px; }
.metric.danger { border-color: rgba(180, 35, 24, .25); }
.metric.warning { border-color: rgba(154, 103, 0, .25); }

.form { text-align: left; }
.stack { display: grid; gap: 14px; }
.grid-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.compact-form label { min-width: 180px; }
.form label { display: grid; gap: 6px; color: var(--text); font-weight: 650; font-size: 14px; }
.form input, .form select, .form textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 12px;
    font: inherit;
    background: #fff;
    color: var(--text);
}
.form textarea { resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus {
    outline: 3px solid rgba(56, 163, 165, .18);
    border-color: var(--primary-2);
}
.check { display: flex !important; grid-template-columns: auto 1fr !important; align-items: center; gap: 8px !important; }
.check input { width: auto; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline { display: inline-flex; margin: 0; }

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 10px 14px;
    border: 1px solid var(--primary);
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    text-decoration: none;
}
.btn:hover { filter: brightness(.96); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--primary); }
.btn.small { min-height: 30px; padding: 6px 10px; font-size: 12px; }
.btn.full { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8fafc; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
small { color: var(--muted); }
.row-warning td { background: #fff8e6; }

.badge, .pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.pill { background: #eef6f7; color: var(--primary); }
.badge.success { background: #dff8ec; color: var(--success); }
.badge.warning { background: #fff2cc; color: var(--warning); }
.badge.danger { background: #fee4e2; color: var(--danger); }
.badge.info { background: #e0ecff; color: var(--info); }
.badge.muted { background: #edf0f5; color: var(--muted); }

.flash { padding: 14px 16px; border-radius: 14px; margin-bottom: 18px; border: 1px solid; font-weight: 650; }
.flash.success { background: #eafaf1; color: var(--success); border-color: #b7edcf; }
.flash.error { background: #fff1f0; color: var(--danger); border-color: #ffd0cc; }
.flash.info { background: #eef6ff; color: var(--info); border-color: #cfe4ff; }

.details { display: grid; grid-template-columns: 160px 1fr; gap: 10px 14px; margin: 0; }
.details dt { color: var(--muted); font-weight: 700; }
.details dd { margin: 0; }
.compact-details { grid-template-columns: 120px 1fr; }

.chair-board { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.chair-slot {
    display: grid;
    gap: 4px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: linear-gradient(180deg, #fff, #f9fbfd);
    color: var(--text);
}
.chair-slot:hover { border-color: var(--primary-2); text-decoration: none; transform: translateY(-1px); }
.chair-slot span { color: var(--primary); font-weight: 800; }
.chair-slot em { color: var(--muted); font-style: normal; }
.chair-board.detailed { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.danger-text { color: var(--danger); font-weight: 800; }

.alert-list { display: grid; gap: 12px; }
.alert-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: start;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}
.alert-item.danger { border-color: rgba(180, 35, 24, .32); background: #fff8f7; }
.alert-item.warning { border-color: rgba(154, 103, 0, .32); background: #fffaf0; }
.alert-item.info { border-color: rgba(29, 78, 216, .25); background: #f5f9ff; }
.alert-item.resolved { opacity: .6; }
.alert-item p { margin: 4px 0; }

.therapy-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.therapy-card { padding: 18px; }
.therapy-card.disabled { opacity: .55; }
.appointment-list, .message-list { display: grid; gap: 14px; }
.appointment-card, .message { padding: 18px; }
.message.unread { border-color: rgba(56, 163, 165, .45); background: #f7fefe; }
.compact-list .message { box-shadow: none; }

.demo-logins {
    display: grid;
    gap: 7px;
    margin: 20px 0;
    padding: 14px;
    border: 1px dashed var(--line);
    border-radius: 14px;
    background: #fbfcfe;
    text-align: left;
}
.demo-logins code {
    display: block;
    padding: 6px 8px;
    background: #eef2f7;
    border-radius: 8px;
    color: #243045;
    white-space: nowrap;
    overflow-x: auto;
}
.progress { height: 10px; background: #edf0f5; border-radius: 999px; overflow: hidden; margin-bottom: 4px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); }

@media (max-width: 1100px) {
    .topbar { grid-template-columns: 1fr; }
    .userbox { justify-content: flex-start; }
    .two-cols, .cards-4, .cards-5 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
    .container { width: min(100% - 22px, 1440px); margin-top: 18px; }
    .brand { min-width: 0; }
    .brand-logo { width: 44px; height: 44px; }
    .auth-card { padding: 26px; }
    .auth-logo-img { width: min(280px, 88%); }
    .page-heading { display: grid; }
    .two-cols, .cards-3, .cards-4, .cards-5, .grid-form { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .inline-form { display: grid; }
    .details { grid-template-columns: 1fr; gap: 4px; }
    .footer { display: grid; gap: 6px; }
    .alert-item { grid-template-columns: 1fr; }
}

/* Centro Multidisciplinar DII */
.patient-switcher { margin-bottom: 18px; }
.patient-hero {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
    gap: 18px;
    align-items: start;
}
.discipline-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.discipline-tab {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 15px 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow);
    color: var(--text);
}
.discipline-tab:hover,
.discipline-tab.active {
    text-decoration: none;
    border-color: var(--primary-2);
    background: #f4fbfb;
}
.discipline-tab span {
    min-width: 30px;
    height: 30px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    background: #eef6f7;
    color: var(--primary);
    font-weight: 800;
}
.wide-left { grid-template-columns: minmax(0, 1.45fr) minmax(340px, .8fr); }
.timeline {
    position: relative;
    display: grid;
    gap: 12px;
}
.timeline:before {
    content: "";
    position: absolute;
    left: 11px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--line);
}
.timeline-item {
    position: relative;
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    color: var(--text);
}
.timeline-item:hover { text-decoration: none; border-color: var(--primary-2); }
.timeline-dot {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 4px solid #fff;
    box-shadow: 0 0 0 1px var(--line);
    background: var(--muted);
    z-index: 1;
}
.timeline-dot.success { background: var(--success); }
.timeline-dot.warning { background: var(--warning); }
.timeline-dot.danger { background: var(--danger); }
.timeline-dot.info { background: var(--info); }
.timeline-item strong { display: block; margin: 2px 0 4px; }
.timeline-item p { color: var(--muted); margin: 0; }
.intervention-list { display: grid; gap: 12px; }
.soft-separator { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

.chair-map-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 18px;
}
.chair-lane { margin-bottom: 0; }
.chair-timeline {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}
.chair-block {
    display: grid;
    align-content: start;
    gap: 5px;
    border: 1px solid var(--line);
    border-left: 6px solid var(--muted);
    border-radius: 16px;
    background: linear-gradient(180deg, #fff, #f9fbfd);
    padding: 14px;
    color: var(--text);
}
.chair-block:hover { text-decoration: none; transform: translateY(-1px); }
.chair-block.success { border-left-color: var(--success); }
.chair-block.warning { border-left-color: var(--warning); }
.chair-block.danger { border-left-color: var(--danger); }
.chair-block.info { border-left-color: var(--info); }
.chair-block span { color: var(--primary); font-weight: 800; }
.chair-block em { font-style: normal; color: var(--muted); }

.roadmap-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
    gap: 18px;
}
.roadmap-phase { margin-bottom: 0; }
.roadmap-items { display: grid; gap: 12px; margin-top: 14px; }
.roadmap-item {
    display: grid;
    gap: 6px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}
.roadmap-item.implementado { border-color: rgba(19, 121, 91, .25); background: #f4fcf8; }
.roadmap-item.parcial { border-color: rgba(154, 103, 0, .25); background: #fffaf0; }

@media (max-width: 900px) {
    .patient-hero, .wide-left { grid-template-columns: 1fr; }
}
