/* Ericksonians design system.
 *
 * Rules baked in:
 *   - Lines not boxes. Hairline dividers + headings + whitespace structure
 *     content. NO card-style shadowed boxes.
 *   - Compact, ample whitespace. Generous padding around sections.
 *   - No tiny fonts (min 14px), no over-faded text (--ink-muted is readable).
 *   - Colored tags for status (active, expired, submitted, etc).
 *   - Highlighted hover state on every clickable element.
 *   - Mobile responsive throughout.
 */

:root {
  --bg: #fafaf8;
  --bg-tint: #f1f1ee;
  --ink: #1a1a1a;
  --ink-muted: #555;          /* readable, not faded */
  --ink-soft: #777;           /* subordinate; still readable */
  --border: #e2e2dd;
  --border-strong: #cccac4;

  --accent: #2c5d3f;
  --accent-soft: #ecf2ee;
  --accent-hover: #1f4a30;

  --danger: #b13c30;
  --danger-soft: #fcecea;
  --warning: #b27a1c;
  --warning-soft: #fbf2dd;
  --success: #2c5d3f;
  --success-soft: #e7eee9;
  --info: #2c4d8f;
  --info-soft: #e9eef9;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --maxw: 1100px;
  --maxw-medium: 760px;
  --maxw-narrow: 480px;

  --font-base: 16px;
  --line-base: 1.55;

  --t-fast: 120ms;
  --t-norm: 200ms;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: var(--font-base) / var(--line-base) -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3, h4 { color: var(--ink); margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h4 { font-size: 16px; }

p { margin: 0 0 var(--space-3) 0; }
p:last-child { margin-bottom: 0; }

code, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* ---------- Top bar / navigation ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 700; font-size: 17px; color: var(--ink);
  letter-spacing: -0.02em;
  display: flex; align-items: center; gap: 8px;
}
.topbar .brand img { height: 22px; width: auto; }
.topnav { display: flex; gap: var(--space-4); align-items: center; font-size: 14px; }
.topnav a {
  color: var(--ink-muted); padding: 6px 8px; border-radius: 6px;
  transition: background var(--t-fast), color var(--t-fast);
}
.topnav a:hover { color: var(--ink); background: var(--bg-tint); text-decoration: none; }
.topnav a.active { color: var(--ink); background: var(--bg-tint); }
.topnav .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.topnav-user { font-size: 13px; color: var(--ink); font-weight: 600; }

.bell { position: relative; cursor: pointer; padding: 4px; }
.bell svg { display: block; }
.bell-count {
  position: absolute; top: 0; right: 0;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  border-radius: 10px; padding: 1px 5px; min-width: 14px;
  text-align: center; line-height: 1.3;
}

/* ---------- Layout ---------- */

main { flex: 1; padding: var(--space-6) var(--space-5); }
.container { max-width: var(--maxw); margin: 0 auto; }
.container.medium { max-width: var(--maxw-medium); }
.container.narrow { max-width: var(--maxw-narrow); }

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.page-header h1 { font-size: 26px; }
.page-header .lead { color: var(--ink-muted); font-size: 15px; margin: 4px 0 0 0; }

/* Section block: heading + content separated by hairline. NO card. */
.section { padding: var(--space-5) 0; border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: 0; }
.section > h2, .section > h3 { margin-bottom: var(--space-3); }
.section .lead { color: var(--ink-muted); font-size: 14px; margin: 0 0 var(--space-4) 0; }

/* Toolbar: actions row above a list */
.toolbar {
  display: flex; gap: var(--space-3); flex-wrap: wrap;
  align-items: center; justify-content: space-between;
  margin-bottom: var(--space-4);
}
.toolbar .filters { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* Grid for stat rows. Inline, no boxes. */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-5);
  padding: var(--space-2) 0;
}
.stat .label { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px; }
.stat .value { font-size: 22px; font-weight: 600; color: var(--ink); }
.stat .sub { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }

/* ---------- Tables / lists ---------- */

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
}
.list-row:hover { background: var(--bg-tint); }
.list-row:last-child { border-bottom: 0; }
.list-row .meta { color: var(--ink-muted); font-size: 13px; }
.list-row .title { font-weight: 500; color: var(--ink); }
.list-row .actions { display: flex; gap: var(--space-2); }
.list-row.is-link { cursor: pointer; }

