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

:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-alt: #f0efe9;
  --border: #e0dfd8;
  --border-strong: #c8c7c0;
  --text: #1a1a18;
  --text-muted: #6b6b65;
  --text-dim: #9b9b94;
  --accent: #185FA5;
  --accent-bg: #e6f1fb;
  --accent-text: #0c447c;
  --success: #3B6D11;
  --success-bg: #eaf3de;
  --danger: #A32D2D;
  --danger-bg: #fcebeb;
  --warning: #854F0B;
  --warning-bg: #faeeda;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --transition: 0.15s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18;
    --surface: #242422;
    --surface-alt: #2c2c2a;
    --border: #3a3a38;
    --border-strong: #525250;
    --text: #f0efe9;
    --text-muted: #9b9b94;
    --text-dim: #6b6b65;
    --accent: #378ADD;
    --accent-bg: #0c2a44;
    --accent-text: #85b7eb;
    --success: #639922;
    --success-bg: #1a2e08;
    --danger: #E24B4A;
    --danger-bg: #2d1010;
    --warning: #EF9F27;
    --warning-bg: #2d1e04;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── Screens ── */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; }

/* ── Auth screens ── */
#screen-login, #screen-register, #screen-setup {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.auth-card .logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-card .logo .icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.auth-card .logo h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.auth-card .logo p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Form elements ── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
  appearance: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}

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

.input-group {
  position: relative;
  display: flex;
}
.input-group input { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .btn-icon {
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0 0.75rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border: 0.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); border-color: var(--border-strong); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-text); border-color: var(--accent-text); }

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-bg); }

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius);
  background: transparent;
  border: 0.5px solid var(--border);
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--surface-alt); color: var(--text); }

.btn-block { width: 100%; }

/* ── App layout ── */
#screen-app {
  flex-direction: column;
}

.app-header {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.25rem;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header .brand {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

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

.lock-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--success-bg);
  color: var(--success);
  font-weight: 500;
}

/* ── Tab navigation ── */
.app-tabs {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.25rem;
  display: flex;
  gap: 0;
  overflow-x: auto;
}

.tab-btn {
  padding: 0.65rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Main content ── */
.app-content {
  flex: 1;
  padding: 1.25rem;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

/* ── Tab panels ── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Stats bar ── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.stat-card .stat-num {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}
.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Search and filters ── */
.vault-toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-wrapper {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-wrapper .search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  pointer-events: none;
  opacity: 0.45;
}
.search-wrapper input {
  padding-left: 2.2rem;
}

.category-filters {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 0.5px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-text); }

/* ── Vault list ── */
.vault-list { display: flex; flex-direction: column; gap: 0.5rem; }

.vault-item {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.vault-item:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }

.item-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--accent-bg);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  font-weight: 600;
}

.item-info { flex: 1; min-width: 0; }
.item-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-actions { display: flex; gap: 0.25rem; }

.strength-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state h3 { font-size: 1rem; margin-bottom: 0.5rem; color: var(--text); }
.empty-state p { font-size: 0.875rem; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal-header {
  padding: 1.25rem 1.25rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.modal-body { padding: 0 1.25rem 1.25rem; }

.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 0.5px solid var(--border);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* ── Password strength bar ── */
.strength-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  margin-top: 0.35rem;
  overflow: hidden;
}
.strength-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}
.strength-label {
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

/* ── Admin panel ── */
.admin-section {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  overflow: hidden;
}

.admin-section-header {
  padding: 0.875rem 1rem;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-section-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.admin-table th {
  padding: 0.6rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 0.5px solid var(--border);
}
.admin-table td {
  padding: 0.65rem 1rem;
  border-bottom: 0.5px solid var(--border);
  color: var(--text);
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--surface-alt); }

.role-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.role-admin { background: var(--accent-bg); color: var(--accent-text); }
.role-user { background: var(--surface-alt); color: var(--text-muted); }

/* ── Settings panel ── */
.settings-section {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  overflow: hidden;
}

.settings-section-header {
  padding: 0.875rem 1rem;
  border-bottom: 0.5px solid var(--border);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

.settings-row {
  padding: 0.875rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid var(--border);
  gap: 1rem;
}
.settings-row:last-child { border-bottom: none; }

.settings-row-info h4 { font-size: 0.9rem; font-weight: 500; }
.settings-row-info p { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* ── Toast notifications ── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 320px;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 0.5px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}
.toast-success { border-color: var(--success); color: var(--success); background: var(--success-bg); }
.toast-error { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }
.toast-info { border-color: var(--accent); color: var(--accent-text); background: var(--accent-bg); }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Loading overlay ── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  flex-direction: column;
  gap: 1rem;
}

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

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Invite token box ── */
.invite-box {
  background: var(--accent-bg);
  border: 0.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.invite-token {
  font-family: monospace;
  font-size: 0.875rem;
  color: var(--accent-text);
  flex: 1;
  word-break: break-all;
}

/* ── Recovery kit warning ── */
.warning-box {
  background: var(--warning-bg);
  border: 0.5px solid var(--warning);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--warning);
  margin-bottom: 1rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

/* ── Session timer ── */
.session-timer {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .auth-card { padding: 1.5rem; }
  .app-content { padding: 0.75rem; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .vault-toolbar { flex-direction: column; align-items: stretch; }
  .item-actions .btn-icon { padding: 0.4rem; }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }
  .settings-row { flex-direction: column; align-items: flex-start; }
  #toast-container { left: 1rem; right: 1rem; max-width: none; }
}

@media (max-width: 400px) {
  .app-header .brand span { display: none; }
  .tab-btn span { display: none; }
}
