/* ==========================================================================
   Family Contact Vault — Global Stylesheet
   Dark theme, glassmorphism, mobile-first, vanilla CSS only.
   ========================================================================== */

:root {
  --bg-primary: #0b0d17;
  --bg-secondary: #12141f;
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glass-blur: 18px;

  --accent-primary: #7c5cff;
  --accent-secondary: #22c1c3;
  --accent-danger: #ff5c7a;
  --accent-warning: #ffd166;
  --accent-success: #22d3a0;

  --text-primary: #f4f5fa;
  --text-secondary: #a4a7c1;
  --text-muted: #6b6e8c;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition-fast: 0.15s ease;
  --transition-med: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

::selection { background: var(--accent-primary); color: white; }

/* ---------------------------------------------------------------------- */
/* Glass card                                                              */
/* ---------------------------------------------------------------------- */
.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: var(--shadow-glass);
}

/* ---------------------------------------------------------------------- */
/* Auth pages                                                              */
/* ---------------------------------------------------------------------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.auth-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(circle at 20% 20%, #1a1d33 0%, #0b0d17 60%);
}

.auth-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.35;
  animation: float 12s ease-in-out infinite;
}
.blob-1 { width: 420px; height: 420px; background: var(--accent-primary); top: -100px; left: -100px; }
.blob-2 { width: 380px; height: 380px; background: var(--accent-secondary); bottom: -120px; right: -80px; animation-delay: -4s; }
.blob-3 { width: 300px; height: 300px; background: var(--accent-danger); top: 40%; left: 60%; animation-delay: -8s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -30px) scale(1.05); }
}

.auth-wrap { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 24px; }
.auth-card { padding: 40px 32px; animation: card-in 0.5s var(--transition-med); }

@keyframes card-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-logo { text-align: center; margin-bottom: 28px; }
.logo-icon { font-size: 42px; margin-bottom: 8px; }
.auth-logo h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth-subtitle { color: var(--text-secondary); font-size: 14px; margin: 0; }

.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-footer { text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 24px; }

/* ---------------------------------------------------------------------- */
/* Form elements                                                          */
/* ---------------------------------------------------------------------- */
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }

input[type="text"], input[type="password"], input[type="email"], input[type="file"], select, textarea {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-primary);
  background: rgba(255, 255, 255, 0.08);
}
input::placeholder { color: var(--text-muted); }

.password-field { position: relative; display: flex; }
.password-field input { flex: 1; padding-right: 44px; }
.toggle-password {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px; padding: 6px;
}

.form-error {
  background: rgba(255, 92, 122, 0.12);
  border: 1px solid rgba(255, 92, 122, 0.4);
  color: #ff9db2;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.hidden { display: none !important; }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-sm);
  padding: 12px 20px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: transform var(--transition-fast), opacity var(--transition-fast), background var(--transition-fast);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: linear-gradient(135deg, var(--accent-primary), #9c7bff); color: white; }
.btn-primary:hover:not(:disabled) { opacity: 0.9; }

.btn-secondary { background: rgba(255, 255, 255, 0.09); color: var(--text-primary); border: 1px solid var(--glass-border); }
.btn-secondary:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }

.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--text-primary); background: rgba(255, 255, 255, 0.06); }

.btn-danger { background: linear-gradient(135deg, var(--accent-danger), #ff8098); color: white; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }

.btn-full { width: 100%; }
.btn-small { padding: 8px 14px; font-size: 13px; }

.btn-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4); border-top-color: white;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.is-loading .btn-text { opacity: 0.5; }
.is-loading .btn-spinner { display: inline-block !important; }

/* ---------------------------------------------------------------------- */
/* Navigation                                                              */
/* ---------------------------------------------------------------------- */
.app-nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  background: rgba(11, 13, 23, 0.75);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--glass-border);
}
.nav-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-right: 12px; }
.nav-logo { font-size: 20px; }
.nav-links { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav-link {
  padding: 8px 14px; border-radius: var(--radius-sm); font-size: 14px; color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-primary); }
.nav-link.nav-active { background: rgba(124, 92, 255, 0.18); color: var(--accent-primary); }

.nav-user { display: flex; align-items: center; gap: 10px; }
.nav-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white;
}
.nav-username { font-size: 14px; color: var(--text-secondary); }
.nav-burger { display: none; background: none; border: none; color: var(--text-primary); font-size: 22px; cursor: pointer; }

/* ---------------------------------------------------------------------- */
/* Page layout                                                             */
/* ---------------------------------------------------------------------- */
.page-container { max-width: 1100px; margin: 0 auto; padding: 28px 20px 80px; }

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.page-header h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -0.02em; }
.page-subtitle { margin: 0; color: var(--text-secondary); font-size: 14px; max-width: 560px; }
.page-header-actions { display: flex; gap: 10px; }

.link-back, .link-more { color: var(--accent-secondary); font-size: 14px; font-weight: 600; }
.link-back { display: inline-block; margin-bottom: 16px; }

