:root {
  color-scheme: light dark;
  font: 100%/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-subtle: #eceef1;
  --surface-glass: rgba(250, 251, 252, 0.78);
  --text: #18191c;
  --text-secondary: #686c74;
  --border: rgba(24, 25, 28, 0.11);
  --border-strong: rgba(24, 25, 28, 0.19);
  --accent: #126f4c;
  --accent-strong: #0b5b3d;
  --accent-soft: #e2f4eb;
  --danger: #c53a32;
  --danger-soft: #fae8e6;
  --shadow: 0 14px 40px rgba(17, 19, 22, 0.1), 0 2px 8px rgba(17, 19, 22, 0.06);
  --ring: 0 0 0 3px rgba(18, 111, 76, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1c1d20;
    --surface-subtle: #292b2f;
    --surface-glass: rgba(20, 21, 24, 0.8);
    --text: #f5f6f7;
    --text-secondary: #a9adb5;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --accent: #44c78b;
    --accent-strong: #63d89e;
    --accent-soft: #173b2c;
    --danger: #ff746b;
    --danger-soft: #472421;
    --shadow: 0 18px 52px rgba(0, 0, 0, 0.38), 0 2px 8px rgba(0, 0, 0, 0.28);
    --ring: 0 0 0 3px rgba(68, 199, 139, 0.24);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button, [role="button"] { touch-action: manipulation; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--ring); }

h1, h2, p { margin: 0; }
h1, h2 { line-height: 1.16; }

.eyebrow {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1.2;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 3.75rem;
  height: 3.75rem;
  place-items: center;
  border-radius: 8px;
  background: #1c1d20;
  color: #fff;
  box-shadow: 0 10px 24px rgba(18, 20, 24, 0.18);
}

.brand-mark svg { width: 1.85rem; height: 1.85rem; stroke: #51d397; }
.brand-mark-small { width: 2.5rem; height: 2.5rem; box-shadow: none; }
.brand-mark-small svg { width: 1.3rem; height: 1.3rem; }

.primary-button, .secondary-button, .danger-button, .icon-button {
  display: inline-flex;
  min-height: 2.75rem;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 680;
  transition: transform 110ms ease-out, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.primary-button:active, .secondary-button:active, .danger-button:active, .icon-button:active, .qr-dropzone:active { transform: scale(0.97); }
.primary-button { padding: 0.68rem 1rem; background: var(--text); color: var(--bg); }
.primary-button:hover { opacity: 0.86; }
.primary-button svg, .secondary-button svg, .danger-button svg { width: 1.05rem; height: 1.05rem; }
.secondary-button { padding: 0.62rem 0.9rem; border: 1px solid var(--border); background: var(--surface); }
.secondary-button:hover { background: var(--surface-subtle); }
.danger-button { padding: 0.62rem 0.95rem; background: var(--danger); color: #fff; }
.icon-button { width: 2.75rem; min-width: 2.75rem; padding: 0; background: transparent; }
.icon-button:hover { background: var(--surface-subtle); }
.icon-button svg { width: 1.15rem; height: 1.15rem; }
.is-hidden { display: none !important; }

/* Login */
.login-page {
  background:
    linear-gradient(rgba(18, 111, 76, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 111, 76, 0.055) 1px, transparent 1px),
    var(--bg);
  background-size: 38px 38px;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

.login-panel {
  width: min(100%, 24rem);
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(150%);
}

.login-heading { margin-top: 1.5rem; }
.login-heading h1 { margin-top: 0.4rem; font-size: 1.85rem; }
.login-heading > p:last-child { margin-top: 0.5rem; color: var(--text-secondary); }
.login-form { margin-top: 1.8rem; }
.login-form > label, .tab-panel > label, .field-group > label {
  display: block;
  margin-bottom: 0.48rem;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 680;
}

.password-field { position: relative; }
.password-field > svg { position: absolute; top: 0.95rem; left: 0.9rem; width: 1rem; height: 1rem; color: var(--text-secondary); pointer-events: none; }
.password-field input { width: 100%; height: 3rem; padding: 0 3rem 0 2.55rem; }
.password-toggle { position: absolute; top: 0.125rem; right: 0.125rem; }

input, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input { height: 2.9rem; padding: 0 0.85rem; }
textarea { min-height: 5.5rem; padding: 0.75rem 0.85rem; resize: vertical; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.88rem; }
input::placeholder, textarea::placeholder { color: var(--text-secondary); opacity: 0.64; }
input:hover, textarea:hover { border-color: var(--text-secondary); }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }

.form-error { min-height: 1.35rem; margin-top: 0.65rem; color: var(--danger); font-size: 0.8rem; }
.login-button { width: 100%; margin-top: 0.7rem; }

/* Application */
.app-shell { min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  padding-top: env(safe-area-inset-top);
  background: var(--surface-glass);
  backdrop-filter: blur(22px) saturate(160%);
  box-shadow: 0 1px 0 var(--border), 0 10px 30px rgba(20, 22, 25, 0.035);
}

.topbar-inner {
  display: flex;
  width: min(100% - 2.5rem, 72rem);
  min-height: 4.75rem;
  align-items: center;
  justify-content: space-between;
  margin: 0 auto;
}

.brand-inline { display: flex; align-items: center; gap: 0.8rem; }
.brand-inline h1 { margin-top: 0.2rem; font-size: 1.12rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.35rem; }
.topbar-actions form { display: contents; }

.workspace { width: min(100% - 2.5rem, 72rem); margin: 0 auto; padding: 2.7rem 0 4rem; }
.workspace-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
.workspace-heading h2 { font-size: 1.45rem; }
.workspace-heading p { margin-top: 0.35rem; color: var(--text-secondary); font-size: 0.86rem; }

.empty-state {
  display: grid;
  min-height: 23rem;
  place-items: center;
  align-content: center;
  padding: 2rem;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  text-align: center;
}
.empty-icon, .danger-icon {
  display: grid;
  width: 3.5rem;
  height: 3.5rem;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}
.empty-icon svg { width: 1.55rem; height: 1.55rem; }
.empty-state h2 { margin-top: 1rem; font-size: 1.18rem; }
.empty-state p { margin: 0.38rem 0 1.25rem; color: var(--text-secondary); }

.account-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
.account-card {
  min-width: 0;
  padding: 1.15rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(18, 20, 23, 0.035);
}
.account-card-header { display: flex; min-width: 0; align-items: flex-start; justify-content: space-between; gap: 0.8rem; }
.account-identity { min-width: 0; }
.account-name { overflow: hidden; font-weight: 720; text-overflow: ellipsis; white-space: nowrap; }
.account-provider { overflow: hidden; margin-top: 0.16rem; color: var(--text-secondary); font-size: 0.82rem; text-overflow: ellipsis; white-space: nowrap; }
.delete-account { margin: -0.55rem -0.55rem 0 0; color: var(--text-secondary); }
.delete-account:hover { color: var(--danger); background: var(--danger-soft); }

.code-row { display: flex; align-items: center; gap: 1rem; margin-top: 1.25rem; }
.totp-code {
  min-width: 0;
  flex: 1;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: clamp(1.7rem, 4.7cqw, 2.25rem);
  font-variant-numeric: tabular-nums;
  font-weight: 720;
  line-height: 1;
  white-space: nowrap;
}
.copy-code { flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface-subtle); }
.countdown {
  --progress: 100%;
  position: relative;
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  flex: 0 0 2.75rem;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--progress), var(--surface-subtle) 0);
}
.countdown::before { content: ""; position: absolute; inset: 3px; border-radius: inherit; background: var(--surface); }
.countdown span { position: relative; font-size: 0.73rem; font-variant-numeric: tabular-nums; font-weight: 730; }
.countdown.is-urgent { background: conic-gradient(var(--danger) var(--progress), var(--surface-subtle) 0); color: var(--danger); }

/* Sheets */
dialog { color: var(--text); }
.sheet, .confirm-dialog { max-width: none; max-height: none; padding: 0; border: 0; background: transparent; }
.sheet::backdrop, .confirm-dialog::backdrop { background: rgba(10, 11, 13, 0.46); backdrop-filter: blur(4px); }
.sheet { width: min(calc(100% - 2rem), 34rem); }
.sheet-panel {
  overflow: hidden auto;
  max-height: min(44rem, calc(100vh - 2rem));
  max-height: min(44rem, calc(100dvh - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.sheet-header h2 { margin-top: 0.25rem; font-size: 1.35rem; }
.close-sheet { margin-right: -0.45rem; }

.segmented-control { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem; margin: 1.3rem 0 1.15rem; padding: 0.25rem; border-radius: 7px; background: var(--surface-subtle); }
.segment { display: inline-flex; min-height: 2.45rem; align-items: center; justify-content: center; gap: 0.45rem; border: 0; border-radius: 5px; background: transparent; color: var(--text-secondary); cursor: pointer; font-weight: 670; }
.segment svg { width: 1rem; height: 1rem; }
.segment.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(15, 17, 20, 0.1); }

.qr-dropzone {
  display: flex;
  width: 100%;
  min-height: 9rem;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--surface-subtle);
  cursor: pointer;
  transition: transform 110ms ease-out, border-color 160ms ease, background-color 160ms ease;
}
.qr-dropzone:hover, .qr-dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.qr-dropzone > span:last-child { color: var(--text-secondary); font-size: 0.8rem; }
.dropzone-icon { display: grid; width: 2.6rem; height: 2.6rem; margin-bottom: 0.25rem; place-items: center; border-radius: 50%; background: var(--surface); color: var(--accent); }
.dropzone-icon svg { width: 1.25rem; height: 1.25rem; }
.clipboard-button { width: 100%; margin-top: 0.65rem; }
.scan-preview { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.75rem; padding: 0.65rem; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-subtle); }
.scan-preview img { width: 3rem; height: 3rem; border-radius: 5px; object-fit: cover; }
.scan-preview div { display: grid; }
.scan-preview strong { font-size: 0.86rem; }
.scan-preview span { color: var(--text-secondary); font-size: 0.76rem; }
.scan-preview.is-error strong { color: var(--danger); }
.scan-preview.is-success strong { color: var(--accent); }

.account-fields { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 0.75rem; margin-top: 1rem; }
.sheet-footer { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.15rem; padding-top: 1rem; border-top: 1px solid var(--border); }

.confirm-dialog { width: min(calc(100% - 2rem), 24rem); }
.confirm-panel { padding: 1.4rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.danger-icon { margin: 0 auto; background: var(--danger-soft); color: var(--danger); }
.danger-icon svg { width: 1.35rem; height: 1.35rem; }
.confirm-panel h2 { margin-top: 0.9rem; font-size: 1.2rem; }
.confirm-panel p { margin-top: 0.45rem; color: var(--text-secondary); font-size: 0.88rem; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-top: 1.25rem; }

.toast-region { position: fixed; z-index: 30; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom)); display: grid; gap: 0.5rem; pointer-events: none; }
.toast { display: flex; min-width: 12rem; align-items: center; gap: 0.55rem; padding: 0.72rem 0.85rem; border: 1px solid var(--border); border-radius: 7px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 0.84rem; font-weight: 650; animation: toast-in 280ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.toast svg { width: 1rem; height: 1rem; }
.toast.is-leaving { animation: toast-out 180ms ease-in both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(0.75rem) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(0.45rem) scale(0.98); } }

