:root {
    --brand: #00afef;
    --brand-dark: #0077c2;
    --navy: #10233f;
    --bg: #f4f7fb;
    --card: #ffffff;
    --line: #e3e9f2;
    --text: #1c2b40;
    --muted: #6b7a90;
    --ok: #1b8a5a;
    --warn: #b7791f;
    --bad: #c0392b;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 35, 63, .06), 0 6px 18px rgba(16, 35, 63, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { margin: 0; font-size: 26px; color: var(--navy); }
h2 { margin: 0 0 12px; font-size: 18px; color: var(--navy); }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.inline { display: inline; }

/* ---------- Formulários e botões ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #46566e; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--text); }
input[type=text], input[type=password], input[type=email], select {
    width: 100%; padding: 12px 13px; border: 1px solid #d3dce9; border-radius: 10px; font-size: 16px; background: #fbfcfe; font-family: inherit; color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(0, 175, 239, .18); }
.hint { font-weight: 400; font-size: 12px; color: var(--muted); }

.btn { display: inline-block; padding: 10px 18px; border: 1px solid #cfd8e6; border-radius: 10px; background: #fff; color: var(--navy); font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; text-align: center; }
.btn:hover { background: #f1f5fa; text-decoration: none; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); border-color: transparent; color: #fff; font-size: 15px; padding: 12px 18px; }
.btn-primary:hover { background: linear-gradient(135deg, #0099d6, #00629e); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { display: block; width: 100%; }
.link-button { background: none; border: 0; padding: 0; color: var(--brand-dark); font-size: 14px; cursor: pointer; font-family: inherit; }
.link-button:hover { text-decoration: underline; }

.flash { border-radius: 10px; padding: 12px 16px; margin-bottom: 14px; font-size: 14px; }
.flash-success { background: #e6f6ee; color: #14633f; }
.flash-error { background: #fdecea; color: #922b21; }
.flash-warn { background: #fff4de; color: #8a5a00; }

.chip { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600; background: #e9eef5; color: #46566e; white-space: nowrap; }
.chip-lg { font-size: 14px; padding: 5px 14px; }
.chip-ok { background: #e1f5ea; color: #14633f; }
.chip-warn { background: #fff0cf; color: #8a5a00; }
.chip-bad { background: #fde5e2; color: #922b21; }

/* ---------- Páginas públicas (entrar, primeiro acesso, definir palavra-passe) ---------- */
body.public { min-height: 100vh; background: #020a1a; position: relative; overflow-x: hidden; }
.public-bg { position: fixed; inset: 0; background: linear-gradient(135deg, #020a1a 0%, #06265c 45%, #00afef 100%); z-index: 0; }
.public-bg::before, .public-bg::after { content: ''; position: absolute; border-radius: 50%; }
.public-bg::before { width: 620px; height: 620px; top: -220px; right: -160px; background: radial-gradient(circle, rgba(0, 175, 239, .55) 0%, rgba(0, 175, 239, 0) 70%); }
.public-bg::after { width: 520px; height: 520px; bottom: -200px; left: -140px; background: radial-gradient(circle, rgba(255, 255, 255, .12) 0%, rgba(255, 255, 255, 0) 70%); }
.public-wrap { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.public-card { width: 100%; max-width: 440px; background: rgba(255, 255, 255, .97); border-radius: 18px; padding: 34px 32px 30px; box-shadow: 0 20px 60px rgba(0, 10, 30, .45); }
.public-logo { display: block; margin-bottom: 22px; }
.public-logo img { display: block; }
.public-card h1 { font-size: 24px; margin-bottom: 8px; }
.public-card .intro { color: var(--muted); margin-bottom: 18px; }
.public-links { text-align: center; margin: 18px 0 0; font-size: 14px; }
.public-foot { margin: 18px 0 0; color: rgba(255, 255, 255, .7); font-size: 12px; text-align: center; }
.email-choices { display: flex; flex-direction: column; gap: 8px; }
.choice { flex-direction: row; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid #d3dce9; border-radius: 10px; font-weight: 600; color: var(--navy); cursor: pointer; background: #fbfcfe; }
.choice:has(input:checked) { border-color: var(--brand); background: #eef8fd; }
.form-cancel { text-align: center; margin-top: 14px; }
.captcha-dev { padding: 10px 12px; border: 1px dashed #b7c2d3; border-radius: 10px; }

/* ---------- Área com sessão ---------- */
.impersonate-bar { position: sticky; top: 0; z-index: 60; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 20px; background: #b23c10; color: #fff; font-size: 14px; }
.impersonate-bar .btn { background: #fff; color: #7a2706; border-color: transparent; }

.topbar { background: var(--card); box-shadow: 0 1px 3px rgba(16, 35, 63, .08); position: sticky; top: 0; z-index: 50; }
.impersonate-bar ~ .topbar { top: 46px; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; gap: 24px; }
.brand img { display: block; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #4b5b73; font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 20px; white-space: nowrap; }
.nav a:hover { background: #eef5fc; color: var(--brand-dark); text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 13px; font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout { font-size: 13px; font-weight: 600; color: var(--bad); background: none; border: 1px solid #f1d4d0; border-radius: 20px; padding: 6px 14px; cursor: pointer; font-family: inherit; }
.btn-logout:hover { background: #fdf0ef; }
.nav-toggle { display: none; background: none; border: 0; font-size: 26px; cursor: pointer; color: var(--navy); }

.content { max-width: 1100px; margin: 0 auto; padding: 26px 24px 40px; min-height: calc(100vh - 140px); }
.app-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 28px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card + .card { margin-top: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; align-items: start; }
.grid-2 > .card + .card { margin-top: 0; }

.hero { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; background: linear-gradient(135deg, #ffffff 0%, #eef8fd 100%); }
.hero p { margin: 0; }

.avatar { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 16px; overflow: hidden; background: #cfd8e6; }
.avatar img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.avatar-xs { width: 32px; height: 32px; border-radius: 9px; font-size: 12px; }
.avatar-lg { width: 76px; height: 76px; font-size: 26px; border-radius: 18px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; color: var(--text); border-top: 4px solid var(--brand); }
a.stat:hover { text-decoration: none; transform: translateY(-1px); }
.stat-num { font-size: 26px; font-weight: 700; color: var(--navy); }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-warn { border-top-color: #e0a526; }
.stat-ok { border-top-color: var(--ok); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filters select { width: auto; min-width: 150px; }

.details { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 0 12px; font-size: 14px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.more { margin: 12px 0 0; font-size: 14px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 11px 10px; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
.table .num { text-align: right; white-space: nowrap; }

/* ---------- Telemóvel ---------- */
@media (max-width: 760px) {
    .topbar-inner { flex-wrap: wrap; padding: 8px 14px; gap: 8px; }
    .nav-toggle { display: block; margin-left: auto; }
    .nav { display: none; flex-basis: 100%; flex-direction: column; order: 3; }
    .nav.open { display: flex; }
    .topbar-user { order: 2; flex: 1 1 100%; justify-content: space-between; }
    .user-name { max-width: none; flex: 1; }
    .content { padding: 18px 14px 30px; }
    h1 { font-size: 22px; }
    .public-card { padding: 28px 22px 24px; }
    .hero { flex-direction: column; text-align: center; }
    .details { grid-template-columns: 1fr; gap: 2px; }
    .details dt { margin-top: 10px; font-size: 12px; text-transform: uppercase; }
    .filters select { flex: 1 1 45%; }
    .grid-2 { grid-template-columns: 1fr; }
    .card-flush { padding: 0; background: none; box-shadow: none; }
    .table.stack thead { display: none; }
    .table.stack tr { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; }
    .table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 6px 0; text-align: right; }
    .table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-transform: uppercase; text-align: left; }
    .table.stack td[data-label=""]::before { content: none; }
}

/* ---------- Fase 3: suporte, mensagens seguras, pedidos de dados ---------- */
textarea { width: 100%; padding: 12px 13px; border: 1px solid #d3dce9; border-radius: 10px; font-size: 16px; background: #fbfcfe; font-family: inherit; color: var(--text); resize: vertical; }
textarea:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px rgba(0, 175, 239, .18); }
input[type=file] { font-size: 14px; }
input:disabled { background: #eef2f7; color: var(--muted); }
.card.narrow, .narrow { max-width: 760px; }
.back { margin: 0 0 14px; font-size: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stat-alert { border-top-color: #e65f2b; }
.chip-info { background: #e1f4fd; color: #005f93; }
.chip-muted { background: #eef1f5; color: #7b8799; }
.wrap { white-space: normal; word-break: break-word; }

.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.msg { max-width: 82%; padding: 12px 16px; border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.msg header { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.msg-body { word-break: break-word; font-size: 15px; }
.msg-customer { align-self: flex-end; background: #e8f6fd; }
.msg-staff { align-self: flex-start; }
.msg-system { align-self: center; max-width: 100%; background: #f1f4f9; box-shadow: none; font-size: 14px; color: #46566e; }
.attachments { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }

.plain-list { list-style: none; margin: 0 0 10px; padding: 0; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #eef2f7; flex-wrap: wrap; }
.request { padding: 12px 0; border-bottom: 1px solid #eef2f7; }
.request-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.changes { margin: 8px 0; padding-left: 18px; font-size: 14px; }

@media (max-width: 760px) {
    .msg { max-width: 100%; }
}
.secret-card { border: 2px solid var(--brand); margin-bottom: 18px; }
.secret-text { background: #f4f9fd; border-radius: 10px; padding: 14px 16px; margin: 0 0 12px; font-family: Consolas, Menlo, monospace; font-size: 15px; word-break: break-word; }
.sub-h { margin-top: 22px; font-size: 16px; }
.nav .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 10px; background: #e65f2b; color: #fff; font-size: 12px; text-align: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
