:root {
  --ink: #1c2a2e; --muted: #67777a; --line: #e2e8e6; --bg: #f4f6f5; --card: #fff;
  --brand: #2f7d74; --brand-d: #22605a; --brand-l: #e6f2f0;
  --ok: #2f855a; --ok-l: #e7f5ee; --warn: #9a6512; --warn-l: #fdf4e3; --err: #b83a2e; --err-l: #fbeceb; --info-l: #eaf1fb;
  --r: 10px; --sh: 0 1px 2px rgba(20,40,40,.05), 0 2px 8px rgba(20,40,40,.04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand-d); }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em; background: #eef2f1; padding: 1px 5px; border-radius: 4px; }
code.key { display: inline-block; font-size: 1rem; letter-spacing: .05em; padding: 6px 10px; margin: 4px 0; user-select: all; }
code.wrap { word-break: break-all; user-select: all; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* Cabeçalho */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: .55rem 1.25rem; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; color: var(--ink); text-decoration: none; white-space: nowrap; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 800; }
#nav { display: flex; align-items: center; gap: .15rem; flex: 1; flex-wrap: wrap; }
#nav > a { padding: .4rem .65rem; border-radius: 7px; color: var(--ink); text-decoration: none; font-size: .93rem; }
#nav > a:hover { background: var(--bg); }
#nav > a.active { background: var(--brand-l); color: var(--brand-d); font-weight: 600; }
.nav-user { margin-left: auto; display: flex; gap: .75rem; align-items: center; font-size: .9rem; }
.nav-user a { color: var(--muted); text-decoration: none; }
.menu-btn { display: none; margin-left: auto; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: .3rem .6rem; font-size: 1.1rem; }

