:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-subtle: #f9fafb;
  --surface-strong: #eef0f4;
  --text: #171923;
  --text-soft: #626777;
  --border: #dfe2e8;
  --border-strong: #cbd0da;
  --accent: #6554e8;
  --accent-hover: #5545d6;
  --accent-soft: #eeecff;
  --danger: #c43d4d;
  --danger-soft: #fff0f2;
  --success: #13795b;
  --success-soft: #eaf8f2;
  --shadow: 0 12px 32px rgba(25, 29, 43, .07);
  --radius-card: 14px;
  --radius-control: 10px;
  --header-height: 72px;
}

.dark {
  color-scheme: dark;
  --bg: #0c0e14;
  --surface: #13161f;
  --surface-subtle: #181b25;
  --surface-strong: #202431;
  --text: #f4f5f8;
  --text-soft: #a8adbc;
  --border: #292e3b;
  --border-strong: #3a4050;
  --accent: #8878ff;
  --accent-hover: #9b8eff;
  --accent-soft: #252143;
  --danger: #ff7785;
  --danger-soft: #351d24;
  --success: #55d6a5;
  --success-soft: #142b26;
  --shadow: 0 16px 40px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
svg { width: 19px; height: 19px; flex: 0 0 auto; }

.app-body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  transition: background-color .18s ease, color .18s ease;
}

.app-glow { display: none; }
.shell { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
.page { padding-block: 46px 64px; }
.page-narrow { max-width: 780px; }
.section-gap { margin-top: 18px; }
.inline-gap { margin-top: 8px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-height);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr);
  align-items: center;
  gap: 24px;
}

.brand, .auth-logo { display: inline-flex; align-items: center; gap: 11px; font-weight: 750; letter-spacing: -.02em; }
.brand-mark, .stat-icon, .security-orb {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: var(--accent);
  background: var(--accent-soft);
}
.brand strong { display: block; font-size: 15px; line-height: 1.15; }
.brand small { display: block; margin-top: 3px; color: var(--text-soft); font-size: 11px; font-weight: 600; letter-spacing: .01em; }

.main-nav { display: flex; align-items: center; gap: 4px; }
.desktop-nav { justify-self: center; }
.mobile-nav { display: none; }
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 13px;
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}
.nav-link svg { width: 17px; height: 17px; }
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-link.is-active { color: var(--accent); background: var(--accent-soft); }

.header-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.header-control { width: auto !important; padding-inline: 11px !important; gap: 7px; }
.action-label { font-size: 12px; font-weight: 750; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 28px; }
.page-title { margin: 7px 0 4px; font-size: clamp(28px, 4vw, 42px); line-height: 1.08; letter-spacing: -.045em; }
.page-subtitle { margin: 0; max-width: 640px; color: var(--text-soft); }
.eyebrow { display: flex; align-items: center; gap: 7px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.eyebrow svg { width: 15px; height: 15px; }
.section-title { display: flex; align-items: center; gap: 9px; margin: 0 0 8px; font-size: 18px; letter-spacing: -.02em; }
.feature-card .section-title { margin-top: 12px; }
.feature-card .section-title + p, .feature-card p { color: var(--text-soft); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow); }
.card-pad { padding: 24px; }
.stat-grid { display: grid; grid-template-columns: 1.35fr 1fr 1fr; gap: 14px; }
.stat { min-height: 154px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.stat:first-child { background: var(--text); color: var(--bg); border-color: var(--text); }
.dark .stat:first-child { background: #f1f2f5; color: #12141b; border-color: #f1f2f5; }
.stat:first-child .stat-icon { background: rgba(255,255,255,.13); color: inherit; }
.dark .stat:first-child .stat-icon { background: rgba(0,0,0,.08); }
.stat-icon, .security-orb { width: 42px; height: 42px; }
.stat-label { margin-top: 20px; color: var(--text-soft); font-size: 12px; font-weight: 700; }
.stat:first-child .stat-label { color: inherit; opacity: .66; }
.stat-value { font-size: 30px; font-weight: 800; letter-spacing: -.04em; }
.stat-value.small { font-size: 17px; letter-spacing: -.02em; }
.quick-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; margin-top: 14px; }
.feature-card { min-height: 150px; padding: 22px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.feature-card p { margin: 0; max-width: 540px; }
.security-orb { flex: 0 0 auto; }

.btn, .icon-button, .control-action {
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}
.btn {
  min-height: 44px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-control);
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: white; background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { color: var(--text); background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-strong); border-color: var(--border-strong); }
.btn-block { width: 100%; }
.btn.compact { min-height: 38px; padding-inline: 12px; }
.count-badge { min-width: 19px; height: 19px; padding: 0 5px; display: inline-grid; place-items: center; border-radius: 99px; background: var(--surface-strong); color: var(--text-soft); font-size: 11px; }

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: var(--surface);
  border-color: var(--border);
  border-radius: var(--radius-control);
}
.icon-button:hover { color: var(--text); background: var(--surface-strong); border-color: var(--border-strong); }
.icon-button.danger:hover { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn:focus-visible, .icon-button:focus-visible, .control-action:focus-visible, .nav-link:focus-visible, .text-link:focus-visible, .control:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent);
  outline-offset: 2px;
}

