:root {
  --bg: #FAF7F1; --panel: #FFFFFF; --panel-sunken: #F1ECE1; --border: #E4DDCC;
  --ink: #22302C; --ink-soft: #5E6E68; --teal: #24899C; --teal-deep: #146A7A; --teal-soft: #E1F2F3; --teal-ink: #0E4A55;
  --coral: #D97456; --coral-soft: #FBE7DE; --coral-ink: #8A3C24;
  --shadow: 0 1px 2px rgba(34,48,44,0.06), 0 10px 26px -14px rgba(34,48,44,0.22); --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1614; --panel: #17211E; --panel-sunken: #1D2925; --border: #2B3833; --ink: #EAF0EC; --ink-soft: #9CB0A8;
    --teal: #67C7D6; --teal-deep: #45AEC0; --teal-soft: #163330; --teal-ink: #B6E7EA;
    --coral: #EE9270; --coral-soft: #3A2A21; --coral-ink: #F4C4AB;
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 12px 28px -14px rgba(0,0,0,0.65);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif; font-size: 15.5px; line-height: 1.5; }
h1, h2, h3 { font-family: "Century Gothic", "Trebuchet MS", "Segoe UI", sans-serif; margin: 0; }
button, input, select { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.55rem 1.1rem; border-radius: 999px; font-weight: 600; font-size: 0.9rem; cursor: pointer; border: 1px solid transparent; white-space: nowrap; }
.btn-primary { background: var(--teal); color: #fff; } .btn-primary:hover { background: var(--teal-deep); }
.btn-ghost { background: transparent; border-color: var(--border); } .btn-ghost:hover { background: var(--panel-sunken); }
.btn-danger { background: transparent; color: var(--coral-ink); border-color: var(--coral); } .btn-danger:hover { background: var(--coral-soft); }
.btn-sm { padding: 0.32rem 0.75rem; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chip { display: inline-flex; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 0.24rem 0.6rem; border-radius: 999px; }
.chip-teal { background: var(--teal-soft); color: var(--teal-ink); } .chip-coral { background: var(--coral-soft); color: var(--coral-ink); } .chip-neutral { background: var(--panel-sunken); color: var(--ink-soft); }

.center-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 2rem 1.2rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.8rem; }
.brand { text-align: center; margin-bottom: 1.4rem; }
.brand .mark { width: 48px; height: 48px; border-radius: 50%; background: var(--teal); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; margin: 0 auto 0.8rem; font-family: "Century Gothic", sans-serif; }
.brand h1 { font-size: 1.35rem; }
.brand p { color: var(--ink-soft); font-size: 0.88rem; margin: 0.3rem 0 0; }

.field-row { margin-bottom: 0.9rem; }
.field-label { display: block; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); margin-bottom: 0.3rem; }
.field { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.75rem; background: var(--panel); }
.field-hint { font-size: 0.78rem; color: var(--ink-soft); margin: 0.3rem 0 0; }
.err-box { border: 1px solid var(--coral); background: var(--coral-soft); color: var(--coral-ink); border-radius: 10px; padding: 0.65rem 0.85rem; font-size: 0.86rem; margin-bottom: 0.9rem; }
.info-box { border: 1px solid var(--border); background: var(--teal-soft); color: var(--teal-ink); border-radius: 10px; padding: 0.65rem 0.85rem; font-size: 0.86rem; margin: 0.6rem 0 1rem; }

.shell { display: grid; grid-template-columns: 226px 1fr; min-height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 1.4rem 1rem; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.4rem 1.2rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); font-weight: 700; }
.side-brand .dot { width: 26px; height: 26px; border-radius: 50%; background: var(--teal); }
.side-nav { list-style: none; margin: 0; padding: 0; flex: 1; }
.side-nav button { all: unset; display: block; width: 100%; padding: 0.6rem 0.75rem; border-radius: 8px; font-size: 0.88rem; color: var(--ink-soft); cursor: pointer; border-left: 3px solid transparent; box-sizing: border-box; }
.side-nav button:hover { background: var(--panel-sunken); color: var(--ink); }
.side-nav button.active { background: var(--teal-soft); color: var(--teal-ink); font-weight: 700; border-left-color: var(--teal); }
.side-nav button:focus-visible { outline: 2px solid var(--teal); }
.side-foot { border-top: 1px solid var(--border); padding-top: 0.9rem; display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.8rem; color: var(--ink-soft); }
.side-foot button { all: unset; cursor: pointer; } .side-foot button:hover { color: var(--teal); }
.side-foot button:focus-visible { outline: 2px solid var(--teal); }

