:root {
  --bg: #f5f6fb;
  --bg-glow: radial-gradient(1200px 600px at 10% -10%, #e4e1ff 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 10%, #dff3ff 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f0f1f7;
  --border: #e3e5ee;
  --text: #171a2b;
  --muted: #6b7088;
  --accent: #6d5dfc;
  --accent-2: #8f6bff;
  --accent-contrast: #ffffff;
  --danger: #e5484d;
  --danger-bg: #fdecec;
  --warn-bg: #fff6e0;
  --warn-text: #7a5600;
  --shadow: 0 10px 30px rgba(23, 26, 43, 0.08), 0 2px 6px rgba(23, 26, 43, 0.05);
  --radius: 18px;
  --radius-sm: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1020;
    --bg-glow: radial-gradient(1200px 600px at 10% -10%, #2a2160 0%, transparent 60%),
               radial-gradient(900px 500px at 110% 10%, #10304a 0%, transparent 55%);
    --surface: #181a2e;
    --surface-2: #22253c;
    --border: #2c2f4a;
    --text: #eceefe;
    --muted: #9599b5;
    --accent: #8b7dff;
    --accent-2: #a98bff;
    --danger: #ff6369;
    --danger-bg: #3a1a22;
    --warn-bg: #3a2f12;
    --warn-text: #f3d48b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.sprite { position: absolute; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

h1, h2 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
p { margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.danger-text { color: var(--danger) !important; }

/* Telas */
.screen { min-height: 100dvh; padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }
.screen.center { display: grid; place-items: center; padding-top: 24px; padding-bottom: 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.35s ease;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 44px; height: 44px; padding: 10px;
  border-radius: 14px;
  color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}
.brand.small { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.brand.small .brand-icon { width: 34px; height: 34px; padding: 7px; border-radius: 11px; }

/* Campos */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); }

input, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* evita zoom no iOS */
  font-weight: 400;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.code-input { text-align: center; font-size: 1.6rem; letter-spacing: 0.5em; font-family: ui-monospace, Menlo, Consolas, monospace; }

.input-group { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: var(--radius-sm); padding-right: 4px; border: 1px solid transparent; transition: border-color 0.15s, box-shadow 0.15s; }
.input-group:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.input-group input { background: transparent; border: none; box-shadow: none; flex: 1; min-width: 0; }
.input-group input:focus { box-shadow: none; background: transparent; }

/* Botões */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { color: var(--accent-contrast); background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex-shrink: 0;
  border: none; border-radius: 12px;
  background: transparent; color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.input-group .icon-btn:hover { background: var(--surface); }

.error { color: var(--danger); font-size: 0.9rem; min-height: 0; }
.error:empty { display: none; }

.warning { background: var(--warn-bg); color: var(--warn-text); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 0.9rem; }

.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: var(--radius-sm); }
.qr img { width: 200px; height: 200px; }
.secret { display: block; word-break: break-all; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; text-align: center; user-select: all; }

.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }

/* Topo */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 720px; margin: 0 auto;
  padding: 14px 0 10px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar-actions { display: flex; gap: 4px; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 46px;
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: pop 0.15s ease;
}
.menu button { font: inherit; text-align: left; padding: 10px 12px; border: none; background: none; color: var(--text); border-radius: 10px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

/* Cofre */
.vault { max-width: 720px; margin: 0 auto; padding-bottom: 110px; }

.search { position: relative; margin: 4px 0 8px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 44px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }

.count { margin: 6px 4px 10px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 8px 12px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
  animation: rise 0.25s ease both;
}
.item:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: var(--shadow); }
.item:active { transform: scale(0.99); }

.avatar {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 13px;
  font-weight: 700; font-size: 1.1rem;
  color: #fff;
  background: hsl(var(--hue, 250) 70% 58%);
}
.item-text { flex: 1; min-width: 0; }
.item-title, .item-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-title { font-weight: 600; }
.item-sub { color: var(--muted); font-size: 0.88rem; }

.empty { text-align: center; padding: 60px 20px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty svg { width: 48px; height: 48px; color: var(--accent); margin-bottom: 8px; }

.fab {
  position: fixed;
  right: max(20px, calc(50% - 360px + 20px));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px; height: 60px;
  display: grid; place-items: center;
  border: none; border-radius: 20px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 12px 28px color-mix(in srgb, var(--accent) 45%, transparent);
  cursor: pointer;
  transition: transform 0.15s;
}
.fab:hover { transform: translateY(-2px); }
.fab:active { transform: scale(0.95); }
.fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* Diálogos */
dialog {
  border: none; padding: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 10, 25, 0.45); backdrop-filter: blur(4px); }

dialog form { display: flex; flex-direction: column; gap: 14px; padding: 22px 20px; }

.sheet { width: min(560px, 100%); max-width: 100%; border-radius: 22px; }
.sheet[open] { animation: rise 0.22s ease; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.sheet-actions .btn.primary { min-width: 120px; }
.sheet-actions .btn.danger { margin-right: auto; }

.modal { width: min(400px, calc(100% - 32px)); border-radius: 20px; }
.modal[open] { animation: pop 0.18s ease; }
.modal .sheet-actions .btn.danger { margin-right: 0; }

/* No celular o editor vira uma "bottom sheet" */
@media (max-width: 600px) {
  .sheet {
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    max-height: 92dvh;
  }
  .sheet form { padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
  .sheet[open] { animation: slide-up 0.25s ease; }
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 0.92rem; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } }
@keyframes slide-up { from { transform: translateY(100%); } }

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