@media (max-width: 680px) {
  .topbar-inner, .workspace { width: min(100% - 1.5rem, 72rem); }
  .topbar-inner { min-height: 4.25rem; }
  .brand-inline .brand-mark { display: none; }
  .brand-inline .eyebrow { display: none; }
  .brand-inline h1 { margin: 0; }
  .topbar-actions { gap: 0; }
  .add-button span { display: none; }
  .add-button { width: 2.75rem; padding: 0; }
  .workspace { padding-top: 1.6rem; }
  .workspace-heading { align-items: center; }
  .workspace-heading h2 { font-size: 1.3rem; }
  .paste-shortcut span { display: none; }
  .paste-shortcut { width: 2.75rem; padding: 0; }
  .account-grid { grid-template-columns: minmax(0, 1fr); }
  .totp-code { font-size: clamp(1.72rem, 9vw, 2.2rem); }
  .sheet { width: 100%; margin: auto 0 0; }
  .sheet-panel { max-height: calc(100dvh - 0.75rem); padding: 1.15rem max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); border-radius: 8px 8px 0 0; }
  .account-fields { grid-template-columns: 1fr; }
  .sheet-footer { position: sticky; bottom: calc(-1rem - env(safe-area-inset-bottom)); margin-inline: -1rem; padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom)); background: var(--surface-glass); backdrop-filter: blur(18px); }
  .sheet-footer > * { flex: 1; }
}

@media (max-width: 370px) {
  .topbar-inner, .workspace { width: min(100% - 1rem, 72rem); }
  .topbar-actions > .icon-button, .topbar-actions form { display: none; }
  .code-row { gap: 0.55rem; }
  .account-card { padding: 1rem; }
  .totp-code { font-size: 1.55rem; }
}

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

@media (prefers-reduced-transparency: reduce) {
  .topbar, .login-panel, .sheet-footer { background: var(--surface); backdrop-filter: none; }
}

@media (prefers-contrast: more) {
  :root { --border: currentColor; --border-strong: currentColor; }
  .topbar, .login-panel { background: var(--surface); backdrop-filter: none; }
}
