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

html {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  width: 100%;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow-x: hidden;
  transition: all 0.3s ease;
}

/* Sidebar */

.sidebar {
  width: 0;
  min-width: 0;
  overflow: hidden;
  background: #0d1b2a;
  border-right: 1px solid #1a4080;
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, min-width 0.3s ease;
}

.app-container.has-sidebar .sidebar {
  width: 280px;
  min-width: 280px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid #1a4080;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
}

#close-sidebar {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}

#close-sidebar:hover {
  background: #1a4080;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-section {
  margin-bottom: 4px;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #7a8a9e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
}

.sidebar-section-header:hover {
  color: #a0b0c0;
}

.sidebar-section-header .chevron {
  font-size: 0.65rem;
  transition: transform 0.2s ease;
}

.sidebar-section.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-section.collapsed .sidebar-section-items {
  display: none;
}

.sidebar-section-items {
  padding: 0;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 8px;
}

.chat-item:hover {
  background: #16213e;
}

.chat-item.active {
  background: #1a3a5c;
}

.chat-item-title {
  flex: 1;
  font-size: 0.85rem;
  color: #c0c8d4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item.active .chat-item-title {
  color: #fff;
}

.chat-item-actions {
  display: none;
  gap: 4px;
  align-items: center;
}

.chat-item:hover .chat-item-actions {
  display: flex;
}

.chat-item-actions button {
  padding: 2px 6px;
  border: none;
  background: transparent;
  color: #7a8a9e;
  cursor: pointer;
  font-size: 0.8rem;
  border-radius: 4px;
}

.chat-item-actions button:hover {
  background: #2a3a5e;
  color: #e0e0e0;
}

.chat-item-rename-input {
  flex: 1;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #4a90d9;
  background: #1a1a2e;
  color: #e0e0e0;
  font-size: 0.85rem;
  outline: none;
}

/* Chat container */

.chat-container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #16213e;
  overflow: hidden;
  transition: all 0.3s ease;
}

.app-container.has-sidebar .chat-container {
  max-width: none;
  margin: 0;
  flex: 1;
}

.app-container.has-artifact .chat-container {
  max-width: none;
  margin: 0;
  border-right: 1px solid #1a4080;
}

.app-container.has-artifact .chat-container {
  width: 40%;
  min-width: 360px;
}

.app-container.has-sidebar.has-artifact .chat-container {
  flex: none;
  width: 40%;
  min-width: 320px;
}

.app-container.has-artifact .artifact-panel {
  display: flex;
}

.app-container.artifact-fullwidth .chat-container {
  display: none;
}

.app-container.artifact-fullwidth .sidebar {
  display: none;
}

.app-container.artifact-fullwidth .artifact-panel {
  width: 100%;
}

/* Artifact panel */

.artifact-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.artifact-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #0f3460;
  border-bottom: 1px solid #1a4080;
}

.artifact-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.artifact-export-menu {
  position: relative;
}

#artifact-select {
  display: none;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: #1a1a2e;
  color: #e0e0e0;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#close-artifact {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

#close-artifact:hover {
  background: #1a4080;
}

#fullwidth-artifact {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

#fullwidth-artifact:hover {
  background: #1a4080;
}

#export-artifact {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

#export-artifact:hover {
  background: #1a4080;
}

.artifact-export-options {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: flex;
  flex-direction: column;
  min-width: 132px;
  padding: 6px;
  border: 1px solid #1a4080;
  border-radius: 10px;
  background: #12233c;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
  z-index: 10;
}

.artifact-export-options[hidden] {
  display: none;
}

.artifact-export-option {
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #e0e0e0;
  text-align: left;
  font-size: 0.85rem;
  cursor: pointer;
}

.artifact-export-option:hover {
  background: #1a4080;
}

.artifact-export-option:disabled,
#export-artifact:disabled {
  opacity: 0.65;
  cursor: wait;
}

.artifact-content {
  flex: 1;
  overflow: hidden;
}

.artifact-content iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

/* Chat header */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: #0f3460;
  border-bottom: 1px solid #1a4080;
  gap: 12px;
}

