/* ==========================================================================
   Loop — "Nocturne Atlas" theme
   Ink / acid-lime / violet, graph-paper texture, editorial micro-labels.
   Alternate palettes: data-theme="ember" and data-theme="paper".
   ========================================================================== */
:root {
  --bg: #070b12;
  --bg-2: #0b111b;
  --panel: #101724;
  --panel-2: #151e2d;
  --panel-3: #1d2939;
  --line: #253449;
  --line-soft: rgba(37, 52, 73, .6);
  --text: #eaf1f7;
  --muted: #8ca0b5;
  --accent: #c6f24e;
  --accent-2: #8b6cff;
  --accent-ink: #0b1206;
  --accent-soft: rgba(198, 242, 78, .1);
  --accent-2-soft: rgba(139, 108, 255, .12);
  --danger: #ff7a66;
  --success: #5be0a5;
  --bubble: #172334;
  --bubble-me: #233a2b;
  --radius: 12px;
  --font-ui: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --shadow: 0 18px 50px rgba(0, 0, 0, .55);
  --grid: linear-gradient(rgba(140, 160, 181, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(140, 160, 181, .05) 1px, transparent 1px);
}

[data-theme="ember"] {
  --bg: #0d0908;
  --bg-2: #16100d;
  --panel: #1d1512;
  --panel-2: #251a16;
  --panel-3: #33231d;
  --line: #4a3128;
  --line-soft: rgba(74, 49, 40, .6);
  --text: #fff2e8;
  --muted: #c0a395;
  --accent: #ff9d5c;
  --accent-2: #ff5c8a;
  --accent-ink: #2a1105;
  --accent-soft: rgba(255, 157, 92, .12);
  --accent-2-soft: rgba(255, 92, 138, .12);
  --bubble: #251a16;
  --bubble-me: #3a2617;
  --grid: linear-gradient(rgba(255, 157, 92, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 157, 92, .05) 1px, transparent 1px);
}

[data-theme="paper"] {
  --bg: #eef1f4;
  --bg-2: #e5e9ee;
  --panel: #ffffff;
  --panel-2: #f3f6f8;
  --panel-3: #e6ecf1;
  --line: #cfd8e1;
  --line-soft: rgba(207, 216, 225, .7);
  --text: #16212c;
  --muted: #65798d;
  --accent: #0a7f68;
  --accent-2: #6b4de0;
  --accent-ink: #ffffff;
  --accent-soft: rgba(10, 127, 104, .1);
  --accent-2-soft: rgba(107, 77, 224, .1);
  --bubble: #eef2f6;
  --bubble-me: #d7f0e8;
  --shadow: 0 18px 44px rgba(30, 50, 70, .14);
  --grid: linear-gradient(rgba(30, 50, 70, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(30, 50, 70, .05) 1px, transparent 1px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  position: relative;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: var(--grid);
  background-size: 34px 34px;
  mask-image: linear-gradient(120deg, rgba(0,0,0,.6), transparent 70%);
  z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  width: 520px; height: 520px;
  right: -180px; top: -220px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-2-soft), transparent 68%);
  pointer-events: none;
  z-index: 0;
}
#auth, #app { position: relative; z-index: 1; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

/* Micro-label used on cards and headings */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ---------- Auth ---------- */
.auth-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 18% 22%, var(--accent-2-soft), transparent 42%), var(--bg);
}
.auth-card {
  width: min(430px, 100%);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line);
  border-top: 2px solid var(--accent);
  border-radius: 4px 4px var(--radius) var(--radius);
  padding: 34px 32px;
  box-shadow: var(--shadow);
  position: relative;
}
.auth-card::before {
  content: 'LOOP // ACCESS';
  position: absolute;
  top: -1px; right: 14px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: .16em;
  color: var(--muted);
  background: var(--panel);
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-top: 0;
}
.auth-logo { display: flex; align-items: center; gap: 11px; font-size: 25px; font-weight: 750; letter-spacing: -.02em; }
.logo-mark {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-weight: 800;
  clip-path: polygon(0 0, 100% 0, 100% 72%, 72% 100%, 0 100%);
}
.auth-sub { color: var(--muted); margin: 10px 0 26px; line-height: 1.55; }
.auth-tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border: 1px solid var(--line); margin-bottom: 20px; }
.auth-tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px; font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.auth-tab.active { background: var(--panel-3); color: var(--accent); }
.auth-form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.form-error { color: var(--danger); min-height: 18px; font-size: 12px; }
.auth-note { color: var(--muted); font-size: 11px; text-align: center; margin: 20px 0 0; }

.input, .field input, textarea, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
}
.input:focus, .field input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.small { padding: 9px 11px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-3);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  transition: transform .12s, filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.14); transform: translateY(-1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--accent-2-soft); border-color: var(--accent-2); color: var(--text); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 7px 11px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 8px; font-size: 18px;
}
.icon-btn:hover { background: var(--panel-3); border-color: var(--accent); }
.icon-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.presence-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); margin-right: 6px; box-shadow: 0 0 0 3px rgba(91, 224, 165, .12);
}
.check-row {
  display: flex; align-items: flex-start; gap: 10px; margin-top: 14px;
  color: var(--muted); line-height: 1.45;
}
.check-row input { margin-top: 3px; accent-color: var(--accent); }