table.tbl {
  width: 100%; border-collapse: collapse;
  font-size: 14px;
}
table.tbl th {
  text-align: left; font-weight: 600; color: var(--ink-soft);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-strong);
}
table.tbl td {
  padding: var(--space-3); border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.tbl tr:hover td { background: var(--bg-tint); }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl .cell-actions { width: 1%; white-space: nowrap; }

.empty {
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--ink-muted);
}
.empty h3 { color: var(--ink); margin-bottom: var(--space-2); }
.empty p { margin: 0; }

/* ---------- Tags / pills ---------- */

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: var(--bg-tint); color: var(--ink-muted);
  border: 1px solid var(--border);
  vertical-align: middle;
}
.tag.accent  { background: var(--accent-soft);  color: var(--accent);  border-color: transparent; }
.tag.success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.tag.warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.tag.danger  { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }
.tag.info    { background: var(--info-soft);    color: var(--info);    border-color: transparent; }
.tag.muted   { background: var(--bg-tint);      color: var(--ink-muted); }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--ink); }
.form-row .help  { font-size: 13px; color: var(--ink-muted); margin-top: 2px; }
.form-row .err   { font-size: 13px; color: var(--danger); margin-top: 2px; }

.form-row.inline {
  flex-direction: row; align-items: center; gap: var(--space-3);
}

.input, .textarea, .select {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  transition: border var(--t-fast), background var(--t-fast);
}
.textarea { min-height: 100px; resize: vertical; }
.input:hover, .textarea:hover, .select:hover { border-color: var(--ink-soft); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.input[disabled], .textarea[disabled] { opacity: 0.6; cursor: not-allowed; }

.form-row.checkbox {
  flex-direction: row; align-items: flex-start; gap: var(--space-2);
}
.form-row.checkbox input[type="checkbox"] { margin-top: 4px; }

/* Two-column form on wide screens */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  font: inherit; font-weight: 500; font-size: 14px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

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

.btn.secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.secondary:hover:not(:disabled) { background: var(--accent-soft); }

.btn.ghost { background: transparent; color: var(--ink-muted); border-color: var(--border-strong); }
.btn.ghost:hover:not(:disabled) { background: var(--bg-tint); color: var(--ink); border-color: var(--ink-soft); }

.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.large { padding: 11px 22px; font-size: 16px; }

.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* Link button (text-style) */
.btn-link {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--accent); font: inherit;
}
.btn-link:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---------- Alerts (inline, no boxes) ---------- */

.alert {
  border-left: 3px solid var(--accent);
  padding: var(--space-3) var(--space-4);
  background: var(--accent-soft);
  margin-bottom: var(--space-4);
  font-size: 14px;
}
.alert.danger  { border-left-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.alert.warning { border-left-color: var(--warning); background: var(--warning-soft); }
.alert.info    { border-left-color: var(--info); background: var(--info-soft); }
.alert h4 { margin: 0 0 4px 0; font-size: 14px; }

/* ---------- Toasts ---------- */

#toast-root {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 1000; display: flex; flex-direction: column; gap: var(--space-2);
  max-width: 360px;
}
.toast {
  padding: 10px 14px;
  background: var(--ink); color: #fff;
  border-radius: 6px;
  font-size: 14px;
  border-left: 3px solid var(--accent);
}
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

/* ---------- Modal (backdrop + centered panel) ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,20,20,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: var(--space-4);
}
.modal {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4); border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 18px; }
.modal-body { padding: var(--space-4); }
.modal-foot {
  display: flex; gap: var(--space-2); justify-content: flex-end;
  padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border);
}
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 22px; color: var(--ink-muted); padding: 4px 8px;
  line-height: 1;
}
.modal-close:hover { color: var(--ink); }

/* ---------- Avatar / circular profile image ---------- */

.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-tint);
  border: 1px solid var(--border);
  overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-muted); font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.large { width: 64px; height: 64px; font-size: 20px; }

/* ---------- DM thread ---------- */

.thread { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3) 0; }
.msg {
  display: flex; flex-direction: column;
  max-width: 80%;
  padding: var(--space-3) var(--space-4);
  border-radius: 8px;
  background: var(--bg-tint);
}
.msg.mine { align-self: flex-end; background: var(--accent-soft); }
.msg .meta { font-size: 11px; color: var(--ink-soft); margin-bottom: 2px; }
.msg .body { font-size: 14px; white-space: pre-wrap; }

