:root {
  --bg: #0a0d11;
  --rail: #0f131a;
  --card: #12171f;
  --card-2: #171d27;
  --input: #1a212c;
  --border: #242d3a;
  --border-soft: #1c2430;
  --text: #e9eef4;
  --muted: #8b99a9;
  --faint: #5d6b7c;
  --accent: #e8613c;
  --accent-2: #f0864a;
  --accent-grad: linear-gradient(135deg, #e8613c, #f0864a);
  --ok: #3fb984;
  --warn: #e0b341;
  --err: #e5533c;
  --info: #5b9dd9;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
}

/* ============ LEFT RAIL ============ */
.rail {
  background: var(--rail);
  border-right: 1px solid var(--border-soft);
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: 0.2px; font-weight: 650; }
.brand .sub { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--accent-grad);
  box-shadow: 0 0 18px rgba(232, 97, 60, 0.35);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 9px;
  border-radius: 50%; background: rgba(255,255,255,0.9);
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
  opacity: 0.85;
}

.rail-section { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.7px; font-weight: 600;
}
.field-label em { text-transform: none; letter-spacing: 0; font-style: normal; color: var(--faint); font-weight: 400; }

input, select, textarea {
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 97, 60, 0.12);
}
input::placeholder, textarea::placeholder { color: var(--faint); }

/* memory */
.memory { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; flex-wrap: wrap; }
.memory-badge {
  background: rgba(63, 185, 132, 0.12); color: var(--ok);
  border: 1px solid rgba(63, 185, 132, 0.35);
  padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: 11px;
  flex: none;
}
.memory-visits { color: var(--muted); line-height: 1.7; }
.memory-visits button {
  background: var(--card-2); border: 1px solid var(--border); color: var(--accent-2);
  cursor: pointer; font-size: 11px; padding: 2px 8px; margin: 0 3px 3px 0;
  border-radius: 999px;
}
.memory-visits button:hover { border-color: var(--accent); }

