:root {
  --pad: 14px;
  --gap: 10px;
  --radius: 10px;
  --bg: #f6f7fb;
  --fg: #222;
  --fg-muted: #666;
  --card: #fff;
  --surface: #f7f7f8;
  --border: #e5e7eb;
  --input-bg: #fff;
  --input-fg: #222;
  --primary: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --hover: rgba(37, 99, 235, 0.04);
  --code-bg: #f3f4f6;
  --table-header: #f8f9fc;
  --table-border: #eee;
}

:root[data-theme="dark"] {
  --bg: #1a1a1a;
  --fg: #e5e5e7;
  --fg-muted: #9aa3b2;
  --card: #242424;
  --surface: #2a2a2a;
  --border: #3a3a3a;
  --input-bg: #2e2e2e;
  --input-fg: #e5e5e7;
  --primary: #3b82f6;
  --hover: rgba(59, 130, 246, 0.08);
  --code-bg: #2a2a2a;
  --table-header: #2a2a2a;
  --table-border: #333;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
}

a { color: inherit; text-decoration: none; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

h1 { font-size: 22px; margin: 0 0 16px; color: var(--fg); }
h2, h3, h4 { color: var(--fg); }

/* Nav */
nav {
  display: flex;
  gap: var(--gap);
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}
nav a, nav form button {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  transition: background 0.2s, color 0.2s;
}
nav a:hover { background: var(--hover); }
nav a.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
nav .spacer { flex: 1 1 auto; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 16px;
}
.card h1, .card h2, .card h3, .card h4 {
  color: var(--fg);
  margin: .5rem 0;
  font-weight: 600;
}

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--table-border); text-align: left; color: var(--fg); }
thead th { background: var(--table-header); font-weight: 600; color: var(--fg); }
tr:hover { background: var(--hover); }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}
.btn:hover { background: var(--hover); }
.btn.primary, .btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff !important;
}
.btn-primary:hover { box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
.btn.danger, .btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff !important;
}
.btn-danger:hover { box-shadow: 0 0 0 3px rgba(239,68,68,.25); }
.btn-sm {
  padding: 4px 10px;
  font-size: 13px;
}
.btn:disabled, button:disabled { opacity: .6; cursor: not-allowed; }

/* Forms */
form.inline { display: inline; }

label {
  display: block;
  margin-bottom: 10px;
  font-weight: 500;
  color: var(--fg);
}
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--input-fg);
  font-size: 14px;
  margin-top: 4px;
}
input::placeholder, textarea::placeholder { color: var(--fg-muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}
input[type="checkbox"] {
  width: auto;
  margin-right: 6px;
}
input[type="range"] {
  background: transparent;
}
textarea { min-height: 80px; resize: vertical; }

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 14px;
}
.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
}
.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #16a34a;
}
:root[data-theme="dark"] .alert-error {
  background: #3b1515;
  border-color: #7f1d1d;
  color: #fca5a5;
}
:root[data-theme="dark"] .alert-success {
  background: #14291a;
  border-color: #166534;
  color: #86efac;
}
.notice { color: var(--fg-muted); font-size: 12px; }

/* Profile link */
.profile-link {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
}
.profile-link:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Field groups */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; color: var(--fg); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--input-fg);
}

/* Two-column grid */
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.pair .half { min-width: 0; }

/* Text helpers */
.text-muted, .help, small { color: var(--fg-muted); }
p { color: var(--fg); }

/* Vault-specific styles */

/* Credential list */
.cred-list { list-style: none; padding: 0; margin: 0; }
.cred-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.cred-item:hover { background: var(--hover); }
.cred-item:last-child { border-bottom: none; }
.cred-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  flex-shrink: 0;
  text-decoration: none;
}
a.cred-icon-link {
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.15s, box-shadow 0.15s;
}
a.cred-icon-link:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59,130,246,.2);
}
a.cred-icon-link img {
  display: block;
  border-radius: 4px;
}
.cred-icon-fallback {
  width: 100%; height: 100%;
  align-items: center; justify-content: center;
  background: var(--primary);
  color: #fff;
  border-radius: 7px;
  font-weight: 700; font-size: 16px;
}
.cred-info { flex: 1; min-width: 0; }
.cred-info .site-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cred-info .site-name a { color: var(--fg); }
.cred-info .cred-username {
  color: var(--fg-muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cred-actions { display: flex; gap: 6px; flex-shrink: 0; }

.fav-star {
  color: var(--warning);
  cursor: pointer;
  font-size: 18px;
}
.fav-star.empty { color: var(--fg-muted); }

/* Password display */
.pw-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 15px;
  color: var(--fg);
  word-break: break-all;
}
.pw-masked { letter-spacing: 3px; }

/* Strength meter */
.strength-meter {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin-top: 6px;
  overflow: hidden;
}
.strength-meter-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}
.strength-label { font-size: 12px; margin-top: 2px; color: var(--fg-muted); }
.strength-weak { background: var(--danger); color: var(--danger); }
.strength-fair { background: var(--warning); color: var(--warning); }
.strength-good { background: #3b82f6; color: #3b82f6; }
.strength-strong { background: var(--success); color: var(--success); }

/* Generator */
.gen-output {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 18px;
  padding: 12px 16px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  word-break: break-all;
  text-align: center;
  margin-bottom: 12px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Search bar */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.search-bar input {
  flex: 1;
  margin: 0;
}

/* Filter tabs */
.filter-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-tab {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  text-decoration: none;
  background: var(--surface);
  transition: all 0.15s;
}
.filter-tab:hover { border-color: var(--primary); color: var(--primary); }
.filter-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Clipboard toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #333;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
:root[data-theme="dark"] .toast {
  background: #555;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--fg-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { margin: 8px 0; color: var(--fg-muted); }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.badge-admin { background: #dbeafe; color: #1e40af; }
.badge-user { background: #f3f4f6; color: #374151; }
:root[data-theme="dark"] .badge-admin { background: #1e3a5f; color: #93c5fd; }
:root[data-theme="dark"] .badge-user { background: #333; color: #d1d5db; }

/* Responsive */
@media (max-width: 720px) {
  .pair { grid-template-columns: 1fr; }
  .container { padding: 16px; }
  .cred-actions { flex-direction: column; gap: 4px; }
  .search-bar { flex-direction: column; }
}

footer {
  margin-top: 24px;
  color: var(--fg-muted);
  font-size: 12px;
}