/* ---------------------------------------------------------------------- */
/* Stat grid                                                               */
/* ---------------------------------------------------------------------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card { padding: 20px; text-align: center; transition: transform var(--transition-fast); }
.stat-card:hover { transform: translateY(-3px); }
.stat-icon { font-size: 22px; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 20px; }
@media (max-width: 800px) { .dashboard-grid { grid-template-columns: 1fr; } }

.panel { padding: 22px; margin-bottom: 20px; }
.panel-title { margin: 0 0 16px; font-size: 16px; font-weight: 700; }
.panel-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-header-row .panel-title { margin: 0; }
.panel-hint { color: var(--text-muted); font-size: 13px; margin-top: 12px; }

/* Bar chart */
.bar-chart { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 80px 1fr 40px; align-items: center; gap: 10px; }
.bar-label { font-size: 13px; color: var(--text-secondary); text-transform: capitalize; }
.bar-track { height: 10px; background: rgba(255, 255, 255, 0.06); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); border-radius: 6px; transition: width 0.6s var(--transition-med); }
.bar-value { text-align: right; font-size: 13px; font-weight: 700; }

.quick-search-form { display: flex; gap: 8px; }
.quick-search-form input { flex: 1; }

/* ---------------------------------------------------------------------- */
/* Activity list / timeline                                                */
/* ---------------------------------------------------------------------- */
.activity-list { display: flex; flex-direction: column; gap: 10px; }
.activity-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: var(--radius-sm); background: rgba(255, 255, 255, 0.03);
  transition: background var(--transition-fast);
}
.activity-item:hover { background: rgba(255, 255, 255, 0.06); }
.activity-icon { font-size: 18px; width: 28px; text-align: center; }
.activity-body { flex: 1; min-width: 0; }
.activity-title { font-size: 14px; font-weight: 600; }
.activity-sub { font-size: 12px; color: var(--text-muted); }
.activity-time { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.timeline { display: flex; flex-direction: column; gap: 0; position: relative; padding-left: 20px; }
.timeline-item { position: relative; padding: 0 0 22px 20px; border-left: 2px solid var(--glass-border); }
.timeline-item:last-child { border-left: 2px solid transparent; padding-bottom: 0; }
.timeline-dot {
  position: absolute; left: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent-primary); border: 2px solid var(--bg-primary);
}
.timeline-missing .timeline-dot { background: var(--accent-danger); }
.timeline-added .timeline-dot { background: var(--accent-success); }
.timeline-title { font-weight: 700; font-size: 14px; }
.timeline-names { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.timeline-date { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.empty-state { color: var(--text-muted); font-size: 14px; padding: 24px; text-align: center; }

/* ---------------------------------------------------------------------- */
/* Search page                                                             */
/* ---------------------------------------------------------------------- */
.search-box-card { padding: 18px 20px; margin-bottom: 20px; }
.search-input-wrap { display: flex; align-items: center; gap: 10px; }
.search-icon { font-size: 18px; }
.search-input-wrap input { border: none; background: transparent; font-size: 17px; padding: 8px 0; }
.search-input-wrap input:focus { background: transparent; }
.clear-search { background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; }
.search-meta { color: var(--text-muted); font-size: 12px; margin-top: 6px; padding-left: 28px; }

.results-list { display: flex; flex-direction: column; gap: 10px; }
.result-card {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px;
  border-radius: var(--radius-md); cursor: pointer; transition: transform var(--transition-fast), background var(--transition-fast);
}
.result-card:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.09); }
.result-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-primary); display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white;
}
.result-body { flex: 1; min-width: 0; }
.result-name { font-weight: 700; font-size: 15px; }
.result-snippets { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }
.result-owners { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
mark { background: rgba(124, 92, 255, 0.35); color: var(--text-primary); border-radius: 3px; padding: 0 2px; }

/* ---------------------------------------------------------------------- */
/* Chips / badges                                                          */
/* ---------------------------------------------------------------------- */
.chip {
  display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px;
  background: rgba(255, 255, 255, 0.08); color: var(--text-secondary); margin: 2px 4px 2px 0;
}
.chip-owner { background: rgba(34, 193, 195, 0.15); color: var(--accent-secondary); }
.chip-current { background: rgba(34, 211, 160, 0.2); color: var(--accent-success); margin-left: 8px; }
.alias-chips, .owner-chips { margin-top: 8px; }

.status-badge { font-size: 11px; padding: 3px 10px; border-radius: 999px; font-weight: 700; }
.status-ok { background: rgba(34, 211, 160, 0.15); color: var(--accent-success); }
.status-missing { background: rgba(255, 92, 122, 0.15); color: var(--accent-danger); }

/* ---------------------------------------------------------------------- */
/* Contact detail                                                          */
/* ---------------------------------------------------------------------- */
.contact-hero { padding: 26px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }
.contact-avatar {
  width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: white;
}
.contact-hero-info { flex: 1; min-width: 200px; }
.contact-hero-info h1 { margin: 0; font-size: 22px; }
.contact-hero-actions { display: flex; gap: 8px; }

.field-list { display: flex; flex-direction: column; gap: 10px; }
.field-row { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.field-row:last-child { border-bottom: none; }
.field-icon { font-size: 16px; }

.owner-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.owner-detail-card { background: rgba(255,255,255,0.03); border-radius: var(--radius-md); padding: 14px; border: 1px solid var(--glass-border); }
.owner-missing { opacity: 0.65; border-style: dashed; }
.owner-detail-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.owner-detail-body { font-size: 13px; color: var(--text-secondary); display: flex; flex-direction: column; gap: 4px; }
.owner-detail-meta { color: var(--text-muted); font-size: 11px; margin-top: 6px; }

/* ---------------------------------------------------------------------- */
/* Upload page                                                             */
/* ---------------------------------------------------------------------- */
.upload-card { padding: 28px; margin-bottom: 20px; }
.dropzone {
  border: 2px dashed var(--glass-border); border-radius: var(--radius-md);
  padding: 48px 20px; text-align: center; cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.dropzone:hover, .dropzone.drag-over { border-color: var(--accent-primary); background: rgba(124, 92, 255, 0.06); }
.dropzone-icon { font-size: 40px; margin-bottom: 10px; }
.dropzone-title { font-weight: 700; margin: 0 0 4px; }
.dropzone-subtitle { color: var(--text-muted); font-size: 13px; margin: 0; }

.selected-file-info { display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 12px 14px; background: rgba(255,255,255,0.04); border-radius: var(--radius-sm); }
.selected-file-info span:nth-child(2) { flex: 1; font-size: 14px; }

.upload-progress-wrap { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.upload-progress-track { flex: 1; height: 8px; background: rgba(255,255,255,0.06); border-radius: 6px; overflow: hidden; }
.upload-progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); transition: width 0.2s ease; }

#upload-submit { margin-top: 20px; }

.upload-report { padding: 22px; }
.howto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.howto-card { background: rgba(255,255,255,0.03); border-radius: var(--radius-md); padding: 16px; text-align: center; }
.howto-icon { font-size: 26px; margin-bottom: 8px; }
.howto-card h3 { margin: 0 0 6px; font-size: 15px; }
.howto-card p { margin: 0; font-size: 13px; color: var(--text-secondary); }

/* ---------------------------------------------------------------------- */
/* Restore / snapshots                                                     */
/* ---------------------------------------------------------------------- */
.snapshot-list { display: flex; flex-direction: column; gap: 10px; }
.snapshot-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; background: rgba(255,255,255,0.03); border-radius: var(--radius-sm);
}
.snapshot-filename { font-weight: 600; font-size: 14px; }
.snapshot-meta { color: var(--text-muted); font-size: 12px; margin-top: 3px; }

/* ---------------------------------------------------------------------- */
/* Modals                                                                  */
/* ---------------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-box { padding: 28px; width: 100%; max-width: 420px; }
.modal-box h3 { margin: 0 0 14px; }
.modal-box form { display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------------------------------------------------------------------- */
/* Admin                                                                   */
/* ---------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; flex-wrap: wrap; }
.tab-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--glass-border); color: var(--text-secondary);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.tab-btn.active { background: var(--accent-primary); color: white; border-color: transparent; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.admin-table { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  background: rgba(255,255,255,0.03); border-radius: var(--radius-sm); flex-wrap: wrap;
}
.admin-row-avatar {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #10121c; flex-shrink: 0;
}
.admin-row-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 160px; }
.admin-row-info .muted { color: var(--text-muted); font-size: 12px; }
.admin-row-actions { display: flex; gap: 8px; }
.log-row { align-items: center; }
.log-action-badge {
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: rgba(124, 92, 255, 0.15); color: var(--accent-primary); text-transform: uppercase;
}
.log-time { white-space: nowrap; }

.history-filters { margin-bottom: 16px; }
.history-filters select { max-width: 220px; }

/* ---------------------------------------------------------------------- */
/* Toasts                                                                  */
/* ---------------------------------------------------------------------- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast {
  padding: 14px 18px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; color: white;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3); animation: toast-in 0.3s var(--transition-med);
  max-width: 320px;
}
.toast-success { background: linear-gradient(135deg, #22d3a0, #1bb389); }
.toast-error { background: linear-gradient(135deg, #ff5c7a, #e8455f); }
.toast-info { background: linear-gradient(135deg, #7c5cff, #6a4de0); }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }

/* ---------------------------------------------------------------------- */
/* Responsive                                                              */
/* ---------------------------------------------------------------------- */
@media (max-width: 760px) {
  .app-nav { flex-wrap: wrap; padding: 12px 16px; }
  .nav-links {
    display: none; width: 100%; order: 3; flex-direction: column; gap: 2px;
    padding-top: 10px; border-top: 1px solid var(--glass-border); margin-top: 10px;
  }
  .nav-links.nav-open { display: flex; }
  .nav-burger { display: block; margin-left: auto; }
  .nav-user { order: 2; }
  .page-header { flex-direction: column; }
  .contact-hero { flex-direction: column; text-align: center; }
  .contact-hero-actions { width: 100%; justify-content: center; }
}