:root {
  --bg-paper: #FAF5EE;
  --bg-sidebar: #F4EDE3;
  --bg-card: #FFFFFF;
  --bg-user: #F1E4D6;
  --bg-soft: #F7F1E8;
  --border: #E8DDD0;
  --border-strong: #DBCBB9;
  --ink: #2F2620;
  --ink-muted: #7C6E63;
  --ink-light: #9D8F82;
  --accent: #B86B43;
  --accent-hover: #9F5934;
  --accent-soft: #F7E8DE;
  --sage: #6E8B74;
  --sage-soft: #E9F0EA;
  --danger: #B84A43;
  --shadow-card: 0 2px 10px rgba(47, 38, 32, 0.045);
  --shadow-float: 0 8px 28px rgba(47, 38, 32, 0.085);
  --radius-card: 18px;
  --radius-pill: 999px;
  --font-serif: Georgia, 'Palatino Linotype', 'Book Antiqua', Palatino, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.brand-serif { font-family: var(--font-serif); font-weight: 600; letter-spacing: -0.01em; }

body {
  background-image:
    radial-gradient(ellipse at 12% 10%, rgba(184, 107, 67, 0.045), transparent 52%),
    radial-gradient(ellipse at 88% 85%, rgba(110, 139, 116, 0.05), transparent 52%);
}

/* Offline Banner */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: #FFF2E6;
  border-bottom: 1px solid #E5C7AE;
  font-size: 13.5px;
  color: var(--ink);
}

/* --- Login Screen --- */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 36px 28px 30px;
  text-align: center;
  box-shadow: var(--shadow-float);
}
.login-icon {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  margin-bottom: 14px;
}
.login-title { margin: 0; font-size: 28px; color: var(--ink); }
.login-sub { margin: 4px 0 24px; color: var(--ink-muted); font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.code-input {
  width: 100%;
  text-align: center;
  font-size: 28px;
  letter-spacing: 0.22em;
  font-weight: 600;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-paper);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.code-input:focus { border-color: var(--accent); background: #fff; }
.login-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.login-hint { margin: 18px 0 0; font-size: 12.5px; color: var(--ink-light); line-height: 1.45; }
.btn-vk {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #0077FF;
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-pill);
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
.btn-vk:hover { background: #0066DD; }
.btn-vk:active { transform: scale(0.98); }
.code-fallback {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.code-fallback summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-muted);
  list-style: none;
  padding: 4px 0;
}
.code-fallback summary::-webkit-details-marker { display: none; }
.code-fallback[open] summary { margin-bottom: 12px; }

/* --- Buttons --- */
button { font-family: inherit; cursor: pointer; }
.btn-primary, .btn-primary-sm {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  font-weight: 500;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary { padding: 13px 22px; font-size: 15px; }
.btn-primary-sm { padding: 8px 15px; font-size: 13.5px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary:hover, .btn-primary-sm:hover { background: var(--accent-hover); }
.btn-primary:active, .btn-primary-sm:active { transform: scale(0.98); }
.btn-primary:disabled, .btn-primary-sm:disabled { opacity: 0.55; cursor: default; }
.btn-full { width: 100%; }

.btn-soft-sm {
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}
.btn-soft-sm:hover { background: var(--bg-user); border-color: var(--border-strong); }

.btn-ghost-sm, .btn-ghost-xs {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.btn-ghost-sm { padding: 7px 12px; font-size: 13px; }
.btn-ghost-xs { padding: 3px 9px; font-size: 12px; }
.btn-ghost-sm:hover, .btn-ghost-xs:hover { background: var(--bg-soft); color: var(--ink); }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.icon-btn:hover { background: rgba(47, 38, 32, 0.06); }

.text-btn {
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 13px;
  padding: 7px 9px;
  border-radius: 8px;
}
.text-btn:hover { background: rgba(47, 38, 32, 0.06); color: var(--ink); }

/* --- App Shell --- */
.app-shell {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 274px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: calc(18px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  gap: 12px;
  z-index: 40;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 2px 6px 6px;
}
.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.brand-text { flex: 1; min-width: 0; }
.brand-name { font-size: 20px; line-height: 1.1; color: var(--ink); }
.brand-sub { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }

.topic-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-right: 2px;
}
.topic-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 13px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  text-align: left;
  transition: background 0.14s, border-color 0.14s;
}
.topic-item:hover { background: rgba(255, 255, 255, 0.6); }
.topic-item.active {
  background: var(--bg-card);
  border-color: var(--border);
  box-shadow: 0 2px 6px rgba(47, 38, 32, 0.04);
  font-weight: 600;
}
.topic-item .t-ico {
  width: 20px;
  height: 20px;
  color: var(--ink-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topic-item.active .t-ico { color: var(--accent); }
.topic-item .t-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.today-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 11px 13px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.today-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-card); }
.today-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--sage);
  margin-bottom: 4px;
}
.today-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sage); }
.today-body { font-size: 12.5px; color: var(--ink-muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.user-badge { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-device { font-size: 11px; color: var(--ink-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.footer-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* Main Panel */
.main-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.topbar {
  min-height: 62px;
  padding: calc(10px + env(safe-area-inset-top)) 22px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(250, 245, 238, 0.94);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-title-wrap { min-width: 0; }
.topbar-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 1px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sage); flex-shrink: 0; }
.status-dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
.status-dot.offline { background: var(--danger); }

.view-tabs {
  display: inline-flex;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}
.tab-btn {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.14s, color 0.14s;
}
.tab-btn.active {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(47, 38, 32, 0.07);
}

/* Mobile topic pills & switcher */
.topic-pills {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 8px 12px;
  scrollbar-width: none;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(232, 221, 208, 0.55);
}
.topic-pills::-webkit-scrollbar { display: none; }
.topic-pill {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--ink-muted);
  font-size: 13.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.topic-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.topic-pill .pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.topic-pill.active .pill-dot { background: #fff; }

.mobile-view-bar {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-paper);
  flex-shrink: 0;
}
.m-tab-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--ink-muted);
  border-radius: 10px;
  padding: 8px;
  font-size: 13px;
  font-weight: 500;
}
.m-tab-btn.active {
  background: var(--bg-user);
  border-color: var(--border-strong);
  color: var(--ink);
  font-weight: 600;
}

/* Views */
.view-pane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view-pane.active { display: flex; }

/* Chat Stream */
.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 16px;
  -webkit-overflow-scrolling: touch;
}
.load-older-wrap {
  max-width: 820px;
  margin: 0 auto 12px;
  text-align: center;
}
.messages-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-row { display: flex; flex-direction: column; max-width: 100%; }
.msg-row.user { align-items: flex-end; }
.msg-row.assistant, .msg-row.dev, .msg-row.system { align-items: flex-start; }

.msg-meta {
  font-size: 11.5px;
  color: var(--ink-light);
  margin: 0 8px 4px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.msg-bubble {
  border-radius: var(--radius-card);
  padding: 15px 18px;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg-row.user .msg-bubble {
  background: var(--bg-user);
  border: 1px solid #E5D4C2;
  max-width: 78%;
  border-bottom-right-radius: 6px;
}
.msg-row.assistant .msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  width: 100%;
  border-bottom-left-radius: 6px;
}
.msg-row.dev .msg-bubble {
  background: var(--sage-soft);
  border: 1px solid #D1DFD4;
  width: 100%;
  border-bottom-left-radius: 6px;
}
.msg-row.system .msg-bubble {
  background: var(--bg-soft);
  border: 1px dashed var(--border-strong);
  font-size: 13.5px;
  color: var(--ink-muted);
  padding: 11px 15px;
}

/* Rich Editorial Typography */
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 {
  font-family: var(--font-serif);
  margin: 12px 0 6px;
  line-height: 1.3;
  color: var(--ink);
}
.msg-body h1:first-child, .msg-body h2:first-child, .msg-body h3:first-child, .msg-body h4:first-child { margin-top: 0; }
.msg-body h1 { font-size: 20px; }
.msg-body h2 { font-size: 18px; }
.msg-body h3 { font-size: 16px; }
.msg-body h4 { font-size: 15px; }
.msg-body p { margin: 0 0 9px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 4px 0 10px; padding-left: 20px; }
.msg-body li { margin-bottom: 4px; }
.msg-body blockquote {
  margin: 10px 0;
  padding: 9px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-paper);
  border-radius: 0 12px 12px 0;
  color: #4D4037;
}
.msg-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg-body code {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 13px;
}
.msg-body pre {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  overflow-x: auto;
  font-size: 13px;
}
.msg-body pre code { border: none; padding: 0; background: none; }
.msg-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.msg-body th, .msg-body td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
}
.msg-body th { background: var(--bg-paper); font-weight: 600; }