main { max-width: 1180px; margin: 0 auto; padding: 1.25rem; min-height: 70vh; }
.foot { max-width: 1180px; margin: 1rem auto 0; padding: 1.25rem; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.foot-links { display: flex; gap: .9rem; flex-wrap: wrap; align-items: flex-start; }
.foot-links a { color: var(--muted); }

/* Blocos */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--sh); }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.head h1, .head h2 { margin-bottom: .5rem; }
.actions, .btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn-row { margin-top: .75rem; }
.grid2, .grid3, .grid4, .grid5 { display: grid; gap: 0 1rem; }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.grid2 > .card { margin-bottom: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.right { text-align: right; white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }
.grow { flex: 1; }

/* Formulários */
label { display: block; margin: 0 0 .8rem; font-size: .9rem; font-weight: 550; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem; font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #cfd8d6; border-radius: 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-l); border-color: var(--brand); }
input[type=color] { padding: 2px; height: 40px; }
textarea { resize: vertical; }
label.check { display: flex; gap: .55rem; align-items: flex-start; font-weight: 400; }
label.check input { width: auto; margin-top: .25rem; flex: none; }
fieldset { border: 1px solid var(--line); border-radius: var(--r); padding: .75rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .3rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.hp { position: absolute; left: -9999px; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; margin: 0; }
.filters input[type=search] { min-width: 280px; }
.row-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row-form select, .row-form input { width: auto; margin: 0; }
form.inline { display: inline; }
details { margin: .5rem 0; }
summary { cursor: pointer; color: var(--brand-d); font-weight: 550; margin-bottom: .5rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; padding: .5rem .9rem; font: inherit; font-weight: 550; font-size: .92rem; color: var(--ink); background: #fff; border: 1px solid #cfd8d6; border-radius: 8px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--err); border-color: #e7b9b4; }
.btn.danger:hover { background: var(--err-l); }
.btn.sm { padding: .25rem .55rem; font-size: .84rem; }
.btn.block { width: 100%; margin-top: .25rem; }
button.link { background: none; border: 0; padding: 0; color: var(--brand-d); text-decoration: underline; cursor: pointer; font: inherit; }

/* Mensagens */
.flash { padding: .7rem .95rem; border-radius: 8px; margin-bottom: .9rem; border: 1px solid transparent; }
.flash-ok { background: var(--ok-l); border-color: #bfe3cf; }
.flash-erro { background: var(--err-l); border-color: #f0c4bf; }
.flash-aviso { background: var(--warn-l); border-color: #efd9ab; }
.flash-info { background: var(--info-l); border-color: #cddcf1; }
.flash label { margin-top: .5rem; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #eef2f1; color: var(--muted); vertical-align: middle; white-space: nowrap; }
.badge.ok, .badge.st-confirmada, .badge.st-realizada { background: var(--ok-l); color: var(--ok); }
.badge.warn, .badge.st-pendente { background: var(--warn-l); color: var(--warn); }
.badge.err, .badge.st-faltou { background: var(--err-l); color: var(--err); }
.badge.st-cancelada_utente, .badge.st-cancelada_clinica { text-decoration: line-through; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: .4rem; vertical-align: middle; }

/* Tabelas */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
.table td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8faf9; }
tr.muted td { opacity: .6; }
.card > .table { margin-top: -.25rem; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; }
.list { margin: 0; padding-left: 1.1rem; }
.list li { margin-bottom: .45rem; }

/* Painel */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: .9rem 1rem; }
.stat-v { font-size: 1.7rem; font-weight: 700; }
.stat-k { color: var(--muted); font-size: .86rem; }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { padding: .5rem .7rem; border-left: 3px solid var(--line); margin-bottom: .4rem; background: #fafbfb; border-radius: 0 6px 6px 0; }
.alerts .al-erro { border-color: var(--err); background: var(--err-l); }
.alerts .al-aviso { border-color: #d39b2a; background: var(--warn-l); }
.alerts .al-info { border-color: #6a93c9; }
.alerts a { color: var(--ink); }

/* Separadores */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand-d); border-color: var(--brand); font-weight: 600; }

/* Agenda */
.cal { background: #fff; border: 1px solid var(--line); border-radius: var(--r); overflow: auto; box-shadow: var(--sh); }
.cal-head, .cal-body { display: grid; grid-template-columns: 56px repeat(var(--dias), minmax(120px, 1fr)); min-width: calc(56px + var(--dias) * 120px); }
.cal-head > div { padding: .5rem; font-size: .85rem; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); text-align: center; }
.cal-head > div:first-child { border-left: 0; }
.cal-head .today { background: var(--brand-l); color: var(--brand-d); }
.cal-body { position: relative; }
.cal-hours > div { font-size: .74rem; color: var(--muted); text-align: right; padding: 0 6px; border-top: 1px solid var(--line); }
.cal-day { position: relative; border-left: 1px solid var(--line); cursor: copy;
  background-image: repeating-linear-gradient(to bottom, var(--line) 0, var(--line) 1px, transparent 1px, transparent 72px); background-color: #fbfcfc; }
.cal-work { position: absolute; left: 0; right: 0; background: #fff; }
.cal-block { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(45deg, #f1f1f1, #f1f1f1 6px, #e8e8e8 6px, #e8e8e8 12px); font-size: .74rem; color: var(--muted); padding: 2px 6px; }
.cal-ev { position: absolute; overflow: hidden; padding: 3px 6px; font-size: .78rem; line-height: 1.25; color: var(--ink); text-decoration: none; background: var(--brand-l); border-left: 4px solid var(--brand); border-radius: 5px; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.cal-ev:hover { z-index: 3; box-shadow: 0 3px 10px rgba(0,0,0,.12); }
.cal-ev strong, .cal-ev span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev span { color: var(--muted); }
.cal-ev.st-pendente { background: var(--warn-l); }
.cal-ev.st-realizada { background: #eef4f3; opacity: .8; }
.cal-ev.st-faltou { background: var(--err-l); }

/* Clínico */
.registo { border-top: 1px solid var(--line); padding: .8rem 0; }
.registo header { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-bottom: .4rem; font-size: .92rem; }
.registo header .btn { margin-left: auto; }
.soap { display: grid; grid-template-columns: 170px 1fr; gap: .75rem; padding: .25rem 0; }
.soap > span { color: var(--muted); font-size: .86rem; }
.spark { margin: 0 0 .75rem; color: var(--brand); }
.spark svg { width: 100%; max-width: 420px; height: auto; display: block; }
.spark figcaption { font-size: .86rem; color: var(--muted); }

/* Plano */
.ref-row { display: grid; grid-template-columns: 180px 90px 1fr auto; gap: .5rem; align-items: start; margin-bottom: .5rem; }
.ref-row input, .ref-row textarea { margin: 0; }
.h-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; flex-wrap: wrap; }
.h-row select, .h-row input { width: auto; margin: 0; }
.plano header { margin-bottom: 1rem; }
.macros { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .6rem; margin: 0 0 1.2rem; }
.macros div { background: var(--brand-l); border-radius: 8px; padding: .55rem .75rem; }
.macros span { display: block; font-size: .78rem; color: var(--brand-d); }
.macros strong { font-size: 1.15rem; }
.refeicoes section, .recs { border-left: 3px solid var(--brand); padding: .2rem 0 .2rem .9rem; margin-bottom: 1rem; break-inside: avoid; }
.refeicoes h3, .recs h3 { margin: 0 0 .25rem; }

/* Portal */
.steps { color: var(--muted); font-size: .88rem; margin: -.5rem 0 1rem; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.choice { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.1rem; text-decoration: none; color: var(--ink); box-shadow: var(--sh); transition: border-color .15s; }
.choice:hover { border-color: var(--brand); }
.choice strong { display: block; font-size: 1.02rem; margin-bottom: .2rem; }
.choice span { display: block; color: var(--muted); font-size: .88rem; }
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: .5rem; }
.day { display: flex; flex-direction: column; align-items: center; padding: .6rem .3rem; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); }
.day:hover, .slot:hover { border-color: var(--brand); background: var(--brand-l); }
.day span, .day small { color: var(--muted); font-size: .8rem; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .5rem; }
.slot { text-align: center; padding: .6rem; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 600; }
.consent-box { max-height: 280px; overflow: auto; background: #fafbfb; border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin-bottom: .8rem; font-size: .92rem; }
.appt { display: flex; gap: .9rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.appt:last-of-type { border-bottom: 0; }
.appt-date { flex: none; width: 52px; text-align: center; background: var(--brand-l); color: var(--brand-d); border-radius: 8px; padding: .35rem 0; font-size: .78rem; }
.appt-date span { display: block; font-size: 1.3rem; font-weight: 700; line-height: 1.1; }
.chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip { background: var(--brand-l); color: var(--brand-d); padding: .3rem .75rem; border-radius: 99px; font-size: .9rem; }

.auth { max-width: 420px; margin: 2rem auto; }
.auth.wide { max-width: 640px; }
.prose { max-width: 820px; }
.danger-zone { border-top: 1px solid var(--line); padding-top: .75rem; margin-top: 1rem; }
.danger-zone summary { color: var(--err); }
.print-only { display: none; }

@media (max-width: 860px) {
  .menu-btn { display: block; }
  #nav { display: none; position: absolute; left: 0; right: 0; top: 100%; background: #fff; border-bottom: 1px solid var(--line); flex-direction: column; align-items: stretch; padding: .5rem; }
  #nav.open { display: flex; }
  .nav-user { margin: .5rem 0 0; padding: .5rem .65rem; border-top: 1px solid var(--line); justify-content: space-between; }
  .grid2, .grid3, .grid4, .grid5 { grid-template-columns: minmax(0, 1fr); }
  .grid3, .grid4, .grid5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: span 2; }
  .soap { grid-template-columns: 1fr; gap: 0; }
  .ref-row { grid-template-columns: 1fr 80px auto; }
  .ref-row textarea { grid-column: 1 / -1; grid-row: 2; }
  .table { display: block; overflow-x: auto; }
  main { padding: 1rem .75rem; }
  .filters input[type=search] { min-width: 0; flex: 1; }
}

@media print {
  .top, .foot, .no-print, .btn, .flash { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; font-size: 12pt; }
  main { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .sign p { margin-top: 2.2rem; }
  a { color: inherit; text-decoration: none; }
}
