/* =============================================
   SA: Epilepsy — Memory Log
   Purple, refined, accessible, mobile-first
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  --ink:         #1a0a2e;
  --ink-mid:     #3d1f5c;
  --purple:      #6b21a8;
  --purple-rich: #7c3aed;
  --purple-soft: #a78bfa;
  --purple-pale: #ede9fe;
  --purple-tint: #f5f0ff;
  --border:      #c4b5fd;
  --border-soft: #ddd6fe;
  --white:       #ffffff;
  --text:        #1a0a2e;
  --text-muted:  #6b7280;
  --text-light:  #9ca3af;
  --danger:      #b91c1c;
  --danger-pale: #fef2f2;
  --danger-border:#fecaca;
  --success:     #15803d;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow:      0 2px 16px rgba(107, 33, 168, 0.10);
  --shadow-md:   0 8px 32px rgba(107, 33, 168, 0.18);
  --font-display:'DM Serif Display', Georgia, serif;
  --font-body:   'DM Sans', system-ui, sans-serif;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--purple-tint);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ---- HEADER ---- */
header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(135deg, #2d0a4e 0%, #5b1e8a 50%, #7c3aed 100%);
  color: var(--white);
  padding: 1rem 1.1rem 0.9rem;
  padding-top: calc(1rem + env(safe-area-inset-top));
  box-shadow: 0 4px 24px rgba(45, 10, 78, 0.4);
  overflow: hidden;
}
.header-glow {
  position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(196, 181, 253, 0.2) 0%, transparent 70%);
  pointer-events: none;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 720px;
  margin: 0 auto;
  gap: 1rem;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.brand-icon {
  font-size: 1.75rem;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(196,181,253,0.4));
}
header h1 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.brand-sub {
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  opacity: 0.75;
  margin-top: 0.15rem;
  text-transform: uppercase;
}
.entry-count {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 99px;
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

/* ---- MAIN ---- */
main {
  flex: 1;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem 0.85rem 2rem;
}

/* ---- TOOLBAR ---- */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
}
.toolbar-right {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: 99px;
  border: none;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
  line-height: 1;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-rich) 100%);
  color: var(--white);
  box-shadow: 0 2px 12px rgba(107, 33, 168, 0.35);
  padding: 0.6rem 1.25rem;
  font-size: 0.95rem;
}
.btn-primary:hover { box-shadow: 0 4px 20px rgba(107, 33, 168, 0.5); transform: translateY(-1px); }

.btn-tool {
  background: var(--white);
  color: var(--purple);
  border: 1.5px solid var(--border-soft);
  padding: 0.45rem 0.8rem;
  font-size: 0.8rem;
  border-radius: 99px;
  box-shadow: 0 1px 4px rgba(107,33,168,0.06);
}
.btn-tool:hover { background: var(--purple-tint); border-color: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid #e5e7eb;
  padding: 0.5rem 1rem;
}
.btn-ghost:hover { background: #f9fafb; }

.btn-danger {
  background: var(--danger-pale);
  color: var(--danger);
  border: 1.5px solid var(--danger-border);
}
.btn-danger:hover { background: #fee2e2; }

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
}
.btn-icon:hover { background: var(--purple-pale); color: var(--purple); }

/* ---- FILTER BAR ---- */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 140px;
  padding: 0.55rem 0.9rem;
  border: 1.5px solid var(--border-soft);
  border-radius: 99px;
  font-size: 0.875rem;
  font-family: var(--font-body);
  background: var(--white);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus {
  border-color: var(--purple-soft);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.2);
}
.filter-select {
  padding: 0.55rem 0.9rem;
  border: 1.5px solid var(--border-soft);
  border-radius: 99px;
  font-size: 0.85rem;
  font-family: var(--font-body);
  background: var(--white);
  color: var(--text);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--purple-soft); }

/* ---- ENTRY CARDS ---- */
.entry-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
  border: 1px solid var(--border-soft);
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s;
  animation: slideIn 0.25s ease both;
}
.entry-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.entry-stripe {
  height: 4px;
  width: 100%;
}

.entry-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.9rem 1rem 0.5rem;
  gap: 0.75rem;
}
.entry-meta { flex: 1; min-width: 0; }

.entry-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  word-break: break-word;
  line-height: 1.4;
  margin-bottom: 0.2rem;
}
.entry-datetime {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: var(--purple-pale);
  color: var(--purple);
  border: 1px solid var(--border-soft);
}

.entry-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}
.entry-actions .btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  border-radius: 8px;
}

