/* Fustat (SIL OFL 1.1, ver fonts/OFL.txt) — variável 200–800, servida localmente. */
@font-face {
  font-family: "Fustat";
  src: url("/ui/fonts/fustat-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: "Fustat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #5f5f6b;
  --border: #e4e4e7;
  --accent: #15803d;
  --accent-hover: #166534;
  --accent-fg: #ffffff;
  --danger: #b91c1c;
  --ok: #16a34a;
  --warn: #b45309;
  --off: #8a8a96;
  --focus: #2563eb;
  --radius: 10px;
  --radius-sm: 7px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11;
    --surface: #18181b;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --border: #2e2e33;
    --accent: #22c55e;
    --accent-hover: #4ade80;
    --accent-fg: #052e16;
    --danger: #f87171;
    --ok: #22c55e;
    --warn: #fbbf24;
    --off: #71717a;
    --focus: #60a5fa;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner, .container { max-width: 960px; margin: 0 auto; padding: 0 var(--s4); }
.topbar-inner { height: 56px; display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.brand { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 650; }
.brand-mark { width: 24px; height: 24px; display: block; }
.topbar-right { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.container { padding-top: var(--s6); padding-bottom: var(--s6); }
main:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-head p { margin-top: var(--s1); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: 0 var(--s4); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn[aria-busy="true"]::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-weight: 550; cursor: pointer; text-decoration: underline; }
@keyframes spin { to { transform: rotate(360deg); } }

/* forms */
.field { display: grid; gap: var(--s1); margin-bottom: var(--s4); }
.field label { font-size: 14px; font-weight: 550; }
.field .hint { font-size: 13px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="tel"], input[type="url"], input[type="number"], textarea {
  width: 100%; min-height: 42px; padding: var(--s2) var(--s3);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 88px; resize: vertical; }
input:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.form-error { color: var(--danger); font-size: 14px; margin-bottom: var(--s3); }
.form-actions { display: flex; justify-content: flex-end; gap: var(--s2); flex-wrap: wrap; }

/* login */
.login { max-width: 400px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s6) var(--s5); }
.login h1 { margin-bottom: var(--s2); }
.login > p { margin-bottom: var(--s5); }
.login .btn { width: 100%; }

/* list */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s3) var(--s4); align-items: center; padding: var(--s4); }
.row + .row { border-top: 1px solid var(--border); }
.row-main { min-width: 0; display: grid; gap: 2px; }
.row-title { display: flex; align-items: center; gap: var(--s3); min-width: 0; flex-wrap: wrap; }
.row-title strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.row-meta { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; align-items: center; gap: var(--s2); }
.row-instance { grid-template-columns: auto minmax(0, 1fr) auto; }

/* avatar: iniciais por baixo, foto por cima quando carrega */
.avatar {
  position: relative; flex: none; width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
  display: inline-grid; place-items: center; background: var(--bg); border: 1px solid var(--border);
  color: var(--muted); font-size: 14px; font-weight: 650; letter-spacing: .02em; user-select: none;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 112px; height: 112px; font-size: 36px; }
.row-avatar { display: flex; }

/* perfil */
.profile { display: grid; justify-items: center; gap: var(--s3); text-align: center; }
.profile-name { font-size: 19px; font-weight: 650; overflow-wrap: anywhere; }
.profile-phone { display: flex; align-items: center; justify-content: center; gap: var(--s3); flex-wrap: wrap; font-size: 16px; }
/* Sem tabular-nums: na Fustat o recurso "tnum" também alarga o espaço (3,5px → 9,6px). */
.facts { width: 100%; margin: var(--s3) 0 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s2) var(--s4); text-align: left; border-top: 1px solid var(--border); padding-top: var(--s4); }
.profile-actions { width: 100%; margin-top: var(--s2); }
input[type="file"] { font: inherit; font-size: 14px; width: 100%; min-width: 0; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; font-size: 14px; overflow-wrap: anywhere; white-space: pre-line; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 550; color: var(--muted); }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.badge[data-tone="ok"] { color: var(--ok); } .badge[data-tone="ok"]::before { background: var(--ok); }
.badge[data-tone="warn"] { color: var(--warn); } .badge[data-tone="warn"]::before { background: var(--warn); }
.badge[data-tone="bad"] { color: var(--danger); } .badge[data-tone="bad"]::before { background: var(--danger); }

/* overflow menu */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgb(0 0 0 / .12); padding: var(--s1); display: grid;
}
.menu-panel button { justify-content: flex-start; border: 0; min-height: 40px; width: 100%; }

/* empty / skeleton */
.empty { text-align: center; padding: var(--s6) var(--s4); display: grid; gap: var(--s3); justify-items: center; }
.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.2s ease infinite; border-radius: var(--radius-sm); }
.skeleton-row { height: 20px; margin: var(--s4); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* dialog */
dialog {
  width: min(460px, calc(100vw - 2 * var(--s4))); max-height: calc(100dvh - 2 * var(--s4));
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); overflow: auto;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border); }
.dialog-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-body { padding: var(--s5); }
.icon-btn { width: 40px; min-height: 40px; padding: 0; font-size: 20px; line-height: 1; }

/* connect */
.qr-box { width: 264px; height: 264px; margin: 0 auto var(--s4); display: grid; place-items: center; border-radius: var(--radius-sm); background: #fff; }
.qr-box img { width: 100%; height: 100%; image-rendering: pixelated; }
.qr-box .skeleton { width: 100%; height: 100%; }
.success-mark { width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center; font-size: 44px; background: var(--ok); color: #fff; }
.qr-box.done { background: transparent; }
.center { text-align: center; }
.steps { margin: var(--s4) 0; padding-left: 20px; color: var(--muted); font-size: 14px; display: grid; gap: 2px; }
details.alt { border-top: 1px solid var(--border); padding-top: var(--s4); margin-top: var(--s4); }
details.alt summary { cursor: pointer; font-weight: 550; margin-bottom: var(--s3); }
.pair-code { font: 600 26px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; text-align: center; margin-top: var(--s4); }

/* secrets */
.secret { display: grid; gap: var(--s1); margin-bottom: var(--s4); }
.secret-value { display: flex; gap: var(--s2); }
.secret-value code { flex: 1; min-width: 0; padding: var(--s2) var(--s3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); font-size: 13px; overflow-wrap: anywhere; }
.callout { padding: var(--s3); border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--border); font-size: 14px; margin-bottom: var(--s4); }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: max(var(--s4), env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: var(--s2); z-index: 50; width: min(420px, calc(100vw - 2 * var(--s4))); }
.toast { background: var(--text); color: var(--bg); padding: var(--s3) var(--s4); border-radius: var(--radius-sm); font-size: 14px; animation: rise .2s ease; }
.toast[data-tone="bad"] { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 600px) {
  .container { padding-top: var(--s5); }
  .row { grid-template-columns: 1fr; }
  .row-instance { grid-template-columns: auto minmax(0, 1fr); }
  .row-instance .row-actions { grid-column: 1 / -1; }
  .row-actions { justify-content: flex-start; }
  .menu-panel { left: 0; right: auto; }
  .page-head .btn-primary { width: 100%; }
  .login { margin-top: var(--s5); padding: var(--s5) var(--s4); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