.chat-header > #toggle-sidebar-btn {
  order: -1;
}

.chat-header > #toggle-artifact-btn {
  order: 99;
  margin-left: auto;
}

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

.chat-header h1 {
  font-size: 1.2rem;
  color: #fff;
}

.toggle-sidebar-btn {
  display: none;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: #1a1a2e;
  color: #e0e0e0;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.2s;
}

.toggle-sidebar-btn.visible {
  display: inline-flex;
}

.toggle-sidebar-btn:hover {
  background: #2a3a5e;
}

#new-chat-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: #1a1a2e;
  color: #e0e0e0;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

#new-chat-btn:hover {
  background: #2a3a5e;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  min-width: 0;
}

.auth-user-email {
  font-size: 0.82rem;
  color: #a8bdd8;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-button {
  min-width: 32px;
  min-height: 32px;
}

.account-menu {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.account-menu-toggle {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #c7d8ee;
  font-size: 0.78rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.2s, border-color 0.2s;
}

.account-menu-toggle:hover,
.account-menu.open .account-menu-toggle {
  background: #1a4080;
  border-color: #4a90d9;
}

.account-menu-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: #102947;
  border: 1px solid #1a4080;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  z-index: 700;
}

.account-menu-dropdown[hidden] {
  display: none;
}

.account-menu-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px 10px;
  border-radius: 10px;
  background: rgba(74, 144, 217, 0.08);
  border: 1px solid rgba(74, 144, 217, 0.18);
}

.account-menu-label {
  font-size: 0.74rem;
  color: #9fb8d9;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.header-link {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #c7d8ee;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s, border-color 0.2s;
}

.header-link:hover {
  background: rgba(74, 144, 217, 0.16);
  border-color: rgba(74, 144, 217, 0.45);
}

.header-link[hidden] {
  display: none;
}

.provider-menu-section select {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: #1a1a2e;
  color: #e0e0e0;
  font-size: 0.85rem;
  cursor: pointer;
  width: 100%;
}

.model-label {
  font-size: 0.72rem;
  color: #8ca5c5;
  font-style: italic;
}

/* Context bar */

.context-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 24px;
  background: #0d1b2a;
  border-bottom: 1px solid #1a4080;
}

.context-label {
  font-size: 0.75rem;
  color: #7a8a9e;
  white-space: nowrap;
}

.context-track {
  flex: 1;
  height: 6px;
  background: #1a2744;
  border-radius: 3px;
  overflow: hidden;
}

.context-fill {
  height: 100%;
  width: 0%;
  background: #4a90d9;
  border-radius: 3px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.context-fill.warning {
  background: #e94560;
}

.context-text {
  font-size: 0.75rem;
  color: #7a8a9e;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

.context-text.warning {
  color: #e94560;
}

.deployment-banner {
  display: none;
  padding: 10px 24px;
  border-bottom: 1px solid #6b5620;
  background: #2f2612;
  color: #f6ddb0;
  font-size: 0.85rem;
  line-height: 1.4;
}

.deployment-banner.visible {
  display: block;
}

.app-notice {
  display: none;
  padding: 10px 24px;
  border-bottom: 1px solid #8f3648;
  background: #40141f;
  color: #ffd7dd;
  font-size: 0.85rem;
  line-height: 1.4;
}

.app-notice.visible {
  display: block;
}

/* Chat messages */

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-shell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 85%;
}

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

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

.message-shell.error {
  align-self: center;
  align-items: center;
  max-width: 100%;
}

.message {
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: #0f3460;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.user.queued {
  background: #164167;
  border: 1px dashed #78b7ff;
}

.message.assistant {
  align-self: flex-start;
  background: #1a2744;
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
  white-space: normal;
}

.message.assistant p {
  margin: 0 0 8px 0;
}

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

.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
  margin: 12px 0 6px 0;
  color: #fff;
}

.message.assistant h1 { font-size: 1.2rem; }
.message.assistant h2 { font-size: 1.05rem; }
.message.assistant h3 { font-size: 0.95rem; }

