/* ═══════════════════════════════════════════════
   RELAXITY — BASE STYLES
   Design tokens, reset, layout, shared components
═══════════════════════════════════════════════ */

/* ── DESIGN TOKENS ── */
:root {
  /* Background layers */
  --bg:        #0a0a0a;
  --surface:   #111111;
  --card:      #1a1a1a;
  --card-hover:#202020;
  --border:    #2a2a2a;
  --border-dim:#1f1f22;

  /* Text */
  --text:      #aaaaaa;
  --text-dim:  #a1a1aa;
  --muted:     #555555;
  --dim:       #3f3f46;

  /* Accent (lime) */
  --accent:        #6a8818;
  --accent-hover:  #7a9a1e;
  --accent-dim:    rgba(132, 204, 22, 0.12);
  --accent-border: rgba(132, 204, 22, 0.25);

  /* Role colours */
  --survivor:        #6dd8f5;
  --survivor-dim:    rgba(109, 216, 245, 0.10);
  --survivor-border: rgba(109, 216, 245, 0.25);

  --therapist:        #f7bc6a;
  --therapist-dim:    rgba(247, 188, 106, 0.10);
  --therapist-border: rgba(247, 188, 106, 0.25);

  --admin:        #d966f5;
  --admin-dim:    rgba(217, 102, 245, 0.10);
  --admin-border: rgba(217, 102, 245, 0.25);

  --community:        #34d399;
  --community-dim:    rgba(52, 211, 153, 0.10);

  /* Status */
  --danger:  #ef4444;
  --warning: #f59e0b;
  --success: #22c55e;

  /* Typography */
  --font-display: 'Syne', sans-serif;
  --font-body:    'DM Sans', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  /* Spacing scale */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;

  /* Radii */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow:    0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);

  /* Nav */
  --nav-height: 64px;        /* bottom bar height (survivor mobile) */
  --sidebar-width: 220px;    /* therapist/admin sidebar */

  /* Transitions */
  --transition: 150ms ease;
  --transition-slow: 300ms ease;

  /* Safe area (Capacitor / notch) */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;           /* prevents pull-to-refresh on mobile */
}

img, svg { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
input, textarea, select { font: inherit; color: inherit; background: none; border: none; outline: none; }
ul, ol { list-style: none; }

/* ── SHELL LAYOUT ── */
#shell {
  display: flex;
  height: 100vh;
  height: 100dvh;   /* dynamic viewport height — respects mobile browser chrome */
  overflow: hidden;
}

/* Main content area */
#app {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ── RECOVERER LAYOUT (bottom nav, full width) ── */
body.role-survivor #shell {
  flex-direction: column;
}

body.role-survivor #nav-container {
  order: 2;                            /* nav goes below content */
  flex-shrink: 0;
  padding-bottom: var(--safe-bottom);
}

body.role-survivor #app {
  order: 1;
  padding-top: var(--safe-top);
}

/* ── THERAPIST / ADMIN LAYOUT (left sidebar — desktop) ── */
body.role-therapist #shell,
body.role-admin #shell {
  flex-direction: row;
}

body.role-therapist #nav-container,
body.role-admin #nav-container {
  flex-shrink: 0;
  width: var(--sidebar-width);
  padding-top: var(--safe-top);
}

body.role-therapist #app,
body.role-admin #app {
  padding-top: var(--safe-top);
}

/* ── THERAPIST / ADMIN — MOBILE (bottom tab bar) ── */
@media (max-width: 767px) {
  body.role-therapist #shell,
  body.role-admin #shell {
    flex-direction: column;
  }
  body.role-therapist #nav-container,
  body.role-admin #nav-container {
    order: 2;
    width: 100% !important;
    padding-top: 0;
    padding-bottom: var(--safe-bottom);
  }
  body.role-therapist #app,
  body.role-admin #app {
    order: 1;
    padding-top: var(--safe-top);
  }
  body.role-therapist #toast-container,
  body.role-admin #toast-container {
    left: 50%;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  }
}

/* ── PAGE WRAPPER ── */
.page {
  min-height: 100%;
  padding: var(--space-6);
  animation: page-in var(--transition-slow) both;
}

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

/* ── SPLASH SCREEN ── */
.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: var(--space-6);
}

.splash-logo {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -2px;
  color: var(--accent);
}

.splash-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── TYPOGRAPHY ── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

h1 { font-size: 28px; letter-spacing: -1px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
h4 { font-size: 14px; font-weight: 600; }

.text-muted  { color: var(--muted); }
.text-dim    { color: var(--dim); }
.text-accent { color: var(--accent); }
.text-mono   { font-family: var(--font-mono); }

/* ── CARDS ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.card-sm { padding: var(--space-4); border-radius: var(--radius); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}

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

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

.btn-danger {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger);
}

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-full { width: 100%; }

/* ── FORM INPUTS ── */
.input-wrap { display: flex; flex-direction: column; gap: var(--space-2); }
.input-label { font-size: 13px; font-weight: 600; color: var(--text-dim); }

.input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 15px;
  color: var(--text);
  transition: border-color var(--transition);
  width: 100%;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--dim); }

/* ── BADGES ── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  border: 1px solid;
}
.badge-accent   { background: var(--accent-dim);    border-color: var(--accent-border);    color: var(--accent); }
.badge-survivor{ background: var(--survivor-dim); border-color: var(--survivor-border); color: var(--survivor); }
.badge-therapist{ background: var(--therapist-dim); border-color: var(--therapist-border); color: var(--therapist); }
.badge-admin    { background: var(--admin-dim);     border-color: var(--admin-border);     color: var(--admin); }
.badge-danger   { background: rgba(239,68,68,0.1);  border-color: rgba(239,68,68,0.3);     color: var(--danger); }
.badge-success  { background: rgba(34,197,94,0.1);  border-color: rgba(34,197,94,0.3);     color: var(--success); }

/* ── DIVIDER ── */
.divider { height: 1px; background: var(--border); margin: var(--space-5) 0; }

/* ── TOAST ── */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1000;
  pointer-events: none;
  width: min(360px, 90vw);
}

body.role-therapist #toast-container,
body.role-admin #toast-container {
  bottom: 20px;
  left: calc(var(--sidebar-width) + 50%);
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in 0.25s ease both;
}
.toast.toast-success { border-color: rgba(34,197,94,0.3); color: var(--success); }
.toast.toast-error   { border-color: rgba(239,68,68,0.3); color: var(--danger); }
.toast.toast-out     { animation: toast-out 0.25s ease both; }

@keyframes toast-in  { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
@keyframes toast-out { from { opacity:1; } to { opacity:0; transform:translateY(-4px); } }

/* ── MODAL ── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 900;
}
#modal-container {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-6);
  padding-bottom: calc(var(--space-6) + var(--safe-bottom));
  z-index: 901;
  animation: sheet-in 0.3s cubic-bezier(0.32,0.72,0,1) both;
  max-height: 85vh;
  overflow-y: auto;
}
@media (min-width: 600px) {
  #modal-container {
    bottom: auto; left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    width: min(480px, 90vw);
    max-height: 80vh;
  }
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }

.hidden { display: none !important; }

/* ── UTILITY ── */
.flex   { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2  { gap: var(--space-2); }
.gap-3  { gap: var(--space-3); }
.gap-4  { gap: var(--space-4); }
.mt-4   { margin-top: var(--space-4); }
.mt-6   { margin-top: var(--space-6); }
.mb-4   { margin-bottom: var(--space-4); }
.mb-6   { margin-bottom: var(--space-6); }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
