/* Nortefy — design tokens */
:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --surface-3: #e4e9f4;
  --text: #0d1424;
  --muted: #5a6680;
  --line: #dfe5f1;
  --brand-1: #14b8a6;
  --brand-2: #4b5cf0;
  --brand: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --accent: #4b5cf0;
  --accent-ink: #ffffff;
  --danger: #d6334a;
  --warn-bg: #fff4dc;
  --warn-ink: #7a5200;
  --info-bg: #e6f6f3;
  --info-ink: #0b5b51;
  --shadow: 0 1px 2px rgb(13 20 36 / .06), 0 12px 32px rgb(13 20 36 / .08);
  --radius: 14px;
  --ring: 0 0 0 3px rgb(75 92 240 / .35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090e1b;
    --surface: #101829;
    --surface-2: #17213a;
    --surface-3: #1f2b49;
    --text: #e8edf8;
    --muted: #8b98b3;
    --line: #222f4b;
    --accent: #7c8bff;
    --accent-ink: #0a0f1c;
    --danger: #ff6b81;
    --warn-bg: #3a2c0c;
    --warn-ink: #ffd88a;
    --info-bg: #0f2c2a;
    --info-ink: #7de3d4;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 16px 40px rgb(0 0 0 / .45);
    --ring: 0 0 0 3px rgb(124 139 255 / .45);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: none; box-shadow: var(--ring); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
.noscript { padding: 24px; text-align: center; }

.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ----------------------------------------------------------------- Botões e campos */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; position: relative;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; transition: transform .08s, background .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand); border-color: transparent; color: #fff; }
.btn--primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn--block { width: 100%; }
.btn--small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.spinner { display: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgb(255 255 255 / .4); border-top-color: #fff; animation: spin .7s linear infinite; }
.is-loading .spinner { display: inline-block; }
.is-loading .btn__label { opacity: .85; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: transparent; color: var(--muted); position: relative; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn--tiny { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn.is-on { color: var(--brand-1); }
.icon-btn.is-alert::after { content: ""; position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--surface); }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface-2); font-size: 13px; font-weight: 600; color: var(--muted); }
.chip:hover { color: var(--text); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field-input {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
.field input:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field__pw { position: relative; }
.field__pw input { padding-right: 84px; }
.field__pw .link { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }
.form { display: grid; gap: 14px; }
.form__error { color: var(--danger); font-size: 13px; font-weight: 600; }
.hint { color: var(--muted); font-size: 12.5px; display: flex; gap: 6px; align-items: center; }
.hint--center { justify-content: center; }
.hint .i { width: 14px; height: 14px; }

.meter { height: 5px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--danger); transition: width .25s, background .25s; }
.meter__label { color: var(--muted); font-size: 12px; }

.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 10px 14px; border-radius: 12px; font-size: 13.5px; }
.banner--info { background: var(--info-bg); color: var(--info-ink); }
.banner--warn { background: var(--warn-bg); color: var(--warn-ink); margin: 0 16px 8px; }
.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); color: var(--muted); font-size: 12.5px; }
.callout .i { color: var(--brand-1); margin-top: 2px; }
.callout strong { color: var(--text); }

/* ----------------------------------------------------------------- Autenticação */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: max(20px, var(--safe-t)) 16px calc(20px + var(--safe-b)); position: relative; overflow: hidden; }
.auth__glow { position: absolute; inset: -20% -10% auto; height: 60vh; pointer-events: none; opacity: .55;
  background: radial-gradient(40% 60% at 25% 30%, rgb(20 184 166 / .35), transparent 70%), radial-gradient(40% 60% at 75% 20%, rgb(75 92 240 / .38), transparent 70%); filter: blur(30px); }