/* capture */
.capture {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  gap: 12px;
}
.record-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--accent-grad); color: #fff; border: none;
  padding: 15px 20px; border-radius: 999px; cursor: pointer;
  font-size: 15px; font-weight: 650; width: 100%;
  transition: filter 0.15s, transform 0.06s;
  box-shadow: 0 4px 18px rgba(232, 97, 60, 0.28);
}
.record-btn:hover { filter: brightness(1.08); }
.record-btn:active { transform: scale(0.985); }
.record-btn.recording {
  background: linear-gradient(135deg, #d63a2f, #e5533c);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(229, 83, 60, 0.45); }
  70% { box-shadow: 0 0 0 16px rgba(229, 83, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(229, 83, 60, 0); }
}
.capture-meta { display: flex; align-items: center; justify-content: center; gap: 12px; }
.timer {
  font-variant-numeric: tabular-nums; font-size: 30px; font-weight: 650;
  letter-spacing: 1.5px;
}
.live-badge {
  color: var(--err); font-size: 11px; font-weight: 800; letter-spacing: 1.2px;
  animation: blink 1.4s infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.status { color: var(--muted); font-size: 12.5px; line-height: 1.55; text-align: center; }
.status.busy { color: var(--warn); }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }

.upload-row { display: flex; justify-content: center; }
.upload-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: none; border: 1px dashed var(--border); color: var(--muted);
  padding: 8px 16px; border-radius: 999px; cursor: pointer; font-size: 12px;
  transition: border-color 0.15s, color 0.15s;
}
.upload-btn:hover { border-color: var(--accent); color: var(--text); }
.upload-hint { font-size: 10.5px; color: var(--faint); text-align: center; margin: 0; }

/* template builder */
.tpl-details summary {
  cursor: pointer; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.7px; font-weight: 600;
  padding: 4px 0;
}
.tpl-details summary:hover { color: var(--text); }
.tpl-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.tpl-form textarea { min-height: 0; resize: vertical; }
.tpl-status { font-size: 12px; color: var(--muted); }

.rail-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.health {
  font-size: 11.5px; color: var(--muted);
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px;
  text-align: center;
}
.health.ok { color: var(--ok); border-color: rgba(63, 185, 132, 0.35); }
.health.bad { color: var(--warn); border-color: rgba(224, 179, 65, 0.35); }
.privacy-line { font-size: 10.5px; color: var(--faint); text-align: center; margin: 0; }

/* ============ WORKSPACE ============ */
.work {
  padding: 26px 30px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px;
}
.card-head h2 {
  font-size: 12px; margin: 0; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px; font-weight: 650;
  display: flex; align-items: center; gap: 8px;
}
.draft-chip {
  background: rgba(232, 97, 60, 0.12); color: var(--accent-2);
  border: 1px solid rgba(232, 97, 60, 0.3);
  font-size: 10px; padding: 2px 8px; border-radius: 999px;
  letter-spacing: 0.5px;
}
.card-actions { display: flex; gap: 8px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 12.5px; font-weight: 600; padding: 9px 15px;
  border: 1px solid transparent;
  transition: filter 0.15s, border-color 0.15s, background 0.15s;
}
.btn.primary { background: var(--accent-grad); color: #fff; box-shadow: 0 2px 10px rgba(232, 97, 60, 0.25); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.secondary { background: var(--card-2); color: var(--text); border-color: var(--border); }
.btn.secondary:hover:not(:disabled) { border-color: var(--accent); }
.btn.ghost { background: none; color: var(--muted); border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.btn.small { font-size: 11px; padding: 5px 10px; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* transcript + note */
#transcript {
  width: 100%; min-height: 170px; resize: vertical; line-height: 1.6;
  font-size: 13.5px;
}
#note { width: 100%; min-height: 320px; resize: vertical; line-height: 1.65; font-size: 13.5px; }

.note-preview {
  background: var(--card-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 22px 26px;
  min-height: 200px;
  line-height: 1.7;
  font-size: 14px;
}
.note-preview.empty { color: var(--faint); font-size: 13px; }
.note-preview h1 { font-size: 18px; margin: 0 0 6px; }
.note-preview h2 { font-size: 15px; margin: 18px 0 6px; }
.note-preview h3 { font-size: 14px; margin: 14px 0 4px; }
.note-preview p { margin: 8px 0; }
.note-preview strong { color: #fff; }
.note-preview ul { margin: 8px 0; padding-left: 22px; }
.note-preview li { margin: 4px 0; }
.note-preview hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* compliance */
.compliance {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--card-2);
}
.compliance-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.compliance-badge {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.4px;
  padding: 4px 12px; border-radius: 999px;
}
.compliance-badge.clean { background: rgba(63,185,132,0.12); color: var(--ok); border: 1px solid rgba(63,185,132,0.35); }
.compliance-badge.info { background: rgba(91,157,217,0.12); color: var(--info); border: 1px solid rgba(91,157,217,0.35); }
.compliance-badge.warning { background: rgba(224,179,65,0.12); color: var(--warn); border: 1px solid rgba(224,179,65,0.35); }
.compliance-badge.critical { background: rgba(229,83,60,0.14); color: var(--err); border: 1px solid rgba(229,83,60,0.4); }
.compliance-badge.busy { background: rgba(139,153,169,0.1); color: var(--muted); border: 1px solid var(--border); }
.compliance-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.compliance-list:empty { margin-top: 0; }
.flag {
  border-left: 3px solid var(--warn);
  padding: 8px 12px;
  background: rgba(255,255,255,0.02);
  border-radius: 0 8px 8px 0;
  font-size: 12.5px;
}
.flag.critical { border-left-color: var(--err); }
.flag.info { border-left-color: var(--info); }
.flag-tag { font-weight: 700; font-size: 10.5px; letter-spacing: 0.6px; text-transform: uppercase; }
.flag.critical .flag-tag { color: var(--err); }
.flag.warning .flag-tag { color: var(--warn); }
.flag.info .flag-tag { color: var(--info); }
.flag-issue { color: var(--text); margin: 3px 0; line-height: 1.5; }
.flag-fix { color: var(--muted); font-size: 12px; line-height: 1.5; }
.flag-excerpt { color: var(--faint); font-style: italic; font-size: 11.5px; }

/* magic edit */
.magic-edit { display: flex; gap: 8px; margin-top: 14px; }
.magic-edit input { flex: 1; }
.disclaimer { font-size: 11px; color: var(--faint); margin: 10px 0 0; }

/* week calendar */
.calendar-card { padding: 18px 20px; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-range { font-size: 12.5px; color: var(--muted); min-width: 150px; text-align: center; }
#calMember { min-width: 170px; margin-right: 8px; }
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
}
.cal-day {
  background: var(--card-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 8px 8px 10px; min-height: 90px;
  display: flex; flex-direction: column; gap: 6px;
}
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(232,97,60,0.35) inset; }
.cal-day.past { opacity: 0.6; }
.cal-day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 1px solid var(--border-soft); padding-bottom: 5px;
}
.cal-dow { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.cal-day.today .cal-dow { color: var(--accent-2); }
.cal-date { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.cal-appt {
  display: flex; flex-direction: column; gap: 1px;
  background: var(--card); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 6px;
  padding: 5px 8px; cursor: pointer; text-align: left; width: 100%;
  transition: border-color 0.12s, transform 0.05s;
}
.cal-appt:hover { border-color: var(--accent); border-left-color: var(--accent-2); }
.cal-appt:active { transform: scale(0.99); }
.cal-appt.done { opacity: 0.5; border-left-color: var(--ok); }
.cal-appt-time { font-size: 10.5px; color: var(--accent-2); font-weight: 700; }
.cal-appt-name { font-size: 12px; color: var(--text); line-height: 1.25; }
.cal-none { font-size: 11px; color: var(--faint); margin: auto 0; text-align: center; }
.cal-empty { font-size: 12px; color: var(--muted); margin: 12px 0 0; text-align: center; }

/* autosave indicator */
.autosave-state { font-size: 11.5px; color: var(--faint); margin-left: auto; }
.autosave-state.saving { color: var(--warn); }
.autosave-state.saved { color: var(--ok); }

@media (max-width: 920px) {
  .calendar-grid { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 150px; overflow-x: auto; }
}

/* mic picker + level meter */
.mic-field { margin-bottom: 4px; }
.mic-field select { font-size: 12px; padding: 7px 10px; }
.level-wrap { display: flex; flex-direction: column; gap: 5px; align-items: center; }
.level-track {
  width: 100%; height: 7px; background: var(--input);
  border-radius: 999px; overflow: hidden; border: 1px solid var(--border);
}
.level-bar {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--ok), var(--warn) 75%, var(--err));
  transition: width 0.08s linear;
}
.level-warn { color: var(--warn); font-size: 11px; font-weight: 600; }

/* finalize */
.finalize-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.btn.finalize {
  background: linear-gradient(135deg, #2fa06a, #3fb984); color: #fff;
  font-size: 13.5px; padding: 11px 20px;
  box-shadow: 0 2px 12px rgba(63, 185, 132, 0.3);
}
.btn.finalize:hover:not(:disabled) { filter: brightness(1.08); }
.btn.finalize:disabled { background: var(--card-2); color: var(--muted); box-shadow: none; }
.finalize-state { font-size: 12.5px; color: var(--ok); }
.finalize-state.blocked { color: var(--err); }

/* recovery banner */
.recovery-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: rgba(224, 179, 65, 0.1); border: 1px solid rgba(224, 179, 65, 0.4);
  color: var(--warn); border-radius: var(--radius-sm); padding: 12px 16px; font-size: 13px;
}
.recovery-actions { display: flex; gap: 8px; }

/* admin users */
.admin-form { margin: 6px 0 14px; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.admin-team { grid-column: 1 / -1; }
.admin-form-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.admin-list { display: flex; flex-direction: column; gap: 6px; }
.admin-row {
  display: flex; align-items: center; gap: 12px; font-size: 12.5px;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 14px;
}
.admin-row .au-role {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 8px; border-radius: 999px; font-weight: 700;
}
.au-role.counselor { background: rgba(91,157,217,0.14); color: var(--info); }
.au-role.supervisor { background: rgba(232,134,74,0.14); color: var(--accent-2); }
.au-role.admin { background: rgba(229,83,60,0.14); color: var(--err); }
.admin-row .au-team { color: var(--faint); font-size: 11px; }
.admin-row .au-reset { margin-left: auto; }

/* today's queue */
.today-queue { display: flex; flex-direction: column; gap: 6px; }
.today-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; cursor: pointer;
  font-size: 12.5px; color: var(--text); text-align: left; width: 100%;
  transition: border-color 0.15s;
}
.today-chip:hover { border-color: var(--accent); }
.today-chip .t-time { color: var(--accent-2); font-weight: 700; font-size: 11px; min-width: 52px; }
.today-chip.done { opacity: 0.45; }
.today-chip.done .t-name { text-decoration: line-through; }

/* user chip / login */
.user-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--muted);
  padding: 6px 4px;
}
.user-chip strong { color: var(--text); }
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.login-overlay[hidden] { display: none; }
.login-box {
  background: var(--card); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 34px 36px;
  display: flex; flex-direction: column; gap: 16px;
  width: 340px; box-shadow: var(--shadow);
}
.login-error { color: var(--err); font-size: 12px; margin: 0; min-height: 15px; text-align: center; }

/* team review */
#teamMember { min-width: 200px; }
.team-visits { display: flex; flex-direction: column; gap: 6px; }
.team-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 14px; cursor: pointer;
  font-size: 12.5px; width: 100%; color: var(--text); text-align: left;
}
.team-row:hover { border-color: var(--accent); }
.team-row .tr-date { color: var(--accent-2); font-weight: 700; font-size: 11px; min-width: 80px; }
.team-row .tr-tpl { color: var(--faint); margin-left: auto; font-size: 11px; }
.team-detail { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
.team-detail h3 {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.8px; margin: 14px 0 8px;
}
.team-detail-head { display: flex; justify-content: space-between; align-items: center; }
.team-detail-head span { font-weight: 650; }
.team-transcript {
  background: var(--card-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 14px 16px;
  white-space: pre-wrap; font-family: inherit; font-size: 12.5px;
  line-height: 1.6; color: var(--muted); max-height: 300px; overflow-y: auto;
}
.team-audio { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.team-audio a {
  color: var(--accent-2); font-size: 11.5px; text-decoration: none;
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px;
}
.team-audio a:hover { border-color: var(--accent); }

/* toasts */
.toasts {
  position: fixed; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px; z-index: 50;
}
.toast {
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 16px; font-size: 12.5px;
  box-shadow: var(--shadow); max-width: 340px;
  animation: slide-in 0.2s ease;
}
.toast.ok { border-color: rgba(63,185,132,0.4); }
.toast.err { border-color: rgba(229,83,60,0.45); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* responsive */
@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border-soft); }
  .work { padding: 18px 14px 50px; }
}