/* Color Palette Swatches */
.palette-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.swatch-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 10px 5px 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink);
  transition: transform 0.12s;
}
.swatch-chip:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.swatch-color {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1px solid rgba(47, 38, 32, 0.14);
}

/* Attachments */
.msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.att-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.att-photo-grid.single { grid-template-columns: minmax(180px, 340px); }
.att-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 13px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--bg-paper);
}
.att-photo-grid.single .att-photo { aspect-ratio: auto; min-height: 120px; max-height: 360px; object-fit: contain; }

.att-file-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 14px;
}
.att-file-info { display: flex; align-items: center; gap: 11px; min-width: 0; }
.att-file-badge {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.att-file-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file-size { font-size: 12px; color: var(--ink-light); }
.att-file-actions { display: flex; gap: 6px; flex-shrink: 0; }

.att-video-card {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
  max-width: 340px;
}
.att-video-card video {
  width: 100%;
  max-height: 460px;
  border-radius: 11px;
  background: #1a1715;
  display: block;
}
.att-video-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 0 2px;
}

.att-audio-card {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}
.att-audio-card audio { width: 100%; margin-top: 6px; height: 36px; }

.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(232, 221, 208, 0.7);
}

/* Quick Chips & Typing */
.quick-chips {
  max-width: 820px;
  margin: 14px auto 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.quick-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  font-size: 13.5px;
  text-align: left;
  box-shadow: var(--shadow-card);
  transition: border-color 0.15s, background 0.15s;
}
.quick-chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.typing-card {
  max-width: 820px;
  margin: 12px auto 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  width: fit-content;
  font-size: 13.5px;
  color: var(--ink-muted);
  box-shadow: var(--shadow-card);
}
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }

/* Composer */
.composer-wrap {
  padding: 8px 20px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg-paper) 78%, rgba(250, 245, 238, 0));
  flex-shrink: 0;
}
.composer-wrap > * { max-width: 820px; margin-left: auto; margin-right: auto; }

.pending-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.pending-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 10px 5px 6px;
  font-size: 12.5px;
}
.pending-chip img { width: 28px; height: 28px; border-radius: 7px; object-fit: cover; }
.pending-chip button { border: none; background: none; color: var(--ink-light); font-size: 16px; padding: 4px 6px; }
.pending-chip button:hover { color: var(--danger); }

.upload-progress {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 9px 13px;
  margin-bottom: 8px;
}
.upload-progress-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-muted); margin-bottom: 6px; }
.upload-progress-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.upload-bar-track { height: 6px; background: var(--bg-soft); border-radius: 999px; overflow: hidden; }
.upload-bar-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s; }

.voice-recording-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--accent-soft);
  border: 1px solid #E7C3AE;
  border-radius: 16px;
  padding: 9px 14px;
  margin-bottom: 8px;
  font-size: 13.5px;
}
.voice-rec-left { display: flex; align-items: center; gap: 9px; }
.rec-pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.voice-rec-actions { display: flex; gap: 7px; flex-shrink: 0; }

.composer-pill {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 26px;
  padding: 6px 7px 6px 9px;
  box-shadow: var(--shadow-float);
}
.composer-pill:focus-within { border-color: var(--accent); }
.composer-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.14s, color 0.14s;
}
.composer-icon-btn:hover { background: var(--bg-soft); color: var(--ink); }
.composer-icon-btn.recording { background: var(--danger); color: #fff; }
.composer-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.42;
  color: var(--ink);
  padding: 8px 4px;
  max-height: 150px;
  min-height: 40px;
}
.composer-input::placeholder { color: var(--ink-light); }
.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.14s, transform 0.1s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.45; cursor: default; }

/* --- Calendar & Materials --- */
.pane-scroll { flex: 1; overflow-y: auto; padding: 20px 22px 30px; -webkit-overflow-scrolling: touch; }
.pane-inner { max-width: 980px; margin: 0 auto; }
.pane-title { margin: 0; font-size: 24px; }
.pane-sub { margin: 4px 0 0; font-size: 13.5px; color: var(--ink-muted); }

.cal-header-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
}
.reminder-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toggle-wrap { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; cursor: pointer; }
.time-input, .select-input, .text-input {
  border: 1px solid var(--border-strong);
  background: var(--bg-paper);
  color: var(--ink);
  border-radius: 11px;
  padding: 7px 11px;
  font-family: inherit;
  font-size: 15px;
}

