/* Ring-Pilot styles */

:root {
  --blue: #0a66c2;
  --blue-hover: #004182;
  --blue-soft: #e8f0f9;
  --btn-bg: #0a66c2;
  --btn-bg-hover: #004182;
  --btn-text: #ffffff;
  --bg: #f3f2ef;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --border: #e0ddd8;
  --text: #1c1c1c;
  --text-mid: #5e5e5e;
  --text-light: #8a8a8a;
  --pill-bg: #eef3f8;
  --user-bubble: #0a66c2;
  --user-text: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --focus: 0 0 0 3px rgba(10, 102, 194, 0.25);
  --radius: 12px;
  --sidebar-w: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue: #70b5f9;
    --blue-hover: #9bcbfb;
    --blue-soft: #1c2c3d;
    --btn-bg: #70b5f9;
    --btn-bg-hover: #9bcbfb;
    --btn-text: #0b1a2a;
    --bg: #121619;
    --surface: #1d2226;
    --surface-2: #232a2f;
    --border: #38434f;
    --text: #e9e9e9;
    --text-mid: #b5bcc4;
    --text-light: #8c959f;
    --pill-bg: #263038;
    --user-bubble: #0a66c2;
    --user-text: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --focus: 0 0 0 3px rgba(112, 181, 249, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--btn-bg); color: var(--btn-text);
  padding: 8px 14px; border-radius: 20px; text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 10px; }

/* ── Top bar ─────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px 0 20px;
  padding-top: env(safe-area-inset-top);
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.logo-mark { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 2px solid var(--blue-soft); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text strong { font-size: 17px; font-weight: 700; color: var(--blue); letter-spacing: -0.3px; }
.brand-text span { font-size: 11px; color: var(--text-light); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.badge {
  background: var(--btn-bg); color: var(--btn-text);
  font-size: 10px; font-weight: 600; letter-spacing: 0.5px;
  padding: 3px 9px; border-radius: 20px; text-transform: uppercase;
}

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text-mid);
}
.icon-btn:hover { background: var(--pill-bg); color: var(--text); }
.menu-btn, #newChatTop { display: none; }

/* ── Layout ──────────────────────────────── */
.layout { display: flex; flex: 1; min-height: 0; position: relative; }

/* ── Sidebar ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 16px 0 12px;
  min-height: 0;
}

.new-btn {
  margin: 0 12px 16px;
  background: var(--btn-bg); color: var(--btn-text);
  border: none; border-radius: 24px;
  font-size: 13px; font-weight: 600;
  padding: 9px 16px;
  display: flex; align-items: center; gap: 6px;
  transition: background 0.15s;
}
.new-btn svg { width: 16px; height: 16px; }
.new-btn:hover { background: var(--btn-bg-hover); }

.sidebar-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-light); padding: 0 16px 8px;
}

.chat-list { flex: 1; overflow-y: auto; min-height: 60px; scrollbar-width: thin; }
.chat-empty { padding: 6px 16px; font-size: 12.5px; color: var(--text-light); line-height: 1.5; }

.chat-row { display: flex; align-items: center; position: relative; }
.chat-item {
  flex: 1; min-width: 0;
  text-align: left; background: none; border: none;
  padding: 9px 36px 9px 16px;
  font-size: 13px; color: var(--text-mid);
  display: flex; align-items: center; gap: 9px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item span { overflow: hidden; text-overflow: ellipsis; }
.chat-item::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.35; flex-shrink: 0; }
.chat-row:hover { background: var(--surface-2); }
.chat-row.active { background: var(--blue-soft); }
.chat-row.active .chat-item { color: var(--blue); font-weight: 500; }
.chat-del {
  position: absolute; right: 8px;
  width: 24px; height: 24px; border-radius: 50%;
  border: none; background: none; color: var(--text-light);
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
}
.chat-del svg { width: 14px; height: 14px; }
.chat-row:hover .chat-del, .chat-del:focus-visible { opacity: 1; }
.chat-del:hover { background: var(--pill-bg); color: var(--text); }

.sidebar-footer { padding: 12px 16px 0; border-top: 1px solid var(--border); margin-top: 8px; }
.sidebar-footer p { font-size: 11px; color: var(--text-light); line-height: 1.6; }
.footer-links { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.footer-links a, .link-btn { color: var(--blue); text-decoration: none; font-weight: 500; font-size: 11px; background: none; border: none; padding: 0; }
.footer-links a:hover, .link-btn:hover { text-decoration: underline; }

.scrim { display: none; }

/* ── Main ────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px 0 20px;
  min-height: 48px;
  flex-shrink: 0;
}

.mode-bar {
  display: flex; gap: 6px; align-items: center;
  flex-wrap: wrap;
  flex: 1; min-width: 0;
  padding: 8px 0;
}
.mode-bar::-webkit-scrollbar { display: none; }
.mode-pill {
  padding: 5px 13px; border-radius: 20px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
  background: var(--pill-bg); color: var(--text-mid);
  border: 1px solid transparent;
  transition: background 0.1s, color 0.1s;
}
.mode-pill:hover { border-color: var(--border); color: var(--text); }
.mode-pill[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-text); border-color: var(--btn-bg); }

.level { display: flex; align-items: center; gap: 8px; flex-shrink: 0; font-size: 12px; color: var(--text-mid); }
.level label { font-weight: 500; }
.level output { min-width: 152px; font-weight: 600; color: var(--blue); white-space: nowrap; }
.level input[type="range"] { width: 96px; accent-color: var(--blue); }

/* ── Messages ────────────────────────────── */
.messages {
  flex: 1; overflow-y: auto;
  padding: 24px 20px;
  display: flex; flex-direction: column; gap: 18px;
  scrollbar-width: thin;
  scroll-behavior: smooth;
}
.messages > * { width: 100%; max-width: 820px; margin-left: auto; margin-right: auto; }

