/* ==========================================================================
   COFRE — tema claro, tecnológico e vibrante
   ========================================================================== */
:root {
  --indigo: #4f46e5;
  --indigo-600: #4338ca;
  --violet: #7c3aed;
  --cyan: #06b6d4;
  --cyan-300: #67e8f9;
  --pink: #ec4899;
  --amber: #f59e0b;
  --green: #10b981;
  --red: #ef4444;

  --bg: #f4f6ff;
  --surface: #ffffff;
  --surface-2: #eef1ff;
  --ink: #101332;
  --ink-2: #4b5175;
  --ink-3: #8a90b8;
  --line: #e3e7fb;

  --grad-brand: linear-gradient(135deg, var(--indigo) 0%, var(--violet) 55%, var(--cyan) 130%);
  --shadow-sm: 0 1px 2px rgba(16, 19, 50, .06), 0 2px 8px rgba(16, 19, 50, .05);
  --shadow-md: 0 6px 24px rgba(79, 70, 229, .14), 0 2px 6px rgba(16, 19, 50, .06);
  --shadow-lg: 0 24px 64px rgba(79, 70, 229, .22);

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;

  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Roboto", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, a, select, summary { touch-action: manipulation; }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; }
button { font-family: inherit; }

/* ============================ TELA DE AUTH ============================ */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, #eef0ff 0%, #f7fbff 45%, #ecfeff 100%);
}
.auth-bg { position: absolute; inset: 0; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .5; }
.orb-1 { width: 420px; height: 420px; background: #c7d2fe; top: -120px; left: -100px; }
.orb-2 { width: 380px; height: 380px; background: #a5f3fc; bottom: -140px; right: -80px; }
.orb-3 { width: 300px; height: 300px; background: #ddd6fe; top: 40%; left: 60%; }
.grid-overlay {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(79,70,229,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,70,229,.06) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
}

.auth-card {
  position: relative;
  width: min(440px, 100%);
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.9);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 34px 34px 26px;
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand-logo {
  width: 54px; height: 54px; border-radius: 16px;
  background: var(--grad-brand);
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(79,70,229,.35);
  flex: none;
}
.brand-logo.sm { width: 38px; height: 38px; border-radius: 12px; }
.brand-logo svg { width: 60%; height: 60%; color: #fff; }
.brand-name {
  font-size: 1.9rem; font-weight: 800; letter-spacing: -.5px;
  background: var(--grad-brand);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  line-height: 1.05;
}
.brand-tag { margin: 2px 0 0; color: var(--ink-2); font-size: .9rem; }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 18px;
}
.auth-tab {
  border: 0; background: transparent; padding: 9px 0; border-radius: 9px;
  font-weight: 600; color: var(--ink-2); cursor: pointer; transition: .18s;
}
.auth-tab.active { background: var(--surface); color: var(--indigo); box-shadow: var(--shadow-sm); }

.unlock-notice {
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  padding: 10px 14px; border-radius: var(--r-sm); font-size: .85rem; margin: 0 0 14px;
}

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field-hint { display: block; font-size: .72rem; color: var(--ink-3); margin-top: 5px; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"],
input[type="search"], select, textarea {
  width: 100%; padding: 12px 13px; min-height: 44px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-sm);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(79,70,229,.14);
}
textarea { resize: vertical; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { padding-right: 104px; }
.input-wrap .icon-btn { position: absolute; right: 4px; }
.input-wrap .icon-btn:nth-last-child(1) { right: 4px; }
.input-wrap .icon-btn:nth-last-child(2) { right: 50px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.strength { display: block; height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.strength-bar { display: block; height: 100%; width: 0; border-radius: 99px; transition: width .25s, background .25s; background: var(--red); }

.form-error {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  padding: 9px 12px; border-radius: var(--r-sm); font-size: .83rem; margin: 0 0 14px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: var(--r-sm); padding: 11px 18px; min-height: 44px;
  font-weight: 700; font-size: .9rem; cursor: pointer; transition: .18s;
}
.btn-primary {
  background: var(--grad-brand); color: #fff;
  box-shadow: 0 6px 16px rgba(79,70,229,.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(79,70,229,.4); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: var(--surface-2); color: var(--ink-2); }
.btn-ghost:hover { background: #e2e6fd; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-block { width: 100%; }
.btn-icon { display: inline-flex; width: 16px; height: 16px; }
.btn-icon svg { width: 100%; height: 100%; }

.auth-footer {
  margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line);
  display: flex; align-items: center; gap: 8px;
  font-size: .72rem; color: var(--ink-3);
}
.badge-secure { display: inline-flex; width: 16px; height: 16px; color: var(--green); flex: none; }
.badge-secure svg { width: 100%; height: 100%; }

/* ============================ VAULT LAYOUT ============================ */
.vault-screen { height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: calc(12px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-title {
  font-weight: 800; font-size: 1.15rem;
  background: var(--grad-brand);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.search-box {
  flex: 1; max-width: 560px; position: relative; display: flex; align-items: center;
}
.search-box input { padding-left: 38px; border-radius: 99px; background: var(--surface-2); border-color: transparent; }
.search-box input:focus { background: var(--surface); }
.search-icon { position: absolute; left: 13px; width: 17px; height: 17px; color: var(--ink-3); pointer-events: none; }
.search-icon svg { width: 100%; height: 100%; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.autolock-select { width: auto; padding: 8px 10px; font-size: 16px; border-radius: 99px; background: var(--surface-2); border-color: transparent; color: var(--ink-2); }

.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: var(--surface-2); color: var(--ink-2);
  display: inline-grid; place-items: center; cursor: pointer; transition: .15s; flex: none;
}
.icon-btn:hover { background: #e0e4fd; color: var(--indigo); }
.icon-btn.danger:hover { background: #fee2e2; color: var(--red); }
.icon-btn.ghost { background: transparent; }
.icon-btn svg { width: 18px; height: 18px; }

.vault-body { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 230px; flex: none; padding: 18px 12px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}
.cat-nav { display: flex; flex-direction: column; gap: 4px; }
.cat-btn {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; cursor: pointer;
  padding: 10px 12px; min-height: 44px; border-radius: var(--r-sm);
  font: inherit; font-size: .88rem; font-weight: 600; color: var(--ink-2);
  transition: .15s; text-align: left; width: 100%;
}
.cat-btn:hover { background: var(--surface-2); }
.cat-btn.active { background: linear-gradient(135deg, rgba(79,70,229,.12), rgba(6,182,212,.10)); color: var(--indigo); }
.cat-btn .cat-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; flex: none; }
.cat-btn .cat-ico svg { width: 16px; height: 16px; }
.cat-btn .cat-count { margin-left: auto; font-size: .72rem; font-weight: 700; color: var(--ink-3); background: var(--surface-2); padding: 2px 8px; border-radius: 99px; }
.cat-btn.active .cat-count { background: #fff; color: var(--indigo); }
.sidebar-foot { margin-top: auto; padding: 10px 12px; }
.vault-count { font-size: .72rem; color: var(--ink-3); }

.content { flex: 1; padding: 22px max(26px, env(safe-area-inset-right)) calc(22px + env(safe-area-inset-bottom)) max(26px, env(safe-area-inset-left)); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.content-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.content-head h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: -.3px; }

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
  padding-bottom: 90px;
}
.item-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 16px; box-shadow: var(--shadow-sm); transition: .18s; position: relative; overflow: hidden;
}
.item-card::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--cat-color, var(--indigo));
}
.item-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: #d3daff; }
.item-top { display: flex; align-items: center; gap: 11px; margin-bottom: 10px; }
.item-ico {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: var(--cat-color, var(--indigo));
}
.item-ico svg { width: 20px; height: 20px; }
.item-title { font-weight: 700; font-size: .95rem; word-break: break-word; line-height: 1.25; }
.item-user { font-size: .78rem; color: var(--ink-3); word-break: break-all; }
.item-fav {
  margin-left: auto; border: 0; background: transparent; cursor: pointer;
  color: #cbd2f0; width: 44px; height: 44px; margin: -8px -8px 0 0; display: grid; place-items: center; flex: none;
  transition: .15s;
}
.item-fav svg { width: 19px; height: 19px; }
.item-fav:hover { color: var(--amber); transform: scale(1.12); }
.item-fav.on { color: var(--amber); }
.item-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.chip {
  font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: 99px;
  background: color-mix(in srgb, var(--cat-color, var(--indigo)) 12%, white);
  color: var(--cat-color, var(--indigo));
}
.item-url { font-size: .72rem; color: var(--ink-3); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-url:hover { color: var(--cyan); }
.item-actions { display: flex; gap: 6px; border-top: 1px solid var(--line); padding-top: 10px; }
.mini-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 7px 12px; min-height: 44px; min-width: 44px; justify-content: center; cursor: pointer;
  background: var(--surface-2); color: var(--ink-2);
  font: inherit; font-size: .74rem; font-weight: 700; transition: .15s;
}
.mini-btn:hover { background: #e0e4fd; color: var(--indigo); }
.mini-btn svg { width: 14px; height: 14px; }
.mini-btn.warn:hover { background: #fee2e2; color: var(--red); }

.empty-state { text-align: center; padding: 70px 20px; color: var(--ink-2); }
.empty-art {
  width: 92px; height: 92px; margin: 0 auto 18px; border-radius: 28px;
  background: var(--grad-brand); display: grid; place-items: center; color: #fff;
  box-shadow: var(--shadow-lg);
}
.empty-art svg { width: 44px; height: 44px; }
.empty-state h3 { font-size: 1.15rem; margin-bottom: 6px; }
.empty-state p { margin: 0 0 18px; font-size: .88rem; color: var(--ink-3); }

/* ============================== MODAIS ============================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(16, 19, 50, .45); backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  animation: fadeIn .18s ease;
}
.modal {
  width: min(520px, 100%); max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: var(--r-lg);
  padding: 24px; box-shadow: var(--shadow-lg);
  animation: popIn .2s ease;
}
.modal.sm { width: min(400px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 1.1rem; font-weight: 800; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.check-line { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: .85rem; color: var(--ink-2); margin-bottom: 9px; cursor: pointer; }
.check-line input { width: 22px; height: 22px; accent-color: var(--indigo); cursor: pointer; }
.confirm-text { color: var(--ink-2); font-size: .9rem; margin: 0; }

.gen-result {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 10px;
}
.gen-result code {
  flex: 1; font-size: 1.02rem; font-weight: 700; letter-spacing: .5px; color: var(--indigo);
  word-break: break-all; font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}
.gen-options { margin-top: 14px; }
.range-line { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: 12px; }
.range-line input { width: 100%; min-height: 44px; margin-top: 2px; accent-color: var(--indigo); }

/* ============================== TOASTS ============================== */
.toast-area {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--ink); color: #fff; font-size: .84rem; font-weight: 600;
  padding: 11px 18px; border-radius: 99px; box-shadow: var(--shadow-md);
  animation: toastIn .22s ease;
}
.toast.ok { background: linear-gradient(135deg, #059669, #10b981); }
.toast.err { background: linear-gradient(135deg, #dc2626, #ef4444); }
.toast svg { width: 16px; height: 16px; flex: none; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96) translateY(8px); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

/* ============================ RESPONSIVO ============================ */
@media (max-width: 860px) {
  .vault-body { flex-direction: column; }
  .sidebar { width: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; flex: none; }
  .cat-nav { flex-direction: row; gap: 6px; }
  .cat-btn { width: auto; white-space: nowrap; }
  .sidebar-foot { display: none; }
  .topbar { flex-wrap: wrap; }
  .search-box { order: 3; flex-basis: 100%; max-width: none; }
  .content { padding-top: 16px; }
  .autolock-select { display: none; }
}
@media (max-width: 480px) {
  .auth-card { padding: 26px 20px; }
  .field-row { grid-template-columns: 1fr; }
}

/* ============================ TECLADO DE PIN ============================ */
.pin-head { text-align: center; margin-bottom: 14px; }
.pin-head h2 { font-size: 1.15rem; font-weight: 800; }
.pin-sub { margin: 4px 0 0; font-size: .88rem; color: var(--ink-2); }
.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 6px 0 18px; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--indigo); background: transparent; transition: background .12s, transform .12s;
}
.pin-dot.on { background: var(--indigo); transform: scale(1.1); }
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  max-width: 300px; margin: 0 auto;
  -webkit-user-select: none; user-select: none;
}
.keypad.disabled { opacity: .45; }
.key {
  min-height: 60px; border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 1.5rem; font-weight: 700;
  cursor: pointer; transition: background .12s, transform .08s; box-shadow: var(--shadow-sm);
}
.key:hover:not(:disabled) { background: var(--surface-2); }
.key:active:not(:disabled) { transform: scale(.95); background: #e0e4fd; }
.key-aux { font-size: .85rem; font-weight: 700; color: var(--ink-2); background: var(--surface-2); box-shadow: none; }
.key:disabled { cursor: not-allowed; }

.no-results { color: var(--ink-3); grid-column: 1 / -1; padding: 24px 4px; }
.item-actions-gap { flex: 1; }

/* ===================== AVISO DE INSTALAÇÃO (iPhone) ===================== */
.ios-install {
  position: fixed; z-index: 60;
  left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); padding: 10px 6px 10px 14px;
}
.ios-install p { margin: 0; flex: 1; font-size: .82rem; line-height: 1.4; color: var(--ink-2); }
.ios-install-ico { width: 24px; height: 24px; color: var(--indigo); flex: none; }
.ios-install-ico svg { width: 100%; height: 100%; }
.ios-share { display: inline-block; width: 15px; height: 15px; vertical-align: -2px; color: var(--indigo); }
.ios-share svg { width: 100%; height: 100%; }
