/* ── Design system ─────────────────────────────────────────────────────────── */
:root {
  --color-bg:          #0f1117;
  --color-surface:     #1a1d27;
  --color-surface-2:   #22263a;
  --color-border:      #2d3148;
  --color-border-2:    #3d4260;
  --color-text:        #e8eaf0;
  --color-text-muted:  #8b91b0;
  --color-accent:      #6c8cff;
  --color-accent-dim:  rgba(108, 140, 255, 0.15);
  --color-success:     #4caf82;
  --color-warn:        #f5a623;
  --color-danger:      #e05a5a;

  --tier-general:      #4caf82;
  --tier-sensitive:    #f5a623;
  --tier-confidential: #e05a5a;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font:   'Inter', system-ui, -apple-system, sans-serif;
  --mono:   'JetBrains Mono', 'Fira Code', monospace;

  --nav-h: 56px;
  --sidebar-w: 240px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.6;
}
a { color: var(--color-accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; }
ul { list-style: none; }

/* ── Typography ─────────────────────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem;    font-weight: 600; }

/* ── Login page ─────────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 20%, rgba(108,140,255,0.12) 0%, transparent 60%),
              var(--color-bg);
}

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-7);
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-card__logo {
  display: block;
  text-align: center;
  margin-bottom: var(--space-5);
}
.login-card__logo-mark { height: 80px; width: auto; display: block; margin: 0 auto var(--space-3); }
.login-card__logo-text { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.login-card__title { margin-bottom: var(--space-2); }
.login-card__sub   { color: var(--color-text-muted); margin-bottom: var(--space-6); font-size: 0.9rem; }
.login-card__footer { margin-top: var(--space-4); color: var(--color-text-muted); font-size: 0.8rem; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  transition: opacity 0.15s, background 0.15s, transform 0.1s;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn--ghost {
  background: transparent;
  border: 1px solid var(--color-border-2);
  color: var(--color-text);
}
.btn--ghost:hover { background: var(--color-surface-2); }

.btn--danger {
  background: var(--color-danger);
  color: #fff;
}
.btn--danger:hover { opacity: 0.85; }

.btn--google {
  width: 100%;
  background: #fff;
  color: #333;
  font-weight: 600;
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-5);
  font-size: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.btn--google:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.25); }
.btn--icon {
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: color 0.15s, background 0.15s;
}
.btn--icon:hover { color: var(--color-text); background: var(--color-surface-2); }
.btn--sm { padding: var(--space-1) var(--space-3); font-size: 0.85rem; }

.btn__icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ── App shell ──────────────────────────────────────────────────────────────── */
.app { display: none; } /* shown by JS after auth check */
.app.is-ready { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Top nav ────────────────────────────────────────────────────────────────── */
.nav {
  height: var(--nav-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav__logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 1.1rem;
  margin-right: auto;
}
.nav__logo-mark { height: 28px; width: auto; display: inline-block; vertical-align: middle; }
.nav__search {
  flex: 1;
  max-width: 360px;
  position: relative;
}
.nav__search-input {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-7);
  color: var(--color-text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.nav__search-input:focus { border-color: var(--color-accent); }
.nav__search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}
.nav__avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-accent-dim);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.85rem;
  color: var(--color-accent);
  overflow: hidden;
  cursor: pointer;
}
.nav__avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-4) 0;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar__section { padding: 0 var(--space-3) var(--space-3); }
.sidebar__label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: var(--space-3) var(--space-3) var(--space-2);
}
.sidebar__nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  user-select: none;
  margin: 1px 0;
}
.sidebar__nav-item:hover { background: var(--color-surface-2); color: var(--color-text); }
.sidebar__nav-item.is-active { background: var(--color-accent-dim); color: var(--color-accent); font-weight: 500; }
.sidebar__nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.tier-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tier-dot--general      { background: var(--tier-general); }
.tier-dot--sensitive    { background: var(--tier-sensitive); }
.tier-dot--confidential { background: var(--tier-confidential); }

/* ── Main content ───────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-6);
}

/* ── View panels ────────────────────────────────────────────────────────────── */
.view { display: none; }
.view.is-active { display: block; }

.view__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
}
.view__title { font-size: 1.3rem; font-weight: 700; }

/* ── Filter bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}
.filter-select {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  padding: var(--space-2) var(--space-3);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--color-accent); }

/* ── Vault grid ─────────────────────────────────────────────────────────────── */
.vault-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: var(--space-4);
}