.message.assistant ul,
.message.assistant ol {
  margin: 4px 0 8px 20px;
}

.message.assistant li {
  margin-bottom: 4px;
}

.message.assistant code {
  background: #0f1a2e;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
}

.message.assistant .assistant-code-block {
  margin: 10px 0;
  border: 1px solid #2a3a5e;
  border-radius: 10px;
  overflow: hidden;
  background: #0b1220;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.message.assistant .assistant-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #101a30;
  border-bottom: 1px solid #23314f;
}

.message.assistant .assistant-code-language {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8fb5ff;
}

.message.assistant pre {
  background: #0b1220;
  padding: 12px;
  border-radius: 0;
  overflow-x: auto;
  margin: 0;
  border: 0;
}

.message.assistant pre code {
  background: none;
  padding: 0;
  display: block;
  font-size: 0.84rem;
  line-height: 1.55;
}

.message.assistant table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
  font-size: 0.85rem;
}

.message.assistant th,
.message.assistant td {
  border: 1px solid #2a3a5e;
  padding: 6px 10px;
  text-align: left;
}

.message.assistant th {
  background: #0f1a2e;
  color: #fff;
}

.message.assistant blockquote {
  border-left: 3px solid #4a90d9;
  padding-left: 12px;
  margin: 8px 0;
  color: #a0b0c0;
}

.message.assistant a {
  color: #4a90d9;
  text-decoration: none;
}

.message.assistant a:hover {
  text-decoration: underline;
}

.message.assistant hr {
  border: none;
  border-top: 1px solid #2a3a5e;
  margin: 12px 0;
}

.message.assistant strong {
  color: #fff;
}

.message.error {
  background: #4a1c1c;
  color: #ff6b6b;
  font-size: 0.85rem;
}

.message-status {
  margin-top: 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.user-message-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.message-shell.user:hover .user-message-actions,
.message-shell.user:focus-within .user-message-actions {
  opacity: 1;
}

.user-message-action {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #7f93ad;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
}

.user-message-action:hover:not(:disabled),
.user-message-action:focus-visible {
  background: #1a2744;
  color: #d9e4f3;
  border-color: #4a90d9;
  outline: none;
}

.user-message-action:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.artifact-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  background: #4a90d9;
  color: #fff;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

.artifact-badge:hover {
  background: #357abd;
}

/* Chat input */

.chat-input {
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  gap: 8px;
  background: #0f3460;
  border-top: 1px solid #1a4080;
}

.jump-to-latest-btn {
  align-self: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid #2d5f98;
  background: rgba(15, 26, 46, 0.92);
  color: #d7e8f9;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(4, 10, 18, 0.28);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.jump-to-latest-btn:hover,
.jump-to-latest-btn:focus-visible {
  background: #18365a;
  border-color: #4a90d9;
  transform: translateY(1px);
  outline: none;
}

.jump-to-latest-btn[hidden] {
  display: none;
}

.chat-input-top-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  width: 100%;
}

.chat-input-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
}

.asset-status {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #1a4080;
  background: #102038;
  color: #c9daf0;
  font-size: 0.84rem;
}

.asset-status.is-error {
  border-color: #8f3648;
  background: #40141f;
  color: #ffd7dd;
}

.asset-status.is-success {
  border-color: #1f6a4a;
  background: #10281d;
  color: #d5ffe7;
}

.asset-status[hidden] {
  display: none;
}

.chat-input-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.chat-input-editor {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  border: 1px solid #1a4080;
  border-radius: 8px;
  background: #1a1a2e;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-editor:focus-within {
  border-color: #4a90d9;
  box-shadow: 0 0 0 1px rgba(74, 144, 217, 0.22);
}

.composer-reference-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 12px 0;
}

.composer-reference-list[hidden] {
  display: none;
}

.chat-input-editor.has-references textarea {
  padding-top: 8px;
}

.composer-reference-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid #2d5f98;
  border-radius: 999px;
  background: #10263f;
  color: #d7e8f9;
  font-size: 0.78rem;
  line-height: 1.2;
}

.composer-reference-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-reference-remove {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0;
  opacity: 0.82;
}

.composer-reference-remove:hover,
.composer-reference-remove:focus-visible {
  opacity: 1;
  outline: none;
}

.last-message-link {
  color: inherit;
  font-size: 0.68rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  white-space: nowrap;
}

.last-message-link:hover {
  opacity: 0.7;
}

#compact-btn {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #1a1a2e;
  color: #aaa;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}

#compact-btn:hover {
  background: #2a3a5e;
  color: #e0e0e0;
}

#asset-picker-btn {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #112640;
  color: #d7e8f9;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

#asset-picker-btn:hover:not(:disabled) {
  background: #1a3a5c;
}

#files-btn {
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #16213e;
  color: #d7e8f9;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

#files-btn:hover:not(:disabled) {
  background: #22355c;
}

#files-btn[hidden] {
  display: none;
}

.chat-input textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #e0e0e0;
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
}

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

.chat-input-top-row button,
.chat-input-controls button {
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  background: #4a90d9;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-input-top-row button:hover,
.chat-input-controls button:hover {
  background: #357abd;
}

.chat-input-top-row button:disabled,
.chat-input-controls button:disabled {
  background: #2a4a6b;
  cursor: not-allowed;
}



.typing-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #1a2744;
  border-radius: 12px;
  font-size: 0.85rem;
  color: #aaa;
}

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

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4a90d9;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

.typing-timer {
  font-size: 0.8rem;
  color: #6a7a8e;
  font-variant-numeric: tabular-nums;
}

.typing-status {
  font-size: 0.8rem;
  color: #8a9ab0;
  font-style: italic;
  animation: fadeIn 0.3s ease;
}

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

/* Clerk auth gate */

.auth-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1200;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(74, 144, 217, 0.24), transparent 32%),
    rgba(6, 12, 24, 0.82);
  backdrop-filter: blur(10px);
}

.auth-gate.visible {
  display: flex;
}

.chat-switch-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1150;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(74, 144, 217, 0.18), transparent 32%),
    rgba(6, 12, 24, 0.54);
  backdrop-filter: blur(12px);
}

.chat-switch-overlay.visible {
  display: flex;
}

.chat-switch-card {
  width: min(100%, 420px);
  padding: 24px;
  border-radius: 18px;
  border: 1px solid rgba(74, 144, 217, 0.28);
  background: linear-gradient(180deg, rgba(13, 27, 42, 0.95), rgba(22, 33, 62, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.chat-switch-eyebrow {
  margin-bottom: 8px;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #6ea7e2;
}

.chat-switch-card h2 {
  margin-bottom: 10px;
  font-size: 1.45rem;
  color: #fff;
}

.chat-switch-copy {
  margin-bottom: 18px;
  color: #9db1ca;
  line-height: 1.5;
}

.chat-switch-tasks {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-switch-task {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(15, 26, 46, 0.92);
  border: 1px solid rgba(26, 64, 128, 0.9);
}

.chat-switch-task-label {
  font-size: 0.88rem;
  color: #d6dfeb;
}

.chat-switch-task-state {
  font-size: 0.8rem;
  color: #7f93ad;
  white-space: nowrap;
}

.chat-switch-task.is-active .chat-switch-task-state {
  color: #6ea7e2;
}

.chat-switch-task.is-done .chat-switch-task-state {
  color: #6fd39c;
}

.chat-switch-task.is-error .chat-switch-task-state {
  color: #ff8f8f;
}

.auth-card {
  width: min(100%, 480px);
  padding: 28px;
  border-radius: 20px;
  border: 1px solid rgba(74, 144, 217, 0.35);
  background: linear-gradient(180deg, rgba(13, 27, 42, 0.96), rgba(22, 33, 62, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.auth-eyebrow {
  margin-bottom: 8px;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #6ea7e2;
}

.auth-card h2 {
  margin-bottom: 10px;
  font-size: 1.6rem;
  color: #fff;
}

.auth-copy {
  margin-bottom: 18px;
  color: #9db1ca;
  line-height: 1.5;
}

.sign-in-root {
  min-height: 120px;
}

.auth-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 180px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #6ea7e2, #4a90d9);
  color: #06121f;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.auth-action:hover {
  filter: brightness(1.05);
}

.auth-action:disabled {
  opacity: 0.7;
  cursor: wait;
}

.auth-help {
  margin-top: 14px;
  color: #7f93ad;
  line-height: 1.5;
}

.auth-action[hidden],
.auth-help[hidden] {
  display: none;
}

/* Compact modal */

.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: #16213e;
  border-radius: 12px;
  border: 1px solid #1a4080;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #1a4080;
}

.modal-header h2 {
  font-size: 1.1rem;
  color: #fff;
}

.modal-header button {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 1rem;
}

.modal-header button:hover {
  background: #1a4080;
}

.modal-body {
  padding: 20px;
}

.modal-description {
  font-size: 0.9rem;
  color: #a0b0c0;
  margin-bottom: 16px;
}

.admin-modal {
  max-width: 760px;
}

.personality-modal {
  max-width: 680px;
}

.files-modal {
  max-width: 720px;
}

.admin-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.personality-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.files-modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.files-modal-empty {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid #1a4080;
  background: #0f1a2e;
  color: #8ea2bc;
  font-size: 0.88rem;
}

.files-modal-empty[hidden] {
  display: none;
}

.files-modal-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.files-modal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid #1a4080;
  background: #0f1a2e;
}

.files-modal-asset-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.files-modal-asset-name {
  font-size: 0.92rem;
  color: #f2f5fb;
  word-break: break-word;
}

.files-modal-asset-meta {
  font-size: 0.78rem;
  color: #8ea2bc;
}

.files-modal-asset-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.files-modal-action {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #1a4080;
  background: transparent;
  color: #d7e8f9;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.files-modal-action:hover:not(:disabled),
.files-modal-action:focus-visible {
  background: #14304e;
  outline: none;
}

.files-modal-action.is-danger {
  border-color: #8f3648;
  color: #ffd7dd;
}

.files-modal-action.is-danger:hover:not(:disabled),
.files-modal-action.is-danger:focus-visible {
  background: #40141f;
}

.files-modal-action:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.personality-label {
  font-size: 0.85rem;
  color: #a0b0c0;
}

#personality-input {
  min-height: 180px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #1a4080;
  background: #0f1a2e;
  color: #e0e0e0;
  font-size: 0.92rem;
  font-family: inherit;
  line-height: 1.55;
  resize: vertical;
  outline: none;
}

#personality-input:focus {
  border-color: #4a90d9;
}

#personality-input:disabled {
  opacity: 0.7;
  cursor: wait;
}

.personality-status {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #102038;
  color: #c9daf0;
  font-size: 0.85rem;
}

.personality-status.is-error {
  border-color: #8f3648;
  background: #40141f;
  color: #ffd7dd;
}

.personality-status.is-success {
  border-color: #1f6a4a;
  background: #10281d;
  color: #d5ffe7;
}

.personality-status[hidden] {
  display: none;
}

.personality-actions {
  display: flex;
  justify-content: flex-end;
}

.admin-add-user-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-add-user-form label {
  font-size: 0.85rem;
  color: #a0b0c0;
}

.admin-add-user-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.admin-add-user-controls input[type="email"] {
  flex: 1 1 280px;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #0f1a2e;
  color: #e0e0e0;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.admin-add-user-controls input[type="email"]:focus {
  border-color: #4a90d9;
}

.admin-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #c0c8d4;
  white-space: nowrap;
}

.admin-checkbox input {
  accent-color: #4a90d9;
}

.admin-status {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #102038;
  color: #c9daf0;
  font-size: 0.85rem;
}

.admin-status.is-error {
  border-color: #8f3648;
  background: #40141f;
  color: #ffd7dd;
}

.admin-status.is-success {
  border-color: #1f6a4a;
  background: #10281d;
  color: #d5ffe7;
}

.admin-status[hidden] {
  display: none;
}

.admin-users {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid #1a4080;
  background: #0f1a2e;
}

.admin-user-info {
  min-width: 0;
}

.admin-user-email {
  font-size: 0.92rem;
  color: #f2f5fb;
  word-break: break-word;
}

.admin-user-meta {
  margin-top: 4px;
  font-size: 0.78rem;
  color: #8ea2bc;
}

.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-remove-btn {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #8f3648;
  background: transparent;
  color: #ffd7dd;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.admin-remove-btn:hover:not(:disabled) {
  background: #40141f;
}

.admin-remove-btn:disabled,
.admin-checkbox input:disabled,
.compact-apply-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.compact-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.compact-loading {
  font-size: 0.85rem;
  color: #7a8a9e;
  font-style: italic;
  padding: 12px;
}

.compact-option {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: #0f1a2e;
  border: 1px solid #1a4080;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.compact-option:hover {
  border-color: #4a90d9;
  background: #13203a;
}

.compact-option-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #4a90d9;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.compact-option-text {
  font-size: 0.85rem;
  color: #c0c8d4;
  line-height: 1.5;
}

