:root {
  --primaria: #6366f1;
  --secundaria: #0a0e1a;
  --destaque: #10b981;

  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f2f3f8;
  --glass: color-mix(in srgb, #ffffff 72%, transparent);
  --ink: #0d1220;
  --ink-2: #565f74;
  --muted: #848da3;
  --line: #eaebf3;
  --line-2: #dfe1ec;
  --ring: color-mix(in srgb, var(--primaria) 20%, transparent);

  --r-sm: 10px; --r: 14px; --r-lg: 18px; --r-xl: 24px;
  --sh-1: 0 1px 2px rgba(20,22,45,.04), 0 1px 1px rgba(20,22,45,.03);
  --sh-2: 0 8px 24px -8px rgba(20,22,45,.14), 0 2px 6px rgba(20,22,45,.05);
  --sh-3: 0 30px 70px -20px rgba(10,12,26,.35), 0 10px 24px -10px rgba(10,12,26,.18);
  --glow: 0 0 0 1px color-mix(in srgb, var(--primaria) 16%, transparent), 0 10px 28px -10px color-mix(in srgb, var(--primaria) 55%, transparent);

  --ease-out: cubic-bezier(.16,1,.3,1);
  --dur-fast: .15s;
  --dur: .25s;
  --dur-slow: .4s;
}
* { box-sizing: border-box; }

/* ===== Tema escuro ===== */
[data-theme="dark"] {
  --bg: #0b0e1a;
  --surface: #131729;
  --surface-2: #1b2038;
  --glass: color-mix(in srgb, #131729 72%, transparent);
  --ink: #e9ebf7;
  --ink-2: #aab0c8;
  --muted: #7e86a5;
  --line: #232a47;
  --line-2: #2d3555;
  --sh-1: 0 1px 2px rgba(0,0,0,.25), 0 1px 1px rgba(0,0,0,.2);
  --sh-2: 0 8px 24px -8px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.3);
  --sh-3: 0 30px 70px -20px rgba(0,0,0,.75), 0 10px 24px -10px rgba(0,0,0,.5);
}
[data-theme="dark"] .badge { background: var(--surface-2); color: var(--ink-2); border-color: var(--line-2); }
[data-theme="dark"] .badge.aberta, [data-theme="dark"] .badge.agendada { background: color-mix(in srgb,#0ea5e9 16%,transparent); color: #7dd3fc; border-color: color-mix(in srgb,#0ea5e9 35%,transparent); }
[data-theme="dark"] .badge.em_curso, [data-theme="dark"] .badge.enviado { background: color-mix(in srgb,#f59e0b 16%,transparent); color: #fcd34d; border-color: color-mix(in srgb,#f59e0b 35%,transparent); }
[data-theme="dark"] .badge.concluida, [data-theme="dark"] .badge.aceite, [data-theme="dark"] .badge.ativo { background: color-mix(in srgb,#10b981 16%,transparent); color: #6ee7b7; border-color: color-mix(in srgb,#10b981 35%,transparent); }
[data-theme="dark"] .badge.faturada { background: color-mix(in srgb,#a855f7 16%,transparent); color: #d8b4fe; border-color: color-mix(in srgb,#a855f7 35%,transparent); }
[data-theme="dark"] .badge.cancelada, [data-theme="dark"] .badge.abatido, [data-theme="dark"] .badge.recusado { background: color-mix(in srgb,#ef4444 16%,transparent); color: #fca5a5; border-color: color-mix(in srgb,#ef4444 35%,transparent); }
[data-theme="dark"] .badge.rascunho { background: color-mix(in srgb,#6366f1 16%,transparent); color: #c7d2fe; border-color: color-mix(in srgb,#6366f1 35%,transparent); }
[data-theme="dark"] .badge.expirado { background: color-mix(in srgb,#a8a29e 14%,transparent); color: #d6d3d1; border-color: color-mix(in srgb,#a8a29e 32%,transparent); }
[data-theme="dark"] .stock-low { color: #f87171; }
[data-theme="dark"] .form-flat input:focus, [data-theme="dark"] .form-flat select:focus,
[data-theme="dark"] .form-flat textarea:focus, [data-theme="dark"] .login-card input:focus { background: var(--surface); }
[data-theme="dark"] .badge.aberta::before { background: #7dd3fc; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}
@keyframes shimmer {
  0% { background-position: -300px 0; }
  100% { background-position: 300px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
html, body { height: 100%; }
body {
  margin: 0; color: var(--ink);
  font-family: "Inter", system-ui, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  letter-spacing: -.011em;
  background:
    radial-gradient(1100px 600px at 108% -8%, color-mix(in srgb, var(--primaria) 10%, transparent), transparent 55%),
    radial-gradient(900px 560px at -12% 108%, color-mix(in srgb, var(--destaque) 7%, transparent), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
::selection { background: color-mix(in srgb, var(--primaria) 24%, transparent); }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
button:focus-visible, .link:focus-visible, a:focus-visible {
  outline: 2px solid var(--primaria); outline-offset: 2px; border-radius: 8px; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.error { color: #e11d48; font-size: .85rem; min-height: 1em; }
.link { background: none; border: none; color: var(--primaria); cursor: pointer; font-weight: 600; font-size: .88rem;
  display: inline-flex; align-items: center; gap: .32rem; vertical-align: middle;
  transition: color var(--dur-fast) var(--ease-out); }
.link:hover { color: color-mix(in srgb, var(--primaria) 78%, #000); }
.link svg { width: 14px; height: 14px; flex: none; }

/* Ações de linha só com ícone (o title explica no hover) */
.link.icon-only { width: 32px; height: 32px; justify-content: center; border-radius: 9px; padding: 0;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.link.icon-only svg { width: 16px; height: 16px; }
.link.icon-only:hover { background: color-mix(in srgb, var(--primaria) 10%, transparent); }
.link.icon-only.danger:hover { background: color-mix(in srgb, #dc2626 10%, transparent); }
svg { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* Logo */
.brand-logo {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  background: linear-gradient(135deg, var(--primaria), color-mix(in srgb, var(--primaria) 45%, #a855f7));
  color: #fff; font-weight: 800; border-radius: var(--r-lg); width: 56px; height: 56px;
  font-size: 1.4rem; overflow: hidden; box-shadow: var(--glow);
}
.brand-logo.sm { width: 40px; height: 40px; font-size: 1rem; border-radius: 13px; }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
/* Modo imagem: logótipo paisagem 235x70 (sem fundo/sombra do quadrado) */
.brand-logo.logo-img { width: 235px; height: 70px; max-width: 100%; border-radius: 8px;
  background: none; box-shadow: none; }
#login-logo.logo-img { margin: 0 auto; }

/* ===== Avatar ===== */
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: .8rem; color: #fff;
  background: linear-gradient(135deg, var(--primaria), color-mix(in srgb, var(--destaque) 65%, var(--primaria)));
  box-shadow: 0 0 0 2px color-mix(in srgb, #fff 12%, transparent); }
.avatar.sm { width: 34px; height: 34px; font-size: .72rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: .5rem; border: none; cursor: pointer;
  font-weight: 600; font-size: .88rem; color: #fff; padding: .64rem 1.1rem; border-radius: var(--r);
  background: var(--primaria);
  box-shadow: 0 1px 2px rgba(20,22,45,.06), 0 0 0 1px color-mix(in srgb, #000 4%, transparent) inset;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur) var(--ease-out), background var(--dur) var(--ease-out);
  font-family: inherit;
}
.btn:hover { transform: translateY(-1px); background: color-mix(in srgb, var(--primaria) 90%, #000);
  box-shadow: var(--glow); }
.btn:active { transform: translateY(0); }
.btn svg { width: 17px; height: 17px; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-2); box-shadow: var(--sh-1); }
.btn.ghost:hover { background: var(--surface-2); box-shadow: var(--sh-1); transform: translateY(-1px); }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm);
  background: transparent; border: 1px solid transparent; color: #93a0b4; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out); }
.icon-btn:hover { background: rgba(255,255,255,.09); color: #fff; transform: translateY(-1px); }
.icon-btn svg { width: 18px; height: 18px; }

/* ===== LOGIN ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.2rem;
  background:
    radial-gradient(900px 480px at 15% -6%, color-mix(in srgb, var(--primaria) 38%, transparent), transparent 62%),
    radial-gradient(700px 460px at 100% 100%, color-mix(in srgb, #a855f7 22%, transparent), transparent 60%),
    linear-gradient(160deg, var(--secundaria), color-mix(in srgb, var(--secundaria) 55%, #161c2e)); }
.login-card {
  background: color-mix(in srgb, #ffffff 94%, transparent); backdrop-filter: blur(24px) saturate(1.4);
  padding: 2.6rem 2.4rem; border-radius: var(--r-xl); width: 372px;
  display: flex; flex-direction: column; gap: .85rem; text-align: center;
  border: 1px solid rgba(255,255,255,.55); box-shadow: var(--sh-3);
  animation: scaleIn var(--dur-slow) var(--ease-out);
}
.login-card .brand-logo { margin: 0 auto; }
.login-card h1 { margin: .6rem 0 0; font-size: 1.55rem; font-weight: 800; letter-spacing: -.02em; }
.login-card .muted { margin: -.2rem 0 .6rem; }
.login-card input {
  padding: .82rem .95rem; border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--surface-2); font-size: .95rem; font-family: inherit;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.login-card input:focus { outline: none; background: #fff; border-color: var(--primaria); box-shadow: 0 0 0 4px var(--ring); }
.login-card .btn { justify-content: center; padding: .85rem; font-size: .95rem; margin-top: .2rem; }

/* ===== APP shell ===== */
.app { display: grid; grid-template-columns: 272px 1fr; min-height: 100vh; }
.sidebar {
  margin: 0; border: none; border-right: 1px solid rgba(255,255,255,.08); border-radius: 0;
  padding: 1.2rem 1rem 1rem;
  display: flex; flex-direction: column; color: #aeb9cb; position: sticky; top: 0; height: 100vh;
  background:
    radial-gradient(420px 260px at 100% 0%, color-mix(in srgb, var(--primaria) 22%, transparent), transparent 65%),
    var(--secundaria);
  box-shadow: none;
}
.brand { display: flex; align-items: center; gap: .7rem; color: #fff; font-weight: 800;
  font-size: 1.08rem; padding: .2rem 0 1.3rem; letter-spacing: -.01em; }
#nav { display: flex; flex-direction: column; gap: .22rem; flex: 1; }
#nav button {
  display: flex; align-items: center; gap: .75rem; text-align: left; cursor: pointer;
  background: none; border: none; color: var(--menu-texto, #9aa7bd); font-family: inherit; font-size: .89rem; font-weight: 500;
  padding: .62rem .8rem; border-radius: var(--r); transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); position: relative;
}
#nav .nav-ico { width: 18px; height: 18px; flex: none; opacity: .85; transition: opacity var(--dur-fast) var(--ease-out); }
#nav button:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav button.active { color: #fff;
  background: color-mix(in srgb, var(--primaria) 88%, #1e1b4b);
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--primaria) 70%, transparent); }
#nav button.active .nav-ico { opacity: 1; }

.sidebar-foot { display: flex; align-items: center; gap: .6rem; margin-top: .6rem; padding: .8rem .5rem 0;
  border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-foot .who { display: flex; flex-direction: column; line-height: 1.2; flex: 1; min-width: 0; }
.sidebar-foot .who span:first-child { color: #fff; font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .who .muted { font-size: .76rem; color: #8492a8; }

/* ===== Main ===== */
main { padding: 20px 32px 16px; min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
#content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin: 0 -32px 1.3rem;
  position: sticky; top: 0; z-index: 40; padding: .55rem 32px;
  background: color-mix(in srgb, var(--bg) 68%, transparent);
  backdrop-filter: blur(16px) saturate(1.2); -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent); }
.topbar h2 { margin: 0; font-size: 1.65rem; font-weight: 800; letter-spacing: -.025em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: .8rem; margin-left: auto; }
.topbar-right .icon-btn { color: var(--muted); }
.topbar-right .icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Botão de menu (só aparece no mobile) + fundo escuro da gaveta */
.menu-toggle { display: none; color: var(--ink); margin-right: .3rem; flex: none; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; z-index: 60;
  background: rgba(6,9,18,.5); opacity: 0; transition: opacity var(--dur) var(--ease-out); }

/* Dashboard — saudação */
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin: .2rem 0 1.3rem; animation: slideUp var(--dur-slow) var(--ease-out); }
.dash-head h3 { margin: 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; }
.dash-head p { margin: .15rem 0 0; color: var(--muted); font-size: .9rem; }
.dash-head p strong { color: var(--primaria); }

/* Widgets em tempo real (relógio + temperatura) */
.dash-live { display: flex; align-items: center; gap: .8rem; flex: none; }
.dash-relogio { display: flex; align-items: center; gap: .4rem; font-variant-numeric: tabular-nums;
  font-size: 1.4rem; font-weight: 800; letter-spacing: -.01em; color: var(--ink); }
.dash-relogio .dash-live-ico { width: 20px; height: 20px; fill: none; stroke: var(--primaria);
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.dash-tempo { display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: .4rem .8rem;
  border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--sh-1); }
.dash-tempo-ico { font-size: 1.5rem; line-height: 1; }
.dash-tempo-t { font-size: 1.3rem; font-weight: 800; color: var(--ink); }
.dash-tempo-loc { font-size: .72rem; color: var(--muted); max-width: 150px; line-height: 1.2; }

@media (max-width: 760px) {
  .dash-head { flex-direction: column; align-items: stretch; }
  .dash-live { justify-content: space-between; }
}

/* Stat cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit,minmax(210px,1fr)); gap: 1.1rem; }
.stat { --accent: var(--primaria);
  position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 1.3rem 1.4rem; box-shadow: var(--sh-1);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
  animation: slideUp var(--dur-slow) var(--ease-out) backwards; }
.stat::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent 70%);
  opacity: 0; transition: opacity var(--dur) var(--ease-out); }
.stat:hover { transform: translateY(-3px); box-shadow: var(--sh-2); }
.stat:hover::before { opacity: 1; }
.cards .stat:nth-child(1) { animation-delay: .02s; }
.cards .stat:nth-child(2) { animation-delay: .07s; --accent: #0ea5e9; }
.cards .stat:nth-child(3) { animation-delay: .12s; --accent: #f59e0b; }
.cards .stat:nth-child(4) { animation-delay: .17s; --accent: #10b981; }
.cards .stat:nth-child(n+5) { animation-delay: .22s; --accent: #a855f7; }
.stat .chip { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  margin-bottom: .9rem; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent); }
.stat .chip svg { width: 20px; height: 20px; }
.stat .n { font-size: 2.15rem; font-weight: 800; line-height: 1; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(150deg, var(--ink), color-mix(in srgb, var(--accent) 70%, var(--ink)));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat .l { color: var(--muted); font-size: .86rem; margin-top: .35rem; font-weight: 500; }

/* Toggle de vista (Lista | Calendário) */
.view-toggle { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  overflow: hidden; background: var(--surface); box-shadow: var(--sh-1); margin-left: auto; }
.view-toggle button { border: none; background: none; cursor: pointer; padding: .5rem .7rem;
  color: var(--muted); display: grid; place-items: center;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.view-toggle button svg { width: 16px; height: 16px; }
.view-toggle button:hover { color: var(--ink); }
.view-toggle button.active { background: var(--primaria); color: #fff; }

/* Calendário de ordens */
.cal-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-1); padding: 1.1rem 1.2rem; animation: slideUp var(--dur-slow) var(--ease-out); }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.cal-head .cal-titulo { font-size: 1.05rem; letter-spacing: -.01em; }
.cal-head .btn { padding: .45rem .8rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); padding-bottom: .45rem; }
.cal-dia { min-height: 92px; border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: .3rem; display: flex; flex-direction: column; gap: 3px; background: var(--surface); }
.cal-dia.vazio { border: none; background: none; }
.cal-dia.hoje { border-color: var(--primaria); box-shadow: inset 0 0 0 1px var(--primaria); }
.cal-dia.hoje .cal-num { background: var(--primaria); color: #fff; }
.cal-num { font-size: .74rem; font-weight: 600; color: var(--muted); width: 22px; height: 22px;
  display: grid; place-items: center; border-radius: 50%; flex: none; }
.cal-evento { position: relative; overflow: hidden; border: none; cursor: pointer;
  display: flex; flex-direction: column; text-align: left; font-family: inherit;
  padding: .3rem .44rem; border-radius: 7px; color: #fff; background: var(--primaria);
  transition: filter var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out); }
.cal-evento:hover { filter: brightness(1.1); transform: translateY(-1px); }
.cal-ev-bg { position: absolute; right: -4px; bottom: -9px; font-size: 2.4rem; line-height: 1;
  opacity: .32; pointer-events: none; }
.cal-ev-hora { display: flex; align-items: baseline; justify-content: space-between; gap: .3rem;
  font-size: .66rem; font-weight: 700; opacity: .95; position: relative; z-index: 1; }
.cal-ev-temp { font-size: .74rem; font-weight: 800; }
.cal-ev-cli { font-size: .8rem; font-weight: 700; line-height: 1.2; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 1; }
.cal-ev-sub { font-size: .63rem; font-weight: 500; opacity: .85; line-height: 1.25; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 1; text-transform: capitalize; }
.cal-evento.est-aberta, .cal-evento.est-agendada { background: #0284c7; }
.cal-evento.est-em_curso { background: #d97706; }
.cal-evento.est-concluida { background: #059669; }
.cal-evento.est-faturada { background: #7c3aed; }
.cal-evento.est-cancelada { background: #6b7280; }

@media (max-width: 760px) {
  .cal-card { padding: .8rem .7rem; }
  .cal-grid { gap: 2px; }
  .cal-dia { min-height: 64px; padding: .2rem; }
  .cal-num { width: 18px; height: 18px; font-size: .68rem; }
  .cal-evento { padding: .2rem .3rem; }
  .cal-ev-hora { font-size: .56rem; }
  .cal-ev-cli { font-size: .66rem; }
  .cal-ev-sub { display: none; }  /* poupa espaço no ecrã pequeno */
  .cal-ev-bg { font-size: 1.7rem; bottom: -6px; }
  .cal-wd { font-size: .62rem; }
}

/* Dashboard do técnico — agenda de intervenções */
.agenda-card { margin-top: 1.2rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-1); padding: 1.2rem 1.3rem;
  animation: slideUp var(--dur-slow) var(--ease-out) .15s backwards; }
.agenda-card h4 { margin: 0 0 .9rem; font-size: 1.02rem; font-weight: 700; letter-spacing: -.01em; }
.agenda-list { display: flex; flex-direction: column; gap: .6rem; }
.agenda-row { display: flex; align-items: center; gap: 1rem; padding: .85rem 1rem;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
.agenda-row:hover { border-color: color-mix(in srgb, var(--primaria) 35%, var(--line)); box-shadow: var(--sh-1); }
.agenda-row.hoje { border-left: 4px solid var(--primaria);
  background: color-mix(in srgb, var(--primaria) 3%, var(--surface)); }
.agenda-quando { display: flex; flex-direction: column; gap: .3rem; flex: none; min-width: 110px; }
.agenda-quando strong { font-size: .85rem; color: var(--ink); }
.agenda-info { display: flex; flex-direction: column; gap: .1rem; flex: 1; min-width: 0; }
.agenda-info strong { font-size: .95rem; }
.agenda-info span { font-size: .82rem; color: var(--ink-2); }
.agenda-info .agenda-morada { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agenda-acoes { display: flex; gap: .5rem; flex: none; }
.agenda-acoes .btn { padding: .5rem .85rem; font-size: .84rem; }
/* Botões de app na agenda (Waze / Google Maps / Ligar) */
.acao-app { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--sh-1);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
.acao-app:hover { transform: translateY(-1px); box-shadow: var(--sh-2); }
.acao-app:active { transform: scale(.96); }
.acao-app svg, .acao-app .icone-app { width: 24px; height: 24px; object-fit: contain; display: block; }
.acao-app.tel { color: #16a34a; }  /* o SVG de fallback do telefone usa currentColor */

@media (max-width: 760px) {
  .agenda-row { flex-direction: column; align-items: stretch; gap: .6rem; }
  .agenda-quando { flex-direction: row; align-items: center; justify-content: space-between; min-width: 0; }
  .agenda-acoes .btn { flex: 1; justify-content: center; padding: .7rem; font-size: .92rem; }
}

/* Previsão meteorológica (agenda, formulário) */
.agenda-info .agenda-meteo { display: inline-flex; align-items: center; gap: .25rem; align-self: flex-start;
  margin-top: .2rem; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  color: var(--ink-2); background: color-mix(in srgb, var(--primaria) 9%, var(--surface-2)); }
.meteo-box { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem;
  padding: .6rem .85rem; border-radius: var(--r); font-size: .88rem; color: var(--ink-2);
  background: color-mix(in srgb, var(--primaria) 6%, var(--surface-2)); border: 1px solid var(--line); }
.meteo-box .meteo-ico { font-size: 1.25rem; line-height: 1; }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-1); overflow: hidden; animation: slideUp var(--dur-slow) var(--ease-out); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .06em; }
tbody tr { transition: background var(--dur-fast) var(--ease-out); }
tbody tr:hover { background: color-mix(in srgb, var(--primaria) 4%, transparent); }
tr:last-child td { border-bottom: none; }

.toolbar { display: flex; gap: .7rem; margin-bottom: 1.2rem; align-items: center; flex-wrap: wrap; }
.toolbar input { padding: .66rem .9rem; border: 1px solid var(--line-2); border-radius: 12px; flex: 1;
  max-width: 320px; background: var(--surface); box-shadow: var(--sh-1); font-family: inherit; font-size: .9rem; }
.toolbar input:focus { outline: none; border-color: var(--primaria); box-shadow: 0 0 0 4px var(--ring); }

/* Caixa de pesquisa com ícone */
.search-box { position: relative; flex: 1; max-width: 320px; }
.search-box > svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
.search-box input { width: 100%; max-width: none; padding-left: 2.35rem; }
.search-box:focus-within > svg { color: var(--primaria); }

/* Estado vazio (listas sem resultados) */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: .35rem;
  padding: 2.6rem 1rem; text-align: center; color: var(--muted); }
.empty-state svg { width: 34px; height: 34px; color: var(--line-2); stroke-width: 1.4;
  margin-bottom: .3rem; }
.empty-state p { margin: 0; font-weight: 600; color: var(--ink-2); font-size: .95rem; }
.empty-state span { font-size: .82rem; }
.toolbar .filtro { padding: .62rem .8rem; border: 1px solid var(--line-2); border-radius: 12px;
  background: var(--surface); box-shadow: var(--sh-1); font-family: inherit; font-size: .88rem;
  color: var(--ink); cursor: pointer; }
.toolbar .filtro:focus { outline: none; border-color: var(--primaria); box-shadow: 0 0 0 4px var(--ring); }

.badge { display: inline-flex; align-items: center; gap: .38rem; padding: .28rem .7rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; background: var(--surface-2); color: #475569; border: 1px solid var(--line-2);
  text-transform: capitalize; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .75; flex: none; }
.badge.aberta, .badge.agendada { background: #e8f4ff; color: #0369a1; border-color: #cbe6ff; }
.badge.em_curso { background: #fff7e0; color: #92600a; border-color: #fde9b0; }
.badge.concluida { background: #e6f9ee; color: #15803d; border-color: #c2efd3; }
.badge.faturada { background: #f0ecfe; color: #6d28d9; border-color: #ddd4fb; }
.badge.cancelada, .badge.abatido { background: #ffeceb; color: #b91c1c; border-color: #fdd3d0; }
.badge.ativo { background: #e6f9ee; color: #15803d; border-color: #c2efd3; }
.badge.inativo { background: var(--surface-2); color: var(--muted); border-color: var(--line-2); }

/* Prioridade das ordens (funciona em tema claro e escuro via color-mix) */
.prio { display: inline-block; padding: .16rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.prio-baixa { background: color-mix(in srgb, var(--muted) 20%, transparent); color: var(--ink-2); }
.prio-normal { background: color-mix(in srgb, #0ea5e9 16%, transparent); color: #0284c7; }
.prio-alta { background: color-mix(in srgb, #f59e0b 20%, transparent); color: #b45309; }
.prio-urgente { background: color-mix(in srgb, #ef4444 18%, transparent); color: #dc2626; }

/* ===== Ficha do cliente (separadores) ===== */
.ficha-tabs { display: flex; gap: .4rem; margin: .2rem 0 1.1rem; flex-wrap: wrap; }
.ficha-tabs button { font-family: inherit; cursor: pointer; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink-2); font-size: .86rem; font-weight: 600;
  padding: .55rem 1rem; border-radius: 999px; transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out); }
.ficha-tabs button:hover { background: var(--surface-2); }
.ficha-tabs button.active { background: var(--primaria); color: #fff; border-color: transparent; box-shadow: var(--glow); }
.ficha-body { animation: fadeIn var(--dur) var(--ease-out); }

/* ===== Inline form: painel único + grelha plana que preenche a largura ===== */
.form-page { animation: fadeUp .28s cubic-bezier(.2,.7,.3,1); width: 100%; flex: 1;
  display: flex; flex-direction: column; min-height: 0; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.form-head { display: flex; align-items: center; gap: .85rem; margin-bottom: 1rem; }
.form-head h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }

.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-1); padding: 1.3rem 1.5rem 1.5rem; flex: 1; min-height: 0; }
.form-flat { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .7rem 1rem; align-content: start; }
/* Cabeçalho de secção: ocupa a linha toda e separa os grupos */
.form-flat .sec-head { grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink);
  margin-top: .45rem; padding-bottom: .4rem; border-bottom: 1px solid var(--line); }
.form-flat .sec-head:first-child { margin-top: 0; }
.form-flat .sec-ico { width: 14px; height: 14px; flex: none; color: var(--primaria); }
/* Campos */
.form-flat label { display: flex; flex-direction: column; gap: .35rem; font-size: .76rem;
  color: var(--muted); font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.form-flat .full { grid-column: 1 / -1; }
.form-flat .wide { grid-column: span 2; }
.form-flat p.muted { margin: 0; font-weight: 500; }
.form-flat input, .form-flat select, .form-flat textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line-2); border-radius: 9px; font-size: .86rem;
  color: var(--ink); background: var(--surface-2); font-family: inherit; transition: .16s; }
.form-flat textarea { resize: vertical; min-height: 2.6rem; }
.form-flat input:focus, .form-flat select:focus, .form-flat textarea:focus {
  outline: none; background: #fff; border-color: var(--primaria); box-shadow: 0 0 0 4px var(--ring); }
.code-chip { font-family: "SFMono-Regular", ui-monospace, "Cascadia Code", Consolas, monospace;
  font-weight: 700; font-size: .9rem; letter-spacing: .03em; color: var(--primaria);
  background: color-mix(in srgb, var(--primaria) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--primaria) 28%, transparent);
  padding: .35rem .75rem; border-radius: 999px; }
.back-btn { display: inline-flex; align-items: center; gap: .45rem; background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 12px; padding: .55rem .9rem; cursor: pointer;
  box-shadow: var(--sh-1); font-weight: 600; color: var(--ink); font-family: inherit; font-size: .88rem;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out); }
.back-btn svg { width: 15px; height: 15px; transition: transform var(--dur-fast) var(--ease-out); }
.back-btn:hover { background: var(--surface-2); }
.back-btn:hover svg { transform: translateX(-2px); }

/* ===== Color picker HTML ===== */
.color-field { display: flex; align-items: center; gap: .5rem; background: var(--surface-2);
  border: 1px solid var(--line-2); border-radius: 9px; padding: .25rem .4rem; transition: .16s; }
.color-field:focus-within { background: #fff; border-color: var(--primaria); box-shadow: 0 0 0 4px var(--ring); }
.color-swatch { width: 26px; height: 26px; border-radius: 7px; cursor: pointer; flex: none;
  border: 1px solid rgba(0,0,0,.12); box-shadow: inset 0 1px 2px rgba(255,255,255,.4); }
.color-swatch.cp-open { box-shadow: 0 0 0 3px var(--ring); }
.color-hex { border: none !important; background: none !important; box-shadow: none !important;
  padding: .3rem .1rem !important; font-family: ui-monospace, Consolas, monospace; text-transform: lowercase; width: 100%; }

.cp-pop { position: absolute; z-index: 200; width: 232px; padding: 12px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--sh-3);
  display: flex; flex-direction: column; gap: 10px; animation: fadeUp .14s ease; }
.cp-sv { position: relative; height: 132px; border-radius: 10px; cursor: crosshair;
  border: 1px solid rgba(0,0,0,.08); touch-action: none; }
.cp-thumb { position: absolute; width: 14px; height: 14px; border-radius: 50%; transform: translate(-50%, -50%);
  border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 1px 3px rgba(0,0,0,.4); pointer-events: none; }
.cp-hue { -webkit-appearance: none; appearance: none; width: 100%; height: 12px; border-radius: 999px; cursor: pointer;
  background: linear-gradient(to right, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.cp-hue::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 1px solid rgba(0,0,0,.3); box-shadow: 0 1px 3px rgba(0,0,0,.4); cursor: pointer; }
.cp-hue::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff;
  border: 1px solid rgba(0,0,0,.3); box-shadow: 0 1px 3px rgba(0,0,0,.4); cursor: pointer; }
.cp-row { display: flex; align-items: center; gap: 8px; }
.cp-prev { width: 30px; height: 30px; border-radius: 8px; flex: none; border: 1px solid rgba(0,0,0,.12); }
.cp-hex { flex: 1; border: 1px solid var(--line-2); border-radius: 8px; padding: .45rem .6rem;
  font-family: ui-monospace, Consolas, monospace; font-size: .85rem; background: var(--surface-2); }
.cp-hex:focus { outline: none; border-color: var(--primaria); box-shadow: 0 0 0 3px var(--ring); }
.cp-presets { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cp-chip { height: 22px; border-radius: 6px; border: 1px solid rgba(0,0,0,.12); cursor: pointer; padding: 0; transition: transform .1s; }
.cp-chip:hover { transform: scale(1.12); }
.form-actions { display: flex; justify-content: flex-end; gap: .7rem; position: sticky; bottom: 0;
  padding: .6rem 0 .1rem; background: linear-gradient(180deg, transparent, var(--bg) 55%); }

.upload-prev img { max-height: 66px; max-width: 190px; border: 1px solid var(--line-2);
  border-radius: 12px; padding: 6px; background: #fff; box-shadow: var(--sh-1); }

@media (max-width: 900px) {
  /* ===== Layout base: sidebar vira gaveta lateral ===== */
  .app { grid-template-columns: 1fr; }
  .menu-toggle { display: grid; }

  .sidebar {
    position: fixed; top: 0; left: 0; height: 100dvh; width: 270px; max-width: 84vw;
    z-index: 70; border-right: none; border-radius: 0 var(--r-lg) var(--r-lg) 0;
    transform: translateX(-102%); transition: transform var(--dur) var(--ease-out);
    box-shadow: 0 24px 60px -12px rgba(0,0,0,.5); overflow-y: auto;
  }
  body.sidebar-aberta .sidebar { transform: translateX(0); }
  body.sidebar-aberta .sidebar-backdrop { display: block; opacity: 1; }
  body.sidebar-aberta { overflow: hidden; }  /* não deixar o fundo fazer scroll */

  main { padding: 12px 16px 16px; }
  .topbar { margin: 0 -16px 1rem; padding: .5rem 16px; }
  .topbar h2 { font-size: 1.25rem; }
  .topbar-right { gap: .3rem; }

  .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
  .stat { padding: 1rem 1.1rem; }
  .stat .n { font-size: 1.7rem; }

  /* Notificações a toda a largura */
  .notif-panel { position: fixed; top: 64px; left: 8px; right: 8px; width: auto; max-width: none; }

  /* Toolbar empilha e ocupa a largura */
  .toolbar { gap: .5rem; }
  .toolbar .search-box, .toolbar input, .toolbar .filtro { max-width: none; width: 100%; flex: 1 1 100%; }
  .toolbar .btn, .toolbar .view-toggle { flex: 1 1 auto; justify-content: center; }

  .form-flat { grid-template-columns: 1fr; }
  .form-flat .wide { grid-column: 1 / -1; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; justify-content: center; }

  .modal-card { padding: 1.2rem 1.1rem; }
  .ficha-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .ficha-tabs button { white-space: nowrap; flex: none; }

  /* Qualquer tabela não-convertida faz scroll horizontal em vez de rebentar */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ===== Tabelas .table-cards-mobile viram cartões empilhados ===== */
  .table-cards-mobile, .table-cards-mobile table, .table-cards-mobile thead,
  .table-cards-mobile tbody, .table-cards-mobile th, .table-cards-mobile td,
  .table-cards-mobile tr { display: block; }
  .table-cards-mobile { overflow-x: visible; }
  .table-cards-mobile thead { display: none; }
  .table-cards-mobile tbody tr { border: 1px solid var(--line); border-radius: var(--r);
    margin: .7rem; padding: .5rem .9rem; box-shadow: var(--sh-1); }
  .table-cards-mobile td { border: none; padding: .5rem 0; display: flex;
    align-items: center; justify-content: space-between; gap: .8rem; font-size: .95rem;
    border-bottom: 1px solid var(--line); }
  .table-cards-mobile td:last-child { border-bottom: none; }
  .table-cards-mobile td[data-label]::before { content: attr(data-label); color: var(--muted);
    font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    flex: none; margin-right: 1rem; }
  .table-cards-mobile td.acoes-cell { justify-content: flex-end; padding-top: .3rem; }
  .table-cards-mobile td.acoes-cell:empty { display: none; }
  .table-cards-mobile td.acoes-cell::before { display: none; }
  .table-cards-mobile .link { padding: .45rem .3rem; font-size: .95rem; }
  .table-cards-mobile .link.icon-only { width: 40px; height: 40px; padding: 0; }
  .table-cards-mobile .link.icon-only svg { width: 19px; height: 19px; }
  .table-cards-mobile .app-ico { width: 40px; height: 40px; align-items: center; justify-content: center; margin-left: .1rem; }
  .table-cards-mobile .app-ico svg, .table-cards-mobile .app-ico .icone-app { width: 24px; height: 24px; }
  .table-cards-mobile .cell-logo-img, .table-cards-mobile .cell-logo-ph { height: 38px; width: auto; }
}

.backup-card {
  margin-top: 1rem;
  padding: 1rem;
}

.backup-head,
.backup-restore,
.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.backup-head h3 {
  margin: 0 0 .25rem;
}

.backup-restore {
  margin-top: 1rem;
  padding: .9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  flex-wrap: wrap;
}

.backup-restore input {
  max-width: 280px;
}

.backup-list {
  margin-top: 1rem;
  display: grid;
  gap: .65rem;
}

.backup-row {
  padding: .8rem .9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.backup-row div {
  min-width: 0;
}

.backup-row strong {
  display: block;
  overflow-wrap: anywhere;
}

.backup-row span {
  display: block;
  margin-top: .2rem;
  color: var(--muted);
  font-size: .82rem;
}

@media (max-width: 720px) {
  .backup-head,
  .backup-restore,
  .backup-row {
    align-items: stretch;
    flex-direction: column;
  }

  .backup-restore input {
    max-width: none;
    width: 100%;
  }
}

.link.danger {
  color: #dc2626;
}

/* ===== Registo de campo na OS (fotos + assinatura) ===== */
.foto-field, .sig-field { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; }
.foto-grid { display: flex; flex-wrap: wrap; gap: .5rem; width: 100%; }
.foto-grid:empty { display: none; }
.foto-thumb { position: relative; }
.foto-thumb img { width: 86px; height: 86px; object-fit: cover; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); display: block; }
.foto-del { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: #dc2626; color: #fff; cursor: pointer; font-size: .9rem; line-height: 1;
  display: grid; place-items: center; box-shadow: var(--sh-1); }
.foto-add { cursor: pointer; }
.sig-preview img { max-height: 80px; background: #fff; border: 1px solid var(--line-2);
  border-radius: var(--r-sm); padding: 4px; }
.sig-card { max-width: 700px; }
.sig-canvas { width: 100%; border: 1.5px dashed var(--line-2); border-radius: var(--r-sm);
  background: #fff; cursor: crosshair; margin-bottom: 1rem; }

/* Indicador de orçamento faturado no Moloni */
.fatura-ok { color: var(--destaque); font-weight: 600; font-size: .74rem; }

/* Link para abrir a morada no Waze (lista de ordens) */
/* Ícones de navegação (Waze/Maps) junto às moradas nas tabelas */
.morada-apps { display: inline-flex; align-items: center; }
.app-ico { display: inline-flex; vertical-align: middle; margin-left: .35rem;
  transition: transform var(--dur-fast) var(--ease-out); }
.app-ico:hover { transform: scale(1.15); }
.app-ico svg, .app-ico .icone-app { width: 18px; height: 18px; object-fit: contain; display: block; }
.app-ico + .app-ico { margin-left: .2rem; }

/* ── Auditoria ─────────────────────────────────────────── */
.audit-card { padding: 1.2rem 1.3rem; }

.audit-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.audit-head h3 { margin: 0 0 .2rem; }
.audit-head p  { margin: 0; }

/* Filtros */
.audit-filters {
  display: flex; gap: .55rem; flex-wrap: wrap;
  padding: .7rem .85rem; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  margin-bottom: 1rem;
}
.audit-filters select,
.audit-filters input { flex: 1; min-width: 160px; background: var(--surface); }

/* Lista tipo linha do tempo */
.audit-list {
  display: flex; flex-direction: column;
  border-left: 2px solid var(--line);
  margin-left: .6rem; padding-left: 1.2rem;
  gap: 0;
}

/* Cada registo */
.audit-row {
  position: relative;
  padding: .75rem .85rem .75rem 0;
  border-bottom: 1px solid var(--line);
  display: grid; gap: .3rem;
}
.audit-row:last-child { border-bottom: none; }

/* Bolinha na linha do tempo */
.audit-row::before {
  content: "";
  position: absolute;
  left: -1.5rem; top: 1.05rem;
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--surface);
}

/* Linha superior: badge + entidade + descrição */
.audit-main { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; min-width: 0; }

/* Badges coloridos */
.audit-badge {
  flex-shrink: 0;
  font-size: .7rem; font-weight: 700; letter-spacing: .02em;
  padding: .18rem .6rem; border-radius: 20px;
  background: var(--surface-2); color: var(--muted);
  text-transform: uppercase; white-space: nowrap;
}
.audit-badge-login    { background: color-mix(in srgb,#22c55e 18%,transparent); color: #16a34a; }
.audit-badge-backup,
.audit-badge-pre      { background: color-mix(in srgb,#3b82f6 16%,transparent); color: #1d4ed8; }
.audit-badge-criar,
.audit-badge-restaurar{ background: color-mix(in srgb,var(--primaria) 16%,transparent); color: var(--primaria); }
.audit-badge-editar,
.audit-badge-utilizador,
.audit-badge-cargo,
.audit-badge-permissoes{ background: color-mix(in srgb,#f59e0b 16%,transparent); color: #b45309; }
.audit-badge-apagar   { background: color-mix(in srgb,#ef4444 16%,transparent); color: #b91c1c; }

/* Bolinha colorida consoante a ação */
.audit-row:has(.audit-badge-login)::before,
.audit-row:has(.audit-badge-criar)::before,
.audit-row:has(.audit-badge-restaurar)::before { border-color: var(--primaria); background: color-mix(in srgb,var(--primaria) 30%,transparent); }
.audit-row:has(.audit-badge-apagar)::before    { border-color: #ef4444; background: color-mix(in srgb,#ef4444 25%,transparent); }
.audit-row:has(.audit-badge-editar)::before    { border-color: #f59e0b; background: color-mix(in srgb,#f59e0b 25%,transparent); }
.audit-row:has(.audit-badge-backup)::before,
.audit-row:has(.audit-badge-pre)::before       { border-color: #3b82f6; background: color-mix(in srgb,#3b82f6 25%,transparent); }

.audit-entity { font-size: .78rem; color: var(--muted); font-weight: 500; }
.audit-desc   { font-size: .875rem; color: var(--text); min-width: 0; }

/* Linha inferior: metadados */
.audit-meta {
  display: flex; align-items: center; gap: .65rem;
  flex-wrap: wrap; font-size: .75rem; color: var(--muted);
}
.audit-user { display: flex; align-items: center; gap: .22rem; font-weight: 500; }
.ico-xs { width: 12px; height: 12px; flex-shrink: 0; stroke-width: 2; }
.audit-ip   { font-family: monospace; font-size: .72rem; opacity: .8; }
.audit-date { margin-left: auto; font-size: .73rem; opacity: .75; }

/* Diff antes/depois */
.audit-diff { margin-top: .15rem; }
.audit-diff summary {
  cursor: pointer; user-select: none;
  font-size: .74rem; color: var(--muted);
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .5rem; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  width: fit-content; transition: background .15s;
}
.audit-diff summary:hover { background: var(--line); }
.audit-diff[open] summary { margin-bottom: .4rem; }
.audit-diff-table { border-collapse: collapse; width: 100%; font-size: .78rem; border-radius: 8px; overflow: hidden; }
.audit-diff-table th,
.audit-diff-table td { padding: .25rem .6rem; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.audit-diff-table th { background: var(--surface-2); font-weight: 600; font-size: .73rem; color: var(--muted); }
.audit-field  { font-family: monospace; font-size: .76rem; color: var(--text); }
.audit-before { color: #b91c1c; background: color-mix(in srgb,#ef4444 6%,transparent); font-family: monospace; font-size: .76rem; }
.audit-after  { color: #15803d; background: color-mix(in srgb,#22c55e 6%,transparent); font-family: monospace; font-size: .76rem; }

/* Paginação */
.audit-pager {
  display: flex; align-items: center; gap: .75rem;
  margin-top: .9rem; justify-content: flex-end;
  padding-top: .7rem; border-top: 1px solid var(--line);
}
.audit-pager #audit-info { font-size: .8rem; color: var(--muted); margin-right: auto; }

@media (max-width: 760px) {
  .audit-head { flex-direction: column; }
  .audit-date { margin-left: 0; }
  .audit-list { margin-left: .3rem; padding-left: .9rem; }
}

/* Definições — submenus no nav */
.nav-group { display: flex; flex-direction: column; gap: .22rem; }
.nav-parent .nav-caret { width: 15px; height: 15px; margin-left: auto; opacity: .7;
  transition: transform var(--dur) var(--ease-out); }
.nav-group.open .nav-parent .nav-caret { transform: rotate(180deg); }
.nav-sub {
  display: grid; grid-template-rows: 0fr; opacity: 0;
  transition: grid-template-rows var(--dur) var(--ease-out), opacity var(--dur-fast) var(--ease-out), margin var(--dur) var(--ease-out);
  margin: 0 0 0 .5rem; padding-left: .7rem; border-left: 1px solid rgba(255,255,255,.12);
}
.nav-sub > div { display: flex; flex-direction: column; gap: .1rem; overflow: hidden; min-height: 0; }
.nav-group.open .nav-sub { grid-template-rows: 1fr; opacity: 1; margin: .1rem 0 .25rem .5rem; }
.nav-sub button { font-size: .87rem; padding: .5rem .7rem; }
.nav-sub .nav-ico { width: 16px; height: 16px; }

.def-single { display: block; }
.def-form { padding: 1.2rem 1.3rem; max-width: 720px; }
.def-form h3 { margin: 0 0 1rem; }

/* ---------- Stock ---------- */
.badge.rascunho { background: #f0f4ff; color: #4338ca; border-color: #c7d2fe; }
.badge.enviado  { background: #fff7e0; color: #92600a; border-color: #fde9b0; }
.badge.aceite   { background: #e6f9ee; color: #15803d; border-color: #c2efd3; }
.badge.recusado { background: #ffeceb; color: #b91c1c; border-color: #fdd3d0; }
.badge.expirado { background: #f4f1ec; color: #78716c; border-color: #e2ddd5; }
.stock-low { color: #b91c1c; font-weight: 600; }

/* ---------- Paginação de tabelas ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: .7rem; flex-wrap: wrap; }
.pager-nav { display: flex; align-items: center; gap: .4rem; }
.pager-nav .btn { padding: .35rem .7rem; }

.stock-info-row { grid-column: 1/-1; display: flex; align-items: center; gap: 1rem;
  padding: .6rem .8rem; background: var(--surface-2); border-radius: var(--r-sm);
  border: 1px solid var(--line); font-size: .88rem; }
.stock-info-row small { margin-left: auto; }

.readonly-label { display: flex; flex-direction: column; gap: .25rem; }
.readonly-label span { font-size: .95rem; font-weight: 600; padding: .35rem 0; }

/* ---------- Orçamentos — tabela de linhas ---------- */
.orc-itens-wrap { overflow-x: auto; }
.orc-itens-table { width: 100%; border-collapse: collapse; font-size: .83rem; }
.orc-itens-table th { text-align: left; padding: .3rem .45rem; font-size: .72rem; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: nowrap; }
.orc-itens-table td { padding: .28rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.orc-itens-table input, .orc-itens-table select { padding: .22rem .4rem; font-size: .82rem; width: 100%;
  border: 1px solid var(--line-2); border-radius: 6px; background: var(--surface); color: var(--ink); }
.orc-itens-table input:focus, .orc-itens-table select:focus { outline: none; border-color: var(--primaria); }
.orc-sub, .orc-total-iva { white-space: nowrap; font-weight: 600; color: var(--ink); min-width: 75px; }
.orc-total-iva { color: var(--primaria); }
.orc-tipo-cell { min-width: 130px; }

/* Pills de tipo de linha */
.orc-tipo-pill { display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; padding: .15rem .5rem; border-radius: 20px; white-space: nowrap; }
.orc-pill-servico { background: color-mix(in srgb,#3b82f6 14%,transparent); color: #1d4ed8; }
.orc-pill-mao_de_obra { background: color-mix(in srgb,#f59e0b 14%,transparent); color: #b45309; }

/* Totais */
.orc-totais { margin-top: .8rem; padding: .6rem .8rem; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-sm); display: flex;
  flex-direction: column; gap: .2rem; max-width: 340px; margin-left: auto; }
.orc-totais-row { display: flex; justify-content: space-between; font-size: .85rem;
  color: var(--ink-2); padding: .1rem 0; }
.orc-total-final { border-top: 1px solid var(--line-2); margin-top: .2rem; padding-top: .35rem;
  color: var(--ink); font-size: .95rem; }
.orc-total-final strong { color: var(--primaria); font-size: 1.05rem; }
.orc-margem { font-size: .8rem; color: var(--muted); }

/* Campos de upload de ficheiro (documentos de fornecedor, etc.) */
.file-field { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .8rem; }
.file-field .file-input { font-size: .85rem; max-width: 100%; }
.file-field .file-link { font-size: .82rem; color: var(--primaria); text-decoration: none; }
.file-field .file-link:hover { text-decoration: underline; }
.file-field .file-status { font-size: .8rem; color: var(--muted); }

/* Logo da marca na lista (logo + nome) */
.cell-logo { display: flex; align-items: center; gap: .7rem; }
.cell-logo-img { height: 46px; width: auto; max-width: 150px; object-fit: contain;
  border-radius: var(--r-sm); background: #fff; border: 1px solid var(--line);
  padding: 4px 8px; flex: none; }
.cell-logo-ph { width: 46px; height: 46px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line);
  color: var(--muted); font-weight: 700; font-size: 1.1rem; flex: none; }

/* ===== Botão perigo (confirmação de eliminação) ===== */
.btn.danger { background: linear-gradient(180deg, #f87171, #dc2626);
  box-shadow: var(--sh-1), inset 0 1px 0 rgba(255,255,255,.3); }
.btn.danger:hover { filter: saturate(1.1) brightness(1.03); }

/* ===== Toasts ===== */
#toast-stack { position: fixed; top: 1.1rem; right: 1.1rem; z-index: 1000;
  display: flex; flex-direction: column; gap: .6rem; max-width: min(360px, calc(100vw - 2.2rem)); }
.toast { display: flex; align-items: flex-start; gap: .6rem; background: var(--surface);
  border: 1px solid var(--line-2); border-left: 4px solid var(--primaria);
  border-radius: var(--r); box-shadow: var(--sh-3); padding: .85rem 1rem;
  font-size: .88rem; color: var(--ink); animation: slideUp var(--dur) var(--ease-out); }
.toast-success { border-left-color: var(--destaque); }
.toast-error { border-left-color: #e11d48; }
.toast-info { border-left-color: var(--primaria); }
.toast-msg { flex: 1; line-height: 1.4; }
.toast-close { background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 1.1rem; line-height: 1; padding: 0; }
.toast-close:hover { color: var(--ink); }
.toast-out { animation: toastOut var(--dur) var(--ease-out) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }

/* ===== Modal de confirmação ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(11,18,32,.45); z-index: 1100;
  display: grid; place-items: center; padding: 1rem; animation: fadeIn var(--dur-fast) var(--ease-out); }
.modal-card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-3);
  padding: 1.5rem 1.6rem; max-width: 420px; width: 100%; animation: scaleIn var(--dur) var(--ease-out); }
.modal-card h3 { margin: 0 0 .6rem; font-size: 1.15rem; }
.modal-card p { margin: 0 0 1.2rem; color: var(--ink-2); font-size: .92rem; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }
/* Nome de animação dedicado: reutilizar "fadeIn" invertido não reinicia a
   animação (o browser só reinicia quando o animation-name muda) e o overlay
   ficava preso no ecrã a bloquear cliques. */
@keyframes modalOut { to { opacity: 0; } }
.modal-out { animation: modalOut var(--dur-fast) var(--ease-out) forwards; }

/* ===== Sino de notificações ===== */
.notif-wrap { position: relative; }
.notif-badge { position: absolute; top: -2px; right: -2px; min-width: 17px; height: 17px;
  padding: 0 4px; border-radius: 999px; background: #e11d48; color: #fff; font-size: .64rem;
  font-weight: 700; display: grid; place-items: center; line-height: 1;
  box-shadow: 0 0 0 2px var(--surface); animation: pulse .5s var(--ease-out); }
.notif-panel { position: absolute; top: calc(100% + 10px); right: 0; width: 340px; max-width: 90vw;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-lg);
  box-shadow: var(--sh-3); z-index: 90; overflow: hidden; animation: scaleIn var(--dur) var(--ease-out); transform-origin: top right; }
.notif-panel-head { display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.notif-panel-head strong { font-size: .92rem; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: .7rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background var(--dur-fast) var(--ease-out); }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: color-mix(in srgb, var(--primaria) 5%, transparent); }
.notif-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: .35rem;
  background: var(--muted); }
.notif-dot.notif-stock_baixo { background: #e11d48; }
.notif-dot.notif-auditoria { background: var(--primaria); }
.notif-dot.notif-prazo { background: #f59e0b; }
.notif-body { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.notif-body strong { font-size: .86rem; }
.notif-body span { font-size: .82rem; color: var(--ink-2); overflow-wrap: break-word; }
.notif-body time { font-size: .74rem; color: var(--muted); }

/* ============================================================
   Polish mobile (telemóvel) — toque, leitura e safe-area.
   Bloco no fim para vencer regras base de igual especificidade.
   ============================================================ */
@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  /* Sem realce cinzento ao tocar — o feedback vem dos estados :active */
  * { -webkit-tap-highlight-color: transparent; }

  /* Campos a 16px: impede o ZOOM automático do iOS ao focar um campo */
  .form-flat input, .form-flat select, .form-flat textarea,
  .login-card input, .toolbar input, .toolbar .filtro,
  .audit-filters input, .backup-restore input,
  input, select, textarea { font-size: 16px; }

  /* Áreas de toque confortáveis (~44px) */
  .btn { padding: .78rem 1.15rem; min-height: 46px; }
  .btn svg { width: 18px; height: 18px; }
  .icon-btn { width: 42px; height: 42px; }
  .icon-btn svg { width: 20px; height: 20px; }
  .link { padding: .3rem .2rem; }
  #nav button { padding: .8rem .85rem; font-size: .95rem; }
  #nav button:active { background: rgba(255,255,255,.1); }
  .btn:active { transform: scale(.98); }

  /* Formulário mais folgado para o dedo */
  .form-flat input, .form-flat select, .form-flat textarea { padding: .72rem .8rem; border-radius: 11px; }
  .form-flat label { font-size: .8rem; gap: .3rem; }
  .form-flat textarea { min-height: 3.4rem; }

  /* Login a preencher melhor o ecrã */
  .login-card { width: 100%; max-width: 400px; padding: 2rem 1.5rem; }
  .login-card input { padding: .9rem 1rem; font-size: 16px; }

  /* Safe-area (notch / barra inferior do telemóvel) */
  main { padding-left: max(16px, env(safe-area-inset-left));
         padding-right: max(16px, env(safe-area-inset-right)); }
  .sidebar { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }

  /* Cartões de tabela: mais respiro e valores legíveis */
  .table-cards-mobile tbody tr { margin: .7rem 0; padding: .3rem 1rem; }
  .table-cards-mobile td { padding: .68rem 0; font-size: 1rem; }
  .table-cards-mobile td[data-label]::before { font-size: .72rem; }

  /* Paginação tocável */
  .pager-nav .btn { min-height: 42px; }

  /* Calendário: células mais altas e chips um pouco maiores */
  .cal-dia { min-height: 78px; }
  .cal-ev-hora { font-size: .6rem; }
  .cal-ev-cli { font-size: .72rem; }
}

/* ============================================================
   Cartões de ordem no telemóvel (estilo app de campo / Uber):
   destino em destaque + barra de ações Waze / Maps / Ligar.
   ============================================================ */
.ordens-cards { display: flex; flex-direction: column; gap: .8rem; }
.ordem-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-1); padding: 1rem 1.05rem; display: flex; flex-direction: column; gap: .7rem;
  transition: transform var(--dur-fast) var(--ease-out); }
.ordem-card.clicavel { cursor: pointer; }
.ordem-card.clicavel:active { transform: scale(.995); }
.ordem-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; }
.ordem-card-cli { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.ordem-card-cli strong { font-size: 1.06rem; font-weight: 700; line-height: 1.2; }
.ordem-card-cli .muted { font-size: .82rem; }
.ordem-card-morada { display: flex; align-items: flex-start; gap: .45rem; font-size: .92rem; color: var(--ink-2); }
.ordem-card-morada svg { width: 17px; height: 17px; flex: none; margin-top: .12rem;
  fill: none; stroke: var(--primaria); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ordem-card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem .9rem; font-size: .85rem; color: var(--ink-2); }
.ordem-card-meta > span { display: inline-flex; align-items: center; gap: .35rem; }
.ordem-card-meta svg { width: 15px; height: 15px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ordem-card-apps { display: flex; flex-direction: column; gap: .5rem; margin-top: .1rem; }
.ordem-nav-row { display: flex; gap: .5rem; }
.ordem-contactar { flex: 0 0 auto; width: 100%; }
.ordem-app { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 50px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line-2);
  font-weight: 700; font-size: .92rem; color: var(--ink); text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out); }
.ordem-app:active { transform: scale(.97); }
.ordem-app.tel { color: #16a34a; }
.ordem-app .icone-app, .ordem-app svg { width: 22px; height: 22px; object-fit: contain; }