/* Welcome */
.welcome { margin: auto; text-align: center; max-width: 640px; padding: 12px 0; }
.welcome-logo {
  width: 72px; height: 72px; border-radius: 50%; object-fit: cover; display: block;
  margin: 0 auto 18px; border: 3px solid var(--blue-soft);
  box-shadow: 0 4px 16px rgba(10, 102, 194, 0.15);
}
.welcome h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.4px; margin-bottom: 8px; }
.welcome > p { font-size: 14px; color: var(--text-mid); margin: 0 auto 24px; line-height: 1.6; max-width: 540px; }

.prompts-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.prompts-head span { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-light); }

.prompts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.prompt-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 13px 15px; font-size: 13px; line-height: 1.45; text-align: left;
  display: flex; flex-direction: column; justify-content: flex-start;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.prompt-card:hover { border-color: var(--blue); box-shadow: 0 2px 10px rgba(10, 102, 194, 0.12); }
.prompt-card strong {
  display: block; font-size: 11px; font-weight: 600; color: var(--blue);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px;
}

/* Message rows */
.message { display: flex; gap: 12px; align-items: flex-start; }
.message.user { flex-direction: row-reverse; }

.av { width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; overflow: hidden; border: 1px solid var(--border); }
.av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av.user-av {
  background: linear-gradient(135deg, #c9d6e3, #a0b4c8);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #0a3d73;
}

.bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); border-top-left-radius: 3px;
  padding: 12px 16px;
  font-size: 14px; line-height: 1.65;
  max-width: min(680px, 100%); min-width: 0;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.message.user .bubble {
  background: var(--user-bubble); color: var(--user-text); border-color: var(--user-bubble);
  border-radius: var(--radius); border-top-right-radius: 3px;
}

.bubble-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.bubble-name { font-size: 11px; font-weight: 600; color: var(--text-light); letter-spacing: 0.3px; }
.message.user .bubble-name { color: rgba(255, 255, 255, 0.75); }
.bubble-tag { font-size: 10.5px; font-weight: 500; color: var(--blue); background: var(--blue-soft); padding: 1px 8px; border-radius: 10px; }
.bubble-text { white-space: pre-wrap; }

.bubble-foot {
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.act {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: 1px solid transparent; border-radius: 16px;
  padding: 4px 10px; font-size: 12px; font-weight: 500; color: var(--text-mid);
}
.act svg { width: 14px; height: 14px; }
.act:hover:not(:disabled) { background: var(--pill-bg); color: var(--text); }
.act:disabled { opacity: 0.45; cursor: not-allowed; }
.act.done { color: #057642; }

.ring-score { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-light); }
.meter { width: 64px; height: 6px; border-radius: 3px; background: var(--pill-bg); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: linear-gradient(90deg, #f5b400, #e8590c, #c92a2a); }
.ring-score b { color: var(--text); font-weight: 600; }

/* Typing */
.typing-dots { display: flex; gap: 4px; align-items: center; padding: 6px 0 2px; }
.typing-dots span { width: 7px; height: 7px; background: var(--blue); border-radius: 50%; opacity: 0.4; animation: tdot 1.3s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tdot { 0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

/* ── Composer ────────────────────────────── */
.composer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.input-card {
  max-width: 820px; margin: 0 auto;
  background: var(--surface-2);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-card:focus-within { border-color: var(--blue); box-shadow: var(--focus); background: var(--surface); }
textarea {
  display: block; width: 100%;
  background: transparent; border: none; outline: none; resize: none;
  font-size: 15px; line-height: 1.55;
  padding: 12px 14px 4px;
  min-height: 48px; max-height: 160px;
}
textarea:focus-visible { box-shadow: none; }
textarea::placeholder { color: var(--text-light); }
.input-actions { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px 14px; }
.input-hint { font-size: 11px; color: var(--text-light); }
.input-hint kbd {
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 5px; font-family: inherit; font-size: 10px;
}
.char-count { margin-left: auto; font-size: 11px; color: var(--text-light); }
.char-count.warn { color: #c92a2a; }
.send-btn {
  margin-left: auto;
  background: var(--btn-bg); color: var(--btn-text);
  border: none; border-radius: 20px;
  font-size: 13px; font-weight: 600;
  padding: 8px 18px;
  display: flex; align-items: center; gap: 6px;
  transition: background 0.15s;
}
.char-count:not(:empty) + .send-btn { margin-left: 0; }
.send-btn svg { width: 14px; height: 14px; fill: currentColor; stroke: none; }
.send-btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.disclaimer { text-align: center; font-size: 11px; color: var(--text-light); margin-top: 8px; }

/* ── Ads ─────────────────────────────────── */
.ad-slot { position: relative; }
.ad-label {
  display: block; font-size: 10px; font-weight: 600; letter-spacing: 0.6px;
  text-transform: uppercase; color: var(--text-light); margin-bottom: 6px;
}
.ad-slot--sidebar { margin: 8px 12px 0; }
.ad-slot--welcome { margin-top: 22px; text-align: left; }
.ad-slot--feed { padding-left: 46px; }

.ad-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.ad-head { display: flex; align-items: center; gap: 10px; }
.ad-logo {
  width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, hsl(var(--ad-hue) 70% 48%), hsl(calc(var(--ad-hue) + 40) 70% 38%));
}
.ad-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ad-who strong { font-size: 13px; }
.ad-who span { font-size: 11px; color: var(--text-light); }
.ad-why { margin-left: auto; background: none; border: none; font-size: 11px; color: var(--text-light); text-decoration: underline; white-space: nowrap; }
.ad-why:hover { color: var(--text); }
.ad-headline { font-size: 14px; font-weight: 600; line-height: 1.4; }
.ad-text { font-size: 13px; color: var(--text-mid); line-height: 1.5; margin-top: 3px; }
.ad-cta {
  align-self: flex-start;
  border: 1.5px solid var(--blue); color: var(--blue); border-radius: 18px;
  padding: 5px 14px; font-size: 13px; font-weight: 600; text-decoration: none;
}
.ad-cta:hover { background: var(--blue-soft); }

.ad-card--sidebar { padding: 12px; }
.ad-card--sidebar .ad-why { display: none; }
.ad-card--sidebar .ad-headline { font-size: 13px; }
.ad-card--sidebar .ad-text { font-size: 12px; }

.ad-card--welcome { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px 14px; }
.ad-card--welcome .ad-head { flex: 0 0 auto; }
.ad-card--welcome .ad-why { display: none; }
.ad-card--welcome .ad-body { flex: 1 1 220px; }
.ad-card--welcome .ad-cta { align-self: center; }

/* ── Toast ───────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: #1c1c1c; color: #fff;
  padding: 10px 16px; border-radius: 22px;
  font-size: 13px; font-weight: 500; z-index: 200;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 32px); text-align: center;
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ── Privacy page ────────────────────────── */
body.page { height: auto; overflow: auto; display: block; }
.legal { max-width: 680px; margin: 0 auto; padding: 40px 20px 60px; line-height: 1.65; font-size: 15px; }
.legal h1 { font-size: 28px; letter-spacing: -0.5px; margin: 16px 0 6px; }
.legal h2 { font-size: 17px; margin: 28px 0 6px; }
.legal p { color: var(--text-mid); margin-bottom: 10px; }
.legal a { color: var(--blue); }
.legal-back { font-size: 13px; font-weight: 500; text-decoration: none; }
.legal-note { font-size: 13px; background: var(--blue-soft); padding: 10px 12px; border-radius: 8px; }

/* ── Responsive ──────────────────────────── */
@media (max-width: 1000px) {
  .level output { min-width: 0; }
  .level label { display: none; }
}

@media (max-width: 820px) {
  .menu-btn, #newChatTop { display: inline-flex; }
  .topbar { padding-left: 8px; padding-right: 8px; }
  .badge { display: none; }

  .sidebar {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 40;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: none;
  }
  .sidebar.open { transform: none; box-shadow: 8px 0 30px rgba(0, 0, 0, 0.2); }
  .scrim { display: block; position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 30; }
  .scrim[hidden] { display: none; }
  .chat-del { opacity: 1; }

  .toolbar { flex-direction: column; align-items: stretch; gap: 0; padding: 0 12px; }
  .mode-bar {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 8px 0 4px;
    mask-image: linear-gradient(90deg, #000 88%, transparent);
  }
  .level { padding: 2px 0 8px; }
  .level label { display: inline; }
  .level input[type="range"] { flex: 1; width: auto; }

  .messages { padding: 16px 12px; gap: 14px; }
  .prompts-grid { grid-template-columns: 1fr; }
  .welcome h1 { font-size: 21px; }
  .av { width: 30px; height: 30px; }
  .message.user .av { display: none; }
  .ad-slot--feed { padding-left: 0; }
  .ring-score { margin-left: 0; width: 100%; }

  .composer { padding: 10px 12px 12px; }
  .input-hint { display: none; }
  .disclaimer { display: none; }
  .toast { bottom: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