/* ---------- Mood / scale slider ---------- */

input[type=range].slider {
  width: 100%; height: 6px;
  appearance: none;
  background: linear-gradient(90deg, var(--success) 0%, var(--warning) 60%, var(--danger) 100%);
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}
input[type=range].slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px; height: 18px;
  background: var(--ink); border-radius: 50%;
  cursor: grab;
  box-shadow: 0 0 0 3px var(--bg);
}
input[type=range].slider::-moz-range-thumb {
  width: 18px; height: 18px;
  background: var(--ink); border-radius: 50%;
  cursor: grab;
  border: 3px solid var(--bg);
}

/* ---------- Mood timeline (graph) ---------- */

.mood-graph {
  width: 100%;
  height: 220px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.mood-graph svg { width: 100%; height: 100%; }

/* ---------- Auth pages (centered) ---------- */

.auth-wrap {
  display: flex; flex-direction: column; align-items: center;
  padding: var(--space-7) var(--space-4) var(--space-6);
}
.auth-wrap .brand-large {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em;
  color: var(--ink); margin-bottom: var(--space-2);
  display: flex; align-items: center; gap: 12px;
}
.auth-wrap .brand-large img { height: 36px; width: auto; }
.auth-wrap .lead { color: var(--ink-muted); margin-bottom: var(--space-6); }
.auth-wrap form { width: 100%; max-width: var(--maxw-narrow); }
.auth-wrap .alt {
  margin-top: var(--space-5); font-size: 14px; color: var(--ink-muted);
  text-align: center;
}

/* Recovery / one-time credential display */
.cred-box {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 16px; font-weight: 600; letter-spacing: 0.04em;
  padding: var(--space-3); background: var(--bg-tint);
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  word-break: break-all;
  margin: var(--space-3) 0;
}

/* ---------- Multi-step wizard nav ---------- */

.steps {
  display: flex; gap: var(--space-2); flex-wrap: wrap;
  margin-bottom: var(--space-5);
  font-size: 13px;
}
.steps .step {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-tint);
  color: var(--ink-muted);
  font-weight: 500;
}
.steps .step.active { background: var(--accent); color: #fff; }
.steps .step.done   { background: var(--accent-soft); color: var(--accent); }

/* ---------- Calendar week view ---------- */

.cal-week {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  gap: 0;
  border-top: 1px solid var(--border);
}
.cal-week .cal-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  min-height: 60px;
  padding: var(--space-1) var(--space-2);
  font-size: 12px;
  position: relative;
}
.cal-week .cal-cell.head {
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-tint);
}
.cal-week .cal-event {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 2px 6px;
  font-size: 11px;
  color: var(--ink);
  margin-top: 2px;
  border-radius: 3px;
  cursor: pointer;
}
.cal-week .cal-event:hover { background: var(--accent); color: #fff; }
.cal-week .cal-event.completed { opacity: 0.6; }

/* ---------- Embed mode ----------
 * When the SPA loads inside an iframe with ?embed=1, the parent already
 * frames the portal — hide our top nav so the experience feels native to
 * the hypnotherapist's site. */
body.embed .topbar { display: none; }
body.embed main { padding-top: var(--space-5); }

/* ---------- Misc helpers ---------- */

.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row.justify-between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: var(--space-3); }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }

.muted { color: var(--ink-muted); }
.soft  { color: var(--ink-soft); }
.center { text-align: center; }
.right  { text-align: right; }
.bold   { font-weight: 600; }
.small  { font-size: 13px; }

.hidden { display: none !important; }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Mobile tweaks ---------- */

@media (max-width: 640px) {
  main { padding: var(--space-4) var(--space-4); }
  .topbar { padding: 12px var(--space-3); }
  .topnav { gap: var(--space-2); font-size: 13px; }
  .topnav-user { display: none; }
  h1 { font-size: 22px; }
  .stats-row { gap: var(--space-3); }
  .cal-week { grid-template-columns: 48px repeat(7, 1fr); font-size: 11px; }
  .modal { max-width: 96vw; }
  .toolbar { flex-direction: column; align-items: stretch; }
}
