/* Alicerce — sistema visual. Tokens em :root; tema escuro por preferência do sistema ou escolha do utilizador. */
:root {
  --bg: #f3f4f6; --surface: #ffffff; --surface-2: #f8f9fb; --ink: #111827; --ink-2: #4b5563; --muted: #7b8494;
  --line: #e3e6eb; --line-2: #eef0f3; --side: #14181f; --side-ink: #c9ced8; --side-active: #232a35;
  --brand: #f5a524; --brand-ink: #1c1304; --focus: #2563eb;
  --good: #0c8a2c; --good-bg: #e3f6e7; --warn: #a15c00; --warn-bg: #fdf0d0; --bad: #c62828; --bad-bg: #fde5e3;
  --info: #1d5fb8; --info-bg: #e2eefc; --chapter: #f1f3f7;
  --s1: #2a78d6; --s2: #eb6834; --grid: #e1e0d9;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 8px 24px -12px rgba(16,24,40,.12);
  /* Textura das zonas escuras: brilho quente no canto, risca diagonal muito fina, degrade vertical. */
  --side-top: #171c25; --side-bottom: #10141b;
  --dark-texture: radial-gradient(140% 55% at 0% 0%, rgba(245,165,36,.10), rgba(245,165,36,0) 60%),
    repeating-linear-gradient(135deg, rgba(255,255,255,.03) 0 1px, rgba(255,255,255,0) 1px 9px),
    linear-gradient(180deg, var(--side-top) 0%, var(--side-bottom) 100%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --dark: 1; } }