.compact-custom {
  border-top: 1px solid #1a4080;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.compact-custom label {
  font-size: 0.85rem;
  color: #a0b0c0;
}

.compact-custom textarea {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #0f1a2e;
  color: #e0e0e0;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.compact-custom textarea:focus {
  border-color: #4a90d9;
}

.compact-apply-btn {
  align-self: flex-end;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  background: #4a90d9;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.compact-apply-btn:hover {
  background: #357abd;
}

/* Focus mode: full-width artifact with pinned chat input */

#focus-mode-btn {
  display: none;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #1a4080;
  background: #1a1a2e;
  color: #aaa;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.app-container.has-artifact #focus-mode-btn,
.app-container.focus-mode #focus-mode-btn {
  display: inline-flex;
}

#focus-mode-btn:hover {
  background: #2a3a5e;
  color: #e0e0e0;
}

.app-container.focus-mode .chat-container {
  display: none;
}

.app-container.focus-mode .sidebar {
  display: none;
}

.app-container.focus-mode .artifact-panel {
  display: flex;
  width: 100%;
  flex: 1;
}

.app-container.focus-mode .artifact-panel .chat-input {
  display: flex;
  flex-direction: column;
  padding: 12px 24px;
  gap: 12px;
  background: #0f3460;
  border-top: 1px solid #1a4080;
}

.app-container.focus-mode .artifact-content {
  flex: 1;
  overflow: hidden;
}

.app-container.focus-mode #focus-mode-btn {
  background: #4a90d9;
  color: #fff;
  border-color: #4a90d9;
}

.focus-typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #1a2744;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #aaa;
  width: 100%;
  order: -1;
  flex-basis: 100%;
}

.focus-typing-indicator .typing-dots {
  display: flex;
  gap: 4px;
}

.focus-typing-indicator .typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4a90d9;
  animation: bounce 1.4s infinite ease-in-out both;
}

.focus-typing-indicator .typing-dots span:nth-child(1) { animation-delay: 0s; }
.focus-typing-indicator .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.focus-typing-indicator .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

.focus-typing-indicator .typing-status {
  font-size: 0.8rem;
  color: #8a9ab0;
  font-style: italic;
  animation: fadeIn 0.3s ease;
}

.focus-typing-indicator .typing-timer {
  font-size: 0.8rem;
  color: #6a7a8e;
  font-variant-numeric: tabular-nums;
}

/* Artifact drawer handle (visible on narrow viewports) */

.artifact-drawer-handle {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  background: #0f3460;
  border-top: 1px solid #1a4080;
  padding: 10px 20px;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.artifact-drawer-handle .drawer-pill {
  width: 36px;
  height: 4px;
  background: #4a90d9;
  border-radius: 2px;
  margin: 0 auto 6px;
}

.artifact-drawer-handle .drawer-label {
  font-size: 0.85rem;
  color: #e0e0e0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Responsive: Tablet portrait and below (<=1024px) */

@media (max-width: 1024px) {
  #focus-mode-btn {
    display: none;
  }

  .chat-header {
    position: relative;
  }

  .auth-user-email {
    display: none;
  }

  /* Sidebar becomes overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 800;
    width: 0;
    min-width: 0;
    transition: width 0.3s ease, min-width 0.3s ease;
  }

  .app-container.has-sidebar .sidebar {
    width: 280px;
    min-width: 280px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  .app-container.has-sidebar .chat-container {
    max-width: none;
    margin: 0;
    flex: 1;
  }

  /* Chat container always full width */
  .chat-container {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    flex: 1 !important;
  }

  .app-container.has-artifact .chat-container {
    width: 100% !important;
    min-width: 0 !important;
    border-right: none;
  }

  /* Artifact panel becomes a bottom drawer */
  .artifact-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: 75vh;
    z-index: 700;
    border-top: 1px solid #1a4080;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
  }

  .app-container.has-artifact .artifact-panel {
    display: flex;
    transform: translateY(100%);
  }

  .app-container.has-artifact.drawer-open .artifact-panel {
    transform: translateY(0);
  }

  /* Show drawer handle when artifacts exist */
  .app-container.has-artifact .artifact-drawer-handle {
    display: block;
  }

  .app-container.has-artifact.drawer-open .artifact-drawer-handle {
    display: none;
  }

  /* Full width mode still works */
  .app-container.artifact-fullwidth .artifact-panel {
    height: 100vh;
    top: 0;
    border-radius: 0;
    transform: translateY(0);
  }

  .app-container.artifact-fullwidth .chat-container {
    display: none;
  }

  /* Adjust chat input to account for drawer handle */
  .app-container.has-artifact .chat-input {
    padding-bottom: 60px;
  }

  .app-container.has-artifact.drawer-open .chat-input {
    padding-bottom: 16px;
  }
}

/* Responsive: Phone (<=768px) */

@media (max-width: 768px) {
  .chat-header {
    padding: 12px 16px;
    gap: 8px;
  }

  .chat-header h1 {
    font-size: 1rem;
  }

  #new-chat-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
  }

  .chat-messages {
    padding: 16px 12px;
  }

  .message-shell {
    max-width: 92%;
  }

  .message {
    padding: 10px 14px;
    font-size: 0.9rem;
  }

  .chat-input {
    padding: 12px;
    gap: 8px;
  }

  .jump-to-latest-btn {
    width: 30px;
    height: 30px;
  }

  .chat-input-top-row {
    gap: 8px;
  }

  .chat-input textarea {
    font-size: 0.9rem;
    padding: 10px 12px;
  }

  .composer-reference-list {
    gap: 6px;
    padding: 10px 10px 0;
  }

  .composer-reference-badge {
    font-size: 0.74rem;
    padding: 5px 9px;
  }

  .chat-input-controls {
    gap: 8px;
  }

  .chat-input-top-row button,
  .chat-input-controls button {
    padding: 10px 16px;
    font-size: 0.85rem;
  }

  #asset-picker-btn,
  #files-btn,
  #compact-btn {
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  .files-modal-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .files-modal-asset-actions {
    width: 100%;
    justify-content: space-between;
  }

  .context-bar {
    padding: 5px 12px;
  }

  .artifact-panel {
    height: 85vh;
  }

  .app-container.has-sidebar .sidebar {
    width: 260px;
    min-width: 260px;
  }

  .modal {
    width: 95%;
    max-height: 85vh;
  }

  .admin-user-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-user-actions {
    width: 100%;
    justify-content: space-between;
  }

  .auth-card {
    padding: 22px 18px;
  }

  .auth-card h2 {
    font-size: 1.3rem;
  }
}

/* Sidebar overlay backdrop */

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 799;
}

@media (max-width: 1024px) {
  .app-container.has-sidebar .sidebar-backdrop {
    display: block;
  }
}

@media (hover: none) {
  .user-message-actions {
    opacity: 1;
  }
}