.entry-notes {
  padding: 0 1rem 0.85rem;
  font-size: 0.875rem;
  color: #374151;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.entry-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  background: #fafafa;
  border-top: 1px solid #f0f0f0;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.entry-footer.linked-yes {
  background: var(--purple-tint);
  color: var(--purple);
  border-top-color: var(--border-soft);
}
.link-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Category stripe colours */
.stripe-word-finding  { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.stripe-names         { background: linear-gradient(90deg, #db2777, #f9a8d4); }
.stripe-appointments  { background: linear-gradient(90deg, #0891b2, #67e8f9); }
.stripe-medication    { background: linear-gradient(90deg, #059669, #6ee7b7); }
.stripe-time-place    { background: linear-gradient(90deg, #d97706, #fcd34d); }
.stripe-conversation  { background: linear-gradient(90deg, #7c3aed, #c4b5fd); }
.stripe-tasks         { background: linear-gradient(90deg, #6d28d9, #ddd6fe); }
.stripe-other         { background: linear-gradient(90deg, #6b7280, #d1d5db); }

/* ---- EMPTY STATES ---- */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem 2.5rem;
  color: var(--text-muted);
}
.empty-ripple {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px; height: 80px;
  border-radius: 50%;
  background: var(--purple-pale);
  font-size: 2.2rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 0 0 12px rgba(167,139,250,0.1), 0 0 0 24px rgba(167,139,250,0.05);
}
.empty-state h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--ink-mid);
  margin-bottom: 0.5rem;
}
.empty-state p { font-size: 0.9rem; line-height: 1.6; margin-bottom: 0.35rem; }
.empty-hint { font-size: 0.78rem; opacity: 0.65; }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 10, 46, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: overlayIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(45, 10, 78, 0.3);
  animation: sheetUp 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-sm { padding: 1.5rem 1.25rem; }

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.modal h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--ink-mid);
}
.modal-close {
  background: var(--purple-tint);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background 0.15s;
}
.modal-close:hover { background: var(--purple-pale); color: var(--purple); }

/* Fields */
.field { margin-bottom: 1.1rem; }
.field label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.4rem;
}
.field label .required { color: var(--purple); }

.field input[type="text"],
.field input[type="datetime-local"],
.field select,
.field textarea {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--purple-soft);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.2);
}
.field textarea { resize: vertical; min-height: 100px; line-height: 1.6; }

/* Radio group */
.radio-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.radio-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}
.radio-btn input[type="radio"] { display: none; }
.radio-btn span {
  padding: 0.4rem 0.9rem;
  border-radius: 99px;
  border: 1.5px solid var(--border-soft);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--white);
  transition: all 0.15s;
  cursor: pointer;
}
.radio-btn input:checked + span {
  background: var(--purple);
  border-color: var(--purple);
  color: var(--white);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #f3f4f6;
}

/* ---- TOAST ---- */
.toast {
  position: fixed;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--white);
  padding: 0.6rem 1.3rem;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 400;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  white-space: nowrap;
  animation: toastIn 0.25s ease;
}
.toast.hidden { display: none; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- FOOTER ---- */
footer {
  text-align: center;
  padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  background: var(--white);
  border-top: 1px solid var(--border-soft);
}
.footer-brand {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--purple);
  margin-bottom: 0.4rem;
}
.footer-note {
  font-size: 0.7rem;
  color: var(--text-light);
  line-height: 1.5;
  max-width: 480px;
  margin: 0 auto;
}
.coffee-btn {
  display: inline-block;
  margin-top: 0.85rem;
  padding: 0.5rem 1.2rem;
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-rich) 100%);
  color: var(--white);
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 2px 10px rgba(107, 33, 168, 0.3);
  transition: box-shadow 0.18s, transform 0.18s;
}
.coffee-btn:hover { box-shadow: 0 4px 18px rgba(107, 33, 168, 0.45); transform: translateY(-1px); }

/* ---- HIDDEN / SHOW ---- */
.hidden { display: none !important; }

/* ---- PRINT HEADER (screen: hidden) ---- */
.print-header { display: none; }

/* =============================
   PRINT STYLES
   ============================= */
@media print {
  @page { margin: 20mm 15mm; }

  body { background: white; font-size: 11pt; }

  header,
  .toolbar,
  .filter-bar,
  .entry-actions,
  footer .footer-note,
  #toast,
  .modal-overlay { display: none !important; }

  .print-header {
    display: block;
    text-align: center;
    border-bottom: 2px solid #4a1272;
    padding-bottom: 10pt;
    margin-bottom: 14pt;
  }
  .print-header h1 { font-size: 18pt; color: #4a1272; }
  .print-header p { font-size: 9pt; color: #666; }
  .print-date { font-size: 8pt; color: #999; margin-top: 4pt; }

  footer {
    display: block;
    text-align: center;
    border-top: 1px solid #4a1272;
    padding: 8pt 0 0;
    margin-top: 14pt;
  }
  .footer-brand { color: #4a1272; font-size: 9pt; }
  .footer-note { display: none; }

  main { padding: 0; }

  .entry-card {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    margin-bottom: 8pt;
    page-break-inside: avoid;
    transform: none !important;
  }
  .entry-stripe { height: 3px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .entry-footer.linked-yes {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .empty-state, #no-results { display: none !important; }

  .entry-count { display: none; }
}

/* ---- RESPONSIVE ---- */
@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 1.5rem;
  }
  .modal {
    border-radius: var(--radius);
    max-height: 85vh;
  }
  header h1 { font-size: 1.6rem; }
  main { padding: 1.25rem 1.25rem 2.5rem; }
}
