/* The page hides screens with the hidden attribute; make it win over display:flex rules (19 Oct fix). */
[hidden] { display: none !important; }

:root {
  --color-primary: #2e7d32;
  --color-primary-light: #4caf50;
  --color-primary-dark: #1b5e20;
  --color-primary-bg: #e8f5e9;
  --color-amber: #ff8f00;
  --color-amber-bg: #fff3e0;
  --color-red: #c62828;
  --color-red-bg: #fbe9e7;
  --color-text: #212121;
  --color-text-muted: #757575;
  --color-border: #e0e0e0;
  --color-bg: #ffffff;
  --color-sidebar-bg: #fafafa;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition: 150ms ease;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --header-height: 56px;
  --sidebar-width: 280px;
}

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

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Login Screen */
.login-header {
  padding: 24px;
  text-align: center;
  border-bottom: 1px solid var(--color-border);
}

.login-header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--color-primary);
}

.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
}

#login-form {
  width: 100%;
  max-width: 360px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-sidebar-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-border);
}

.btn-danger {
  background: var(--color-red-bg);
  color: var(--color-red);
}

.btn-danger:hover:not(:disabled) {
  background: #fce4ec;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--transition);
}

.icon-btn:hover:not(:disabled) {
  background: var(--color-border);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.error-message {
  margin-top: 16px;
  padding: 12px;
  background: var(--color-red-bg);
  color: var(--color-red);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  text-align: center;
}

/* App Screen */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-primary);
}

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 300px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.bots-nav {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bot-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition);
}

.bot-item:hover {
  background: var(--color-border);
}

.bot-item.active {
  background: var(--color-primary-bg);
}

.bot-item:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.bot-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  color: white;
  flex-shrink: 0;
}

.bot-info {
  flex: 1;
  min-width: 0;
}

.bot-name {
  display: block;
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bot-title {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Chat View */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.chat-bot-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.chat-bot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  color: white;
  flex-shrink: 0;
}

.chat-bot-name {
  display: block;
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-bot-title {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.chats-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--color-sidebar-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition);
}

.chat-item:hover {
  background: var(--color-border);
}

.chat-item.active {
  border-color: var(--color-primary);
  background: var(--color-primary-bg);
}

.chat-item:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.chat-item-title {
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 150ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--color-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--color-sidebar-bg);
  color: var(--color-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--color-border);
}

.message-bubble p {
  margin: 0.5em 0;
}

.message-bubble p:first-child {
  margin-top: 0;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul, .message-bubble ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.message-bubble li {
  margin: 0.25em 0;
}

.message-bubble strong {
  font-weight: 600;
}

.message-bubble .chat-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin-top: 8px;
  border-radius: 8px;
}

.message-time {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message.thinking .message-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: bounce 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Chat Input */
.chat-input-form {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

#chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 14px;
  font-size: 0.9375rem;
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-sidebar-bg);
  color: var(--color-text);
  resize: none;
  line-height: 1.5;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#chat-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-bg);
  background: var(--color-bg);
}

#chat-input::placeholder {
  color: var(--color-text-muted);
}

/* Settings View */
#settings-view {
  padding: 24px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

#settings-view h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 24px;
}

.settings-section {
  margin-bottom: 32px;
}

.settings-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
}

.account-info {
  padding: 16px;
  background: var(--color-sidebar-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.account-info p {
  margin: 4px 0;
  font-size: 0.9375rem;
}

.account-info strong {
  color: var(--color-text);
}

.coming-soon {
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

/* Mobile adjustments */
@media (max-width: 640px) {
  :root {
    --sidebar-width: 100%;
  }

  .header-center {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 250ms ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .chat-header {
    position: sticky;
    top: 0;
    z-index: 5;
  }

  #chat-bots-btn {
    display: inline-flex !important;
  }

  .app-title {
    display: none;
  }
}

@media (min-width: 641px) {
  #chat-bots-btn {
    display: none !important;
  }

  #sidebar-toggle {
    display: none;
  }
}

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

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --color-border: #000;
    --color-text-muted: #333;
  }
}

/* Media Library */
.media-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.media-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text);
}

.media-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.media-tab {
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-sidebar-bg);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition);
}

.media-tab:hover:not(:disabled) {
  background: var(--color-border);
}

.media-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.media-tab:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.media-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.media-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--color-text-muted);
  padding: 48px 16px;
  font-size: 0.9375rem;
}

.media-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition), border-color var(--transition);
}

.media-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary-light);
}

.media-preview-wrapper {
  position: relative;
  aspect-ratio: 1;
  background: var(--color-sidebar-bg);
  overflow: hidden;
}