:root[data-theme="dark"], :root.auto-dark {
  --bg: #0e1116; --surface: #171b22; --surface-2: #1c212a; --ink: #eceef2; --ink-2: #b8bfcb; --muted: #8b93a1;
  --line: #2a303b; --line-2: #222833; --side: #0a0c10; --side-active: #1b212b; --side-top: #0e1218; --side-bottom: #08090c;
  --good: #4cc56a; --good-bg: #12301b; --warn: #f0b545; --warn-bg: #38290a; --bad: #f2776f; --bad-bg: #3a1614;
  --info: #7db1f5; --info-bg: #14263f; --chapter: #1f2530; --s1: #3987e5; --s2: #d95926; --grid: #2c2c2a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 22px; letter-spacing: -.02em; } h2 { font-size: 16px; } h3 { font-size: 14px; }
a { color: inherit; }
.boot { padding: 40px; color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.grow { flex: 1; } .hide { display: none !important; }

/* ---------- estrutura ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--dark-texture); box-shadow: inset -1px 0 0 rgba(255,255,255,.06); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 14px 10px; }
.logo { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; color: #fff; font-weight: 700; font-size: 17px; text-decoration: none; }
.side .logo { padding-bottom: 16px; margin-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo img { width: 30px; height: 30px; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: var(--side-ink); font-weight: 500; transition: background .15s, color .15s; }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: rgba(255,255,255,.07); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--brand), inset 0 0 0 1px rgba(255,255,255,.05); }
.nav a.active svg { color: var(--brand); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.side-foot { margin-top: auto; padding: 14px 8px 2px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side-foot .who { display: flex; align-items: center; gap: 10px; }
.avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: rgba(245,165,36,.16); color: var(--brand); font-weight: 700; font-size: 13px; }
.side-foot strong { display: block; color: #fff; font-size: 13px; }
.side-foot .row { margin-top: 8px; }
.side-foot button { background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.14); color: var(--side-ink); border-radius: 6px; padding: 4px 8px; font: inherit; cursor: pointer; }
.side-foot button:hover { color: #fff; border-color: #56607a; }
.main { min-width: 0; padding: 22px 26px 60px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); margin-top: 3px; }
.crumb { color: var(--muted); font-size: 12px; text-decoration: none; display: inline-block; margin-bottom: 4px; }
.crumb:hover { color: var(--ink); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.bottom-nav { display: none; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 13px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid > * { min-width: 0; }  /* tabelas largas deslizam dentro do cartão em vez de alargarem a página */
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 14px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .hint { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.cols-2 { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 7px 12px; font: 600 13px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn { transition: border-color .15s, filter .15s, background .15s; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 1px 2px rgba(16,24,40,.12); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 700; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.brand { background: var(--brand); color: var(--brand-ink); }
.chip { display: inline-block; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: 11px; font-weight: 700; color: var(--ink-2); background: var(--surface-2); margin: 1px 2px 1px 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 9px 13px; text-decoration: none; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 700; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border-radius: 8px; background: var(--info-bg); color: var(--ink); text-decoration: none; margin-bottom: 6px; font-size: 13px; }
.alert.warn { background: var(--warn-bg); } .alert.danger { background: var(--bad-bg); }
.alert b { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--info); }
.alert.warn b { background: var(--warn); } .alert.danger b { background: var(--bad); }
.note { background: var(--info-bg); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }

/* ---------- formulários ---------- */
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; width: 100%; }
label.f input, label.f select, label.f textarea { margin-top: 4px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.toolbar input[type=search], .toolbar select { width: auto; min-width: 150px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.check input { width: auto; }

/* ---------- tabelas ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
.table-wrap.tall { max-height: calc(100vh - 290px); min-height: 260px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); white-space: nowrap; border-bottom: 1px solid var(--line); }
.card > .table-wrap:last-child { border-radius: 0 0 var(--radius) var(--radius); }
th.num { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }
tr.chapter td { background: var(--chapter); font-weight: 700; }
tr.chapter.l2 td { font-weight: 600; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); background: var(--surface-2); position: sticky; bottom: 0; }
tr.clickable { cursor: pointer; }
td.desc { min-width: 260px; max-width: 520px; }
td.code { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink-2); font-weight: 600; }
td.edit { cursor: text; }
td.edit:hover { box-shadow: inset 0 0 0 1px var(--muted); border-radius: 4px; }
td.edit input, td.cell-input input { text-align: right; padding: 3px 6px; min-width: 76px; }
td.best { background: var(--good-bg) !important; color: var(--good); font-weight: 700; }
td.worst { color: var(--bad); }
th.group { text-align: center; border-left: 1px solid var(--line); }
td.gl, th.gl { border-left: 1px solid var(--line); }
.bar { height: 8px; border-radius: 4px; background: var(--line-2); overflow: hidden; min-width: 70px; }
.bar i { display: block; height: 100%; background: var(--s1); border-radius: 4px; }

/* ---------- sobreposições ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(10,14,20,.5); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--surface); border-radius: 12px; width: min(560px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal.wide { width: min(1100px, 100%); }
.modal.mid { width: min(780px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; font-weight: 500; }
.toast.error { background: var(--bad); color: #fff; }

/* ---------- login ---------- */
/* Entrada: 30% formulario a esquerda, 70% imagem a direita; em ecras estreitos a imagem passa a faixa no topo. */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(340px, 3fr) 7fr; background: var(--surface); }
.login-panel { display: flex; flex-direction: column; gap: 28px; padding: 48px clamp(24px, 3.2vw, 48px); min-width: 0; }
.login .logo { color: var(--ink); padding: 0; font-size: 18px; }
.login .logo img { width: 34px; height: 34px; }
.login-intro { margin-top: auto; }
.login-intro h1 { font-size: 28px; }
.login-intro p { margin: 6px 0 0; color: var(--ink-2); font-size: 15px; }
.login form { display: grid; gap: 16px; }
.login form label.f { font-size: 13px; }
.login form input { height: 46px; padding: 0 12px; border-radius: 9px; font-size: 15px; margin-top: 6px; }
.login form .btn { height: 48px; justify-content: center; border-radius: 9px; font-size: 15px; font-weight: 700; }
.login-foot { margin-top: auto; padding-top: 20px; border-top: 1px solid var(--line-2); color: var(--muted); font-size: 12px; }
.login-art { position: relative; overflow: hidden; background: #10151d; color: #fff; min-height: 100vh; }
.login-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.login-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(13,18,25,.72) 0%, rgba(13,18,25,0) 38%); }
.login-claim { position: relative; z-index: 1; padding: 56px 0 56px 60px; max-width: min(640px, 56%); display: grid; gap: 14px; }
.login-claim span { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--brand); }
.login-claim strong { font-size: clamp(26px, 3vw, 38px); line-height: 1.12; letter-spacing: -.02em; }
.login-claim p { margin: 0; font-size: 16px; color: #c9ced8; }
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; grid-template-rows: 190px 1fr; }
  .login-art { order: -1; min-height: 0; }
  .login-claim { padding: 22px 24px; gap: 6px; max-width: none; } .login-claim p { display: none; } .login-claim strong { font-size: 22px; }
  .login-panel { padding: 28px 24px; gap: 22px; } .login-intro { margin-top: 0; }
}

/* ---------- planeamento ---------- */
.gantt { display: grid; grid-template-columns: minmax(150px, 240px) 1fr; font-size: 12px; }
.gantt .g-name { padding: 7px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.gantt .g-name:hover { color: var(--info); }
.gantt .g-track { position: relative; border-bottom: 1px solid var(--line-2); min-height: 32px; background-image: linear-gradient(to right, var(--line-2) 1px, transparent 1px); }
.gantt .g-head { font-weight: 700; color: var(--ink-2); background: var(--surface-2); display: flex; }
.gantt .g-head span { border-left: 1px solid var(--line); padding: 7px 6px; overflow: hidden; white-space: nowrap; }
.g-bar { position: absolute; top: 7px; height: 18px; border-radius: 4px; background: color-mix(in srgb, var(--s1) 30%, var(--surface)); border: 1px solid var(--s1); overflow: hidden; cursor: pointer; }
.g-bar i { display: block; height: 100%; background: var(--s1); }
.g-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); z-index: 1; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); padding: 6px 9px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); z-index: 5; }

/* ---------- telemóvel / tablet ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 14px 12px 84px; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--dark-texture); box-shadow: 0 -1px 0 rgba(255,255,255,.06); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a { flex: 1; display: grid; justify-items: center; gap: 2px; color: var(--side-ink); text-decoration: none; font-size: 10px; font-weight: 600; padding: 4px; border-radius: 8px; }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav svg { width: 20px; height: 20px; }
  .cols-2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .value { font-size: 19px; }
  .m-hide { display: none; }
  td.desc { min-width: 180px; }
  .toolbar { gap: 6px; padding: 8px; }
  .toolbar input[type=search], .toolbar select { flex: 1 1 130px; min-width: 0; }
  .toolbar .grow { display: none; }
  .toolbar .btn { padding: 6px 9px; font-size: 12px; }
  th, td { padding: 7px 8px; }
  .backdrop { padding: 0; align-items: stretch; }
  .modal, .modal.wide, .modal.mid { width: 100%; border-radius: 0; min-height: 100%; display: flex; flex-direction: column; }
  .modal-body { flex: 1; overflow: auto; padding: 14px; }
  .table-wrap.tall { max-height: none; }
  .toasts { left: 12px; right: 12px; bottom: 76px; }
  .gantt { grid-template-columns: 110px 1fr; }
}
@media print { .side, .bottom-nav, .toolbar, .btn { display: none !important; } .shell { display: block; } }

/* ---------- acompanhamento: tarefas e notas ---------- */
.todos { display: grid; gap: 2px; padding-top: 6px; padding-bottom: 6px; }
.todo { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.todo:last-child { border-bottom: 0; }
.todo input[type=checkbox] { width: 18px; height: 18px; flex: none; accent-color: var(--brand); }
.todo-main { flex: 1; min-width: 0; }
.todo-text { display: block; max-width: 100%; text-align: left; background: none; border: 0; padding: 0; font: inherit; color: var(--ink); cursor: pointer; }
.todo-text:hover { text-decoration: underline; }
.todo.done .todo-text { color: var(--ink-2); text-decoration: line-through; }
.todo-proj { display: block; text-decoration: none; }
.note-form { display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.note-form textarea { width: 100%; resize: vertical; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.obra-note { padding: 12px 16px; border-bottom: 1px solid var(--line-2); }
.obra-note:last-child { border-bottom: 0; }
.obra-note p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.chip.file { padding: 4px 8px; text-decoration: none; font-weight: 600; }
@media (max-width: 899px) { .todo { flex-wrap: wrap; } .todo-main { flex-basis: calc(100% - 30px); } }