.action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.search-control, .control-wrap { position: relative; }
.search-control > svg { position: absolute; z-index: 1; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-soft); }
.search-control .control { padding-left: 44px; }
.control {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  outline: none;
}
.control::placeholder { color: color-mix(in srgb, var(--text-soft) 78%, transparent); }
.control:focus { border-color: var(--accent); background: var(--surface); }
textarea.control { min-height: 112px; resize: vertical; }
.control-wrap .control { padding-right: 48px; }
.control-action { position: absolute; right: 4px; top: 4px; width: 36px; height: 36px; display: grid; place-items: center; color: var(--text-soft); background: transparent; border-radius: 8px; }
.control-action:hover { color: var(--text); background: var(--surface-strong); }

.vault-list { overflow: hidden; margin-top: 16px; box-shadow: none; }
.vault-item {
  display: grid;
  grid-template-columns: 44px minmax(180px, .9fr) minmax(300px, 1.45fr) auto;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.vault-item:last-child { border-bottom: 0; }
.vault-item:hover { background: var(--surface-subtle); }
.site-avatar { width: 42px; height: 42px; display: grid; place-items: center; color: var(--accent); background: var(--accent-soft); border-radius: 12px; font-weight: 800; text-transform: uppercase; }
.item-identity { min-width: 0; }
.item-title { overflow: hidden; color: var(--text); font-size: 14px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { overflow: hidden; margin-top: 3px; color: var(--text-soft); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.password-inline { display: grid; grid-template-columns: minmax(0, 1fr) 40px 40px; gap: 7px; min-width: 0; }
.password-inline .control { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }
.item-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.trash-item { grid-template-columns: 44px minmax(220px, 1fr) auto auto; }
.deleted-label { display: inline-flex; align-items: center; gap: 7px; color: var(--text-soft); font-size: 12px; font-weight: 700; }
.vault-empty { padding: 56px 20px; display: grid; justify-items: center; gap: 8px; color: var(--text-soft); text-align: center; }
.vault-empty > svg { width: 30px; height: 30px; color: var(--accent); }
.vault-empty strong { display: block; color: var(--text); }

.alert { margin: 0 0 16px; padding: 12px 14px; display: flex; align-items: center; gap: 9px; border: 1px solid; border-radius: var(--radius-control); font-size: 13px; font-weight: 650; }
.alert-success { color: var(--success); background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, var(--border)); }
.alert-error { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }

.form-stack { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: grid; gap: 7px; }
.field-label { color: var(--text); font-size: 12px; font-weight: 750; }
.field-hint, .helper { color: var(--text-soft); font-size: 12px; font-weight: 500; }
.divider { height: 1px; margin: 22px 0; background: var(--border); }
.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 900px; }
.file-control { padding-block: 8px; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, .85fr) minmax(520px, 1.15fr); }
.auth-visual { position: relative; padding: 54px clamp(34px, 6vw, 82px); display: flex; flex-direction: column; justify-content: space-between; color: #f6f6fa; background: #161824; overflow: hidden; }
.auth-visual::after { content: ""; position: absolute; right: -80px; bottom: -90px; width: 250px; height: 250px; border: 1px solid rgba(255,255,255,.12); border-radius: 50%; box-shadow: 0 0 0 46px rgba(255,255,255,.035), 0 0 0 92px rgba(255,255,255,.02); }
.auth-logo { position: relative; z-index: 1; font-size: 17px; }
.auth-logo .brand-mark { color: white; background: rgba(255,255,255,.11); }
.auth-copy { position: relative; z-index: 1; max-width: 520px; }
.auth-copy h2 { margin: 0 0 18px; font-size: clamp(40px, 5vw, 68px); line-height: .98; letter-spacing: -.055em; }
.auth-copy p { max-width: 440px; margin: 0; color: #b8bdca; font-size: 16px; }
.trust-row { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 18px; color: #c4c8d2; font-size: 12px; font-weight: 650; }
.trust-row span { display: inline-flex; align-items: center; gap: 7px; }
.trust-row svg { width: 16px; height: 16px; }
.auth-panel { padding: 42px; display: grid; place-items: center; background: var(--bg); }
.auth-card { width: min(100%, 450px); }
.auth-card.wide { width: min(100%, 680px); }
.auth-top { min-height: 42px; display: flex; justify-content: flex-end; }
.auth-heading { margin: 16px 0 28px; }
.auth-heading h1 { margin: 8px 0 7px; font-size: 34px; line-height: 1.08; letter-spacing: -.04em; }
.auth-heading p { margin: 0; color: var(--text-soft); }
.auth-links { margin-top: 22px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: 13px; }
.text-link { color: var(--accent); font-weight: 750; }
.text-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.text-link svg { display: inline; vertical-align: -2px; }
.idle-timer { position: fixed; right: 18px; bottom: 18px; z-index: 70; pointer-events: none; color: var(--text-soft); font-size: 11px; }

@media (max-width: 900px) {
  .header-inner { grid-template-columns: 1fr auto; }
  .desktop-nav { display: none; }
  .stat-grid { grid-template-columns: 1.2fr 1fr; }
  .stat:first-child { grid-row: span 2; }
  .quick-grid { grid-template-columns: 1fr; }
  .vault-item { grid-template-columns: 44px minmax(150px, .75fr) minmax(260px, 1.25fr) auto; gap: 12px; }
  .trash-item { grid-template-columns: 44px minmax(180px, 1fr) auto; }
  .trash-item .deleted-label { display: none; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-visual { display: none; }
  .auth-panel { min-height: 100vh; }
}

@media (max-width: 767px) {
  :root { --header-height: 64px; }
  .shell { width: min(100% - 28px, 680px); }
  .page { padding-block: 28px calc(104px + env(safe-area-inset-bottom)); }
  .app-header { position: sticky; }
  .header-inner { gap: 10px; }
  .brand { gap: 8px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .brand small { display: none; }
  .header-actions { gap: 6px; }
  .header-control { min-width: 39px; height: 39px; padding-inline: 9px !important; }
  .header-control .action-label { display: inline; }
  .mobile-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    min-height: 66px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 16px 42px rgba(0,0,0,.24);
  }
  .mobile-nav .nav-link { min-width: 0; min-height: 52px; padding: 5px 3px; flex-direction: column; justify-content: center; gap: 3px; font-size: 10px; }
  .mobile-nav .nav-link svg { width: 19px; height: 19px; }
  .page-head { align-items: stretch; flex-direction: column; gap: 18px; margin-bottom: 22px; }
  .page-title { font-size: 31px; }
  .page-head > .btn, .page-head > .action-row { width: 100%; }
  .page-head > .btn { justify-content: center; }
  .page-head .action-row { display: grid; grid-template-columns: 1fr 1.1fr; }
  .page-head .action-row .btn { width: 100%; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat { min-height: 132px; padding: 18px; }
  .stat:first-child { grid-column: 1 / -1; grid-row: auto; min-height: 150px; }
  .stat-value { font-size: 27px; }
  .stat-value.small { font-size: 15px; }
  .feature-card { min-height: 0; padding: 20px; align-items: flex-start; flex-direction: column; }
  .feature-card .btn { width: 100%; }
  .search-row { grid-template-columns: 1fr auto; }
  .search-row .btn { width: 44px; padding: 0; }
  .search-row .btn svg { margin: 0; }
  .search-row .btn { font-size: 0; }
  .vault-list { overflow: visible; border: 0; background: transparent; box-shadow: none; }
  .vault-item {
    grid-template-columns: 42px minmax(0, 1fr) auto;
    grid-template-areas: "avatar identity actions" "password password password";
    gap: 12px;
    margin-bottom: 10px;
    padding: 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: none;
  }
  .vault-item:last-child { border-bottom: 1px solid var(--border); }
  .vault-item:hover { background: var(--surface); }
  .vault-item > .site-avatar { grid-area: avatar; width: 42px; height: 42px; }
  .vault-item > .item-identity { grid-area: identity; align-self: center; }
  .vault-item > .password-inline { grid-area: password; }
  .vault-item > .item-actions { grid-area: actions; align-self: start; }
  .password-inline { grid-template-columns: minmax(0, 1fr) 40px 40px; }
  .trash-item { grid-template-areas: "avatar identity actions"; }
  .trash-item .item-actions { flex-direction: row; }
  .trash-item .btn.compact { font-size: 0; width: 40px; padding: 0; }
  .trash-item .btn.compact svg { margin: 0; }
  .form-grid, .profile-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .card-pad { padding: 19px; }
  .auth-panel { padding: 22px 20px 36px; place-items: start center; }
  .auth-card { margin-top: 6px; }
  .auth-heading { margin-top: 12px; }
  .auth-heading h1 { font-size: 30px; }
  .idle-timer { display: none; }
}

@media (max-width: 390px) {
  .brand > span:last-child { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat:first-child { grid-column: auto; }
  .page-head .action-row { grid-template-columns: 1fr; }
  .password-inline { grid-template-columns: minmax(0, 1fr) 38px 38px; gap: 5px; }
  .password-inline .icon-button { width: 38px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
