/* ---------- Design tokens ---------- */
:root {
  color-scheme: dark;
  --bg: #05070a;
  --bg-soft: #0a0d12;
  --card: #0d1015;
  --card-hover: #12161c;
  --input-bg: #070909;
  --border: #1c2027;
  --border-strong: #2a2f38;
  --text: #e8eaed;
  --muted: #8a919c;
  --muted-dim: #565c66;

  --accent: #22c55e;
  --accent-strong: #3ddb75;
  --accent-ink: #04140b;
  --accent-dim: rgba(34, 197, 94, 0.13);
  --accent-border: rgba(34, 197, 94, 0.35);

  --success: var(--accent);
  --success-dim: var(--accent-dim);
  --warning: #e0a52c;
  --warning-dim: rgba(224, 165, 44, 0.13);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.13);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 24px -12px rgba(0, 0, 0, 0.65);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset & base ---------- */
* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background-color: var(--bg);
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 22px 22px;
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 48px 16px 64px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.container {
  width: 100%;
  max-width: 760px;
  animation: rise 0.4s var(--ease) both;
}
.container.narrow { max-width: 420px; }

body.center-page { align-items: center; min-height: 100vh; }

a { color: var(--accent); }

::selection { background: var(--accent-dim); color: var(--text); }

/* ---------- Layout helpers ---------- */
.center { text-align: center; }

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.top-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.86rem;
  transition: color 0.15s var(--ease);
}
.top-nav a:hover { color: var(--text); }

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-header p { margin: 2px 0 0; }

.eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

/* ---------- Typography ---------- */
h1 { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1.02rem; font-weight: 650; margin: 0 0 16px; color: var(--text); }
p.muted, span.muted, .muted { color: var(--muted); font-size: 0.9rem; }
code {
  font-family: var(--font-mono);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.85em;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  animation: rise 0.4s var(--ease) both;
}

a.card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
a.card:hover {
  border-color: var(--border-strong);
  background: var(--card-hover);
}

/* ---------- Forms ---------- */
label { display: block; font-size: 0.8rem; color: var(--muted); margin: 16px 0 6px; font-weight: 500; }
label:first-of-type { margin-top: 0; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input::placeholder, textarea::placeholder { color: var(--muted-dim); }

input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

textarea { font-family: var(--font-mono); resize: vertical; font-size: 0.86rem; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

label.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 16px;
  color: var(--text);
  font-size: 0.87rem;
  cursor: pointer;
}
label.checkbox-row input { width: auto; accent-color: var(--accent); }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 18px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), opacity 0.15s var(--ease);
}
button:hover, .btn:hover { background: var(--accent-strong); }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-dim); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

button.danger, .btn.danger { background: var(--danger); color: #1a0708; }
button.danger:hover, .btn.danger:hover { background: #f76b6b; }

button.secondary, .btn.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  font-weight: 500;
}
button.secondary:hover, .btn.secondary:hover {
  border-color: var(--border-strong);
  background: var(--card-hover);
}

/* botoes fora do fluxo de um formulario (nav, celulas de tabela, grupos de acao)
   nao devem herdar o margin-top pensado para "botao logo apos o ultimo campo" */
.top-nav button, .top-nav .btn,
.actions button, .actions .btn,
td button, td .btn {
  margin-top: 0;
}

.notif-btn { position: relative; }
.notif-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--warning);
  color: #1a1204;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}

button.ghost {
  background: transparent;
  border: none;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 10px;
  margin-top: 0;
}
button.ghost:hover { color: var(--text); background: var(--card-hover); }

/* ---------- Icons ---------- */
.icon { width: 1em; height: 1em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; vertical-align: -0.14em; }

/* ---------- Code / OTP display ---------- */
.code-panel {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  margin: 22px 0 10px;
}
.code-display {
  font-family: var(--font-mono);
  font-size: 2.6rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: opacity 0.15s var(--ease);
  cursor: pointer;
  user-select: none;
}
.code-display:hover { color: var(--accent-strong); }

/* ---------- Progress bar ---------- */
.progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}
.progress > div {
  height: 100%;
  background: var(--accent);
  transition: width 1s linear;
}