.auth__card { position: relative; width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); padding: 28px 26px 22px; display: grid; gap: 18px; }
.brand { text-align: center; display: grid; gap: 6px; justify-items: center; }
.brand__mark { width: 56px; height: 56px; filter: drop-shadow(0 8px 18px rgb(75 92 240 / .35)); }
.brand h1 { font-size: 26px; letter-spacing: -.02em; }
.brand p { color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.tab { border: 0; background: transparent; border-radius: 10px; min-height: 40px; font-weight: 600; color: var(--muted); }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.trust { list-style: none; margin: 0; padding: 14px 0 0; display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.trust li { display: inline-flex; gap: 6px; align-items: center; }
.trust .i { width: 14px; height: 14px; color: var(--brand-1); }

/* ----------------------------------------------------------------- App */
.app { display: grid; grid-template-columns: 360px 1fr; height: var(--app-h, 100dvh); overflow: hidden; position: relative; background: var(--bg); }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.side__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: max(14px, var(--safe-t)) 14px 10px 18px; }
.side__actions { display: flex; gap: 2px; }
.me { display: flex; align-items: center; gap: 12px; min-width: 0; }
.me__text { display: grid; min-width: 0; line-height: 1.25; }
.me__text strong, .me__text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me__text small { color: var(--muted); }

.avatar { --h: 220; width: 42px; height: 42px; border-radius: 14px; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; letter-spacing: .02em;
  background: linear-gradient(135deg, hsl(var(--h) 70% 52%), hsl(calc(var(--h) + 40) 70% 42%)); }

.notify-prompt { display: flex; align-items: center; gap: 10px; margin: 0 14px 8px; padding: 10px 10px 10px 12px; border-radius: 14px; background: var(--info-bg); color: var(--info-ink); font-size: 13px; }
.notify-prompt p { flex: 1; }

.search { position: relative; margin: 4px 14px 8px; }
.search .i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { width: 100%; min-height: 42px; padding: 0 14px 0 38px; border-radius: 12px; border: 1px solid transparent; background: var(--surface-2); }
.search input:focus { border-color: var(--accent); outline: none; box-shadow: var(--ring); background: var(--surface); }

.contacts { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.contact { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 0; background: transparent; border-radius: 14px; text-align: left; transition: background .12s; }
.contact:hover { background: var(--surface-2); }
.contact[aria-current="true"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--brand-2); }
.contact__text { display: grid; min-width: 0; flex: 1; line-height: 1.3; }
.contact__text strong, .contact__text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact__text small { color: var(--muted); }
.contact.has-unread .contact__text small { color: var(--accent); font-weight: 600; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 99px; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; animation: pop .35s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.list-empty { padding: 28px 18px; text-align: center; color: var(--muted); font-size: 13.5px; }

.side__foot { padding: 10px 14px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); }
.session { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.session strong { color: var(--text); font-variant-numeric: tabular-nums; }
.session__bar { grid-column: 1 / -1; height: 3px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.session__bar i { display: block; height: 100%; width: 100%; background: var(--brand); transform-origin: left; transition: transform 1s linear; }
.session.is-low strong { color: var(--danger); }
.session.is-low .session__bar i { background: var(--danger); }

.idle-warning { position: fixed; z-index: 30; left: 50%; top: max(12px, var(--safe-t)); transform: translateX(-50%); display: flex; gap: 12px; align-items: center; padding: 10px 12px 10px 16px; border-radius: 99px; background: var(--warn-bg); color: var(--warn-ink); box-shadow: var(--shadow); font-size: 14px; animation: drop .3s ease; max-width: calc(100vw - 24px); }
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }

/* ----------------------------------------------------------------- Conversa */
.chat { min-width: 0; min-height: 0; display: flex; flex-direction: column; background:
  radial-gradient(600px 300px at 80% -10%, rgb(75 92 240 / .08), transparent 70%), var(--bg); }
.chat__empty { margin: auto; max-width: 360px; text-align: center; display: grid; gap: 10px; justify-items: center; padding: 24px; color: var(--muted); }
.chat__empty h2 { color: var(--text); font-size: 20px; }
.chat__empty-art { width: 72px; height: 72px; border-radius: 24px; display: grid; place-items: center; background: var(--brand); color: #fff; margin-bottom: 6px; box-shadow: 0 14px 30px rgb(75 92 240 / .3); }
.chat__empty-art .i { width: 32px; height: 32px; }

.room { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.room__head { display: flex; align-items: center; gap: 12px; padding: max(12px, var(--safe-t)) 16px 12px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.room__who { display: grid; line-height: 1.25; min-width: 0; flex: 1; }
.room__who small { color: var(--muted); }
.room__back { display: none; }

.thread { list-style: none; margin: 0; padding: 20px 16px 8px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.thread__empty { margin: auto; text-align: center; color: var(--muted); font-size: 13.5px; max-width: 280px; display: grid; gap: 6px; justify-items: center; }
.thread__empty .i { width: 22px; height: 22px; color: var(--brand-1); }
.msg { max-width: min(78%, 560px); padding: 10px 14px; border-radius: 18px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; animation: rise .22s ease; position: relative; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.msg--out { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.msg--in { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg__meta { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 4px; font-size: 11px; opacity: .8; white-space: normal; }
.msg__meta .i { width: 14px; height: 14px; }
.msg--out.is-read .msg__meta .i { color: #bff6ee; }
.msg--in .msg__meta { justify-content: flex-start; color: var(--muted); }

.sealed { align-self: flex-start; width: min(340px, 86%); display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; padding: 12px 14px; border-radius: 18px; border: 1.5px dashed color-mix(in srgb, var(--brand-2) 55%, transparent); background: color-mix(in srgb, var(--brand-2) 7%, var(--surface)); animation: rise .25s ease; }
.sealed__icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand); color: #fff; grid-row: span 2; }
.sealed strong { font-size: 14px; }
.sealed small { color: var(--muted); font-size: 12px; }
.sealed .btn { grid-column: 1 / -1; margin-top: 8px; }
.sealed.is-opening { opacity: .7; pointer-events: none; }
.sealed.is-error { border-color: var(--danger); }

.composer { padding: 8px 16px calc(14px + var(--safe-b)); display: grid; gap: 6px; }
.composer__top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.composer__note { color: var(--muted); font-size: 11.5px; line-height: 1.3; min-width: 0; }
.composer__row { display: flex; gap: 10px; align-items: flex-end; padding: 6px 6px 6px 16px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); transition: border-color .15s, box-shadow .15s; }
.composer__row:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.composer textarea:focus-visible { box-shadow: none; }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; max-height: 140px; padding: 9px 0; outline: none; line-height: 1.4; }
.send { width: 42px; height: 42px; border-radius: 16px; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; transition: transform .1s, opacity .15s; }
.send:active { transform: scale(.94); }
.send[disabled] { opacity: .35; cursor: default; }
.composer__count { text-align: right; color: var(--muted); font-size: 11px; padding-right: 8px; }
.composer__count.is-near { color: var(--danger); }

.mode { display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: 32px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 700; transition: background .15s, color .15s, border-color .15s; }
.mode .i { width: 15px; height: 15px; }
.mode:hover { color: var(--text); }
.mode.is-keep { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.composer__row .icon-btn { align-self: flex-end; flex: none; margin-left: -8px; }
.attach { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 10px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.attach img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; }
.attach span { flex: 1; }
.msg__imgbtn { display: block; padding: 0; border: 0; background: none; border-radius: 12px; overflow: hidden; margin: -4px -8px 6px; width: min(320px, calc(100vw - 120px)); }
.msg__img { display: block; width: 100%; height: auto; max-height: 340px; object-fit: cover; border-radius: 12px; background: var(--surface-3); }
.msg__broken { opacity: .8; font-style: italic; }
.meta-btn { display: inline-grid; place-items: center; width: 26px; height: 26px; border: 0; border-radius: 8px; background: transparent; color: inherit; opacity: .85; }
.meta-btn:hover { background: rgb(127 127 127 / .2); opacity: 1; }
.meta-btn .i { width: 15px; height: 15px; }
.msg__meta { flex-wrap: wrap; }

/* ----------------------------------------------------------------- Diálogos e toasts */
.dlg { border: 0; padding: 0; border-radius: 22px; width: min(460px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); max-height: calc(100dvh - 24px); }
.dlg--image { width: min(900px, calc(100vw - 16px)); background: transparent; box-shadow: none; }
.lightbox { display: grid; gap: 12px; justify-items: center; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 120px); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.lightbox__bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.dlg::backdrop { background: rgb(5 8 18 / .55); backdrop-filter: blur(4px); }
.dlg__body { padding: 24px; display: grid; gap: 14px; }
.dlg__body h2 { font-size: 19px; }
.dlg__body p { color: var(--muted); font-size: 14px; }
.dlg__section { display: grid; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.dlg__section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dlg__actions { display: flex; justify-content: flex-end; gap: 8px; }
.safety { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 16px; border-radius: 14px; background: var(--surface-2); font: 600 17px/1 ui-monospace, "SF Mono", Consolas, monospace; text-align: center; letter-spacing: .04em; }
.safety--small { font-size: 13px; padding: 12px; }

.toasts { position: fixed; z-index: 50; right: 16px; bottom: calc(16px + var(--safe-b)); display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 14px; border-radius: 14px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 14px; display: flex; gap: 10px; align-items: center; animation: rise .25s ease; }
.toast--error { background: var(--danger); color: #fff; }
.toast--ok .i { color: var(--brand-1); }

/* ----------------------------------------------------------------- Responsivo */
.net-bar { position: fixed; z-index: 60; left: 0; right: 0; top: 0; padding: max(6px, var(--safe-t)) 12px 6px; text-align: center; font-size: 13px; font-weight: 600; background: var(--warn-bg); color: var(--warn-ink); }
.install-box { display: grid; gap: 10px; }
.install-box p { color: var(--muted); font-size: 13.5px; }
body.is-standalone .auth, body.is-standalone .app { padding-top: 0; }

/* Tablet: duas colunas com barra lateral mais estreita (retrato e paisagem) */
@media (min-width: 700px) and (max-width: 1100px) {
  .app { grid-template-columns: 300px 1fr; }
  .msg { max-width: 82%; }
  .thread { padding-inline: 24px; }
  .composer { padding-inline: 24px; }
}

/* Telemóvel: um painel de cada vez */
@media (max-width: 699px) {
  .app { grid-template-columns: 1fr; }
  .side, .chat { grid-area: 1 / 1; }
  .app[data-pane="list"] .chat { display: none; }
  .app[data-pane="chat"] .side { display: none; }
  .room__back { display: grid; }
  .msg { max-width: 88%; }
  .toasts { right: 12px; left: 12px; width: auto; bottom: calc(86px + var(--safe-b)); }
  .dlg { width: calc(100vw - 16px); }
  .dlg__body { padding: 20px; }
}

/* Ecrãs táteis: alvos de 44px e campos a 16px (evita o zoom automático do iOS) */
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .icon-btn--tiny { width: 36px; height: 36px; }
  .btn--small { min-height: 40px; }
  .contact { padding: 12px 10px; }
  .tab { min-height: 44px; }
  .field input, .search input, .composer textarea { font-size: 16px; }
  .link { padding: 8px; }
  .send { width: 46px; height: 46px; }
}

/* Telemóvel em paisagem: cabeçalhos compactos para sobrar espaço às mensagens */
@media (max-height: 520px) and (orientation: landscape) {
  .room__head { padding-block: 6px; }
  .composer__note { display: none; }
  .side__head { padding-top: 6px; padding-bottom: 4px; }
  .auth { place-items: start center; }
  .brand p, .trust { display: none; }
}

@media (max-width: 440px) {
  .auth__card { padding: 24px 18px 18px; border-radius: 20px; }
  .field-row { grid-template-columns: 1fr; }
  .safety { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