.main-col { display: flex; flex-direction: column; min-width: 0; height: 100vh; overflow-y: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 2rem; border-bottom: 1px solid var(--border); background: var(--panel); flex-wrap: wrap; }
.topbar h1 { font-size: 1.25rem; }
.who { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--ink-soft); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--coral); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.74rem; }
.content { padding: 1.75rem 2rem 4rem; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.3rem; margin-bottom: 1.25rem; }
.card h2 { font-size: 1.02rem; margin-bottom: 0.3rem; }
.card-sub { font-size: 0.82rem; color: var(--ink-soft); margin: 0 0 1rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; min-width: 520px; font-size: 0.87rem; background: var(--panel); }
th { text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); padding: 0.7rem 1rem; background: var(--panel-sunken); border-bottom: 1px solid var(--border); }
td { padding: 0.65rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 0.8rem; align-items: end; }
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 0.7rem 1.2rem; border-radius: 999px; font-size: 0.85rem; box-shadow: var(--shadow); z-index: 60; max-width: 90vw; text-align: center; }
.secret { font-family: "SFMono-Regular", Consolas, monospace; font-size: 1.1rem; background: var(--panel); border: 1px dashed var(--teal); border-radius: 8px; padding: 0.5rem 0.8rem; display: inline-block; margin-top: 0.4rem; user-select: all; }

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; overflow-x: auto; align-items: center; gap: 1rem; }
  .side-brand { border-bottom: none; padding-bottom: 0; margin-bottom: 0; white-space: nowrap; }
  .side-nav { display: flex; gap: 0.3rem; flex: none; } .side-nav button { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .side-nav button.active { border-bottom-color: var(--teal); border-left: none; }
  .side-foot { flex-direction: row; } .main-col { height: auto; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) { .content { padding: 1.25rem 1rem 3rem; } .topbar { padding: 0.85rem 1rem; } }

/* ---------- Componentes compartidos ---------- */
.btn-accent { background: var(--coral); color: #fff; } .btn-accent:hover { opacity: 0.9; }
.btn:active { transform: scale(0.97); }
.link-btn { all: unset; cursor: pointer; font-weight: 600; text-align: left; }
.link-btn:hover { color: var(--teal); text-decoration: underline; } .link-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.2rem; }
.fchip { border: 1px solid var(--border); background: var(--panel); color: var(--ink-soft); border-radius: 999px; padding: 0.35rem 0.85rem; font-size: 0.82rem; cursor: pointer; }
.fchip:hover { border-color: var(--teal); } .fchip.active { background: var(--teal-soft); color: var(--teal-ink); border-color: var(--teal); font-weight: 700; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 1.5rem; box-shadow: var(--shadow); }
.stat-row > div { background: var(--panel); padding: 1rem 1.15rem; }
.stat-row dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin: 0 0 0.3rem; }
.stat-row dd { margin: 0; font-size: 1.4rem; font-weight: 700; }
.stat-row { margin-top: 0; } dl.stat-row { margin-left: 0; margin-right: 0; }
.board { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; align-items: start; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.6rem; }
.card-head .card-sub { margin-bottom: 0; }
.agenda-row { display: flex; align-items: center; gap: 0.9rem; padding: 0.7rem 0; border-bottom: 1px solid var(--panel-sunken); }
.agenda-row:last-child { border-bottom: none; }
.agenda-time { width: 92px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--teal-ink); flex-shrink: 0; font-size: 0.86rem; }
.agenda-info { flex: 1; min-width: 0; } .agenda-info .meta { font-size: 0.78rem; color: var(--ink-soft); margin-top: 0.1rem; }
.agenda-actions { display: flex; gap: 0.4rem; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.empty-note { color: var(--ink-soft); font-size: 0.86rem; padding: 0.5rem 0; }
tbody tr.clickable { cursor: pointer; } tbody tr.clickable:hover td { background: var(--panel-sunken); }
.search-bar input { width: 100%; max-width: 320px; margin-bottom: 1rem; border-radius: 999px; }
.patient-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.patient-head h1 { font-size: 1.5rem; margin-bottom: 0.2rem; }
.patient-head .meta { color: var(--ink-soft); font-size: 0.86rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 0.3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; flex-wrap: wrap; }
.tabs button { all: unset; cursor: pointer; padding: 0.6rem 0.9rem; font-size: 0.86rem; color: var(--ink-soft); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--teal-ink); border-bottom-color: var(--teal); font-weight: 700; } .tabs button:focus-visible { outline: 2px solid var(--teal); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 0.35rem 1rem; margin: 0; font-size: 0.9rem; } .kv dt { color: var(--ink-soft); font-size: 0.8rem; padding-top: 0.1rem; } .kv dd { margin: 0; }
.member-block + .member-block { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--panel-sunken); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.9rem; }
fieldset.fs { border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem 0.9rem 0.2rem; margin: 0 0 1rem; }
fieldset.fs legend { font-size: 0.78rem; font-weight: 700; color: var(--teal-ink); padding: 0 0.4rem; }
.check-row { display: flex; align-items: center; gap: 0.55rem; margin: 0.4rem 0 0.85rem; font-size: 0.88rem; }
.warn-box { border: 1px solid var(--coral); background: var(--coral-soft); color: var(--coral-ink); border-radius: 10px; padding: 0.7rem 0.9rem; font-size: 0.84rem; margin: 0.4rem 0 0.9rem; }
.week-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); background: var(--panel); }
.week-grid { display: grid; grid-template-columns: 56px repeat(7, minmax(96px, 1fr)); min-width: 780px; }
.week-grid .head-cell { background: var(--panel-sunken); padding: 0.55rem 0.4rem; font-size: 0.74rem; font-weight: 700; text-align: center; border-bottom: 1px solid var(--border); border-left: 1px solid var(--border); }
.week-grid .head-cell:first-child { border-left: none; } .week-grid .head-cell.today { color: var(--teal-ink); background: var(--teal-soft); }
.week-grid .hour-cell { padding: 0.35rem; font-size: 0.7rem; color: var(--ink-soft); text-align: right; border-top: 1px solid var(--border); }
.week-grid .slot-cell { border-top: 1px solid var(--border); border-left: 1px solid var(--border); padding: 0.2rem; min-height: 48px; }
.apt-chip { display: block; width: 100%; text-align: left; border: none; cursor: pointer; font: inherit; font-size: 0.68rem; padding: 0.25rem 0.4rem; border-radius: 6px; margin-bottom: 0.2rem; line-height: 1.3; }
.apt-teal { background: var(--teal-soft); color: var(--teal-ink); } .apt-neutral { background: var(--panel-sunken); color: var(--ink-soft); } .apt-coral { background: var(--coral-soft); color: var(--coral-ink); }
.apt-block { background: repeating-linear-gradient(135deg, var(--panel-sunken), var(--panel-sunken) 6px, var(--border) 6px, var(--border) 7px); color: var(--ink-soft); }
.apt-th { float: right; font-weight: 700; opacity: 0.75; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,22,20,0.5); display: flex; align-items: center; justify-content: center; padding: 1.2rem; z-index: 50; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 1.5rem; max-width: 520px; width: 100%; box-shadow: var(--shadow); max-height: calc(100vh - 2.4rem); overflow-y: auto; }
.modal.wide { max-width: 640px; } .modal h2 { margin: 0 0 0.5rem; font-size: 1.1rem; } .modal p { color: var(--ink-soft); font-size: 0.88rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; flex-wrap: wrap; }
.cfg-days { display: flex; gap: 0.6rem; flex-wrap: wrap; } .cfg-days label { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.8rem; }
@media (max-width: 1180px) { .board { grid-template-columns: 1fr; } }
@media (max-width: 880px) { .stat-row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .stat-row, .field-grid { grid-template-columns: 1fr; } .kv { grid-template-columns: 1fr; } .agenda-row { flex-wrap: wrap; } }
