/* DrewsBot — Builder, agents, members, accounts */

:root {
  /* Ocarina of Time greens + soft gold — light */
  --bg: #eef5e8;
  --bg-elevated: #f7fbf3;
  --bg-soft: #dce8d4;
  --border: #b7c9a8;
  --text: #122016;
  --text-muted: #4d6354;
  --accent: #b8922a;
  --accent-hover: #9a7820;
  --accent-soft: rgba(184, 146, 42, 0.16);
  --user-bubble: #3d7a4a;
  --user-bubble-text: #f7fbf3;
  --bot-bubble: #dce8d4;
  --bot-bubble-text: #122016;
  --card: #f7fbf3;
  --overlay: rgba(13, 40, 24, 0.45);
  --danger: #c62828;
  --danger-soft: rgba(198, 40, 40, 0.12);
  --warn: #c47a1a;
  --ok: #2e7d32;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(18, 32, 22, 0.08);
  --shadow-lg: 0 12px 40px rgba(18, 32, 22, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --header-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* OoT forest night + soft gold */
    --bg: #0d2818;
    --bg-elevated: #143222;
    --bg-soft: #1a3d2a;
    --border: #2a5538;
    --text: #e8f5e9;
    --text-muted: #9bb5a4;
    --accent: #d4b56a;
    --accent-hover: #e4c878;
    --accent-soft: rgba(212, 181, 106, 0.16);
    --user-bubble: #3d7a4a;
    --user-bubble-text: #f0fff2;
    --bot-bubble: #1a3d2a;
    --bot-bubble-text: #e8f5e9;
    --card: #143222;
    --overlay: rgba(0, 0, 0, 0.58);
    --danger: #ef5350;
    --danger-soft: rgba(239, 83, 80, 0.15);
    --warn: #e0a04a;
    --ok: #66bb6a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d2818;
  --bg-elevated: #143222;
  --bg-soft: #1a3d2a;
  --border: #2a5538;
  --text: #e8f5e9;
  --text-muted: #9bb5a4;
  --accent: #d4b56a;
  --accent-hover: #e4c878;
  --accent-soft: rgba(212, 181, 106, 0.16);
  --user-bubble: #3d7a4a;
  --user-bubble-text: #f0fff2;
  --bot-bubble: #1a3d2a;
  --bot-bubble-text: #e8f5e9;
  --card: #143222;
  --overlay: rgba(0, 0, 0, 0.58);
  --danger: #ef5350;
  --danger-soft: rgba(239, 83, 80, 0.15);
  --warn: #e0a04a;
  --ok: #66bb6a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

:root[data-theme="light"] { color-scheme: light; }

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { min-height: 100dvh; overflow: hidden; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}
.min-w-0 { min-width: 0; }
.muted { color: var(--text-muted); margin: 0; font-size: 0.85rem; }

.app {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}
@media (min-width: 768px) {
  .app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* —— Auth —— */
.auth-view {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.auth-view[hidden] { display: none !important; }

.auth-card {
  width: 100%;
  max-width: 400px;
  margin: auto 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-logo {
  display: block;
  margin: 0 auto 12px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.auth-card > h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}
.auth-tagline {
  margin: 6px 0 22px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.auth-panel { text-align: left; }
.auth-panel h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
  font-weight: 700;
}
.auth-panel[hidden] { display: none !important; }
.auth-switch {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.auth-note {
  margin: 18px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.link-btn {
  border: none; background: none; color: var(--accent);
  font: inherit; font-weight: 600; cursor: pointer; padding: 0;
  text-decoration: underline;
}
.form-error {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.8125rem;
}
.form-error[hidden] { display: none !important; }

/* —— Chat views —— */
.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.chat-view[hidden] { display: none !important; }

.top-header {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: var(--header-h);
  padding: 8px 6px 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.brand-logo {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: block;
}
.brand-text h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.brand-sub, .chat-status {
  margin: 2px 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex-shrink: 0;
}

.icon-btn {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border: none; border-radius: 12px;
  background: transparent; color: var(--text);
  font-size: 1.2rem; cursor: pointer;
  display: grid; place-items: center;
  position: relative;
  transition: background 0.15s ease;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--bg-soft); outline: none; }
.icon-btn:active { transform: scale(0.96); }

.badge {
  position: absolute;
  top: 5px; right: 5px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent); color: #fff;
  font-size: 0.625rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}
.badge[hidden] { display: none; }

.header-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: grid; place-items: center;
}

.theme-icon-light { display: none; }
.theme-icon-dark { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-dark { display: none; }
  :root:not([data-theme="light"]) .theme-icon-light { display: inline; }
}
:root[data-theme="dark"] .theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon-light { display: inline; }
:root[data-theme="light"] .theme-icon-dark { display: inline; }
:root[data-theme="light"] .theme-icon-light { display: none; }

.back-btn span { font-size: 1.75rem; line-height: 1; font-weight: 300; }

.chat-header-info {
  display: flex; align-items: center; gap: 12px;
  flex: 1; min-width: 0;
}
.chat-avatar, .person-avatar, .agent-avatar {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 0.9rem; color: #fff;
  flex-shrink: 0;
}
.chat-header-info h2, .top-header h2, .drawer-header h2 {
  margin: 0; font-size: 1.05rem; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { display: flex; max-width: 88%; animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user { align-self: flex-end; }
.msg.bot { align-self: flex-start; }
.msg-bubble {
  padding: 10px 14px; border-radius: 18px;
  font-size: 0.9375rem; line-height: 1.45;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.user .msg-bubble {
  background: var(--user-bubble); color: var(--user-bubble-text);
  border-bottom-right-radius: 6px;
}
.msg.bot .msg-bubble {
  background: var(--bot-bubble); color: var(--bot-bubble-text);
  border-bottom-left-radius: 6px;
}
.msg-meta { display: block; margin-top: 4px; font-size: 0.6875rem; opacity: 0.7; }
.msg.typing .msg-bubble {
  display: flex; gap: 5px; align-items: center; padding: 14px 18px;
}
.msg-bubble.streaming::after {
  content: "▍"; margin-left: 1px; opacity: 0.55;
  animation: stream-caret 1s steps(2, start) infinite;
}
@keyframes stream-caret { to { visibility: hidden; } }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.agent-created-card {
  align-self: stretch; max-width: 100%; margin: 4px 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-elevated); padding: 12px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
  animation: fadeIn 0.25s ease;
}
.agent-created-card .row { display: flex; align-items: center; gap: 12px; }
.agent-created-card h3 { margin: 0; font-size: 0.95rem; font-weight: 650; }
.agent-created-card p { margin: 2px 0 0; font-size: 0.8rem; color: var(--text-muted); }
.agent-created-card .open-btn,
.member-invite-card .open-btn {
  align-self: flex-start;
  border: none; border-radius: 999px;
  padding: 8px 14px; min-height: 36px;
  background: var(--accent); color: #fff;
  font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer;
}

.member-invite-card {
  align-self: stretch; max-width: 100%;
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: var(--accent-soft); padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}

.composer-wrap {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding-bottom: var(--safe-bottom);
  position: sticky; bottom: 0;
}
.chips {
  display: flex; gap: 8px;
  padding: 10px 12px 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  border-radius: 999px; padding: 8px 12px; min-height: 36px;
  font: inherit; font-size: 0.8125rem; font-weight: 550; cursor: pointer;
  white-space: nowrap;
}
.chip:hover, .chip:focus-visible {
  border-color: var(--accent); background: var(--accent-soft); outline: none;
}
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 10px 12px;
}
.composer-input {
  flex: 1; min-height: 44px; max-height: 120px; resize: none;
  border: 1px solid var(--border); border-radius: 22px;
  padding: 11px 16px; font: inherit; font-size: 1rem; line-height: 1.35;
  background: var(--bg); color: var(--text); outline: none;
}
.composer-input:focus { border-color: var(--accent); }
.composer-input::placeholder { color: var(--text-muted); }
.send-btn {
  flex-shrink: 0; width: 44px; height: 44px; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.25rem; font-weight: 700;
  cursor: pointer; display: grid; place-items: center;
}
.send-btn:hover:not(:disabled), .send-btn:focus-visible:not(:disabled) {
  background: var(--accent-hover); outline: none;
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Drawers */
.drawer-backdrop {
  position: absolute; inset: 0; background: var(--overlay);
  z-index: 40; animation: fade 0.2s ease;
}
.drawer-backdrop[hidden] { display: none !important; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.side-drawer {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(100%, 360px);
  background: var(--bg-elevated); z-index: 50;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.22s ease;
}
.side-drawer[hidden] { display: none !important; }
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 16px; min-height: var(--header-h);
  border-bottom: 1px solid var(--border);
}
.drawer-hint {
  margin: 0; padding: 10px 16px 4px;
  font-size: 0.8rem; color: var(--text-muted); line-height: 1.4;
}
.drawer-list {
  flex: 1; overflow-y: auto; padding: 8px 12px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.drawer-footer {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

.facepile {
  display: flex; padding: 4px 16px 8px; gap: 0;
}
.facepile .person-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--bg-elevated);
  margin-left: -8px; font-size: 0.7rem;
}
.facepile .person-avatar:first-child { margin-left: 0; }

.list-empty {
  margin: 24px 8px; text-align: center;
  color: var(--text-muted); font-size: 0.9rem; line-height: 1.45;
}
.list-empty strong {
  display: block; color: var(--text); margin-bottom: 6px; font-size: 1rem;
}

.list-card {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 12px; min-height: 64px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: inherit; text-align: left;
  font: inherit; box-shadow: var(--shadow);
}
.list-card.buttonish { cursor: pointer; }
.list-card.buttonish:hover, .list-card.buttonish:focus-visible {
  border-color: var(--accent); background: var(--accent-soft); outline: none;
}
.list-card .meta { flex: 1; min-width: 0; }
.list-card h3 {
  margin: 0; font-size: 0.95rem; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-card p {
  margin: 3px 0 0; font-size: 0.78rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-card .card-actions {
  display: flex; flex-direction: column; gap: 4px; flex-shrink: 0;
}

.status-pill {
  display: inline-block;
  font-size: 0.65rem; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.02em;
}
.status-pill.active, .status-pill.owner {
  background: rgba(46, 125, 50, 0.15); color: var(--ok);
}
.status-pill.pending {
  background: rgba(230, 126, 34, 0.18); color: var(--warn);
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text);
  border-radius: 8px; padding: 6px 8px;
  font: inherit; font-size: 0.7rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; min-height: 32px;
}
.mini-btn.accent { border-color: var(--accent); color: var(--accent); }
.mini-btn.danger { border-color: transparent; color: var(--danger); background: var(--danger-soft); }

.account-panel { padding: 16px; }
.account-hero {
  display: flex; align-items: center; gap: 14px; margin-bottom: 12px;
}
.account-hero-avatar {
  width: 56px; height: 56px; border-radius: 16px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.2rem; color: #fff;
}
.account-hero h3 { margin: 0; font-size: 1.1rem; }

.primary-btn, .ghost-btn, .danger-btn {
  border: none; border-radius: 12px;
  min-height: 44px; padding: 0 16px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.primary-btn { width: 100%; background: var(--accent); color: #fff; }
.primary-btn:hover, .primary-btn:focus-visible { background: var(--accent-hover); outline: none; }
.ghost-btn { background: transparent; color: var(--text-muted); }
.ghost-btn:hover { color: var(--text); background: var(--bg-soft); }
.danger-btn {
  width: 100%; background: var(--danger-soft); color: var(--danger);
  margin-top: 8px;
}

/* Modals */
.modal {
  position: absolute; inset: 0; z-index: 60;
  background: var(--overlay);
  display: grid; place-items: end center;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}
.modal[hidden] { display: none !important; }
@media (min-width: 480px) { .modal { place-items: center; } }

.modal-card {
  width: 100%; max-width: 400px;
  background: var(--card); border-radius: 20px; padding: 20px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  animation: fadeIn 0.2s ease;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}
.modal-card h2 { margin: 0; font-size: 1.2rem; font-weight: 700; }
.modal-sub { margin: 6px 0 16px; font-size: 0.85rem; color: var(--text-muted); line-height: 1.4; }
.field-label {
  display: block; font-size: 0.75rem; font-weight: 600;
  color: var(--text-muted); margin: 0 0 6px;
}
.field-input {
  width: 100%; min-height: 44px;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font: inherit; font-size: 1rem;
  background: var(--bg); color: var(--text);
  margin-bottom: 12px; outline: none;
}
.field-input:focus { border-color: var(--accent); }
.field-input[readonly] { opacity: 0.75; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px;
}
.modal-actions .primary-btn { width: auto; min-width: 100px; }

/* AI status banner */
.ai-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  font-size: 0.78rem;
  line-height: 1.35;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--text);
}
.ai-banner[hidden] { display: none !important; }
.ai-banner.warn {
  background: rgba(230, 126, 34, 0.18);
}
.ai-banner.ok {
  background: rgba(46, 125, 50, 0.12);
}
.ai-banner.err {
  background: var(--danger-soft);
  color: var(--danger);
}
.ai-banner .link-btn { flex-shrink: 0; font-size: 0.75rem; }

/* Private | Shared | Bots | News | Videos tabs */
.scope-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  flex-shrink: 0;
  background: var(--bg-elevated);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scope-tabs::-webkit-scrollbar { display: none; }
.scope-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
.scope-tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}
.scope-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.scope-hint {
  margin: 0;
  padding: 6px 14px 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.age-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 4px 0 14px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text);
  text-align: left;
}
.age-check input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
select.field-input {
  appearance: auto;
}

.mic-btn, .speak-btn { width: 40px; height: 40px; font-size: 1.05rem; }
.mic-btn.is-listening { background: var(--danger-soft); color: var(--danger); }
.composer .composer-input { min-width: 0; }

.tools-body { flex: 1; overflow-y: auto; padding: 8px 16px 20px; }
.tools-section { margin-bottom: 22px; }
.tools-section h3 { margin: 0 0 8px; font-size: 0.95rem; }
.memory-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.memory-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg); font-size: 0.85rem;
}
.memory-item span { flex: 1; }
.memory-add-row { display: flex; gap: 8px; align-items: center; }
.memory-add-row .field-input { margin: 0; flex: 1; }
.quiet-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.quiet-row .field-input { margin-bottom: 0; }
.templates-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.template-card {
  text-align: left; width: 100%; border: 1px solid var(--border); border-radius: 14px;
  padding: 12px; background: var(--bg); color: inherit; font: inherit; cursor: pointer;
}
.template-card:hover, .template-card:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.template-card h3 { margin: 0; font-size: 0.95rem; }
.template-card p { margin: 4px 0 0; font-size: 0.8rem; color: var(--text-muted); }
.quiet-banner {
  flex-shrink: 0; padding: 8px 14px; font-size: 0.78rem;
  background: rgba(230,126,34,0.18); border-bottom: 1px solid var(--border); color: var(--text);
}
.quiet-banner[hidden] { display: none !important; }

/* Agent Duels */
.duel-card { max-width: 520px; }
.duel-pick { margin-bottom: 8px; }
.duel-vs {
  text-align: center; font-weight: 800; letter-spacing: 0.12em;
  color: var(--accent); margin: 4px 0 10px; font-size: 0.85rem;
}
.duel-actions-top {
  display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px;
}
.duel-actions-top .primary-btn { width: auto; min-width: 120px; flex: 1; }
.duel-actions-top .ghost-btn { flex: 1; min-height: 44px; }
.duel-status {
  margin: 0 0 10px; font-size: 0.85rem; color: var(--text-muted);
  font-style: italic;
}
.duel-ring {
  display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 12px;
}
@media (min-width: 420px) {
  .duel-ring { grid-template-columns: 1fr 1fr; }
}
.duel-corner {
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--bg); padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 160px;
}
.duel-corner.is-winner {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.duel-corner.is-loser { opacity: 0.72; }
.duel-corner-head { display: flex; align-items: center; gap: 10px; }
.duel-corner-head h3 { margin: 0; font-size: 0.95rem; }
.duel-bubble {
  flex: 1; font-size: 0.88rem; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bot-bubble); color: var(--bot-bubble-text);
  border-radius: 14px; padding: 10px 12px; min-height: 72px;
}
.duel-bubble.is-loading { opacity: 0.7; font-style: italic; }
.duel-crown { width: 100%; }
.duel-winner {
  margin: 0 0 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--accent-soft); font-weight: 650; font-size: 0.9rem;
  text-align: center;
}

.ht-timer { margin: 8px 0 12px; }
.ht-timer-bar {
  height: 8px; border-radius: 999px; background: var(--bg-soft);
  overflow: hidden; border: 1px solid var(--border);
}
.ht-timer-bar span {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #e67e22, #c0392b);
  transition: width 0.1s linear;
}
#ht-timer-label {
  margin: 6px 0 0; font-size: 0.8rem; color: var(--text-muted); font-style: italic;
}
.rd-block { margin-top: 12px; }
.rd-block h3 { margin: 0 0 6px; font-size: 0.95rem; }

.news-subtabs { border-bottom: 1px solid var(--border); }
.news-local-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 12px; background: var(--bg-elevated);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.news-local-bar[hidden] { display: none !important; }
.news-local-bar .field-input { margin: 0; flex: 1; min-height: 40px; }
.news-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 10px 12px 20px; display: flex; flex-direction: column; gap: 8px;
}
.news-item {
  display: block; text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: 14px;
  padding: 12px; background: var(--bg-elevated); box-shadow: var(--shadow);
}
.news-item:active { transform: scale(0.99); }
.news-item h3 { margin: 0; font-size: 0.95rem; line-height: 1.35; font-weight: 650; }
.news-item p { margin: 6px 0 0; font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }
.news-meta { margin-top: 8px; font-size: 0.7rem; color: var(--text-muted); display: flex; justify-content: space-between; gap: 8px; }
.news-status { margin: 0; padding: 8px 14px 16px; font-size: 0.8rem; color: var(--text-muted); flex-shrink: 0; }
.news-ask {
  margin-top: 8px; border: none; background: var(--accent-soft); color: var(--accent);
  font: inherit; font-size: 0.75rem; font-weight: 650; border-radius: 999px;
  padding: 6px 10px; cursor: pointer;
}

