/* SIG KYRAN — estilos (sem frameworks externas, leve para ligações lentas) */
:root {
  --bg: #f4f6f8; --surface: #fff; --text: #1d2733; --muted: #6b7785; --line: #e2e7ec;
  --primary: #0f4c5c; --primary-2: #16697a; --accent: #e36414; --ok: #2a9d5c; --warn: #c98a0b; --err: #c0392b;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --side: 220px; --top: 56px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11161c; --surface: #1a2129; --text: #e6ebf0; --muted: #94a0ad; --line: #2b3540; --primary: #2a9db3; --primary-2: #3fb6cc; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { font-size: 12px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .right { text-align: right; }
.pos { color: var(--ok); } .neg { color: var(--err); } .warn { color: var(--warn); }

/* Layout */
.topbar { position: fixed; inset: 0 0 auto 0; height: var(--top); background: var(--primary); color: #fff; display: flex; align-items: center; gap: 14px; padding: 0 16px; z-index: 20; }
.topbar a { color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand.big { font-size: 22px; color: var(--primary); justify-content: center; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: #fff; color: #0f4c5c; font-weight: 800; }
.brand.big .logo { background: var(--primary); color: #fff; width: 40px; height: 40px; font-size: 22px; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
.user { margin-left: auto; font-size: 13px; white-space: nowrap; }
.user .logout { margin-left: 10px; opacity: .85; }
.sidebar { position: fixed; top: var(--top); bottom: 0; left: 0; width: var(--side); background: var(--surface); border-right: 1px solid var(--line); padding: 12px 8px; overflow-y: auto; z-index: 15; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.active { background: var(--primary); color: #fff; }
.sidebar .ico { width: 18px; text-align: center; opacity: .8; }
.sidebar .offline-link { margin-top: 12px; border-top: 1px solid var(--line); border-radius: 0; padding-top: 14px; }
.sidebar .version { color: var(--muted); font-size: 11px; padding: 12px; }
.content { margin: var(--top) 0 0 var(--side); padding: 20px 24px 40px; max-width: 1400px; }
.offline-page .content { margin-left: 0; }
.narrow-page { max-width: 720px; margin-left: auto !important; margin-right: auto; }

/* Estado de sincronização */
.sync { display: flex; align-items: center; gap: 8px; font-size: 12.5px; background: rgba(255,255,255,.12); padding: 4px 6px 4px 10px; border-radius: 999px; }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; }
.sync.offline .dot { background: #fbbf24; }
.sync.busy .dot { background: #60a5fa; animation: pulse 1s infinite; }
.sync .pending { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 8px; }
.sync .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); }
@keyframes pulse { 50% { opacity: .3; } }

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.span2 { grid-column: span 2; } .span3 { grid-column: 1 / -1; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; color: var(--text); box-shadow: var(--shadow); }
.kpi:hover { text-decoration: none; border-color: var(--primary-2); }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi.warn .kpi-value { color: var(--warn); } .kpi.danger .kpi-value { color: var(--err); }
.kpi.accent { background: var(--accent); color: #fff; border-color: var(--accent); } .kpi.accent .kpi-label { color: #fff; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.stat strong { font-size: 17px; }
.big { font-size: 20px; font-weight: 700; }
.account { display: flex; flex-direction: column; gap: 4px; color: var(--text); }
.account:hover { text-decoration: none; border-color: var(--primary-2); }
.account.inactive { opacity: .55; }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar span { display: block; height: 100%; background: var(--primary-2); }
.bar.sm { height: 6px; width: 80px; display: inline-block; vertical-align: middle; margin: 0 6px 0 0; }
.bar.over span { background: var(--err); }
.hbar { display: grid; grid-template-columns: 150px 1fr 110px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.hbar .track { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.hbar .track span { display: block; height: 100%; background: var(--accent); }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.table.small td, .table.small th { padding: 6px 8px; font-size: 12.5px; }
.scroll { overflow-x: auto; }
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 6px 4px; border-bottom: 1px dashed var(--line); }
.kv td:first-child { color: var(--muted); width: 38%; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--line); }
.grid-edit .cell { width: 92px; padding: 5px 6px; text-align: right; font-size: 12.5px; }
.grid-edit .sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; min-width: 190px; }
.receipt { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
code.wrap { white-space: pre-wrap; word-break: break-all; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge.green { background: #dcfce7; color: #166534; } .badge.blue { background: #dbeafe; color: #1e40af; }
.badge.red { background: #fee2e2; color: #991b1b; } .badge.amber { background: #fef3c7; color: #92400e; }
.badge.grey { background: #e5e7eb; color: #374151; } .badge.teal { background: #ccfbf1; color: #115e59; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 0 0 14px; border: 1px solid; }
.alert.ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

/* Formulários */
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
label.check.tiny { font-size: 11px; display: inline-flex; gap: 3px; margin-right: 6px; }
.form fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 14px; margin: 0; }
.form legend { font-weight: 700; padding: 0 6px; }
.form.narrow { max-width: 460px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; }
input[type=checkbox] { width: auto; min-height: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-2); outline-offset: -1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--primary); color: #fff; border: 1px solid var(--primary); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; min-height: 38px; white-space: nowrap; }
.btn:hover { background: var(--primary-2); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--primary-2); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--err); border-color: #fecaca; }
.btn.small { padding: 4px 10px; min-height: 28px; font-size: 12.5px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; cursor: pointer; color: var(--primary-2); padding: 0 4px; font: inherit; }
.link.danger { color: var(--err); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar.filters input, .toolbar.filters select { width: auto; }
.toolbar label { display: flex; gap: 6px; align-items: center; }
.spacer { flex: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.actions.stack { flex-direction: column; align-items: stretch; }
.form-inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-inline select, .form-inline input { width: auto; flex: 1 1 160px; }
form.inline { display: inline; }
details summary { cursor: pointer; color: var(--primary-2); margin: 6px 0; }

/* Autenticação */
.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); text-align: center; }
.auth-card.wide { max-width: 560px; text-align: left; }
.auth-card .form { display: flex; flex-direction: column; gap: 12px; text-align: left; margin-top: 16px; }

/* Recibos de vencimento (impressão) */
.print { background: #fff; color: #000; padding: 20px; }
.payslip { max-width: 760px; margin: 0 auto 30px; border: 1px solid #999; padding: 18px 22px; page-break-after: always; font-size: 13px; }
.payslip header { display: flex; justify-content: space-between; border-bottom: 2px solid #0f4c5c; padding-bottom: 10px; margin-bottom: 10px; }
.payslip .table th, .payslip .table td { border-color: #ccc; color: #000; }
.payslip .net { text-align: right; font-size: 16px; margin: 12px 0; padding: 10px; background: #f1f5f9; }
.payslip .signs { display: flex; justify-content: space-around; margin-top: 40px; }
.payslip .signs div { border-top: 1px solid #000; width: 220px; text-align: center; padding-top: 4px; }
@media print { .no-print { display: none !important; } .print { padding: 0; } .payslip { border: 0; } }

/* Telemóvel */
@media (max-width: 900px) {
  .menu-btn { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .nav-open .sidebar { transform: none; }
  .content { margin-left: 0; padding: 16px; }
  .grid.two, .grid.three, .grid.four { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3 { grid-column: auto; }
  .user small, .user { display: none; }
  .sync .btn { display: none; }
  .hbar { grid-template-columns: 110px 1fr 90px; }
  .card { overflow-x: auto; }
  .topbar { gap: 8px; padding: 0 10px; }
}
