:root {
  --brand: #e08862;
  --brand-strong: #b65c37;
  --brand-soft: #fbece4;
  --on-brand: #ffffff;
  --bg: #faf7f5;
  --surface: #ffffff;
  --surface-2: #f4eeea;
  --text: #2b2320;
  --muted: #7a6d67;
  --border: #ebe0d9;
  --ok: #2f8456;
  --ok-soft: #e3f3ea;
  --warn: #a8650f;
  --warn-soft: #fbf0dc;
  --danger: #c0392b;
  --danger-soft: #fbe5e2;
  --info: #4f5fbf;
  --info-soft: #e8ebfa;
  --shadow: 0 1px 2px rgba(60, 30, 20, .05), 0 6px 20px rgba(60, 30, 20, .06);
  --radius: 14px;
  --sidebar: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #e99573; --brand-strong: #f2a888; --brand-soft: #3a2820; --on-brand: #1d1512;
    --bg: #161210; --surface: #201a17; --surface-2: #2a221e; --text: #f3ebe7; --muted: #a99b94; --border: #3a302b;
    --ok: #6fcf97; --ok-soft: #1f3529; --warn: #f0b45a; --warn-soft: #3a2e1a; --danger: #ff8a7a; --danger-soft: #3d221e;
    --info: #9aa8f5; --info-soft: #262b45; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #e99573; --brand-strong: #f2a888; --brand-soft: #3a2820; --on-brand: #1d1512;
  --bg: #161210; --surface: #201a17; --surface-2: #2a221e; --text: #f3ebe7; --muted: #a99b94; --border: #3a302b;
  --ok: #6fcf97; --ok-soft: #1f3529; --warn: #f0b45a; --warn-soft: #3a2e1a; --danger: #ff8a7a; --danger-soft: #3d221e;
  --info: #9aa8f5; --info-soft: #262b45; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45;
}
[hidden] { display: none !important; }
h1, h2, h3, .brandfont { font-family: Quicksand, Inter, system-ui, sans-serif; font-weight: 700; text-wrap: balance; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
a { color: var(--brand-strong); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.error { color: var(--danger); margin: 0; }
.right { text-align: right; }
.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* botões e campos */
.btn {
  font: inherit; font-weight: 500; border-radius: 10px; padding: 8px 14px; cursor: pointer; line-height: 1.2;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); background: var(--brand); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: 50%; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label.field, div.field { display: grid; gap: 5px; font-weight: 500; font-size: 13px; min-width: 0; }
label.field > span, div.field > span { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* entrada */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 32px; width: min(400px, 100%); display: grid; gap: 14px;
}
.login-card img { width: 220px; max-width: 100%; justify-self: center; margin-bottom: 4px; }
.logo-dark { display: none; }

/* estrutura */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 20px 14px; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 4px;
}
.sidebar .logo { width: 170px; margin: 0 6px 18px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text);
  text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; }
.nav .count { margin-left: auto; background: var(--brand); color: var(--on-brand); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.sidebar .me { margin-top: auto; padding: 12px; border-top: 1px solid var(--border); display: grid; gap: 6px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-block: 12px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
.topbar .mobile-logo { display: none; height: 30px; }
.content {
  width: 100%; max-width: 1240px; margin: 0 auto; display: grid; gap: 18px; align-content: start;
  padding-block: 22px 60px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px));
}
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 26px; font-weight: 700; font-family: Quicksand, Inter, sans-serif; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.stack { display: grid; gap: 14px; }

/* cronómetro */
.timer-pill {
  display: inline-flex; align-items: center; gap: 8px; background: var(--brand-soft); color: var(--brand-strong);
  border-radius: 99px; padding: 6px 8px 6px 14px; font-weight: 600; max-width: 100%;
}
.timer-pill .t { font-variant-numeric: tabular-nums; }
.timer-pill .what { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); animation: pulse 1.4s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .3; } }

/* barras */
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--brand); border-radius: 99px; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--danger); }
.bar .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: .35; }