.media-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-status {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  font-size: 0.6875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.7);
  color: white;
}

.media-status.status-ready {
  background: rgba(46, 125, 50, 0.9);
}

.media-status.status-pending {
  background: rgba(255, 143, 0, 0.9);
}

.media-status.status-failed {
  background: rgba(198, 40, 40, 0.9);
}

.media-info {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.media-prompt {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.media-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.6875rem;
  color: var(--color-text-muted);
}

.media-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 4px;
}

.media-actions .btn {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  font-size: 0.75rem;
}

.media-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  flex-shrink: 0;
}

.media-page-info {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  min-width: 80px;
  text-align: center;
}

.media-error {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--color-red);
  padding: 48px 16px;
  font-size: 0.9375rem;
}

/* Focus visible polyfill */
:focus:not(:focus-visible) {
  outline: none;
}
/* ===== Amara brand (light green theme) ===== */
:root {
  --brand-green: oklch(0.68 0.16 155);
  --brand-blue: oklch(0.64 0.16 250);
  --color-primary: oklch(0.56 0.15 155);
  --color-primary-light: oklch(0.68 0.16 155);
  --color-primary-dark: oklch(0.47 0.13 155);
  --color-primary-bg: oklch(0.955 0.025 170);
  --color-text: oklch(0.235 0.03 240);
  --color-text-muted: oklch(0.5 0.03 240);
  --color-border: oklch(0.915 0.012 175);
  --color-bg: oklch(0.985 0.006 165);
  --color-sidebar-bg: oklch(0.975 0.012 170);
  --radius-md: 0.6rem;
  --radius-lg: 0.85rem;
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
body { background: var(--color-bg); color: var(--color-text); }

.brand-mark { display: inline-flex; align-items: center; gap: 0.5rem; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark .brand-logo {
  width: 32px; height: 32px; border-radius: 0.5rem; overflow: hidden; background: #fff; flex-shrink: 0;
  box-shadow: 0 0 0 1.5px color-mix(in oklch, var(--brand-green) 55%, var(--brand-blue));
  animation: brand-bob 4s ease-in-out infinite;
}
.brand-mark .brand-logo img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.1); }
.brand-mark .brand-a { background: linear-gradient(135deg, var(--brand-blue), var(--brand-green)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-mark .brand-beta { border: 1px solid color-mix(in oklch, var(--color-primary) 25%, transparent); color: var(--color-primary); border-radius: 999px; padding: 2px 6px; font-size: 10px; font-weight: 600; line-height: 1; }
.brand-mark .brand-for { color: var(--color-text-muted); font-weight: 500; font-size: 0.9em; }
.brand-mark.brand-lg { font-size: 1.75rem; }
.brand-mark.brand-lg .brand-logo { width: 56px; height: 56px; border-radius: 0.85rem; }
.login-tagline { color: var(--color-text-muted); margin-top: 0.25rem; text-align: center; }
@keyframes brand-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .brand-mark .brand-logo { animation: none; } }

.bot-avatar.mascot { background: #fff !important; padding: 0; overflow: hidden; box-shadow: 0 0 0 1.5px color-mix(in oklch, var(--brand-green) 45%, var(--brand-blue)); }
.bot-avatar.mascot img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.1); display: block; }
/* Yes/No approval cards */
.message.approval { max-width: 100%; }
.approval-card { background: var(--color-sidebar-bg); border: 1px solid var(--color-border); border-left: 4px solid var(--color-amber); border-radius: var(--radius-md); padding: 16px; width: 100%; }
.approval-card.risk-big { border-left-color: var(--color-red); }
.approval-card.risk-read { border-left-color: var(--color-primary); }
.approval-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 0.75rem; }
.approval-risk { color: white; padding: 2px 8px; border-radius: var(--radius-sm); font-weight: 500; background: var(--color-amber); }
.approval-risk.risk-big { background: var(--color-red); }
.approval-risk.risk-read { background: var(--color-primary); }
.approval-id { color: var(--color-text-muted); }
.approval-summary { margin: 0 0 12px 0; font-size: 0.9375rem; }
.approval-actions { display: flex; gap: 8px; justify-content: flex-end; }
.approval-state { margin: 0; font-weight: 600; }
.approval-result { margin: 6px 0 0 0; font-size: 0.875rem; color: var(--color-text-muted); white-space: pre-wrap; word-break: break-word; }

