/* ============================================================
   Claude Code Chat - Mobile-first Dark Theme
   ============================================================ */

/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --surface-hover: #1c2d54;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --text-dim: #52525b;
  --accent: #e94560;
  --accent-hover: #d63d56;
  --accent2: #533483;
  --user-bubble: #0f3460;
  --user-bubble-text: #e4e4e7;
  --assistant-bubble: #1e1e36;
  --assistant-bubble-border: #2a2a4a;
  --border: #27273f;
  --border-light: #33335a;
  --input-bg: #16213e;
  --code-bg: #0d1117;
  --success: #22c55e;
  --warning: #eab308;
  --error: #ef4444;
  --sidebar-width: 280px;
  --topbar-height: 52px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  height: -webkit-fill-available;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent pull-to-refresh on mobile */
body {
  overscroll-behavior-y: none;
}

/* ============================================================
   Login Screen
   ============================================================ */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.login-screen.hidden {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}

/* Animated background particles */
.login-particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0.15;
  background:
    radial-gradient(circle at 20% 30%, var(--accent) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, var(--accent2) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, var(--surface2) 0%, transparent 60%);
  animation: particles-drift 20s ease-in-out infinite alternate;
}

@keyframes particles-drift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-2%, 3%) scale(1.05); }
  100% { transform: translate(2%, -2%) scale(1); }
}

/* Card */
.login-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px 32px;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  animation: card-enter 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.login-title {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 4px;
}

.login-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
  letter-spacing: 0.02em;
}

/* Form fields */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-field {
  position: relative;
}

.login-field-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
  transition: color 0.2s;
}

.login-field:focus-within .login-field-icon {
  color: var(--accent);
}

.login-field input {
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 14px 44px;
  font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.1);
}

.login-field input::placeholder {
  color: var(--text-dim);
}

/* Error message */
.login-error {
  font-size: 13px;
  color: var(--error);
  text-align: center;
  padding: 8px 0 0;
  animation: shake 0.4s ease;
}

.login-error.hidden {
  display: none;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Submit button */
.login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  margin-top: 8px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  min-height: 50px;
}

.login-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px rgba(233, 69, 96, 0.3);
}

.login-btn:active {
  transform: scale(0.98);
}

.login-btn.loading {
  pointer-events: none;
  opacity: 0.85;
}

.login-btn.loading .login-btn-text,
.login-btn.loading .login-btn-arrow {
  display: none;
}

.login-btn.loading .login-btn-spinner {
  display: flex !important;
}

.login-btn-spinner {
  display: none;
}

/* Footer */
.login-footer {
  position: relative;
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.login-footer::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding-top: var(--safe-area-top);
  padding-left: var(--safe-area-left);
}

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

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

.session-item {
  padding: 12px;
  margin: 2px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 44px; /* touch target */
  position: relative;
}

.session-item:hover {
  background: var(--surface-hover);
}

.session-item.active {
  background: var(--surface2);
}

.session-item .session-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.session-status.running {
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.session-status.idle {
  background: var(--text-muted);
}

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

.session-item .session-name {
  font-weight: 500;
  font-size: 14px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item .session-dir {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item .btn-delete-session {
  opacity: 0.4;
  transition: opacity 0.15s;
  flex-shrink: 0;
  padding: 4px;
  margin-top: -2px;
}

.session-item:hover .btn-delete-session,
.session-item:active .btn-delete-session {
  opacity: 0.6;
}

.session-item .btn-delete-session:hover,
.session-item .btn-delete-session:active {
  opacity: 1;
  color: var(--error);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: calc(12px + var(--safe-area-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  min-height: 36px;
}

.btn-logout:hover {
  color: var(--error);
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.06);
}

.btn-logout svg {
  flex-shrink: 0;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.connection-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.connection-status.connected .status-dot {
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.connection-status.disconnected .status-dot {
  background: var(--error);
}

.connection-status.reconnecting .status-dot {
  background: var(--warning);
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ============================================================
   Main Content
   ============================================================ */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* dynamic viewport for mobile keyboards */
  width: 100%;
}

/* ============================================================
   Top Bar
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-height) + var(--safe-area-top));
  padding: var(--safe-area-top) 8px 0 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-center span:last-child {
  font-weight: 500;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.topbar-status-dot.connected {
  background: var(--success);
}

.topbar-status-dot.disconnected {
  background: var(--error);
}

.topbar-status-dot.reconnecting {
  background: var(--warning);
  animation: pulse-dot 1.5s infinite;
}

/* ============================================================
   Chat Area
   ============================================================ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100%;
}

/* Welcome state */
.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  margin: auto;
  color: var(--text-muted);
}

.welcome-icon {
  margin-bottom: 16px;
  opacity: 0.6;
}

.welcome-message h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.welcome-message p {
  font-size: 14px;
  line-height: 1.5;
  max-width: 260px;
}

/* ============================================================
   Message Bubbles
   ============================================================ */
.message {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: msg-in 0.2s ease-out;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bubble);
  border: 1px solid var(--assistant-bubble-border);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  color: var(--text-muted);
  font-size: 12px;
  background: none;
  padding: 6px 12px;
  border: none;
}

/* Assistant message content (rendered markdown) */
.message.assistant .content p {
  margin: 0.4em 0;
}

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

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

.message.assistant .content ul,
.message.assistant .content ol {
  padding-left: 1.5em;
  margin: 0.4em 0;
}

.message.assistant .content li {
  margin: 0.2em 0;
}

.message.assistant .content strong {
  font-weight: 600;
  color: #fff;
}

.message.assistant .content em {
  font-style: italic;
  color: var(--text);
}

.message.assistant .content a {
  color: var(--accent);
  text-decoration: none;
}

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

.message.assistant .content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 0.5em 0;
  color: var(--text-muted);
}

/* Inline code */
.message.assistant .content code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;
  font-size: 13px;
}

/* Code blocks */
.message.assistant .content pre {
  background: var(--code-bg);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.message.assistant .content pre code {
  padding: 0;
  background: none;
  font-size: 12.5px;
  line-height: 1.5;
}

/* Timestamp */
.message .timestamp {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: right;
}

.message.assistant .timestamp {
  text-align: left;
}

/* ============================================================
   Typing Indicator
   ============================================================ */
.typing-indicator {
  align-self: flex-start;
  padding: 10px 16px;
  background: var(--assistant-bubble);
  border: 1px solid var(--assistant-bubble-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  margin-top: 4px;
  margin-left: 0;
  transition: opacity 0.2s, max-height 0.2s;
}

.typing-indicator.hidden {
  display: none;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 20px;
}

.typing-dots span {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* ============================================================
   Code Panel (bottom collapsible)
   ============================================================ */
.code-panel {
  background: var(--code-bg);
  border-top: 2px solid var(--accent);
  max-height: 40vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              border-top-width 0.3s ease;
  flex-shrink: 0;
}

.code-panel.hidden {
  max-height: 0;
  border-top-width: 0;
}

.code-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
  border-bottom: 1px solid var(--border);
}

.code-panel-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.code-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
}

.code-content pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ============================================================
   Input Area
   ============================================================ */
.input-area {
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-area-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

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

.input-area textarea {
  flex: 1;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 16px; /* 16px prevents iOS auto-zoom on focus */
  resize: none;
  max-height: 120px;
  font-family: inherit;
  outline: none;
  line-height: 1.4;
  transition: border-color 0.15s ease;
}

.input-area textarea:focus {
  border-color: var(--accent);
}

.input-area textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-area textarea::placeholder {
  color: var(--text-dim);
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:active {
  transform: scale(0.95);
}

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

.btn-send:disabled:hover {
  background: var(--accent);
}

/* Keyboard shortcut hint (desktop only) */
.input-hint {
  display: none;
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 0 0 4px;
  flex-shrink: 0;
  white-space: nowrap;
  align-self: center;
}

.input-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 10px;
  font-family: inherit;
  background: var(--border);
  border-radius: 3px;
  color: var(--text-muted);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-icon {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: background 0.15s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.06);
}

.btn-icon:active {
  opacity: 0.6;
}

.btn-icon.btn-small {
  min-width: 32px;
  min-height: 32px;
  padding: 4px;
}

/* ============================================================
   Modal
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
  animation: modal-in 0.2s ease-out;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-content h3 {
  margin-bottom: 20px;
  font-size: 18px;
  font-weight: 600;
}

.input-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-content input[type="text"] {
  width: 100%;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.modal-content input[type="text"]:focus {
  border-color: var(--accent);
}

.modal-content input[type="text"]::placeholder {
  color: var(--text-dim);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
  min-height: 44px;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
  border: none;
  padding: 10px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
  min-height: 44px;
}

.btn-secondary:hover {
  background: var(--border-light);
}

.btn-secondary:active {
  transform: scale(0.98);
}

/* ============================================================
   Scrollbar Styling
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* ============================================================
   Utility
   ============================================================ */
.hidden {
  display: none !important;
}

/* ============================================================
   Desktop Breakpoint (768px+)
   ============================================================ */
@media (min-width: 768px) {
  .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none !important;
  }

  .main {
    margin-left: var(--sidebar-width);
  }

  .message {
    max-width: 70%;
  }

  #btn-sidebar {
    display: none;
  }

  .topbar {
    padding-left: 16px;
  }

  .chat-area {
    padding: 16px 20px;
  }

  .input-area {
    padding: 10px 20px;
    padding-bottom: 10px;
  }

  .input-area textarea {
    border-radius: 12px;
    padding: 12px 16px;
  }

  .btn-send {
    width: 40px;
    height: 40px;
  }

  /* Keyboard shortcut hint */
  .input-hint {
    display: block;
  }
}

/* ============================================================
   Large Desktop (1200px+)
   ============================================================ */
@media (min-width: 1200px) {
  :root {
    --sidebar-width: 300px;
  }

  .message {
    max-width: 60%;
  }

  .chat-area {
    padding: 20px 32px;
  }

  .input-area {
    padding: 12px 32px 12px;
  }

  /* Center-constrained content for very wide screens */
  .messages {
    max-width: 900px;
    margin: 0 auto;
  }

  .input-area-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
  }
}

/* ============================================================
   Extra Large Desktop (1600px+)
   ============================================================ */
@media (min-width: 1600px) {
  .messages {
    max-width: 1000px;
  }

  .input-area-inner {
    max-width: 1000px;
  }

  .chat-area {
    padding: 24px 48px;
  }

  .input-area {
    padding: 12px 48px 14px;
  }
}

/* ============================================================
   Small screen height (keyboard open on mobile)
   ============================================================ */
@media (max-height: 500px) {
  .topbar {
    height: 40px;
    padding-top: 0;
  }

  .input-area {
    padding: 4px 8px;
    padding-bottom: calc(4px + var(--safe-area-bottom));
  }

  .input-area textarea {
    padding: 8px 12px;
  }
}

/* ============================================================
   iOS Virtual Keyboard - resize layout when keyboard opens
   ============================================================ */
.main.keyboard-open .chat-area {
  /* Handled dynamically via JS visualViewport API */
}

/* ============================================================
   Network Banner - shown when offline
   ============================================================ */
.network-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--error);
  color: white;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  flex-shrink: 0;
  z-index: 11;
}

