
/* ============ SKINS (CSS variable themes) ============ */
:root, [data-skin="ocean"] {
  --bg: #f2f7f9; --panel: #ffffff; --panel-2: #e9f2f5; --ink: #16323c;
  --ink-soft: #4f6b76; --brand: #1a7f8e; --brand-2: #0e5a66; --accent: #e8a33d;
  --line: #d5e4e9; --ok: #2e8b57; --warn: #c9762b; --danger: #c0392b;
  --room-bg: linear-gradient(160deg, #10333d 0%, #1a5560 100%);
  --card-shadow: 0 2px 10px rgba(22,50,60,.08); --radius: 14px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
[data-skin="warm"] {
  --bg: #faf5ef; --panel: #fffdf9; --panel-2: #f5ebdd; --ink: #3d2f24;
  --ink-soft: #7a6a58; --brand: #b0652f; --brand-2: #8a4c1f; --accent: #5d8a66;
  --line: #e8dccb; --ok: #4a7c59; --warn: #b07d2f; --danger: #b03a2e;
  --room-bg: linear-gradient(160deg, #4a3423 0%, #7a5533 100%);
  --card-shadow: 0 2px 10px rgba(61,47,36,.09);
}
[data-skin="forest"] {
  --bg: #f1f6f0; --panel: #ffffff; --panel-2: #e5efe3; --ink: #23372a;
  --ink-soft: #5a7261; --brand: #3a7d44; --brand-2: #275c30; --accent: #c98a2b;
  --line: #d3e3d2; --ok: #2e7d32; --warn: #b8862f; --danger: #b3392b;
  --room-bg: linear-gradient(160deg, #1d3a24 0%, #35603f 100%);
  --card-shadow: 0 2px 10px rgba(35,55,42,.08);
}
[data-skin="lavender"] {
  --bg: #f6f3fa; --panel: #ffffff; --panel-2: #ece5f5; --ink: #322a44;
  --ink-soft: #6d6383; --brand: #6d5aa8; --brand-2: #4f3f85; --accent: #c9803d;
  --line: #e0d7ee; --ok: #3f8a58; --warn: #b8792f; --danger: #b53a3a;
  --room-bg: linear-gradient(160deg, #2c2347 0%, #4d3e78 100%);
  --card-shadow: 0 2px 10px rgba(50,42,68,.09);
}
[data-skin="slate"] {
  --bg: #14181d; --panel: #1e242b; --panel-2: #262e37; --ink: #e6edf3;
  --ink-soft: #9fb0bf; --brand: #4da3b8; --brand-2: #6fc3d8; --accent: #d9a441;
  --line: #313b46; --ok: #4caf7d; --warn: #d09a3e; --danger: #d05548;
  --room-bg: linear-gradient(160deg, #0c1014 0%, #1a2229 100%);
  --card-shadow: 0 2px 12px rgba(0,0,0,.35);
}
[data-skin="classic"] {
  --bg: #f4f4f2; --panel: #ffffff; --panel-2: #ebebe6; --ink: #26292e;
  --ink-soft: #5d636b; --brand: #35597a; --brand-2: #24405a; --accent: #a8763e;
  --line: #dcdcd4; --ok: #38793f; --warn: #a8763e; --danger: #a83232;
  --room-bg: linear-gradient(160deg, #1e2a36 0%, #35597a 100%);
  --card-shadow: 0 2px 10px rgba(38,41,46,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font, 'Segoe UI', system-ui, sans-serif);
  background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--ink); }

/* ============ LAYOUT ============ */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: 232px; min-width: 232px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 6px 10px 16px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px; background: var(--brand);
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 17px;
  flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand-name small { display: block; font-weight: 500; font-size: 10.5px; color: var(--ink-soft); letter-spacing: .04em; }
.navbtn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: none;
  background: transparent; color: var(--ink-soft); border-radius: 9px; font-size: 13.5px; font-weight: 600;
  text-align: left; transition: background .15s;
}
.navbtn:hover { background: var(--panel-2); color: var(--ink); }
.navbtn.active { background: var(--brand); color: #fff; }
.navbtn .ic { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-section { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); padding: 14px 12px 5px; font-weight: 700; }
.sidebar-foot { margin-top: auto; padding: 10px 8px 4px; font-size: 11px; color: var(--ink-soft); border-top: 1px solid var(--line); }
.badge-secure { display:inline-flex; align-items:center; gap:5px; background: var(--panel-2); border:1px solid var(--line); border-radius: 20px; padding: 4px 10px; font-size: 10.5px; font-weight:600; color: var(--ink-soft); margin-bottom: 6px;}

#main { flex: 1; overflow-y: auto; position: relative; }
.view { display: none; padding: 26px 30px 60px; max-width: 1180px; margin: 0 auto; }
.view.active { display: block; }
.view-title { font-size: 22px; font-weight: 750; margin-bottom: 4px; }
.view-sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 22px; }

/* ============ SHARED COMPONENTS ============ */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius, 14px); box-shadow: var(--card-shadow); padding: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 650; font-size: 13.5px;
  transition: filter .15s;
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 650; }
.pill.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pill.neutral { background: var(--panel-2); color: var(--ink-soft); }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
h3.section { font-size: 15px; font-weight: 750; margin: 0 0 12px; }
.muted { color: var(--ink-soft); font-size: 13px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.chip { display: inline-flex; align-items: center; gap: 5px; background: var(--panel-2); border: 1px solid var(--line); padding: 4px 11px; border-radius: 18px; font-size: 12px; font-weight: 600; margin: 0 5px 6px 0; }
.chip button { border: none; background: none; color: var(--ink-soft); font-size: 13px; padding: 0 0 0 2px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); z-index: 300;
  background: var(--ink); color: var(--bg); padding: 11px 20px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  opacity: 0; transition: all .3s; pointer-events: none; max-width: 480px; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
table.plain { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.plain th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.plain td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }

/* ============ DASHBOARD ============ */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .stat-row { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--card-shadow); }
.stat .num { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat .lbl { font-size: 12px; color: var(--ink-soft); font-weight: 650; margin-top: 3px; }
.appt { display: flex; align-items: center; gap: 13px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.appt:last-child { border-bottom: none; }
.appt .time { font-weight: 800; font-size: 13px; width: 74px; color: var(--brand); flex-shrink: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--panel-2); display: flex; align-items: center; justify-content: center; font-weight: 750; font-size: 14px; color: var(--brand); flex-shrink: 0; border: 1px solid var(--line); overflow: hidden;}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.compliance-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.compliance-item:last-child { border-bottom: none; }

/* ============ SESSION ROOM ============ */
#view-session.active { display: flex; flex-direction: column; padding: 0; max-width: none; height: 100vh; }
.room-top {
  display: flex; align-items: center; gap: 14px; padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.room-top .who { font-weight: 750; font-size: 14.5px; }
.room-top .timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand); font-size: 13.5px; }
.loc-banner {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 650;
  padding: 5px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-soft);
}
.loc-banner.verified { border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.loc-banner.missing { border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.room-body { flex: 1; display: flex; min-height: 0; background: var(--room-bg); }
.stage { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; padding: 18px; min-width: 0; }
.video-wrap { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
#clientTile {
  width: min(100%, 1040px); aspect-ratio: 16/9; max-height: 100%; border-radius: 16px; overflow: hidden;
  background: #0b1518; display: flex; align-items: center; justify-content: center; position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,.4);
}
.client-placeholder { text-align: center; color: #cfe3e8; }
.client-placeholder .big-avatar {
  width: 110px; height: 110px; border-radius: 50%; margin: 0 auto 14px;
  background: rgba(255,255,255,.12); display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 700; color: #fff; border: 2px solid rgba(255,255,255,.25);
}
.tile-label {
  position: absolute; left: 12px; bottom: 12px; background: rgba(0,0,0,.55); color: #fff;
  padding: 4px 12px; border-radius: 8px; font-size: 12px; font-weight: 650; backdrop-filter: blur(4px);
}
#selfTile {
  position: absolute; right: 30px; bottom: 30px; width: 240px; aspect-ratio: 4/3; border-radius: 13px;
  overflow: hidden; background: #000; box-shadow: 0 6px 24px rgba(0,0,0,.45); border: 2px solid rgba(255,255,255,.25); z-index: 5;
}
#selfVideo, #selfCanvas { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
#selfCanvas { display: none; position: absolute; inset: 0; }
#selfOff { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; color: #9db6bd; font-size: 12.5px; font-weight: 650; background: #101c20; text-align: center; padding: 10px; }
#screenTile { display: none; position: absolute; inset: 18px; border-radius: 14px; overflow: hidden; background: #000; z-index: 4; box-shadow: 0 8px 40px rgba(0,0,0,.5); }
#screenVideo { width: 100%; height: 100%; object-fit: contain; }
.room-side {
  width: 340px; min-width: 340px; background: var(--panel); border-left: 1px solid var(--line);
  display: none; flex-direction: column; min-height: 0;
}
.room-side.open { display: flex; }
.room-side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.room-side-tabs button {
  flex: 1; padding: 11px 4px; border: none; background: none; font-size: 12.5px; font-weight: 700; color: var(--ink-soft);
  border-bottom: 2px solid transparent;
}
.room-side-tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.side-pane { flex: 1; display: none; flex-direction: column; min-height: 0; }
.side-pane.active { display: flex; }
#chatLog { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 9px; }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 13px; font-size: 13.5px; }
.msg .who { font-size: 10.5px; font-weight: 700; opacity: .7; margin-bottom: 2px; }
.msg.me { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: none; color: var(--ink-soft); font-size: 11.5px; font-style: italic; padding: 2px; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-input input { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.controls {
  display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px;
  background: var(--panel); border-top: 1px solid var(--line); flex-wrap: wrap;
}
.ctl {
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 66px; padding: 8px 10px;
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 12px; font-size: 10.5px; font-weight: 700; color: var(--ink-soft);
}
.ctl .ic { font-size: 18px; }
.ctl.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.ctl.alert { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl:hover { filter: brightness(.95); }

/* session notes pane */
#paneNotes { padding: 0; }
#paneNotes .inner { padding: 14px; overflow-y: auto; flex: 1; }
#sessionNoteArea { width: 100%; min-height: 220px; border: 1px solid var(--line); border-radius: 9px; padding: 10px; font-size: 13px; }

/* safety pane */
#paneSafety .inner { padding: 14px; overflow-y: auto; flex: 1; }
.hospital { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.hospital:last-child { border-bottom: none; }
.emergency-cta { background: color-mix(in srgb, var(--danger) 8%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); border-radius: 11px; padding: 13px; margin-bottom: 13px; }

/* ============ ASSESSMENTS ============ */
.q-row { padding: 11px 0; border-bottom: 1px solid var(--line); }
.q-row:last-child { border-bottom: none; }
.q-text { font-size: 13.5px; font-weight: 600; margin-bottom: 7px; }
.q-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.q-opts button {
  padding: 5px 11px; border: 1px solid var(--line); background: var(--panel); border-radius: 18px; font-size: 12px; font-weight: 600; color: var(--ink-soft);
}
.q-opts button.sel { background: var(--brand); color: #fff; border-color: var(--brand); }
.score-box { text-align: center; padding: 18px; border-radius: 12px; background: var(--panel-2); margin-top: 14px; }
.score-box .val { font-size: 34px; font-weight: 800; }

/* ============ DIRECTORY ============ */
.therapist-card { display: flex; gap: 16px; }
.tc-photo { width: 86px; height: 86px; border-radius: 14px; object-fit: cover; background: var(--panel-2); flex-shrink: 0; border: 1px solid var(--line); }
.verify-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 0; }

/* ============ CONSENT DOC ============ */
.doc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 30px 34px; font-size: 14px; line-height: 1.65; }
.doc h2 { font-size: 18px; margin-bottom: 4px; }
.doc h4 { font-size: 13.5px; margin: 16px 0 5px; }
.doc .letterhead { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--brand); padding-bottom: 12px; margin-bottom: 16px; }
.sig-line { border-bottom: 1.5px solid var(--ink); min-width: 220px; display: inline-block; font-family: 'Brush Script MT', cursive; font-size: 20px; padding: 0 8px; min-height: 26px; }

/* skins grid */
.skin-card { border: 2px solid var(--line); border-radius: 13px; padding: 0; overflow: hidden; cursor: pointer; background: var(--panel); text-align: left; }
.skin-card.sel { border-color: var(--brand); }
.skin-preview { height: 74px; display: flex; }
.skin-preview span { flex: 1; }
.skin-card .nm { padding: 9px 12px; font-size: 13px; font-weight: 700; }

/* waiting room */
.breath { width: 120px; height: 120px; border-radius: 50%; background: color-mix(in srgb, var(--brand) 22%, transparent);
  border: 2px solid var(--brand); animation: breathe 8s ease-in-out infinite; display: flex; align-items: center;
  justify-content: center; font-size: 11.5px; font-weight: 700; color: var(--brand); text-align: center; margin: 0 auto; }
@keyframes breathe { 0%,100% { transform: scale(.72); } 45%,55% { transform: scale(1.12); } }
#wrVideo { width: 100%; aspect-ratio: 4/3; border-radius: 12px; background: #0b1518; object-fit: cover; transform: scaleX(-1); display: block; }
.wr-step { display: flex; gap: 11px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.wr-step:last-child { border-bottom: none; }
.wr-num { width: 26px; height: 26px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 800; color: var(--ink-soft); flex-shrink: 0; }
.wr-step.done .wr-num { background: var(--ok); border-color: var(--ok); color: #fff; }

/* welcome modal */
#welcome {
  position: fixed; inset: 0; background: rgba(10,25,30,.55); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px;
}
#welcome .box { background: var(--panel); border-radius: 18px; max-width: 560px; padding: 34px 36px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.wl-point { display: flex; gap: 11px; margin: 11px 0; font-size: 13.5px; align-items: flex-start; }
.wl-point .ic { color: var(--ok); font-weight: 800; flex-shrink: 0; }

/* ============ REAL APP ADDITIONS ============ */
body.client-mode #sidebar { display: none !important; }
body.client-mode .view.active { max-width: 860px; }

/* ============ 4-4-8 BREATHING (16s cycle: in 4 · hold 4 · out 8) ============ */
.breath { animation: breathe448 16s ease-in-out infinite; }
@keyframes breathe448 {
  0%   { transform: scale(.72); }
  25%  { transform: scale(1.14); }  /* 4s inhale */
  50%  { transform: scale(1.14); }  /* 4s hold  */
  100% { transform: scale(.72); }   /* 8s exhale */
}

/* ============ MOBILE PASS (client-facing views) ============ */
@media (max-width: 640px) {
  body.client-mode .view.active { padding: 18px 14px 48px; }
  body.client-mode .grid2 { grid-template-columns: 1fr !important; gap: 14px; }
  body.client-mode .card { padding: 18px; }
  .breath { width: 104px; height: 104px; }
  /* in-call layout on phones */
  #clientCall #cSelfTile { width: 104px !important; right: 12px !important; bottom: 12px !important; }
  #clientCall #cChatPane { position: absolute; inset: auto 0 0 0; width: 100% !important; min-width: 0 !important; height: 46%; border-left: none; border-top: 1px solid var(--line); z-index: 5; }
  #clientCall #cRemoteVideo { border-radius: 10px; }
  #clientAssess { inset: 10px !important; padding: 16px !important; }
}
