:root {
  --app-bg: #f3f5f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #111827;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --brand: #0f172a;
  --brand-soft: #1e293b;
  --accent: #0ea5e9;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body.app-body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1300px 500px at 20% -20%, rgba(14, 165, 233, 0.08), transparent 60%),
    radial-gradient(1200px 600px at 100% -10%, rgba(15, 23, 42, 0.08), transparent 70%),
    var(--app-bg);
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
}

.app-sidebar {
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-soft) 100%);
  color: #e2e8f0;
  border-right: 1px solid rgba(148, 163, 184, 0.2);
}

.app-sidebar a,
.app-sidebar button {
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: 0.75rem;
  color: #cbd5e1;
  padding: 0.6rem 0.75rem;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
}

.app-nav-link:hover {
  background: rgba(148, 163, 184, 0.12);
  color: #f8fafc;
}

.app-nav-link.active {
  background: rgba(14, 165, 233, 0.22);
  color: #e0f2fe;
}

.app-main {
  min-height: 100vh;
}

.app-topbar {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.page-frame {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.25rem;
}

.card-surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow-sm);
}

.card-surface-elevated {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow-md);
}

.section-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #0b1220;
  line-height: 1.2;
}

.section-subtitle {
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.btn-primary {
  background: #0284c7;
  color: white;
  border: 1px solid #0284c7;
  border-radius: 0.75rem;
  padding: 0.56rem 0.95rem;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-primary:hover {
  background: #0369a1;
  border-color: #0369a1;
}

.btn-secondary {
  background: #fff;
  color: #0f172a;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.56rem 0.95rem;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-secondary:hover {
  background: #f8fafc;
}

.badge-soft {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #0f172a;
  background: #f8fafc;
}

.metric-value {
  font-size: 1.7rem;
  line-height: 1.1;
  font-weight: 700;
  color: #0f172a;
}

.metric-label {
  color: var(--text-muted);
  font-size: 0.79rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.notice-banner {
  border-radius: 0.9rem;
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #14532d;
  padding: 0.75rem 1rem;
}

.alert-banner {
  border-radius: 0.9rem;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #991b1b;
  padding: 0.75rem 1rem;
}

.chat-scroll {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.chat-scroll::-webkit-scrollbar {
  width: 8px;
}

.chat-scroll::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.chat-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.messages-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 5rem;
}

.chat-empty-state {
  width: min(560px, 100%);
  border: 1px dashed #c7d2fe;
  border-radius: 1.1rem;
  background:
    linear-gradient(160deg, rgba(56, 189, 248, 0.08), rgba(15, 23, 42, 0.03)),
    #f8fafc;
  padding: 1.4rem 1.2rem;
  text-align: center;
}

.chat-empty-icon {
  width: 2rem;
  height: 2rem;
  margin: 0 auto 0.65rem;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-empty-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
}

.chat-empty-copy {
  margin: 0.35rem 0 0;
  color: #475569;
  font-size: 0.87rem;
}

.chat-empty-prompts {
  margin-top: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
}

.chat-empty-prompt {
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 0.24rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #334155;
  background: #ffffff;
  transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.chat-empty-prompt:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.chat-empty-prompt:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}

.floating-composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(243, 245, 249, 0), var(--app-bg) 22%, var(--app-bg) 100%);
  padding-top: 0.75rem;
  backdrop-filter: blur(2px);
}

.voice-state {
  font-size: 0.74rem;
  color: #475569;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.voice-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: #94a3b8;
}

.voice-dot.recording {
  background: #dc2626;
  animation: pulseDot 0.9s ease-in-out infinite alternate;
}

.voice-fallback {
  border: 1px solid #fbcfe8;
  border-radius: 0.85rem;
  background: #fff1f2;
  padding: 0.6rem 0.75rem;
}

.voice-fallback-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: #9f1239;
}

.voice-fallback-copy {
  margin: 0.2rem 0 0;
  font-size: 0.74rem;
  color: #9f1239;
}

.chat-model-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.chat-model-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #64748b;
}

.chat-model-select {
  min-width: 13.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.62rem;
  background: #fff;
  color: #0f172a;
  font-size: 0.74rem;
  padding: 0.28rem 0.5rem;
}

.chat-model-select:disabled {
  opacity: 0.65;
}

.chat-capabilities {
  border: 1px solid #dbeafe;
  border-radius: 0.85rem;
  background: #f8fbff;
  padding: 0.55rem 0.7rem;
}

.chat-capabilities > summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  color: #0c4a6e;
  list-style: none;
}

.chat-capabilities > summary::-webkit-details-marker {
  display: none;
}

.chat-capabilities-body {
  margin-top: 0.45rem;
}

.chat-capabilities-intro {
  margin: 0;
  font-size: 0.73rem;
  color: #334155;
}

.chat-capability-list {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.45rem;
}

.chat-capability-item {
  border: 1px solid #dbeafe;
  border-radius: 0.7rem;
  background: #ffffff;
  padding: 0.45rem 0.55rem;
}

.chat-capability-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.chat-capability-title {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 600;
  color: #0f172a;
}

.chat-capability-detail {
  margin: 0.32rem 0 0;
  font-size: 0.71rem;
  color: #334155;
}

.chat-capability-link {
  margin-top: 0.3rem;
  display: inline-flex;
  font-size: 0.7rem;
  font-weight: 600;
  color: #0369a1;
  text-decoration: none;
}

.chat-capability-link:hover {
  text-decoration: underline;
}

@keyframes pulseDot {
  from {
    transform: scale(0.85);
    opacity: 0.7;
  }
  to {
    transform: scale(1.1);
    opacity: 1;
  }
}

.status-pill {
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.status-success {
  color: #065f46;
  background: #d1fae5;
}

.status-warning {
  color: #92400e;
  background: #fef3c7;
}

.status-error {
  color: #991b1b;
  background: #fee2e2;
}

.status-neutral {
  color: #334155;
  background: #e2e8f0;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

@media (max-width: 1023px) {
  .page-frame {
    padding: 1rem;
  }
}

/* Chat premium upgrade */
#chat-container {
  overflow-x: hidden;
}

#messages-container {
  overflow-x: hidden;
}

.chat-scroll {
  overflow-x: hidden;
}

.chat-message {
  display: flex;
  align-items: flex-start;
  gap: 0.68rem;
  margin-bottom: 0.8rem;
  min-width: 0;
  animation: chatMessageIn 180ms ease-out;
}

.chat-message--user {
  justify-content: flex-end;
}