/* ── Vault card ─────────────────────────────────────────────────────────────── */
.vault-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.vault-card:hover {
  border-color: var(--color-border-2);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.vault-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.vault-card__title {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.3;
}
.vault-card__username {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vault-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.vault-card__updated {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}
.vault-card__actions {
  display: flex;
  gap: var(--space-1);
  opacity: 0;
  transition: opacity 0.15s;
}
.vault-card:hover .vault-card__actions { opacity: 1; }
.vault-card__fav {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  color: var(--color-text-muted);
  font-size: 0.9rem;
  transition: color 0.15s;
  line-height: 1;
}
.vault-card__fav.is-fav { color: var(--color-warn); }

/* ── Tier badge ─────────────────────────────────────────────────────────────── */
.tier-badge {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
}
.tier-badge--general      { background: rgba(76,175,130,0.15); color: var(--tier-general); }
.tier-badge--sensitive    { background: rgba(245,166,35,0.15);  color: var(--tier-sensitive); }
.tier-badge--confidential { background: rgba(224,90,90,0.15);   color: var(--tier-confidential); }

/* ── Tag chip ───────────────────────────────────────────────────────────────── */
.tag-chip {
  font-size: 0.72rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--color-text-muted);
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  transform: translateY(12px);
  transition: transform 0.2s;
}
.modal-overlay.is-open .modal { transform: translateY(0); }
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.modal__title { font-size: 1.1rem; font-weight: 600; }
.modal__body { padding: var(--space-5); }
.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
}

/* ── Form ───────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-4); }
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: var(--space-2);
  color: var(--color-text-muted);
}
.form-input {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--color-accent); }
.form-input--mono { font-family: var(--mono); letter-spacing: 0.04em; }
select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; min-height: 80px; }

/* ── Password field ─────────────────────────────────────────────────────────── */
.pw-field {
  position: relative;
}
.pw-field .form-input { padding-right: var(--space-8); }
.pw-field__toggle {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  padding: var(--space-1);
  border-radius: 4px;
  transition: color 0.15s;
}
.pw-field__toggle:hover { color: var(--color-text); }

/* ── Password strength ──────────────────────────────────────────────────────── */
.pw-strength { margin-top: var(--space-2); }
.pw-strength__bar {
  height: 4px;
  border-radius: 2px;
  background: var(--color-surface-2);
  overflow: hidden;
  margin-bottom: 4px;
}
.pw-strength__fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
}
.pw-strength__label { font-size: 0.75rem; color: var(--color-text-muted); }

/* ── Password generator ─────────────────────────────────────────────────────── */
.pw-gen-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-2);
}
.pw-gen-row .form-input { font-family: var(--mono); font-size: 0.85rem; }

/* ── Detail panel (side-drawer style) ──────────────────────────────────────── */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  pointer-events: none;
}
.detail-overlay.is-open { pointer-events: auto; }
.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.25s;
}
.detail-overlay.is-open .detail-backdrop { opacity: 1; }
.detail-drawer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(480px, 100vw);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: -8px 0 40px rgba(0,0,0,0.4);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
  padding: var(--space-5);
}
.detail-overlay.is-open .detail-drawer { transform: translateX(0); }
.detail-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}
.detail-drawer__title { font-size: 1.2rem; font-weight: 700; }
.detail-drawer__section { margin-bottom: var(--space-5); }
.detail-drawer__section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}
.detail-field {
  margin-bottom: var(--space-3);
}
.detail-field__label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.detail-field__value {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: 0.9rem;
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.detail-field__value--mono { font-family: var(--mono); }
.detail-field__copy {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.detail-field__copy:hover { color: var(--color-text); background: var(--color-border); }

/* ── Expiry warning ─────────────────────────────────────────────────────────── */
.expiry-warn {
  background: rgba(224,90,90,0.1);
  border: 1px solid rgba(224,90,90,0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  color: var(--color-danger);
  font-size: 0.85rem;
  margin-bottom: var(--space-4);
}

/* ── Admin table ────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: 0.88rem;
}
.data-table th { color: var(--color-text-muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.data-table tbody tr:hover { background: var(--color-surface-2); }

/* ── Role permission matrix ─────────────────────────────────────────────────── */
.perm-group { margin-bottom: var(--space-4); }
.perm-group__title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}
.perm-checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: 0.88rem;
}
.perm-checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

/* ── Health report ──────────────────────────────────────────────────────────── */
.health-stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.health-stat__label { font-size: 0.82rem; color: var(--color-text-muted); }
.health-stat__value { font-size: 1.8rem; font-weight: 700; }
.health-stat--warn  .health-stat__value { color: var(--color-warn); }
.health-stat--danger .health-stat__value { color: var(--color-danger); }
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-5);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}
.toast--success { border-color: var(--color-success); color: var(--color-success); }
.toast--error   { border-color: var(--color-danger);  color: var(--color-danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--color-text-muted);
}
.empty-state__icon { font-size: 3rem; margin-bottom: var(--space-4); opacity: 0.4; }
.empty-state__title { font-weight: 600; margin-bottom: var(--space-2); color: var(--color-text); }

/* ── Audit log ──────────────────────────────────────────────────────────────── */
.audit-action {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
}

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border-2); border-radius: 3px; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: var(--space-4); }
  .vault-grid { grid-template-columns: 1fr; }
}