/* ---------- Flash messages ---------- */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 0.88rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  animation: slide-in 0.2s var(--ease) both;
}
.flash.error { border-left-color: var(--danger); color: #ff9494; }
.flash.success { border-left-color: var(--accent); color: #86ecab; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; min-width: 480px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td:nth-child(1), th:nth-child(1) { padding-left: 2px; }
th { color: var(--muted); font-weight: 600; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; }
tbody tr { transition: background 0.12s var(--ease); }
tbody tr:hover { background: var(--bg-soft); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-family: var(--font-mono);
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge.ativa, .badge.vendida { background: var(--success-dim); color: var(--success); }
.badge.expirada { background: rgba(138, 145, 156, 0.14); color: var(--muted); }
.badge.revogada, .badge.cancelada { background: var(--danger-dim); color: var(--danger); }
.badge.pendente { background: var(--warning-dim); color: var(--warning); }
.badge.desativada { background: rgba(138, 145, 156, 0.14); color: var(--muted-dim); }

.status-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.status-select select {
  width: auto;
  padding: 5px 24px 5px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  font-family: var(--font-mono);
  border-radius: var(--radius-sm);
}
.status-select.vendida select { background: var(--success-dim); color: var(--success); border-color: transparent; }
.status-select.pendente select { background: var(--warning-dim); color: var(--warning); border-color: transparent; }
.status-select.cancelada select { background: var(--danger-dim); color: var(--danger); border-color: transparent; }
.status-select.desativada select { background: rgba(138, 145, 156, 0.14); color: var(--muted-dim); border-color: transparent; }

/* ---------- Key reveal ---------- */
.key-reveal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-family: var(--font-mono);
  font-size: 0.98rem;
  word-break: break-all;
  margin: 10px 0;
}
.key-reveal span { flex: 1; }

/* ---------- Mail list ---------- */
.mail-list { display: flex; flex-direction: column; gap: 10px; }
/* a lista e re-renderizada a cada poll (5s); sem isso o fade de entrada do .card
   piscaria a cada atualizacao mesmo quando nada mudou */
.mail-item { padding: 16px 18px; animation: none; }
.mail-item .mail-top { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; }
.mail-item .mail-subject { font-weight: 500; color: var(--muted); }
.mail-item.unread .mail-subject { font-weight: 650; color: var(--text); }
.mail-item.unread .mail-subject::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 8px;
  vertical-align: middle;
}
.mail-item .mail-date { color: var(--muted-dim); font-size: 0.8rem; white-space: nowrap; font-family: var(--font-mono); }
.mail-item .mail-from { color: var(--muted); font-size: 0.85rem; margin: 5px 0 0; }
.mail-item .mail-preview {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 8px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-code {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s var(--ease);
}
.mail-code:hover { background: var(--card-hover); }
.mail-code-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text);
}
.mail-code-hint { font-size: 0.76rem; color: var(--muted); white-space: nowrap; }

.mail-more {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--muted-dim);
  text-decoration: none;
}
.mail-more:hover { color: var(--muted); }

.card.danger-zone { border-left: 3px solid var(--danger); }

/* ---------- Collapsible card (details/summary) ---------- */
details.card { padding: 0; overflow: hidden; }
details.card summary {
  cursor: pointer;
  padding: 20px 28px;
  font-weight: 650;
  font-size: 1.02rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.15s var(--ease);
}
details.card summary:hover { background: var(--card-hover); }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.2s var(--ease);
  flex-shrink: 0;
}
details.card[open] summary::after { transform: rotate(45deg); }
details.card .details-body { padding: 4px 28px 26px; }

/* ---------- Misc ---------- */
form.inline { display: inline; }

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  font-size: 0.9rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ---------- Service picker ---------- */
.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.service-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 14px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.service-card:hover { border-color: var(--border-strong); background: var(--card-hover); }
.service-card .service-name { font-weight: 600; font-size: 0.9rem; }
.service-card .service-sub { font-size: 0.72rem; color: var(--muted-dim); font-family: var(--font-mono); }

.service-card.add-service {
  border-style: dashed;
  color: var(--muted);
}
.service-card.add-service:hover { color: var(--text); }

.icon-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  color: rgba(0, 0, 0, 0.72);
  letter-spacing: 0.01em;
}
.icon-avatar.sm { width: 36px; height: 36px; border-radius: var(--radius-sm); font-size: 0.82rem; }
.icon-avatar.plus { background: transparent; border: 1px dashed var(--border-strong); color: var(--muted); }
img.icon-avatar { object-fit: cover; background: var(--input-bg); border: 1px solid var(--border); }