/* tarefas */
.task-list { display: grid; }
.task {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.task:last-child { border-bottom: 0; }
.task .done-btn {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); background: transparent; cursor: pointer; padding: 0;
  display: grid; place-items: center; color: transparent; font-size: 12px;
}
.task .done-btn:hover { border-color: var(--ok); color: var(--ok); }
.task.is-done .done-btn { background: var(--ok); border-color: var(--ok); color: #fff; }
.task.is-done .title { text-decoration: line-through; color: var(--muted); }
.task .title { font-weight: 500; cursor: pointer; overflow-wrap: anywhere; }
.task .title:hover { color: var(--brand-strong); }
.task .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; color: var(--muted); font-size: 12px; align-items: center; }
.task .actions { display: flex; gap: 4px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }
.chip.client { background: var(--brand-soft); color: var(--brand-strong); }
.chip.st-em_curso { background: var(--info-soft); color: var(--info); }
.chip.st-bloqueada { background: var(--danger-soft); color: var(--danger); }
.chip.st-pendente { background: var(--warn-soft); color: var(--warn); }
.chip.st-em_validacao { background: var(--info-soft); color: var(--info); }
.chip.st-concluida { background: var(--ok-soft); color: var(--ok); }
.chip.st-cancelada { text-decoration: line-through; }
.chip.late { background: var(--danger-soft); color: var(--danger); }
.chip.pr-urgente { background: var(--danger); color: #fff; }
.chip.pr-alta { background: var(--warn-soft); color: var(--warn); }
.sync-err { color: var(--danger); cursor: help; }
.empty { text-align: center; color: var(--muted); padding: 26px 8px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 0 2px; }

/* semana */
.week { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.week.with-weekend { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 180px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.day.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.day-head b { font-family: Quicksand, Inter, sans-serif; }
.day-load { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
.mini {
  border: 1px solid var(--border); border-left: 3px solid var(--brand); border-radius: 8px; padding: 6px 8px; background: var(--surface);
  cursor: pointer; display: grid; gap: 2px; font-size: 13px;
}
.mini:hover { background: var(--surface-2); }
.mini.is-done { opacity: .6; border-left-color: var(--ok); }
.mini.pr-urgente { border-left-color: var(--danger); }
.mini .t { font-weight: 500; overflow-wrap: anywhere; }
.mini .m { font-size: 11px; color: var(--muted); }
.day.drop { outline: 2px dashed var(--brand); outline-offset: -4px; }

/* filtros e separadores */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input { width: auto; min-width: 150px; flex: 0 1 auto; }
.filters input[type="search"] { min-width: 200px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; flex-wrap: wrap; }
.seg button { font: inherit; border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }

/* tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
td.wrap { white-space: normal; min-width: 200px; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.chart { position: relative; height: 240px; }

/* diálogos */
dialog {
  border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(620px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; box-shadow: 0 24px 70px rgba(0,0,0,.28);
}
dialog::backdrop { background: rgba(30, 16, 10, .45); }
.dlg { padding: 20px 22px; display: grid; gap: 12px; }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.dlg .section { border-top: 1px solid var(--border); padding-top: 12px; display: grid; gap: 10px; }
.weekdays { display: flex; gap: 6px; flex-wrap: wrap; }
.weekdays label { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; cursor: pointer; }
.weekdays input { width: auto; }
.comments { display: grid; gap: 8px; max-height: 240px; overflow: auto; }
.comment { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.comment.k-devolvida { background: var(--warn-soft); }
.comment.k-validada { background: var(--ok-soft); }
.comment .who { font-size: 12px; color: var(--muted); }
.results { list-style: none; margin: 0; padding: 4px; border: 1px solid var(--border); border-radius: 10px; max-height: 200px; overflow: auto; }
.results li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.results li:hover { background: var(--brand-soft); }
.results small { color: var(--muted); display: block; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.notice.info { background: var(--info-soft); color: var(--info); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 32px);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500;
}
.toast.err { background: var(--danger); color: #fff; }

/* telemóvel */
.tabbar { display: none; }
@media (max-width: 960px) {
  .two-col { grid-template-columns: 1fr; }
  .week, .week.with-weekend { grid-template-columns: 1fr; }
  .day { min-height: 0; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .topbar .mobile-logo { display: block; }
  .topbar .hide-mobile { display: none; }
  .content { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
  }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: 8px 2px; font-size: 11px; color: var(--muted); text-decoration: none; }
  .tabbar a .ico { font-size: 18px; }
  .tabbar a.on { color: var(--brand-strong); font-weight: 600; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .value { font-size: 22px; }
  .kpi .label { font-size: 11px; letter-spacing: .03em; }
  .filters select, .filters input, .filters input[type="search"] { flex: 1 1 100%; min-width: 0; }
  .task { grid-template-columns: auto minmax(0, 1fr); }
  .task .actions { grid-column: 2; }
  .timer-pill .what { max-width: 120px; }
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .dlg { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: block; }
}
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }
