*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-raised: #22263a;
  --border: #2e3348;
  --text: #e8eaf0;
  --text-muted: #8b90a5;
  --primary: #6c63ff;
  --primary-hover: #5a52e0;
  --primary-glow: rgba(108, 99, 255, 0.25);
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
  min-height: 100vh;
}

/* Center native dialog when open */
dialog.modal[open] {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 1000;
  max-height: 90vh;
  overflow: auto;
}

/* Screens */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.unlock-card {
  margin-top: 10vh;
  text-align: center;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.logo svg {
  width: 48px;
  height: 48px;
  color: var(--primary);
}

.logo h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-small {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.1rem;
}

.logo-small svg {
  width: 24px;
  height: 24px;
  color: var(--primary);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.welcome-actions .btn-primary,
.welcome-actions .btn-secondary {
  width: auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

/* Forms */
label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-align: left;
}

.optional {
  font-weight: 400;
  opacity: 0.7;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"],
textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

textarea {
  resize: vertical;
  min-height: 60px;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.input-group input {
  flex: 1;
  margin-bottom: 0;
}

#unlock-form label {
  margin-top: 0;
}

#unlock-form .input-group {
  margin-bottom: 0.5rem;
}

#unlock-form {
  text-align: left;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--border);
  width: 100%;
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  padding: 0.5rem 0.75rem;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-raised);
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.btn-icon:hover {
  color: var(--text);
  background: var(--surface-raised);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.hidden {
  display: none !important;
}

/* Welcome-screen "Open a Vault File" split button: wide main button (opens
   a local file directly, unchanged behavior) + narrow chevron revealing a
   one-item menu for Drive. Same visual language as the header's
   .saveas-split buttons, adapted to this screen's full-width layout. */
.open-vault-split {
  position: relative;
  display: flex;
  width: auto;
}

.split-main-wide {
  flex: 0 0 auto;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.split-chevron {
  flex: 0 0 auto;
  width: 2.75rem;
  padding: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.split-chevron svg {
  transition: transform 0.15s;
}

.split-chevron[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 20;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 0.7rem 1rem;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: var(--border);
}

.open-vault-split .dropdown-menu {
  right: auto;
  min-width: 100%;
}

.open-vault-split .dropdown-item {
  white-space: nowrap;
}

/* Header split buttons (Merge / Save As) are only as wide as their own
   label, unlike the full-width welcome-screen split button, so their
   dropdown needs to size to its own content and hang off the right edge
   (under the chevron) instead of stretching edge-to-edge. */
.saveas-split .dropdown-menu {
  left: auto;
  right: 0;
  min-width: 190px;
}

.saveas-split .dropdown-item {
  white-space: nowrap;
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Error */
.error {
  color: var(--error);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  text-align: left;
}

.entry-count {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
}

.header-select,
.toolbar-select {
  padding: 0.45rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
}

.header-select:focus,
.toolbar-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.btn-danger {
  background: #991b1b;
}

.btn-danger:hover {
  background: #7f1d1d;
}

.password-strength {
  margin: 0.5rem 0 1rem;
}

.strength-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.strength-fill {
  height: 100%;
  width: 0;
  border-radius: 2px;
  transition: width 0.2s, background 0.2s;
}

.strength-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.strength-empty .strength-fill { width: 0; background: var(--border); }
.strength-weak .strength-fill { width: 25%; background: var(--error); }
.strength-fair .strength-fill { width: 50%; background: var(--warning); }
.strength-good .strength-fill { width: 75%; background: #60a5fa; }
.strength-strong .strength-fill { width: 100%; background: var(--success); }

.strength-weak .strength-label { color: var(--error); }
.strength-fair .strength-label { color: var(--warning); }
.strength-good .strength-label { color: #60a5fa; }
.strength-strong .strength-label { color: var(--success); }

.btn:focus-visible,
.btn-icon:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Vault header */
.vault-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.drive-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.35rem 0.6rem;
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

/* Disabled = "Drive: disconnected". Not clickable — there is no manual
   "connect" here, only the automatic connection made by opening/saving to
   Drive. */
.drive-status:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

/* Enabled = "Drive: connected". Clickable to manually disconnect. */
.drive-status:not(:disabled) {
  color: var(--success);
  border-color: var(--border);
  cursor: pointer;
}

.drive-status:not(:disabled):hover {
  background: var(--surface-raised);
  border-color: var(--error);
  color: var(--error);
}

/* Save As split button */
.saveas-split {
  display: inline-flex;
  align-items: center;
  position: relative;
}
.saveas-split .split-btn {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.6rem;
  border-left: 1px solid var(--border);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.saveas-split > .split-main {
  /* make room for the chevron inside the button */
  padding-right: 2.2rem;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.saveas-split .split-btn svg {
  width: 14px;
  height: 14px;
}
/* legacy split-menu styles removed (no inline menu used) */

/* Lock + auto-lock timeout as one compact group */
.lock-split {
  display: inline-flex;
  align-items: stretch;
}

.lock-split .lock-main {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.lock-split .lock-timeout {
  appearance: none;
  -webkit-appearance: none;
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b90a5' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.35rem center;
  background-size: 12px;
  border: 1px solid transparent;
  border-left: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0 1.3rem 0 0.55rem;
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s;
}

.lock-split .lock-timeout:hover {
  color: var(--text);
  background-color: var(--surface-raised);
}

.lock-split .lock-timeout option {
  background: var(--surface);
  color: var(--text);
}

/* Toolbar */
.vault-toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.search-box {
  flex: 1;
  position: relative;
}

.search-box svg {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  padding-left: 2.5rem;
}

.vault-toolbar .btn-primary {
  width: auto;
}

/* Entries */
.entries-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.5rem 1rem;
  transition: border-color 0.2s;
}

.entry-card:hover {
  border-color: var(--primary);
}

.entry-info {
  grid-column: 1;
}

.entry-site {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.entry-username {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.entry-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-style: italic;
}

.entry-password-row {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.entry-password {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  min-width: 80px;
}

.entry-password.masked {
  color: var(--text-muted);
}

.entry-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

/* Modals */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 440px;
  width: calc(100% - 2rem);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal form {
  padding: 2rem;
}

.modal h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.modal-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.modal label {
  margin-top: 0.75rem;
}

.modal .input-group {
  margin-bottom: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.modal-actions .btn-primary {
  width: auto;
}

.modal-wide {
  max-width: 560px;
}

.conflict-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.conflict-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

.conflict-item-header {
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.conflict-item-user {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.conflict-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.conflict-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.conflict-option:hover {
  background: var(--surface-raised);
}

.conflict-option:has(input:checked) {
  border-color: var(--primary);
  background: rgba(108, 99, 255, 0.08);
}

.conflict-option input {
  margin-top: 0.2rem;
  accent-color: var(--primary);
}

.conflict-option-text {
  font-size: 0.85rem;
  line-height: 1.4;
}

.conflict-option-label {
  font-weight: 500;
  display: block;
  margin-bottom: 0.15rem;
}

.conflict-option-password {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  color: var(--text-muted);
  word-break: break-all;
}

.conflict-bulk-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

/* Persistent unsaved-changes banner (separate from the toast queue — see
   index.html for why). Reuses the warning toast palette for visual
   consistency. Pinned to the bottom, stacked just above the toast, so it
   never covers the header buttons (Merge / Export / Lock etc.) up top. */
.unsaved-banner {
  position: fixed;
  bottom: 4.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 1000;
  background: #450a0a;
  border: 1px solid var(--error);
  color: var(--error);
  box-shadow: var(--shadow);
  text-align: center;
  max-width: calc(100% - 2rem);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  animation: slideUp 0.3s ease;
  box-shadow: var(--shadow);
}

.toast-info {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
}

.toast-success {
  background: #064e3b;
  border: 1px solid var(--success);
  color: var(--success);
}

.toast-error {
  background: #450a0a;
  border: 1px solid var(--error);
  color: var(--error);
}

.toast-warning {
    background: #451a03;
    border: 1px solid var(--error);
    color: var(--warning);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(1rem);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Responsive */
@media (max-width: 540px) {
  .vault-toolbar {
    flex-direction: column;
  }

  .vault-toolbar .btn-primary {
    width: 100%;
  }

  .entry-card {
    grid-template-columns: 1fr;
  }

  .entry-password-row {
    grid-column: 1;
    grid-row: auto;
  }
}