.cal-focus-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.focus-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}
.focus-card.today { border-color: var(--accent); background: linear-gradient(135deg, #FFFFFF 0%, #FDF6F0 100%); }
.focus-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); margin-bottom: 8px; }
.focus-card:not(.today) .focus-label { color: var(--sage); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 11px;
}
.cal-day-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  box-shadow: var(--shadow-card);
}
.cal-day-card.today { border: 1.5px solid var(--accent); background: #FFFBF7; }
.cal-day-card.empty-day { opacity: 0.68; }
.cal-day-card.out-of-month { opacity: 0.52; border-style: dashed; }
.cal-day-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cal-day-num { font-family: var(--font-serif); font-size: 19px; font-weight: 700; }
.cal-today-tag { background: var(--accent); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.cal-shift-tag { background: var(--bg-soft); color: var(--ink-muted); font-size: 11px; padding: 2px 7px; border-radius: 8px; }
.cal-line { font-size: 12.5px; line-height: 1.4; }
.cal-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; margin-right: 5px; }
.cal-tag.pub { background: var(--accent-soft); color: var(--accent); }
.cal-tag.don { background: var(--sage-soft); color: #4A6950; }
.cal-tag.con { background: #EFE8F6; color: #6B4D8A; }

/* Materials */
.mat-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.mat-filters { display: flex; flex-wrap: wrap; gap: 7px; }
.filter-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
}
.filter-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.materials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.mat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 17px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
}
.mat-preview {
  position: relative;
  height: 168px;
  background: var(--bg-paper);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}
.mat-preview img, .mat-preview video { width: 100%; height: 100%; object-fit: cover; }
.mat-play-overlay {
  position: absolute;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(47, 38, 32, 0.72);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}
.mat-preview-badge { font-family: var(--font-serif); font-size: 26px; color: var(--accent); }
.mat-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.mat-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mat-meta { font-size: 12px; color: var(--ink-light); }
.mat-actions { display: flex; gap: 7px; margin-top: auto; padding-top: 6px; }

.empty-state {
  grid-column: 1 / -1;
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: 20px;
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-muted);
}

/* Modals & Toast */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 24, 19, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.lightbox-inner {
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lightbox-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #fff;
}
.lightbox-caption { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox-top-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.lightbox-inner img, .lightbox-inner video {
  max-width: 92vw;
  max-height: 78vh;
  border-radius: 14px;
  background: #1a1715;
}
.lightbox-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 17px;
  box-shadow: var(--shadow-float);
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px 22px;
  box-shadow: var(--shadow-float);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 20px; }
.access-section { margin-bottom: 18px; }
.access-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.access-row .text-input { flex: 1; min-width: 140px; }
.generated-code-box {
  margin-top: 12px;
  padding: 13px 15px;
  background: var(--bg-paper);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  font-size: 14px;
}
.section-label { margin: 0 0 8px; font-size: 13px; color: var(--ink-muted); }
.sessions-list { display: flex; flex-direction: column; gap: 7px; }
.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
}
.session-row.revoked { opacity: 0.55; }
.this-device-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  background: var(--sage-soft);
  color: #4A6950;
  padding: 1px 7px;
  border-radius: 8px;
}

.toast {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  box-shadow: var(--shadow-float);
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 24, 19, 0.36);
  z-index: 35;
}

.mobile-only { display: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.75); opacity: 0.45; }
  40% { transform: scale(1.1); opacity: 1; }
}

@media (max-width: 840px) {
  .mobile-only { display: inline-flex; }
  .topic-pills.mobile-only { display: flex; }
  .mobile-view-bar.mobile-only { display: flex; }
  .view-tabs { display: none; }

  .icon-btn, .composer-icon-btn, .send-btn { width: 44px; height: 44px; }
  .time-input, .select-input, .text-input { font-size: 16px; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 288px;
    max-width: 86vw;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-float);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; min-height: 56px; }
  .topbar-title { font-size: 17px; }
  .messages-scroll { padding: 14px 12px 10px; }
  .msg-row.user .msg-bubble { max-width: 88%; }
  .msg-bubble { padding: 13px 14px; }
  .composer-wrap { padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  .pane-scroll { padding: 14px 12px 24px; }
  .cal-header-card { padding: 14px; }
}