/* ---------- App shell ---------- */
.app { height: 100%; display: grid; grid-template-columns: 318px 1fr; }
.sidebar {
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.brand-row { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 750; letter-spacing: -.02em; }
.brand .logo-mark { width: 30px; height: 30px; font-size: 15px; }
.nav-rail { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 0 12px 12px; border-bottom: 1px solid var(--line); }
.nav-btn {
  display: grid; gap: 3px; justify-items: center;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 8px 2px; border-radius: 8px; font-size: 17px;
}
.nav-btn small { font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.nav-btn:hover, .nav-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--line); }
.list-head { padding: 12px 14px 8px; }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.me-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg-2); }
.me-row .grow { flex: 1; min-width: 0; }
.me-row .handle { color: var(--muted); font-size: 12px; font-family: var(--font-mono); }
.avatar {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; font-weight: 800; color: #06210f;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25), 0 3px 10px rgba(0,0,0,.25);
  clip-path: polygon(0 0, 100% 0, 100% 78%, 78% 100%, 0 100%);
}
.avatar.sm { width: 30px; height: 30px; font-size: 12px; border-radius: 9px; }

.chat-item {
  display: flex; gap: 10px; align-items: center; width: 100%;
  background: transparent; border: 1px solid transparent; color: var(--text);
  padding: 10px; border-radius: 9px; text-align: left;
}
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--accent-soft); border-color: var(--accent); }
.chat-item .body { flex: 1; min-width: 0; }
.chat-item .top { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { color: var(--muted); font-size: 10px; flex: none; font-family: var(--font-mono); }
.chat-item .preview { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 3px; padding: 1px 6px; font-size: 10px; font-family: var(--font-mono); font-weight: 700; }

/* ---------- Chat view ---------- */
.main { min-width: 0; min-height: 0; }
.view { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  position: relative;
}
.chat-header::after {
  content: '';
  position: absolute; bottom: -1px; left: 0;
  width: 120px; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.chat-header .grow { flex: 1; }
.chat-header h2 { margin: 0; font-size: 16px; letter-spacing: -.01em; }
.chat-header .sub { color: var(--muted); font-size: 11px; font-family: var(--font-mono); }
.messages { flex: 1; overflow-y: auto; padding: 24px 6vw; display: flex; flex-direction: column; gap: 9px; }
.empty-state { margin: auto; text-align: center; color: var(--muted); }
.empty-icon { font-size: 42px; }
.empty-state h2 { color: var(--text); margin: 12px 0 4px; }
.day-divider { text-align: center; color: var(--muted); font-size: 10px; font-family: var(--font-mono); letter-spacing: .1em; margin: 12px 0; }
.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.bubble {
  max-width: min(560px, 78%);
  background: var(--bubble);
  border: 1px solid var(--line-soft);
  border-radius: 12px 12px 12px 3px;
  padding: 10px 13px 7px;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.msg-row.mine .bubble { background: var(--bubble-me); border-color: color-mix(in srgb, var(--accent) 28%, transparent); border-radius: 12px 12px 3px 12px; }
.bubble .text { white-space: pre-wrap; word-break: break-word; }
.bubble .meta { display: flex; justify-content: flex-end; gap: 6px; color: var(--muted); font-size: 10px; font-family: var(--font-mono); margin-top: 4px; }
.msg-row.mine .bubble .meta { color: var(--accent); }
.bubble.media { padding: 6px; }
.bubble img, .bubble video { max-width: 100%; border-radius: 8px; display: block; }
.bubble a.file { display: flex; gap: 8px; align-items: center; color: var(--text); text-decoration: none; }
.message-actions { display: flex; justify-content: flex-end; gap: 5px; margin-top: 5px; }
.icon-btn.tiny { width: 26px; height: 26px; padding: 0; font-size: 12px; border-radius: 7px; }
.icon-btn.tiny.danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); border-color: var(--danger); }
.message-edit { min-height: 130px; resize: vertical; line-height: 1.5; }
.view-once-card {
  display: flex; align-items: center; gap: 10px; width: 100%; min-width: 240px;
  background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px;
  color: var(--text); padding: 10px; text-align: left;
}
.view-once-card:hover { border-color: var(--accent); background: var(--panel-3); }
.view-once-card:disabled { opacity: .5; cursor: wait; }
.view-once-card .grow { display: grid; gap: 2px; flex: 1; }
.view-once-icon { font-size: 22px; }
.view-once-label { font-weight: 650; }
.view-once-note { color: var(--accent); font-family: var(--font-mono); font-size: 10px; margin-top: 6px; }
.typing { color: var(--accent); font-size: 11px; font-family: var(--font-mono); padding: 0 6vw; height: 18px; }
.composer { display: flex; gap: 8px; padding: 12px 6vw 18px; border-top: 1px solid var(--line); background: var(--bg-2); }
.composer .input { flex: 1; }

/* ---------- Generic content views ---------- */
.content-view { flex: 1; overflow-y: auto; padding: 30px clamp(20px, 5vw, 68px); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 4px 0 8px; font-size: 27px; letter-spacing: -.03em; }
.page-head p { margin: 0; color: var(--muted); max-width: 680px; line-height: 1.6; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.card {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent-2);
  border-radius: 4px var(--radius) var(--radius) 4px;
  padding: 18px;
}
.card h3 { margin: 0 0 9px; font-size: 15px; letter-spacing: -.01em; }
.card p { color: var(--muted); margin: 0; line-height: 1.6; }
.card .row { display: flex; align-items: center; gap: 10px; }
.card .row + .row { margin-top: 12px; }
.tag {
  display: inline-block; background: var(--panel-3); border: 1px solid var(--line);
  border-radius: 3px; padding: 3px 8px; font-family: var(--font-mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.tag.accent { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.notice {
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  background: var(--accent-soft); color: var(--text);
  border-radius: 4px; padding: 12px 14px; font-size: 12px; line-height: 1.6;
}
.section-title { margin: 28px 0 12px; font-family: var(--font-mono); font-size: 10px; color: var(--accent); text-transform: uppercase; letter-spacing: .16em; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.switch {
  width: 44px; height: 24px; border-radius: 3px; border: 1px solid var(--line);
  background: var(--panel-3); position: relative; flex: none; padding: 0;
}
.switch::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 2px;
  background: var(--muted); top: 2px; left: 3px; transition: .18s;
}
.switch.on { background: var(--accent); border-color: var(--accent); }
.switch.on::after { background: var(--accent-ink); transform: translateX(19px); }

/* ---------- Nearby ---------- */
.person-card { display: flex; gap: 12px; align-items: center; }
.person-card .grow { flex: 1; min-width: 0; }
.person-card .name { font-weight: 650; }
.person-card .sub { color: var(--muted); font-size: 12px; }
.person-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Studio ---------- */
.studio-layout { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 20px; align-items: start; }
.studio-preview {
  background: #000; border: 1px solid var(--line); border-left: 2px solid var(--accent);
  border-radius: 4px; overflow: hidden; position: relative; aspect-ratio: 16 / 9;
}
.studio-preview canvas { width: 100%; height: 100%; display: block; }
.studio-controls { display: grid; gap: 14px; }
.studio-controls label { display: grid; gap: 6px; }
.studio-controls label span { color: var(--muted); font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.studio-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.progress { height: 6px; background: var(--panel-3); border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; transition: width .2s; }

/* ---------- Calls ---------- */
.call-stage { flex: 1; display: grid; place-items: center; position: relative; background: #04080d; overflow: hidden; }
.call-stage video { max-width: 100%; max-height: 100%; border-radius: 8px; }
.call-local { position: absolute; right: 18px; bottom: 18px; width: 180px; border: 1px solid var(--line); border-radius: 8px; }
.call-controls { display: flex; justify-content: center; gap: 10px; padding: 16px; background: var(--bg-2); border-top: 1px solid var(--line); }
.call-badge { position: absolute; top: 16px; left: 16px; background: rgba(0,0,0,.55); padding: 5px 9px; border-radius: 3px; font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3, 6, 10, .78); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal {
  width: min(560px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-top: 2px solid var(--accent);
  border-radius: 4px; padding: 22px; box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.user-option {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: var(--panel-2); border: 1px solid transparent; color: var(--text);
  border-radius: 8px; padding: 10px; text-align: left;
}
.user-option:hover { border-color: var(--accent); }
.user-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.user-option .grow { flex: 1; }
.user-option small { color: var(--muted); }

/* ---------- Toast ---------- */
.toast-root { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--panel-3); border: 1px solid var(--line); border-left: 2px solid var(--accent);
  border-radius: 4px; padding: 11px 14px; box-shadow: var(--shadow);
  max-width: 320px; animation: slide .2s ease-out;
}
.toast.error { border-left-color: var(--danger); color: var(--danger); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.mobile-menu-btn { display: none; }
.mobile-backdrop { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .chat-header { padding: 12px 14px; }
  .mobile-menu-btn { display: inline-grid; }
  .mobile-backdrop {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(0, 0, 0, .55); opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: min(86vw, 340px); box-shadow: 12px 0 40px rgba(0, 0, 0, .4);
    transform: translateX(-105%); transition: transform .2s ease;
  }
  body.chat-drawer-open .sidebar { transform: none; }
  body.chat-drawer-open .mobile-backdrop { opacity: 1; pointer-events: auto; }
  .brand-row .brand { display: flex; }
  .nav-btn small { display: block; }
  .nav-rail { grid-template-columns: repeat(4, 1fr); }
  .list-head { display: block; }
  .me-row .grow { display: block; }
  .studio-layout { grid-template-columns: 1fr; }
  .messages { padding: 16px 12px; }
  .composer { padding: 10px 12px 14px; }
}