/* Settings -> Scheduled */
.scheduled-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.scheduled-main { min-width: 0; }
.scheduled-summary { margin: 0 0 4px 0; font-size: 0.9375rem; word-break: break-word; }
.scheduled-meta, .scheduled-result { margin: 0; font-size: 0.8125rem; color: var(--color-text-muted); }
.scheduled-item.status-cancelled .scheduled-summary { text-decoration: line-through; }
.scheduled-item.status-failed .scheduled-status { color: var(--color-red); }
/* Help page */
.help-btn { width: auto; gap: 6px; display: inline-flex; align-items: center; padding: 0 10px; }
.help-btn-label { font-size: 0.875rem; font-weight: 500; }
.help-view { max-width: 760px; margin: 0 auto; padding: 16px; overflow-y: auto; }
.help-card { background: var(--color-sidebar-bg); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 16px; margin-bottom: 16px; }
.help-card h3 { margin: 0 0 8px 0; color: var(--color-primary-dark); }
.help-card p { margin: 0 0 8px 0; }
.help-card ul, .help-card ol { margin: 0 0 8px 0; padding-left: 20px; }
.help-card li { margin-bottom: 6px; }
.help-video-wrap { position: relative; width: 100%; }
.help-video-wrap video { width: 100%; max-height: 60vh; border-radius: var(--radius-md); background: #000; display: block; }
.help-video-fallback { padding: 32px 16px; text-align: center; border-radius: var(--radius-md); background: var(--color-primary-bg); color: var(--color-primary-dark); font-weight: 500; }
.help-apps { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.help-app { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--color-border); }
.help-app-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.help-app-note { font-size: 0.8125rem; color: var(--color-text-muted); }
.help-badge { flex-shrink: 0; font-size: 0.75rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.help-badge.connected { background: var(--color-primary-bg); color: var(--color-primary-dark); }
.help-badge.not-connected { background: var(--color-amber-bg); color: var(--color-amber); }
.help-note { margin: 0 0 8px 0; color: var(--color-text-muted); }
@media (max-width: 640px) {
  .help-view { padding: 12px; }
  .help-btn-label { display: none; }
  .help-btn { padding: 0; width: 40px; justify-content: center; }
}
/* Settings -> Telegram */
.telegram-body input.tg-token { width: 100%; max-width: 420px; padding: 8px 10px; margin: 8px 8px 8px 0; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font: inherit; }
.tg-steps { margin: 0 0 8px 0; padding-left: 20px; }
.tg-code { font-size: 1.5rem; letter-spacing: 0.15em; }
.tg-error { margin: 8px 0 0 0; color: var(--color-red); }
/* Report a problem */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-box { background: var(--color-bg, #fff); border-radius: var(--radius-md); padding: 20px; width: 100%; max-width: 480px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); }
.modal-box h3 { margin: 0 0 12px 0; }
.modal-box label { display: block; font-weight: 500; margin-bottom: 6px; }
.modal-box textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font: inherit; resize: vertical; box-sizing: border-box; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.report-status { min-height: 1.2em; margin: 8px 0 0 0; }
.report-status.error { color: var(--color-red); }
.approval-report, .chat-report { margin-top: 8px; }
/* Phone app polish (390 px wide and up to 640): tap targets of at least 44 px, no sideways scroll, safe areas */
html, body { max-width: 100%; overflow-x: hidden; }
.message-bubble { overflow-wrap: anywhere; word-break: break-word; max-width: 100%; }
.message-bubble img, .message-bubble video, .media-preview { max-width: 100%; height: auto; }
.app-header { height: calc(var(--header-height) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
@media (max-width: 640px) { .sidebar { top: calc(var(--header-height) + env(safe-area-inset-top)); } }
.chat-input-form { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.sidebar { padding-bottom: env(safe-area-inset-bottom); }
.modal { padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); }
@media (max-width: 640px) {
  .icon-btn, .help-btn { min-width: 44px; min-height: 44px; }
  .btn, .media-tab, .bot-item, .chat-item { min-height: 44px; }
  .media-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .media-actions .btn { flex: 1 1 calc(50% - 8px); min-height: 44px; }
  .media-tab { padding-top: 10px; padding-bottom: 10px; }
  .chat-input-form textarea, .modal-box textarea, .telegram-body input.tg-token, input, select { font-size: 16px; } /* stops iPhone zooming into the box */
  .approval-actions .btn { flex: 1; }
  .chat-header { flex-wrap: wrap; gap: 8px; }
  .modal-actions .btn { flex: 1; }
}@media (max-width: 640px) {
  .brand-for { display: none; }
  .chat-bot-info { flex: 1 1 calc(100% - 64px); }
  #new-chat-btn, #report-btn { flex: 1 1 calc(50% - 8px); }
}