.network-banner.show {
  display: flex;
}

.network-banner svg {
  flex-shrink: 0;
}

/* ============================================================
   Pull-to-reconnect indicator
   ============================================================ */
.pull-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  color: var(--text-muted);
  font-size: 12px;
  gap: 6px;
  transition: opacity 0.2s;
}

.pull-indicator.show {
  display: flex;
}

.pull-indicator .pull-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Touch Active States
   ============================================================ */
@media (hover: none) {
  .session-item:active {
    background: var(--surface2);
    transition: none;
  }

  .btn-icon:active {
    background: rgba(255, 255, 255, 0.1);
    transition: none;
  }

  .btn-primary:active,
  .btn-secondary:active {
    transform: scale(0.97);
    transition: none;
  }

  .login-btn:active {
    transform: scale(0.97);
  }
}

/* ============================================================
   Standalone mode (Add to Home Screen)
   ============================================================ */
@media (display-mode: standalone) {
  /* Extra top padding already handled by safe-area-inset-top */
  .topbar {
    padding-top: calc(var(--safe-area-top) + 4px);
    height: calc(var(--topbar-height) + var(--safe-area-top) + 4px);
  }
}

/* ============================================================
   Modal - mobile full-width
   ============================================================ */
@media (max-width: 420px) {
  .modal-content {
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: none;
    padding-bottom: calc(24px + var(--safe-area-bottom));
    animation: modal-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes modal-slide-up {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .modal {
    align-items: flex-end;
  }
}