.chat-message-avatar {
  margin-top: 0.1rem;
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-message-avatar--assistant {
  background: #eef2ff;
  color: #475569;
}

.chat-message-avatar--user {
  background: #cbd5e1;
  color: #475569;
}

.chat-message-bubble {
  min-width: 0;
  border-radius: 1rem;
  padding: 0.82rem 0.95rem;
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
}

.chat-message-bubble--user {
  max-width: min(58%, 38rem);
  background: linear-gradient(180deg, #0ea5e9, #0284c7);
  color: #fff;
}

.chat-message-bubble--assistant {
  max-width: min(70%, 44rem);
  background: #fff;
  color: #1e293b;
  border-color: #e2e8f0;
}

.chat-message-bubble--error {
  border-color: #fecaca;
  background: linear-gradient(180deg, #fff7f7 0%, #fff1f2 100%);
  color: #991b1b;
}

.chat-error-topline {
  margin-bottom: 0.35rem;
  color: #dc2626;
  font-weight: 700;
  line-height: 1;
}

.chat-error-icon {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 999px;
  border: 1px solid #fecaca;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  background: #ffe4e6;
}

.chat-message-footer {
  margin-top: 0.42rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

.chat-message-meta {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.2;
}

.chat-message-meta--user {
  color: #dbeafe;
}

.chat-message-meta--assistant {
  color: #94a3b8;
}

.chat-meta-badge {
  margin-left: 0.35rem;
  border: 1px solid #dbeafe;
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  font-size: 0.67rem;
  font-weight: 600;
  color: #0c4a6e;
  background: #eff6ff;
  display: inline-flex;
  align-items: center;
}

.chat-meta-link {
  margin-left: 0.35rem;
  font-size: 0.67rem;
  font-weight: 600;
  color: #0369a1;
  text-decoration: none;
}

.chat-meta-link:hover {
  text-decoration: underline;
}

.chat-error-label {
  margin-left: 0.38rem;
  color: #fca5a5;
  font-weight: 600;
}

.chat-retry-button {
  border: 1px solid #fecaca;
  background: #fff;
  color: #b91c1c;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.1;
  transition: background-color 0.16s ease, color 0.16s ease, opacity 0.16s ease;
}

.chat-retry-button:hover {
  background: #fee2e2;
}

.chat-retry-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.chat-retry-button.is-loading {
  opacity: 0.75;
}

.chat-retry-button.hidden {
  display: none;
}

.chat-error-hint {
  margin: 0.45rem 0 0;
  font-size: 0.73rem;
  color: #be123c;
}

.message-content {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.floating-composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(243, 245, 249, 0) 0%, rgba(243, 245, 249, 0.9) 24%, #f3f5f9 100%);
  padding-top: 0.72rem;
  backdrop-filter: blur(7px);
}

.chat-composer-shell {
  border: 1px solid #e2e8f0;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 0.9rem;
  padding: 0.6rem;
}

.chat-connection-banner {
  margin-bottom: 0.6rem;
  border: 1px solid #f59e0b;
  background: #fffbeb;
  color: #92400e;
  border-radius: 0.75rem;
  padding: 0.45rem 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  line-height: 1.3;
}

.chat-connection-banner.hidden {
  display: none;
}

.chat-connection-banner p {
  margin: 0;
}

.chat-connection-reconnect {
  border: 1px solid #d97706;
  background: #fff;
  color: #b45309;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.chat-connection-reconnect:hover {
  background: #fef3c7;
}

.chat-connection-reconnect.hidden {
  display: none;
}

.chat-connection-reconnect:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.chat-task-hint {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  color: #475569;
}

.chat-task-mode-active {
  border-color: #0ea5e9;
  background: #e0f2fe;
  color: #0c4a6e;
}

.chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
}

.chat-quick-action {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #334155;
  border-radius: 999px;
  padding: 0.2rem 0.58rem;
  font-size: 0.7rem;
  font-weight: 600;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chat-quick-action:hover {
  background: #f8fafc;
  border-color: #93c5fd;
}

.chat-composer-input {
  min-height: 2.6rem;
  max-height: 10rem;
  padding-right: 2.1rem;
  resize: none;
  line-height: 1.42;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.chat-composer-input:focus {
  outline: none;
}

.chat-composer-input:focus-visible {
  border-color: #38bdf8;
  outline: 2px solid rgba(56, 189, 248, 0.35);
  outline-offset: 0;
  box-shadow: none;
}

.chat-send-button {
  min-width: 3rem;
  min-height: 2.35rem;
}

.chat-send-button.is-disabled,
.chat-send-button:disabled {
  opacity: 0.58;
}

.chat-send-button.is-sending {
  cursor: wait;
}

.chat-voice-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.chat-voice-compact-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: #475569;
}

.chat-voice-compact-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.chat-voice-menu-wrap {
  position: relative;
}

.chat-voice-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 10;
  min-width: 14rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.85rem;
  padding: 0.4rem;
  background: #fff;
  box-shadow: var(--shadow-md);
  display: grid;
  gap: 0.35rem;
}

.chat-voice-menu .btn-secondary {
  width: 100%;
  justify-content: flex-start;
  border-radius: 0.62rem;
  white-space: nowrap;
  padding-left: 0.7rem;
  padding-right: 0.7rem;
  line-height: 1.25;
}

.chat-message--typing .chat-message-bubble,
.chat-message--streaming .chat-message-bubble {
  max-width: min(74%, 50rem);
}

.conversation-pagination-meta {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  color: #64748b;
}

.conversation-pagination .pagination {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.conversation-pagination .pagination a,
.conversation-pagination .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.65rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.55rem;
  padding: 0.1rem 0.5rem;
  font-size: 0.72rem;
  color: #334155;
  text-decoration: none;
}

.conversation-pagination .pagination .current {
  border-color: #38bdf8;
  background: #e0f2fe;
  color: #0c4a6e;
  font-weight: 700;
}

.conversation-pagination .pagination .disabled {
  opacity: 0.55;
}

@keyframes chatMessageIn {
  from {
    transform: translateY(6px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 640px) {
  #messages-container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .chat-message {
    gap: 0.48rem;
    margin-bottom: 0.66rem;
  }

  .chat-message-avatar {
    width: 1.7rem;
    height: 1.7rem;
  }

  .chat-message-bubble--user {
    max-width: 88%;
  }

  .chat-message-bubble--assistant,
  .chat-message--typing .chat-message-bubble,
  .chat-message--streaming .chat-message-bubble {
    max-width: 92%;
  }

  .chat-message-bubble {
    padding: 0.7rem 0.8rem;
    border-radius: 0.86rem;
  }

  .floating-composer {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    padding-bottom: 0.75rem;
  }

  .chat-composer-shell {
    border-radius: 0.8rem;
    padding: 0.5rem;
  }

  .chat-voice-compact {
    align-items: stretch;
  }

  .chat-voice-compact-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-connection-banner {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-voice-menu {
    left: 0;
    right: auto;
    min-width: min(16rem, calc(100vw - 2.2rem));
  }

  .chat-model-picker {
    width: 100%;
    justify-content: space-between;
  }

  .chat-model-select {
    min-width: 0;
    width: 100%;
  }

  .chat-capability-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-quick-actions {
    gap: 0.35rem;
  }

  .chat-quick-action {
    font-size: 0.68rem;
  }
}