.videos-ai-brief {
  margin: 0; padding: 8px 14px; font-size: 0.82rem; line-height: 1.4;
  color: var(--text); background: var(--accent-soft); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.videos-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 10px 12px 20px; display: flex; flex-direction: column; gap: 12px;
}
.video-card {
  border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elevated);
  box-shadow: var(--shadow); overflow: hidden;
}
.video-card.is-ai-pick { border-color: var(--accent); }
.video-thumb-wrap { position: relative; background: #0d2818; aspect-ratio: 16/9; }
.video-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-thumb-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }
.video-body { padding: 10px 12px 12px; }
.video-body h3 { margin: 0; font-size: 0.92rem; line-height: 1.35; font-weight: 650; }
.video-body p { margin: 6px 0 0; font-size: 0.78rem; color: var(--text-muted); line-height: 1.4; }
.video-meta { margin-top: 8px; font-size: 0.7rem; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 6px 10px; }
.video-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.video-badge {
  display: inline-block; font-size: 0.65rem; font-weight: 700; letter-spacing: 0.02em;
  padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}


/* Per-bot navigation strip (mobile-friendly) */
.bot-switcher {
  display: flex;
  gap: 8px;
  padding: 8px 12px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border, rgba(255,255,255,0.08));
  background: var(--bg-elevated, rgba(0,0,0,0.18));
}
.bot-switcher::-webkit-scrollbar { display: none; }
.bot-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 160px;
  padding: 6px 10px 6px 6px;
  border-radius: 999px;
  border: 1px solid var(--border, rgba(212,175,55,0.35));
  background: var(--surface, #122018);
  color: var(--text, #e8f5e9);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.bot-chip .bot-chip-av {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
}
.bot-chip .bot-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bot-chip.is-active {
  border-color: var(--gold, #d4af37);
  box-shadow: 0 0 0 1px rgba(212,175,55,0.35);
  background: rgba(26, 90, 46, 0.45);
}

.bot-chip.bot-chip-home {
  border-color: var(--accent, #2e7d32);
  background: var(--accent-soft, rgba(46, 125, 50, 0.2));
}
.bot-chip-home-av {
  background: var(--accent, #1a5a2e) !important;
  color: #fff !important;
  font-size: 0.85rem !important;
}

.list-card .meta .thread-preview {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted, #9bb5a3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— Bots directory tab —— */
.bots-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.bots-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bots-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 4px;
}
.bots-section-head h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.bots-section-count {
  font-weight: 650;
  color: var(--accent);
  margin-left: 6px;
  letter-spacing: 0;
  text-transform: none;
}
.bots-section-add {
  min-width: 40px;
  min-height: 40px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.bots-section-add:active,
.bots-section-add:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  background: var(--accent);
  color: var(--bg);
}
.bots-section-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bots-scope-pill {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--accent-soft);
  color: var(--text);
  margin-top: 4px;
}
.bots-scope-pill.shared {
  background: rgba(61, 122, 74, 0.2);
}
.bots-plus-glyph {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}
.bots-create-header {
  min-width: 44px;
  min-height: 44px;
}
.bots-fab {
  position: absolute;
  right: calc(16px + var(--safe-right));
  bottom: calc(18px + var(--safe-bottom));
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 20px 0 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #122016;
  font: inherit;
  font-size: 1rem;
  font-weight: 750;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}
.bots-fab > span:first-child {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}
.bots-fab:active,
.bots-fab:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  filter: brightness(1.05);
}
#bots-view {
  position: relative;
}
.bots-empty-cta {
  margin-top: 10px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.bots-empty-cta:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


/* —— v1.14 Linked Accounts + Email + tap polish —— */
.icon-btn {
  min-width: 48px;
  min-height: 48px;
}
.chip {
  min-height: 44px;
  padding: 10px 16px;
  font-size: 0.95rem;
}
.scope-tab {
  min-height: 44px;
  padding: 10px 14px;
  font-weight: 700;
}
.send-btn {
  min-width: 48px;
  min-height: 48px;
}
.primary-btn, .danger-btn, .ghost-btn {
  min-height: 52px;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 14px;
}
.mini-btn {
  min-height: 44px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 12px;
}
.field-input {
  min-height: 48px;
  font-size: 1.05rem;
  border-radius: 12px;
}
textarea.field-input {
  min-height: 120px;
}

.linked-cta {
  margin: 12px 0 8px;
  background: linear-gradient(135deg, #b8922a 0%, #3d7a4a 100%);
  border: none;
  box-shadow: 0 4px 16px rgba(61, 122, 74, 0.28);
  letter-spacing: 0.01em;
}
.linked-cta:hover, .linked-cta:focus-visible {
  filter: brightness(1.06);
  background: linear-gradient(135deg, #c9a234 0%, #458a54 100%);
}
.linked-summary {
  margin: 0 0 16px;
  font-size: 0.9rem;
}

.linked-drawer .drawer-hint {
  font-size: 0.95rem;
  line-height: 1.45;
}
.linked-section-title {
  margin: 18px 16px 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 800;
}
.linked-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 14px 18px;
}
.linked-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 14px;
  min-height: 72px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.linked-card:active {
  transform: scale(0.98);
}
.linked-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.linked-card.is-live {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--accent-soft), var(--card));
}
.linked-card.is-connected {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px rgba(46, 125, 50, 0.25), var(--shadow);
}
.linked-card.is-soon {
  opacity: 0.78;
}
.linked-icon {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
}
.linked-meta {
  flex: 1;
  min-width: 0;
}
.linked-meta h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}
.linked-meta p {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.35;
}
.linked-badge {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-muted);
}
.linked-badge.live { background: var(--accent-soft); color: var(--accent-hover); }
.linked-badge.on { background: rgba(46,125,50,0.18); color: var(--ok); }
.linked-badge.soon { background: var(--danger-soft); color: var(--warn); }

.email-panel {
  margin: 0 12px 8px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--accent-soft), var(--card));
  box-shadow: var(--shadow);
}
.email-panel[hidden] { display: none !important; }
.email-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.email-panel-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
}
.email-panel-status {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.email-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.email-tap { min-height: 44px; }
.email-inbox-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.email-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 12px;
  min-height: 56px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.email-row:focus-visible { outline: 2px solid var(--accent); }
.email-row.is-unread { border-color: var(--accent); font-weight: 700; }
.email-row-from {
  font-size: 0.88rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-row-sub {
  font-size: 0.9rem;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-row-snip {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-empty {
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.email-msg-body {
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  line-height: 1.45;
  margin-bottom: 12px;
}
.modal-card-wide {
  max-width: min(560px, 100%);
}
.warn-line { color: var(--warn); font-weight: 600; }
.danger-send {
  background: var(--ok) !important;
}
.danger-send:hover { filter: brightness(1.05); }
.gmail-modal-actions { flex-wrap: wrap; gap: 8px; }
.gmail-oauth-btn { width: 100%; margin-top: 8px; }

.account-hero-avatar {
  width: 64px;
  height: 64px;
  font-size: 1.4rem;
}
.bots-fab {
  min-height: 56px;
  padding-left: 18px;
  padding-right: 18px;
  box-shadow: 0 8px 24px rgba(61, 122, 74, 0.35);
}
.top-header .brand-logo {
  width: 44px;
  height: 44px;
}


/* —— v1.15 Sleek left tab rail (Private / Shared / Bots / News / Videos) —— */
:root {
  --rail-w: 68px;
  --rail-bg: linear-gradient(180deg, #0f2c1b 0%, #0a2013 55%, #071a0f 100%);
  --rail-edge: rgba(212, 181, 106, 0.22);
  --rail-ink: #8fae99;
  --rail-ink-hover: #d7ead9;
  --rail-gold: #d4b56a;
  --rail-gold-hi: #f0d68e;
  --rail-glow: rgba(212, 181, 106, 0.16);
}
@media (min-width: 420px) { :root { --rail-w: 74px; } }

.chat-view.has-rail {
  position: relative;
  padding-left: calc(var(--rail-w) + var(--safe-left));
}

/* Rail container (overrides old horizontal .scope-tabs) */
.scope-tabs.side-rail {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  z-index: 20;
  width: calc(var(--rail-w) + var(--safe-left));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 6px;
  margin: 0;
  padding: calc(var(--safe-top) + 12px) 6px calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 6px);
  background: var(--rail-bg);
  border-right: 1px solid var(--rail-edge);
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.35), 4px 0 18px rgba(0, 0, 0, 0.18);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
}
.scope-tabs.side-rail::-webkit-scrollbar { display: none; }

/* Rail tab */
.side-rail .scope-tab.rail-tab {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-width: 0;
  min-height: 58px;
  padding: 8px 2px 7px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--rail-ink);
  font: inherit;
  font-size: 0.625rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.18s ease, background-color 0.22s ease, border-color 0.22s ease, box-shadow 0.25s ease, transform 0.12s ease;
}
.side-rail .rail-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 28px;
  border-radius: 10px;
  transition: background-color 0.22s ease, transform 0.22s ease, filter 0.25s ease;
}
.side-rail .rail-icon svg { display: block; width: 22px; height: 22px; }
.side-rail .rail-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: uppercase;
  font-size: 0.6rem;
  letter-spacing: 0.06em;
}

/* Active indicator: soft gold bar on the left edge */
.side-rail .scope-tab.rail-tab::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(180deg, var(--rail-gold-hi), var(--rail-gold));
  box-shadow: 0 0 10px rgba(240, 214, 142, 0.6);
  transform: translateY(-50%);
  transition: height 0.25s cubic-bezier(.2, .8, .2, 1);
}

@media (hover: hover) {
  .side-rail .scope-tab.rail-tab:hover {
    color: var(--rail-ink-hover);
    background: rgba(255, 255, 255, 0.04);
  }
}
.side-rail .scope-tab.rail-tab:active { transform: scale(0.95); }
.side-rail .scope-tab.rail-tab:focus-visible {
  outline: 2px solid var(--rail-gold);
  outline-offset: -2px;
}

.side-rail .scope-tab.rail-tab.is-active {
  color: var(--rail-gold-hi);
  background: linear-gradient(180deg, rgba(212, 181, 106, 0.14), rgba(212, 181, 106, 0.06));
  border-color: rgba(212, 181, 106, 0.32);
  box-shadow: 0 0 16px var(--rail-glow), inset 0 1px 0 rgba(240, 214, 142, 0.12);
}
.side-rail .scope-tab.rail-tab.is-active::before { height: 28px; }
.side-rail .scope-tab.rail-tab.is-active .rail-icon {
  background: rgba(212, 181, 106, 0.16);
  filter: drop-shadow(0 0 5px rgba(240, 214, 142, 0.45));
}

/* Short phones: tighten so all 5 tabs fit without scrolling */
@media (max-height: 560px) {
  .side-rail .scope-tab.rail-tab { min-height: 48px; padding: 5px 2px; gap: 2px; }
  .side-rail .rail-icon { height: 24px; }
}

/* Header room next to the rail on narrow phones */
.has-rail .top-header { padding-left: 10px; }
.has-rail .brand-text { min-width: 0; }
.has-rail .brand-text h1,
.has-rail .brand-sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 440px) {
  .has-rail .top-header { gap: 2px; padding-right: 4px; }
  .has-rail .top-header .icon-btn { min-width: 44px; min-height: 44px; width: 44px; height: 44px; }
  .has-rail .top-header .brand-logo { width: 36px; height: 36px; }
  .has-rail .brand { gap: 8px; }
}
@media (max-width: 400px) {
  /* Logo already identifies the app; give the builder header icons breathing room */
  #builder-view .top-header .brand-text h1 { font-size: 0.95rem; }
}

/* Bots FAB stays clear of the rail; hint text aligned to content column */
.has-rail .bots-fab { right: calc(14px + var(--safe-right)); }
.has-rail .scope-hint { padding-top: 8px; }

/* Light theme keeps the dark OoT rail for contrast; just soften the edge */
:root[data-theme="light"] .scope-tabs.side-rail { border-right-color: rgba(13, 40, 24, 0.35); }

@media (prefers-reduced-motion: reduce) {
  .side-rail .scope-tab.rail-tab,
  .side-rail .rail-icon,
  .side-rail .scope-tab.rail-tab::before { transition: none; }
}

/* Agent chat header: keep title + status to tidy single lines beside the rail */
.has-rail .chat-header-info { flex: 1; min-width: 0; gap: 8px; }
.has-rail .chat-header-info h2 {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.has-rail .chat-header-info .chat-status {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
@media (max-width: 440px) {
  .has-rail .chat-header-info .chat-avatar { width: 36px; height: 36px; flex-shrink: 0; }
}

/* Brand mark sits at the top of the rail; header logo hidden beside it to free room */
.side-rail .rail-logo {
  flex: 0 0 auto;
  display: block;
  width: 40px; height: 40px;
  margin: 0 auto 8px;
  border-radius: 11px;
  box-shadow: 0 0 0 1px rgba(212, 181, 106, 0.18), 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.side-rail .rail-logo + .rail-tab { margin-top: 2px; }
.side-rail .rail-logo::after { content: none; }
.has-rail .top-header .brand-logo { display: none; }
.has-rail .top-header { padding-left: 14px; }
@media (max-height: 560px) {
  .side-rail .rail-logo { width: 32px; height: 32px; margin-bottom: 4px; }
}

/* —— v1.17 Slide-out nav drawer (phones) · rail stays on wide screens —— */
.side-rail .rail-head {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.side-rail .rail-brand,
.side-rail .rail-close { display: none; }

/* One menu button: Triforce logo + small gold ☰ badge (top-left of every header) */
.nav-menu-btn {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  margin-right: 6px;
  padding: 0;
  border: 1px solid rgba(212, 181, 106, 0.28);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(212, 181, 106, 0.10), rgba(212, 181, 106, 0.03));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.nav-menu-btn:active { transform: scale(0.94); }
.nav-menu-btn:focus-visible { outline: 2px solid var(--rail-gold); outline-offset: 2px; }
@media (hover: hover) {
  .nav-menu-btn:hover { border-color: rgba(212, 181, 106, 0.55); box-shadow: 0 0 14px rgba(212, 181, 106, 0.18); }
}
.nav-menu-logo {
  display: block;
  width: 32px; height: 32px;
  border-radius: 9px;
  pointer-events: none;
}
.nav-menu-badge {
  position: absolute;
  right: -4px; bottom: -4px;
  display: grid;
  place-items: center;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--rail-gold-hi), var(--rail-gold));
  color: #0d2818;
  border: 2px solid var(--bg-elevated);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.nav-menu-badge svg { display: block; width: 10px; height: 10px; }
.app.nav-open .nav-menu-btn { border-color: rgba(212, 181, 106, 0.6); }

.nav-backdrop {
  position: absolute;
  inset: 0;
  z-index: 46;
  background: rgba(3, 12, 7, 0.58);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.28s ease;
  touch-action: none;
}
.nav-backdrop.is-visible { opacity: 1; }
.nav-backdrop[hidden] { display: none !important; }

@media (max-width: 899.98px) {
  /* Content gets the full width — rail becomes an off-canvas drawer */
  .chat-view.has-rail { padding-left: var(--safe-left); }

  .scope-tabs.side-rail {
    z-index: 48;
    width: calc(min(84%, 304px) + var(--safe-left));
    gap: 4px;
    padding: calc(var(--safe-top) + 10px) 12px calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 12px);
    border-radius: 0 22px 22px 0;
    box-shadow: none;
    transform: translate3d(-105%, 0, 0);
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.22, 0.8, 0.24, 1), box-shadow 0.3s ease, visibility 0s linear 0.3s;
    will-change: transform;
    touch-action: pan-y;
  }
  .app.nav-open .scope-tabs.side-rail {
    transform: translate3d(0, 0, 0);
    visibility: visible;
    box-shadow: 18px 0 48px rgba(0, 0, 0, 0.5), inset -1px 0 0 rgba(0, 0, 0, 0.35);
    transition: transform 0.3s cubic-bezier(0.22, 0.8, 0.24, 1), box-shadow 0.3s ease, visibility 0s;
  }
  .app.nav-dragging .scope-tabs.side-rail,
  .app.nav-dragging .nav-backdrop { transition: none; }

  /* Drawer header: logo + name + close */
  .side-rail .rail-head {
    flex-direction: row;
    gap: 12px;
    padding: 4px 2px 14px 4px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--rail-edge);
  }
  .side-rail .rail-head .rail-logo { width: 44px; height: 44px; margin: 0; }
  .side-rail .rail-brand {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
  }
  .side-rail .rail-brand-name {
    color: var(--rail-gold-hi);
    font-size: 1.08rem;
    font-weight: 750;
    letter-spacing: -0.01em;
    white-space: nowrap;
  }
  .side-rail .rail-brand-sub {
    margin-top: 2px;
    color: var(--rail-ink);
    font-size: 0.66rem;
    font-weight: 650;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }
  .side-rail .rail-close {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 40px; height: 40px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--rail-ink);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .side-rail .rail-close:active { transform: scale(0.94); }
  .side-rail .rail-close:focus-visible { outline: 2px solid var(--rail-gold); outline-offset: -2px; }

  /* Full-width rows: icon + label */
  .side-rail .scope-tab.rail-tab {
    flex-direction: row;
    justify-content: flex-start;
    gap: 14px;
    min-height: 54px;
    padding: 9px 14px 9px 8px;
    border-radius: 14px;
    font-size: 0.95rem;
  }
  .side-rail .rail-icon { flex: 0 0 auto; width: 40px; height: 36px; border-radius: 11px; }
  .side-rail .rail-label {
    font-size: 0.98rem;
    font-weight: 650;
    letter-spacing: 0.01em;
    text-transform: none;
  }
  .side-rail .scope-tab.rail-tab::before { left: -12px; }
  .side-rail .scope-tab.rail-tab.is-active::before { height: 30px; }

  .has-rail .top-header { padding-left: 8px; }
}
@media (max-width: 899.98px) and (max-height: 560px) {
  .side-rail .scope-tab.rail-tab { min-height: 46px; padding: 5px 14px 5px 8px; }
  .side-rail .rail-head { padding-bottom: 8px; margin-bottom: 4px; }
  .side-rail .rail-head .rail-logo { width: 34px; height: 34px; }
}

