/* ═══════════════════════════════════════════
   PERSONAL DATA BANK — SHARED STYLES
   ═══════════════════════════════════════════
   Loaded by both landing.html and app.html.
   Contains design tokens + universal atoms (buttons, modals,
   toasts, forms, animations) used by both sides.

   Phase 2 extract: copies of rules currently in styles.css.
   In Phase 3+ duplicates are removed from styles.css.
   ═══════════════════════════════════════════ */

/* ─── RESET ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── DESIGN TOKENS ─── */
:root {
  /* Base Colors */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.8);
  --bg-hover: rgba(255, 255, 255, 0.04);
  --bg-active: rgba(255, 255, 255, 0.08);

  /* Surface */
  --surface-1: rgba(255, 255, 255, 0.03);
  --surface-2: rgba(255, 255, 255, 0.06);
  --surface-3: rgba(255, 255, 255, 0.09);

  /* Border */
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  /* Text */
  --text-primary: rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-muted: rgba(255, 255, 255, 0.35);

  /* Node Family Colors */
  --color-file: #ffd54f;
  --color-entity: #ff8a65;
  --color-tag: #4fc3f7;
  --color-project: #81c784;
  --color-pack: #4dd0e1;
  --color-person: #b39ddb;
  --color-note: #aed581;

  /* Layer Colors */
  --color-profile: #b39ddb;
  --color-packs: #4fc3f7;
  --color-collection: #81c784;
  --color-files: #ffd54f;
  --color-graph: #ff8a65;

  /* Accent */
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);

  /* Status */
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;

  /* Spacing (app shell layout) */
  --sidebar-width: 220px;
  --detail-panel-width: 320px;
  --sources-panel-width: 300px;
}

/* ─── BODY ─── */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

/* When landing page is visible, allow scrolling */
body.show-landing {
  overflow-y: auto;
  height: auto;
}

/* ─── ANIMATIONS ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── BUTTONS (universal) ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--border-hover); color: var(--text-primary); }

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 6px;
}
.btn-sm:hover { background: var(--surface-2); color: var(--text-primary); }

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
}
.btn-close:hover { color: var(--text-primary); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s;
}
.btn-ghost:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

.btn-glow {
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.3), 0 0 60px rgba(99, 102, 241, 0.1);
}
.btn-glow:hover {
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.5), 0 0 80px rgba(99, 102, 241, 0.2);
}

.btn-glass {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  backdrop-filter: blur(8px);
  transition: all 0.2s;
}
.btn-glass:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: var(--text-primary);
}

.btn-lg {
  padding: 14px 28px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  transition: all 0.25s;
}
.btn-lg:hover { transform: translateY(-2px); }

.btn-block { width: 100%; }

.btn-gold {
  background: linear-gradient(135deg, #d4a96a, #b08442);
  color: #1a1208;
  font-weight: 700;
  border: none;
  letter-spacing: 0.02em;
}
.btn-gold:hover { filter: brightness(1.12); transform: translateY(-1px); }

/* ─── MODALS (universal) ─── */
/* v7.3.0 — z-index hierarchy:
     guide-drawer    : 10000   (styles.css)
     modal-overlay   : 10500   ← above guide drawer, was 100
     loading-overlay : 10800   (styles.css, was 10000)
     toast-container : 11000   (below, was 10000)
   Lets users open modals on top of an open guide drawer. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10500;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(480px, 90vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.2s ease;
}

/* v7.3.0 — On phones, ensure every modal (incl. ones that pass an
   inline `style="max-width:600px"` or similar) collapses to viewport. */
@media (max-width: 768px) {
  .modal {
    width: 92vw !important;
    max-height: 88vh;
  }
}

/* v7.4.0 — Generic Kebab menu (3-dots dropdown).
   Used by file-list and ctx-card cards on mobile (and as a future
   pattern on desktop). The menu is position:absolute relative to its
   parent, so any wrapper that contains a `.kebab-menu` must be
   `position: relative`. */
.kebab-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.kebab-btn:hover { background: var(--surface-2); color: var(--text-primary); }

.kebab-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  padding: 4px;
  z-index: 1500;
  animation: fadeIn 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kebab-menu.hidden { display: none; }

.kebab-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-primary);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.kebab-menu-item:hover { background: var(--surface-2); }
.kebab-menu-item.danger { color: var(--error); }
.kebab-menu-item.danger:hover { background: rgba(239, 68, 68, 0.12); }

/* v7.4.0 — Touch ergonomics on phones: WCAG / Apple HIG recommend a
   minimum 44×44px tap target. Bump padding + min-height inside the
   mobile media query so desktop UI stays compact. */
@media (max-width: 768px) {
  .btn,
  .btn-primary,
  .btn-outline,
  .btn-danger,
  .btn-ghost,
  .btn-glass {
    min-height: 44px;
    padding: 10px 18px;
    font-size: 14px;
  }
  .btn-sm {
    min-height: 38px;     /* secondary actions a touch smaller, still finger-friendly */
    padding: 8px 14px;
    font-size: 12px;
  }
  .btn-close {
    min-width: 44px;
    min-height: 44px;
    font-size: 22px;
  }
  .form-input,
  textarea.form-input,
  select.form-input {
    min-height: 44px;
    padding: 12px 14px;
    font-size: 14px;
  }
  /* Bigger kebab tap target + bigger menu items on phones */
  .kebab-btn { min-width: 44px; min-height: 44px; font-size: 22px; }
  .kebab-menu-item { min-height: 44px; font-size: 15px; padding: 12px 14px; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ─── FORMS (universal) ─── */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.form-input:focus {
  border-color: var(--accent);
}

/* v7.3.0 — Invalid field highlight.
   `!important` is needed because some legacy modals (notably the
   Context create modal) define `border` as inline styles which
   would otherwise win the cascade over a class rule. */
.is-invalid,
input.is-invalid,
textarea.is-invalid,
select.is-invalid {
  border-color: var(--error) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18) !important;
}

/* ─── TOAST (universal) ─── */
/* v7.3.0 — bumped to 11000 so toasts (especially errors during a save in
   a modal) stay above modal-overlay (10500) and loading-overlay (10800). */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 11000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  animation: slideUp 0.3s ease;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  max-width: 320px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.info { border-left: 3px solid var(--accent); }

.toast-msg {
  flex: 1;
  word-break: break-word;
  line-height: 1.4;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 4px;
  align-self: flex-start;
  transition: all 0.15s;
}
.toast-close:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

/* ─── UTILITIES ─── */
.hidden { display: none !important; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }
