/* ============================================================
   PsiGest — estilos (MVP)
   ============================================================ */
:root {
  --bg: #f8f2ec;
  --surface: #ffffff;
  --border: #e8dcd2;
  --text: #2c2016;
  --muted: #8a7568;
  --primary: #9f6e5c;      /* terracota creme */
  --primary-dark: #7d5647;
  --primary-soft: #efe3de;
  --peach: #ffdaa2;
  --accent: #4f6ef7;
  --danger: #d9534f;
  --danger-soft: #fbe9e8;
  --warn: #c98a1b;
  --warn-soft: #fbf1dc;
  --ok: #2e9e5b;
  --ok-soft: #e4f5eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow-x: clip; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary-dark); }
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 650; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #fdf3ea, #ffdaa2);
}
.login-card {
  background: var(--surface);
  width: 100%; max-width: 400px;
  padding: 32px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand .logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.brand h1 { margin: 0; font-size: 20px; }
.login-card .sub { color: var(--muted); margin: 0 0 22px; }
.demo-hint {
  margin-top: 18px; padding: 12px 14px; background: var(--primary-soft);
  border-radius: 10px; font-size: 12.5px; color: var(--primary-dark);
}
.demo-hint b { color: var(--text); }
.demo-hint code { background: #fff; padding: 1px 5px; border-radius: 4px; }
.demo-row { cursor: pointer; display: block; padding: 3px 0; }
.demo-row:hover { text-decoration: underline; }

/* ---------- Form ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 64px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.error-msg { color: var(--danger); font-size: 13px; margin: 6px 0 0; min-height: 18px; }
.commission-preview { background: var(--primary-soft); color: var(--primary-dark); padding: 9px 12px; border-radius: 8px; font-size: 13.5px; }
.time24 { display: flex; align-items: center; gap: 6px; }
.time24 select { width: auto; flex: 1; text-align: center; }
.time24 span { color: var(--muted); font-weight: 700; }
.date3 { display: flex; align-items: center; gap: 6px; }
.date3 select { width: auto; flex: 1; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 15px; border: 1px solid transparent; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; background: #f3e9e2; color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--primary-dark); color: #f6e6da; padding: 18px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
}
.sidebar .brand { color: #fff; margin-bottom: 22px; }
.sidebar .brand h1 { color: #fff; font-size: 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  color: #e8cdbb; text-decoration: none; padding: 9px 12px; border-radius: 8px;
  font-weight: 550; font-size: 13.5px; display: flex; align-items: center; gap: 9px;
}
.nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav a.active { background: #ffdaa2; color: #5b3a2c; }
.nav .section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #c99b83; margin: 14px 0 4px 12px; }
.notif-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); margin-left: 4px; vertical-align: middle; }
.sidebar-foot {
  border-top: 1px solid rgba(255,255,255,.15); padding-top: 14px; font-size: 12px; color: #dcbba5;
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-foot .btn {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.2);
  color: #f3e2d5; font-size: 12px; line-height: 1.3;
}
.sidebar-foot .btn:hover { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.32); }
.sidebar-foot .btn.danger {
  background: rgba(217,83,79,.16); border-color: rgba(217,83,79,.45); color: #ffd9d6;
}
.sidebar-foot .btn.danger:hover { background: rgba(217,83,79,.3); border-color: rgba(217,83,79,.6); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.topbar .who { display: flex; align-items: center; gap: 12px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center; font-weight: 700; }
.content { padding: 24px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Cards / KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .value.sm { font-size: 20px; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.accent { border-top: 3px solid var(--primary); }
.section-title { margin: 24px 0 12px; font-size: 15px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: #faf5f0; }
tfoot .totals-row td { border-bottom: none; border-top: 2px solid var(--border); background: var(--bg); }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
.th-filter { display: inline-flex; align-items: center; gap: 3px; position: relative; }
.th-filter-btn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 9px; padding: 2px; line-height: 1; }
.th-filter-btn:hover { color: var(--text); }
.th-filter-btn.active { color: white; font-weight: 900; background: var(--primary); width: 20px; height: 20px; border-radius: 50%; }
.th-filter-menu { display: none; position: fixed; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); min-width: 150px; z-index: 200; overflow: hidden; }
.th-filter-menu.open { display: block; }
.th-filter-opt { padding: 7px 12px; font-size: 12.5px; font-weight: 500; text-transform: none; letter-spacing: normal; color: var(--text); cursor: pointer; white-space: nowrap; }
.th-filter-opt:hover { background: var(--bg); }
.th-filter-opt.sel { color: var(--primary-dark); font-weight: 700; background: var(--primary-soft); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; border-top: 1px solid var(--border); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 650; }
.badge.ativo, .badge.pago, .badge.realizada { background: var(--ok-soft); color: var(--ok); }
.badge.arquivado, .badge.agendada, .badge.declarada { background: #e8eefb; color: var(--accent); }
.badge.drop_out, .badge.falta { background: var(--danger-soft); color: var(--danger); }
.badge.pendente, .badge.cancelada { background: var(--warn-soft); color: var(--warn); }
.badge.isento { background: #f1e6de; color: var(--muted); }
.badge.role { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar .spacer { flex: 1; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.x-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------- Histórico de observações ---------- */
.obs-form { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 18px; }
.obs-form textarea { flex: 1; min-height: 44px; }
.obs-form .btn { flex-shrink: 0; }
.obs-list { display: flex; flex-direction: column; gap: 12px; }
.obs-item { padding: 10px 12px; background: var(--bg); border-radius: 8px; border-left: 3px solid var(--primary); }
.obs-meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.obs-text { font-size: 13.5px; white-space: pre-wrap; }

/* ---------- Notificações ---------- */
.notif-list { display: flex; flex-direction: column; }
.notif-item {
  display: flex; align-items: flex-start; gap: 14px; padding: 16px 18px;
  border-bottom: 1px solid var(--border); border-left: 3px solid var(--primary);
}
.notif-item:last-child { border-bottom: none; }
.notif-item.seen { border-left-color: var(--border); opacity: .65; }
.notif-icon { font-size: 20px; line-height: 1; }
.notif-body { flex: 1; min-width: 0; }
.notif-msg { font-size: 13.5px; font-weight: 600; }
.notif-item.seen .notif-msg { font-weight: 500; }
.notif-meta { display: flex; align-items: center; gap: 14px; font-size: 13.5px; margin-top: 5px; }
.nm-item { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.notif-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.notif-seen-tag { font-size: 12px; }

/* ---------- Progress bar (retenção) ---------- */
.bar { height: 8px; background: #f1e6de; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); }

/* ---------- Segmented toggle ---------- */
.seg-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: #fff; }
.seg-toggle button { border: none; background: #fff; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); font-family: inherit; }
.seg-toggle button + button { border-left: 1px solid var(--border); }
.seg-toggle button.active { background: var(--primary); color: #fff; }

/* ---------- Calendário ---------- */
.cal-toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.cal-nav { display: flex; gap: 6px; }
.cal-title { font-weight: 700; font-size: 17px; }
.cal-scroll { overflow-x: auto; }
.cal-inner { min-width: 680px; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.cal-weekdays > div { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; min-height: 104px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.cal-cell.blank { background: transparent; border: none; }
.cal-cell.today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.cal-cell.clickable { cursor: pointer; }
.cal-cell.clickable:hover { border-color: var(--primary); background: #fdf8f4; }
.cal-daynum { font-size: 12px; font-weight: 700; color: var(--muted); }
.cal-cell.today .cal-daynum { color: var(--primary-dark); }
.cal-items { display: flex; flex-direction: column; gap: 3px; }
.cal-chip {
  font-size: 11px; padding: 2px 6px; border-radius: 5px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--primary-soft); color: var(--primary-dark); border-left: 3px solid var(--primary);
  transition: filter .12s ease, box-shadow .12s ease, transform .12s ease;
}
.cal-chip:hover { filter: brightness(.93); box-shadow: 0 2px 6px rgba(16,24,40,.2); transform: translateY(-1px); }
.cal-chip.realizada, .cal-chip.free { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.cal-chip.agendada, .cal-chip.booked { background: #e8eefb; color: var(--accent); border-color: var(--accent); }
.cal-chip.pago { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--primary); }
.cal-chip.falta { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.cal-chip.cancelada { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.cal-more { font-size: 10.5px; color: var(--muted); padding-left: 2px; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.legend .dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.legend .dot.free { background: var(--ok); }
.legend .dot.booked { background: var(--accent); }
.legend .dot.realizada { background: var(--ok); }
.legend .dot.agendada { background: var(--accent); }
.legend .dot.pago { background: var(--primary); }
.legend .dot.falta { background: var(--danger); }
.legend .dot.cancelada { background: var(--warn); }

/* ---------- misc ---------- */
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 16px; }
.flex { display: flex; gap: 8px; align-items: center; }
.hidden { display: none !important; }

/* ---------- Menu mobile (drawer) ---------- */
.menu-toggle { display: none; background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text); padding: 2px 6px; }
.drawer-backdrop { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .content { max-width: 100%; }
  .menu-toggle { display: inline-flex; }

  /* barra lateral vira drawer fora do ecrã */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 256px;
    flex-direction: column; z-index: 200; overflow-y: auto;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  body.drawer-open .sidebar { transform: none; }
  body.drawer-open { overflow: hidden; }
  .nav { flex-direction: column; flex-wrap: nowrap; overflow: visible; gap: 2px; }
  .nav a { white-space: nowrap; }
  .nav .section-label { display: block; }
  .sidebar-foot { display: block; }

  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 150; background: rgba(16,24,40,.45); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }

  .content { padding: 16px; }
  .page-head h2 { font-size: 19px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .kpi .value { font-size: 22px; }
}
@media (max-width: 560px) {
  .topbar { padding: 10px 14px; }
  .topbar .who { gap: 8px; }
  #whoName, #whoRole { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .cal-cell { min-height: 78px; }
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { min-width: 0; flex: 1; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
}

/* ---------- Wiki / Ajuda ---------- */
.wiki-page { --serif: Iowan Old Style, Palatino Linotype, Palatino, Georgia, ui-serif, serif; max-width: 860px; }
.wiki-toc { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 28px; }
.wiki-toc .toc-link {
  font-size: 12.5px; font-weight: 650; color: var(--primary-dark); text-decoration: none;
  background: var(--primary-soft); padding: 6px 13px; border-radius: 999px;
  border: none; cursor: pointer; font-family: inherit;
}
.wiki-toc .toc-link:hover { background: var(--peach); }
.wiki-section { margin-bottom: 40px; scroll-margin-top: 20px; }
.wiki-shead { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.wiki-snum { font-family: var(--serif); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.wiki-section h3 { font-family: var(--serif); font-size: 23px; font-weight: 600; margin: 0; }
.wiki-dek { color: var(--muted); font-size: 14px; margin: 6px 0 18px; max-width: 66ch; }
.wiki-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 12px; }
.wiki-card h4 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700;
  color: var(--muted); margin: 0 0 14px;
}
.wiki-feature-list { display: flex; flex-direction: column; gap: 14px; }
.wiki-feature { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: start; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.wiki-feature:last-child { border-bottom: none; padding-bottom: 0; }
.wiki-feature b.ft-title { grid-column: 1; font-size: 14.5px; font-weight: 650; }
.wiki-feature p { grid-column: 1; margin: 0; font-size: 13.5px; color: var(--muted); max-width: 58ch; }
.wiki-faq { display: flex; flex-direction: column; gap: 2px; }
.wiki-faq-item { border-bottom: 1px solid var(--border); }
.wiki-faq-item:last-child { border-bottom: none; }
.wiki-faq-q {
  width: 100%; text-align: left; background: none; border: none; cursor: pointer;
  padding: 13px 0; font-size: 14px; font-weight: 600; color: var(--text); font-family: inherit;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.wiki-faq-q .car { color: var(--muted); transition: transform .15s ease; flex-shrink: 0; }
.wiki-faq-item.open .wiki-faq-q .car { transform: rotate(180deg); }
.wiki-faq-a { max-height: 0; overflow: hidden; transition: max-height .2s ease; }
.wiki-faq-item.open .wiki-faq-a { max-height: 300px; }
.wiki-faq-a p { margin: 0 0 14px; font-size: 13.5px; color: var(--muted); max-width: 62ch; }
.wiki-flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 16px; }
.wiki-flow .step { padding: 6px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 650; }
.wiki-flow .step.a { background: #e8eefb; color: var(--accent); }
.wiki-flow .step.b { background: var(--primary-soft); color: var(--primary-dark); }
.wiki-flow .step.c { background: var(--ok-soft); color: var(--ok); }
.wiki-flow .arrow { color: var(--muted); font-size: 14px; }
.wiki-tourbtn { flex-shrink: 0; align-self: flex-start; }

/* ---------- Tour guiado ---------- */
.tour-overlay { position: fixed; inset: 0; z-index: 9000; }
.tour-highlight {
  position: fixed; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(31, 20, 12, .62);
  border: 2px solid var(--peach, #ffdaa2);
  transition: top .25s ease, left .25s ease, width .25s ease, height .25s ease;
  z-index: 9001;
}
.tour-tooltip {
  position: fixed; z-index: 9002; background: var(--surface); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 18px 20px; width: 300px; max-width: calc(100vw - 32px);
  transition: top .25s ease, left .25s ease;
}
.tour-tooltip h5 { font-family: Iowan Old Style, Palatino Linotype, Georgia, serif; font-size: 17px; margin: 0 0 8px; }
.tour-tooltip p { font-size: 13.5px; color: var(--muted); margin: 0 0 16px; line-height: 1.5; }
.tour-tt-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tour-step-count { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tour-actions { display: flex; gap: 6px; }