/* ---------- Logo uploader (tela do servico) ---------- */
.logo-uploader { position: relative; width: 48px; height: 48px; flex-shrink: 0; }
.logo-uploader .icon-avatar { width: 48px; height: 48px; }
.logo-uploader form { margin: 0; display: contents; }
.logo-edit-btn,
.logo-remove-btn {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--border-strong);
  color: var(--muted);
  padding: 0;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.logo-edit-btn { bottom: -4px; right: -4px; }
.logo-edit-btn .icon, .logo-remove-btn .icon { width: 11px; height: 11px; }
.logo-edit-btn:hover { color: var(--accent); border-color: var(--accent-border); }
.logo-remove-btn { top: -4px; right: -4px; background: var(--danger-dim); border-color: transparent; color: var(--danger); }
.logo-remove-btn:hover { background: var(--danger); color: #fff; }

/* ---------- Vencimento nos cards (data de vencimento da ultima chave) ---------- */
.item-expiry { color: var(--muted-dim); }
.item-expiry.expired { color: var(--danger); font-weight: 600; }

/* ---------- Aguardando renovacao ---------- */
.renewal-card { border-left: 3px solid var(--warning); }
.renewal-group { margin-top: 14px; }
.renewal-group:first-of-type { margin-top: 4px; }
.renewal-group-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-dim);
  margin: 0 0 8px 2px;
}
.renewal-list { display: flex; flex-direction: column; gap: 6px; }
.renewal-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.renewal-item:hover { border-color: var(--border-strong); background: var(--card-hover); }
.renewal-item-label { font-weight: 600; font-size: 0.88rem; flex: 1; }
.renewal-item-date { font-size: 0.78rem; color: var(--muted); font-family: var(--font-mono); }

/* ---------- View toggle (2FA / email) ---------- */
.view-toggle {
  display: inline-flex;
  padding: 2px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  gap: 2px;
}
.view-toggle a {
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font-mono);
  text-decoration: none;
  color: var(--muted);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.view-toggle a.active { background: var(--accent); color: var(--accent-ink); }
.view-toggle a:not(.active):hover { color: var(--text); }

/* ---------- Date group headers ---------- */
.date-group { margin-bottom: 22px; }
.date-group-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-dim);
  margin: 0 0 10px 2px;
}
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.item-card { padding: 18px 20px; }
.item-card .item-title { font-weight: 600; margin: 0 0 2px; }
.item-card .item-sub { font-size: 0.82rem; color: var(--muted); margin: 0 0 12px; }
.item-card .item-notes {
  font-size: 0.78rem;
  color: var(--muted-dim);
  margin: -8px 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-style: italic;
}

/* ---------- Countdown ring ---------- */
.countdown {
  display: flex;
  align-items: center;
  gap: 16px;
}
.countdown-ring { flex-shrink: 0; }
.countdown-ring circle { transition: stroke-dashoffset 0.6s var(--ease); }
.countdown-ring .ring-bg { stroke: var(--border); fill: none; }
.countdown-ring .ring-fg { stroke: var(--accent); fill: none; stroke-linecap: round; }
.countdown-ring text {
  font-family: var(--font-mono);
  font-weight: 700;
  fill: var(--text);
  text-anchor: middle;
}
.countdown-info .countdown-label { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.countdown-info .countdown-date { font-size: 0.96rem; font-weight: 600; margin-top: 2px; }

/* ---------- Key value + copy (visible key history) ---------- */
.key-value-row { display: flex; align-items: center; gap: 8px; }
.key-value {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.03em;
  font-size: 0.9rem;
}
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  padding: 4px 9px;
  margin: 0;
  border-radius: var(--radius-sm);
}
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--card-hover); }

/* ---------- Registry page ---------- */
.reminder-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
  background: var(--danger-dim);
  color: var(--danger);
}
.reminder-badge::before { content: "!"; display:flex; align-items:center; justify-content:center; width:13px; height:13px; border-radius:50%; background:var(--danger); color:#1a0708; font-size:0.62rem; font-family: var(--font-sans); }

/* ---------- Animations ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.pulse { animation: pulse-soft 1.6s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  body { padding: 24px 12px 48px; }
  .card { padding: 20px 18px; border-radius: var(--radius-md); }
  .code-display { font-size: 2.1rem; }
  .row { flex-direction: column; gap: 0; }
  .top-nav { align-items: flex-start; }
}