/* Wide screens: rail always visible, no menu button / backdrop */
@media (min-width: 900px) {
  .nav-menu-btn, .nav-backdrop { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .scope-tabs.side-rail, .nav-backdrop, .nav-menu-btn { transition: none !important; }
}

/* —— Videos tab: single scroll area + YouTube panel (v1.19) —— */
.videos-scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(12px + var(--safe-bottom));
}
.videos-scroll .videos-list { flex: none; overflow: visible; }
.yt-panel {
  margin: 10px 12px 4px; padding: 10px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg-elevated); box-shadow: var(--shadow);
}
.yt-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.yt-mark { display: inline-flex; }
.yt-title { font-weight: 700; font-size: 0.92rem; }
.yt-form { display: flex; gap: 8px; }
.yt-input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; /* 16px stops iOS/Android zoom */
  padding: 9px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); outline: none;
}
.yt-input:focus { border-color: var(--accent); }
.yt-go {
  flex-shrink: 0; border: none; border-radius: 999px; padding: 0 16px; font: inherit; font-weight: 700;
  font-size: 0.85rem; background: var(--accent); color: #122016; cursor: pointer;
}
.yt-player { margin-top: 10px; }
.yt-frame { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 10px; overflow: hidden; }
.yt-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.yt-now { padding: 8px 2px 2px; }
.yt-now h3 { margin: 0; font-size: 0.9rem; line-height: 1.35; font-weight: 650; }
.yt-now-meta { margin: 4px 0 0; font-size: 0.74rem; color: var(--text-muted); }
.yt-now .video-actions { margin-top: 6px; }
.yt-now .news-ask { margin-top: 0; text-decoration: none; }
.yt-now .news-ask:disabled { opacity: 0.7; }
.yt-status { margin: 8px 2px 0; font-size: 0.8rem; color: var(--text-muted); }
.yt-results { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.yt-results:empty { display: none; }
.yt-row {
  display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
  padding: 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
  color: inherit; font: inherit; cursor: pointer;
}
.yt-row:active { transform: scale(0.99); }
.yt-row-thumb { position: relative; flex: 0 0 128px; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; background: #0d2818; }
.yt-row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.yt-dur {
  position: absolute; right: 4px; bottom: 4px; font-size: 0.66rem; font-weight: 700;
  padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,0.78); color: #fff;
}
.yt-dur.is-live { background: #e62117; }
.yt-row-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.yt-row-title {
  font-size: 0.82rem; font-weight: 650; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.yt-row-meta, .yt-row-note { font-size: 0.7rem; color: var(--text-muted); }
.yt-row-note { font-style: italic; }
.videos-posts-wrap { margin: 8px 12px 0; }
.videos-section-title { margin: 6px 2px 0; font-size: 0.8rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
@media (max-width: 360px) { .yt-row-thumb { flex-basis: 108px; } }

/* —— v1.20: web-search sources + NaviAi memory —— */
.msg-bubble a.msg-link { color: var(--accent, #4f8cff); text-decoration: underline; word-break: break-word; }
.msg-sources { margin-top: 8px; padding-top: 6px; border-top: 1px solid rgba(127,127,127,0.25); font-size: 0.78rem; }
.msg-sources-head { font-weight: 600; opacity: 0.8; margin-bottom: 2px; }
.msg-sources ol { margin: 2px 0 0; padding-left: 18px; }
.msg-sources li { margin: 2px 0; }
.msg-sources a { color: var(--accent, #4f8cff); text-decoration: none; word-break: break-word; }
.msg-sources a:hover { text-decoration: underline; }
.msg-searching { font-size: 0.75rem; opacity: 0.75; margin: 4px 0 0 6px; }
.navimem-item span { word-break: break-word; }
.navimem-empty { font-size: 0.85rem; }
#open-memory-btn { margin-top: 4px; }

/* ===== v1.1.0 — tool chips, draft card, unread badges, toasts, schedule modal, Teach NaviAi ===== */
.msg-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tool-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  font-size: 0.72rem; font-weight: 600; line-height: 1.2; padding: 4px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--text); border: 1px solid rgba(184, 146, 42, 0.35);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool-chip.is-ok { border-color: rgba(46, 125, 50, 0.45); background: rgba(46, 125, 50, 0.12); }
.tool-chip.is-fail { border-color: rgba(196, 122, 26, 0.5); background: rgba(196, 122, 26, 0.12); }
.tool-chip.is-sched { border-color: rgba(41, 128, 185, 0.45); background: rgba(41, 128, 185, 0.12); }
.draft-card {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  border: 1px dashed var(--accent); background: var(--accent-soft);
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start;
}
.draft-card-head { font-weight: 700; font-size: 0.82rem; }
.draft-card-meta { font-size: 0.75rem; color: var(--text-muted); word-break: break-word; }
.unread-badge, .nav-unread, .rail-unread {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 0.68rem; font-weight: 800; line-height: 1;
  vertical-align: middle;
}
.unread-badge[hidden], .nav-unread[hidden], .rail-unread[hidden] { display: none !important; }
.bot-chip .unread-badge { margin-left: 4px; min-width: 16px; height: 16px; font-size: 0.62rem; }
.nav-menu-btn { position: relative; }
.nav-menu-btn .nav-unread { position: absolute; top: -4px; left: -4px; box-shadow: 0 0 0 2px var(--bg); }
.side-rail .scope-tab.rail-tab { position: relative; }
.side-rail .rail-tab .rail-unread { position: absolute; top: 4px; right: 6px; }
.navi-toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 9999;
  top: calc(var(--safe-top) + 64px); width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.navi-toast {
  pointer-events: auto; text-align: left; cursor: pointer; font: inherit; color: var(--text);
  display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-radius: 14px;
  background: var(--bg-elevated); border: 1px solid var(--accent); box-shadow: var(--shadow-lg);
  animation: naviToastIn 0.22s ease-out;
}
.navi-toast strong { font-size: 0.86rem; }
.navi-toast span { font-size: 0.8rem; color: var(--text-muted); }
@keyframes naviToastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.sched-card { max-height: 88vh; overflow-y: auto; }
.sched-list { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 12px; }
.sched-row {
  display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 9px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-soft);
}
.sched-row.is-paused { opacity: 0.65; }
.sched-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 160px; }
.sched-info strong { font-size: 0.88rem; }
.sched-info span { font-size: 0.74rem; }
.sched-acts { display: flex; gap: 6px; flex-wrap: wrap; }
.sched-acts .mini-btn.danger { color: var(--danger); }
.sched-h3 { font-size: 0.9rem; margin: 6px 0 6px; }
.sched-row-form select, .sched-card select { width: 100%; }
.teach-text { width: 100%; min-height: 96px; resize: vertical; font: inherit; }
.teach-count { font-size: 0.72rem; text-align: right; margin: 4px 0 0; }
.teach-ex { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px dashed var(--border); }
.teach-ex textarea { resize: vertical; font: inherit; }
.mytools-item { align-items: center; gap: 6px; }
.mytools-item .mytools-text { flex: 1 1 auto; min-width: 0; word-break: break-word; }
.mytools-item.is-done .mytools-text { text-decoration: line-through; opacity: 0.6; }
.mytools-rem-row { flex-wrap: wrap; }
.mytools-rem-row #mytools-rem-text { flex: 2 1 140px; }
.mytools-rem-row #mytools-rem-when { flex: 1 1 100px; }
.app-version { font-size: 0.72rem; text-align: center; margin-top: 12px; opacity: 0.7; }

/* ═══ v1.2.0 — attachments, voice, inbox picker, files, modals (Ocarina green / gold) ═══ */
.composer { gap: 6px; }
.attach-btn { width: 40px; height: 40px; font-size: 1.05rem; }
.mic-btn.is-listening { animation: navi-pulse 1.1s ease-in-out infinite; box-shadow: 0 0 0 3px var(--danger-soft); }
.mic-btn.is-loading, .speak-btn.is-loading, .msg-speak.is-loading { opacity: 0.6; animation: navi-pulse 1s ease-in-out infinite; }
.speak-btn.is-speaking, .msg-speak.is-speaking { color: var(--accent); background: var(--accent-soft); }
@keyframes navi-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.attach-tray { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px 0; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 5px 10px; border-radius: 999px; font-size: 0.8rem; line-height: 1.2;
  background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach-chip.is-busy { opacity: 0.75; border-style: dashed; }
.attach-chip.is-error { border-color: var(--danger); background: var(--danger-soft); white-space: normal; }
.attach-chip.in-msg { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.45); color: inherit; }
.attach-x { border: 0; background: transparent; color: inherit; font-size: 0.85rem; cursor: pointer; padding: 0 2px; min-width: 22px; min-height: 22px; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-speak {
  border: 0; background: transparent; cursor: pointer; font-size: 0.85rem; margin-left: 8px;
  padding: 2px 6px; border-radius: 10px; color: var(--text-muted); vertical-align: middle; min-height: 26px;
}
.msg-speak:hover { background: var(--accent-soft); }
.email-inbox-select {
  margin-left: 6px; font: inherit; font-size: 0.75rem; max-width: 52vw;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); padding: 2px 6px;
}
.email-row-inbox { font-weight: 400; font-size: 0.7rem; color: var(--accent); margin-left: 6px; }
.field-row { display: flex; gap: 8px; }
.field-row .field-input { flex: 1; }
.field-row .field-port { flex: 0 0 86px; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 0.9rem; color: var(--text); }
.files-list { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; margin: 8px 0; }
.file-row {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px;
  background: var(--bg-soft); border: 1px solid var(--border);
}
.file-icon { font-size: 1.4rem; }
.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file-meta strong { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { font-size: 0.72rem; color: var(--text-muted); }
.file-meta em { font-size: 0.75rem; color: var(--text-muted); font-style: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) {
  .composer { padding: 8px 8px; }
  .attach-btn, .mic-btn, .speak-btn { width: 36px; height: 36px; font-size: 0.98rem; }
}
