/* ARC Chat Web — Faithful to Swift UI */

:root {
  --user-bubble: #bd93f9; --user-text: #282a36;
  --assistant-bubble: #383a4d; --assistant-text: #e6e6eb; --assistant-border: #474c61;
  --accent: #bd93f9; --bg: #292b3a; --sidebar: #2c2e3d;
  --text-primary: #e6e6eb; --text-secondary: #808494;
  --radius: 16px; --radius-sm: 10px;
  --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  --font-size: 13px; --font-weight: 400; --line-height: 1.5; --letter-spacing: 0px;
  --msg-spacing: 14px; --avatar-size: 28px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; font-family: var(--font-family); background: var(--bg); color: var(--text-primary); font-size: var(--font-size); font-weight: var(--font-weight); line-height: var(--line-height); letter-spacing: var(--letter-spacing); }
#app { display: flex; flex-direction: column; height: 100dvh; position: relative; background: var(--bg); }

.view { display: none; flex-direction: column; flex: 1; min-height: 0; background: var(--bg); color: var(--text-primary); }
.view.active { display: flex; }

/* ============ CHAT HEADER ============ */
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--sidebar);
  border-bottom: 1px solid var(--assistant-border); flex-shrink: 0;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #ff3b30; flex-shrink: 0; }
.status-dot.connected { background: #34c759; }
.header-title { font-size: 14px; font-weight: 600; flex: 1; }
.header-right { display: flex; gap: 2px; }
.icon-btn { background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 6px; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.icon-btn:active { background: rgba(128,128,128,0.12); }

/* ============ MESSAGES ============ */
.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px; display: flex; flex-direction: column; gap: var(--msg-spacing);
}

/* Empty state — matches EmptyChatState */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; text-align: center; gap: 6px; }
.empty-avatar { border-radius: 50%; opacity: 0.8; }
.empty-state h2 { font-size: 18px; font-weight: 600; margin-top: 4px; }
.secondary-text { font-size: 13px; color: var(--text-secondary); }
.suggestions { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; width: 100%; max-width: 260px; }

/* PromptChip */
.chip {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 11px; font-size: 11px;
  color: var(--accent); background: transparent;
  border: 1px solid rgba(128,128,128,0.15); border-radius: 12px;
  cursor: pointer; transition: all 0.12s; font-family: var(--font-family); text-align: left; width: 100%;
}
.chip svg { flex-shrink: 0; opacity: 0.6; }
.chip:active { transform: scale(0.95); background: var(--accent); color: var(--user-text); border-color: var(--accent); }

/* ============ MESSAGE BUBBLE — matches MessageBubble ============ */
/* Each .msg is a VStack: name row, then bubble */
.msg { display: flex; flex-direction: column; gap: 0; }

/* Name + timestamp row */
.msg-meta {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 4px; font-size: 11px;
}
.msg-meta .name { font-weight: 500; color: var(--text-secondary); }
.msg-meta .time { font-size: 10px; color: var(--text-secondary); opacity: 0.5; }
.msg.user .msg-meta { justify-content: flex-end; }

/* Avatar in meta row — now an <img> for banana reactions */
.msg-avatar, img.msg-avatar {
  width: var(--avatar-size); height: var(--avatar-size); border-radius: 50%;
  object-fit: cover; flex-shrink: 0; display: block;
}

/* Bubble row */
.msg-row { display: flex; }
.msg.user .msg-row { justify-content: flex-end; }
.msg.assistant .msg-row { justify-content: flex-start; }

.msg-bubble {
  padding: 10px 14px; border-radius: var(--radius);
  font-size: var(--font-size); line-height: var(--line-height);
  max-width: calc(100% - 60px); word-wrap: break-word;
  position: relative;
}
.msg-text p { margin: 0 0 6px; }
.msg-text p:last-child { margin-bottom: 0; }
.msg.user .msg-bubble {
  background: var(--user-bubble); color: var(--user-text);
  border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
  background: var(--assistant-bubble); color: var(--assistant-text);
  border: 1px solid var(--assistant-border); border-bottom-left-radius: 4px;
}

/* Action bar — appears ABOVE bubble on hover/tap, matching Swift offset(y: -8) */
.msg-actions {
  display: flex; gap: 2px; padding: 3px;
  background: var(--sidebar); border-radius: 8px;
  border: 1px solid rgba(128,128,128,0.12);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  position: absolute; top: -32px; z-index: 5;
  opacity: 0; transition: opacity 0.12s; pointer-events: none;
}
.msg.assistant .msg-actions { left: 0; }
.msg.user .msg-actions { right: 0; }
.msg-bubble.show-actions .msg-actions { opacity: 1; pointer-events: auto; }
.msg-actions button {
  background: none; border: none; cursor: pointer;
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); border-radius: 6px;
}
.msg-actions button:active { background: rgba(128,128,128,0.12); }
.msg-actions button.copied { color: #34c759; }

/* Streaming cursor */
.msg-bubble.streaming .msg-text::after { content: "\25CA"; animation: blink 0.8s infinite; color: var(--accent); margin-left: 2px; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* Code blocks in assistant messages */
.msg-bubble pre { background: rgba(0,0,0,0.2); border: 1px solid var(--assistant-border); border-radius: 8px; padding: 10px; margin: 8px 0; overflow-x: auto; font-size: 12px; }
.msg-bubble code { font-family: "SF Mono", Menlo, monospace; font-size: 12px; }
.msg-bubble p { margin: 4px 0; }
.msg-bubble strong { font-weight: 600; }

/* Session divider */
.session-divider {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; color: var(--text-secondary); opacity: 0.5;
}
.session-divider::before, .session-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--assistant-border);
}
.session-divider span { font-size: 10px; font-weight: 500; white-space: nowrap; }

/* Typing indicator */
.typing { display: flex; flex-direction: column; gap: 0; }
.typing .msg-meta { margin-bottom: 4px; }
.typing .msg-avatar { width: var(--avatar-size); height: var(--avatar-size); border-radius: 50%; object-fit: cover; }
.typing-dots {
  display: flex; gap: 5px; padding: 12px 14px;
  background: var(--assistant-bubble); border: 1px solid var(--assistant-border); border-radius: var(--radius);
}
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: 0.5; animation: bounce 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

/* ============ INPUT BAR — matches Swift ChatView input ============ */
.input-bar {
  display: flex; align-items: flex-end; gap: 10px; padding: 8px 12px;
  background: var(--sidebar); border-top: 1px solid var(--assistant-border); flex-shrink: 0;
}
.input-bar .icon-btn { color: var(--text-secondary); padding: 4px; margin-bottom: 4px; }
#msg-input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: var(--font-size); font-family: var(--font-family);
  font-weight: var(--font-weight); resize: none; line-height: 1.4;
  max-height: 120px; min-height: 20px; padding: 6px 0;
  overflow-y: auto;
}
#msg-input::placeholder { color: var(--text-secondary); opacity: 0.6; }
.send-btn {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: transparent; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: color 0.12s; margin-bottom: 2px;
}
.send-btn svg { width: 24px; height: 24px; }
.send-btn { color: var(--text-secondary); opacity: 0.4; }
.send-btn:not(:disabled) { color: var(--accent); opacity: 1; }
.send-btn:disabled { cursor: default; }

/* Scroll FAB */
.scroll-fab {
  position: absolute; bottom: 64px; right: 16px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--sidebar); border: 1px solid rgba(128,128,128,0.2);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  color: var(--accent); cursor: pointer;
  display: none; align-items: center; justify-content: center; z-index: 10;
}
.scroll-fab.visible { display: flex; }

/* ============ TAB BAR — matches Swift MobileTab ============ */
.tab-bar {
  display: flex; background: var(--sidebar);
  border-top: 1px solid var(--assistant-border);
  padding: 4px 0 env(safe-area-inset-bottom, 2px); flex-shrink: 0;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0 2px; background: none; border: none; cursor: pointer;
  color: var(--text-secondary); opacity: 0.4; transition: all 0.15s; font-family: var(--font-family);
}
.tab.active { color: var(--accent); opacity: 1; }
.tab svg { width: 22px; height: 22px; }
.tab-label { font-size: 10px; font-weight: 400; }
.tab.active .tab-label { font-weight: 600; }

/* ============ VIEW HEADER ============ */
.view-header { padding: 16px 16px 12px; background: var(--sidebar); border-bottom: 1px solid var(--assistant-border); flex-shrink: 0; }
.view-header h1 { font-size: 28px; font-weight: 700; }
.view-content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; }
.center-content { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; }
.muted { color: var(--text-secondary); font-size: 13px; }

/* ============ TODO ============ */
.stat-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.stat-pill { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 10px 8px; border-radius: var(--radius-sm); background: var(--assistant-bubble); border: 1px solid var(--assistant-border); }
.stat-pill.accent { border-color: var(--accent); }
.stat-num { font-size: 20px; font-weight: 700; }
.stat-pill.accent .stat-num { color: var(--accent); }
.stat-label { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

.todo-section { margin-bottom: 20px; }
.todo-section h3 { font-size: 10px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.todo-section h3 svg { opacity: 0.5; }
.todo-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--assistant-bubble);
  border: 1px solid var(--assistant-border); border-radius: var(--radius-sm);
  margin-bottom: 6px; cursor: pointer; font-size: 14px;
}
.todo-item input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--text-secondary); background: none; cursor: pointer; position: relative; transition: all 0.15s;
}
.todo-item input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.todo-item input[type="checkbox"]:checked::after { content: ''; position: absolute; top: 3px; left: 6px; width: 5px; height: 9px; border: solid var(--user-text); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.todo-item:has(input:checked) span { text-decoration: line-through; opacity: 0.35; }
.todo-item.sub { padding: 8px 10px; margin-bottom: 4px; font-size: 12px; background: transparent; border: none; border-left: 2px solid var(--assistant-border); border-radius: 0; margin-left: 4px; }

.project-card { background: var(--assistant-bubble); border: 1px solid var(--assistant-border); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; }
.project-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.project-title { font-size: 14px; font-weight: 600; }
.project-progress { font-size: 11px; color: var(--text-secondary); font-weight: 500; }
.progress-bar { height: 3px; background: var(--assistant-border); border-radius: 2px; margin-bottom: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.3s; }

.waiting-item { display: flex; gap: 10px; padding: 10px 14px; background: var(--assistant-bubble); border: 1px solid var(--assistant-border); border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 13px; }
.waiting-who { font-weight: 600; min-width: 60px; }
.waiting-what { color: var(--text-secondary); }

/* ============ NOTES ============ */
.notes-section-label { font-size: 10px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 8px; }
.note-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--assistant-bubble); border: 1px solid var(--assistant-border); border-radius: var(--radius-sm); margin-bottom: 6px; cursor: pointer; transition: background 0.12s; }
.note-card:active { background: rgba(128,128,128,0.1); }
.note-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.note-icon.lg { width: 44px; height: 44px; }
.note-info { flex: 1; min-width: 0; }
.note-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-meta { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.note-chevron { color: var(--text-secondary); opacity: 0.3; flex-shrink: 0; }

.back-btn { display: inline-flex; align-items: center; gap: 4px; background: none; border: none; color: var(--accent); font-size: 14px; font-weight: 500; cursor: pointer; padding: 4px 0; margin-bottom: 12px; font-family: var(--font-family); }
.folder-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.folder-header h2 { font-size: 22px; font-weight: 700; }

.note-viewer { padding: 4px 0; }
.md-h1 { font-size: 22px; font-weight: 700; margin: 16px 0 8px; color: var(--accent); }
.md-h2 { font-size: 17px; font-weight: 700; margin: 14px 0 6px; color: var(--accent); opacity: 0.85; }
.md-h3 { font-size: 14px; font-weight: 600; margin: 10px 0 4px; }
.md-p { margin: 4px 0; }
.md-bullet { padding-left: 16px; position: relative; margin: 3px 0; }
.md-bullet::before { content: ''; position: absolute; left: 4px; top: 8px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: 0.5; }
.md-spacer { height: 8px; }
.md-table-row { display: flex; gap: 12px; padding: 4px 0; font-size: 12px; border-bottom: 1px solid var(--assistant-border); }
.md-table-row span { flex: 1; }
.todo-item.inline { padding: 6px 0; margin: 2px 0; background: none; border: none; border-radius: 0; font-size: 13px; }

/* ============ SETTINGS ============ */
.settings-group { background: var(--assistant-bubble); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 16px; }
.settings-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 16px; background: none; border: none; border-bottom: 1px solid var(--assistant-border); color: var(--text-primary); font-size: 14px; font-family: var(--font-family); cursor: pointer; text-align: left; }
.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: rgba(128,128,128,0.06); }
.settings-icon { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: #fff; }
.settings-icon svg { width: 14px; height: 14px; }
.settings-chevron { margin-left: auto; color: var(--text-secondary); opacity: 0.3; }
.settings-row-label { flex: 1; }

/* ============ SHEETS ============ */
.sheet { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.sheet-content { position: relative; background: var(--bg); border-radius: 14px 14px 0 0; max-height: 85vh; display: flex; flex-direction: column; animation: slideUp 0.25s ease-out; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; flex-shrink: 0; border-bottom: 1px solid var(--assistant-border); }
.sheet-header h2 { font-size: 16px; font-weight: 600; }
.sheet-done { background: none; border: none; color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; font-family: var(--font-family); }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 24px; }

.setting-card { background: var(--sidebar); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 10px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; }
.setting-row.clickable { cursor: pointer; }
.setting-label { font-size: 13px; font-weight: 500; }
.setting-value { font-size: 12px; color: var(--text-secondary); }

.slider-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.slider-label-sm { font-size: 11px; color: var(--text-secondary); }
.slider-label-lg { font-size: 18px; font-weight: 500; color: var(--text-secondary); }
.slider { -webkit-appearance: none; appearance: none; flex: 1; height: 4px; border-radius: 2px; background: var(--assistant-border); outline: none; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }

.toggle { width: 44px; height: 26px; border-radius: 13px; background: var(--assistant-border); position: relative; cursor: pointer; transition: background 0.2s; flex-shrink: 0; }
.toggle.on { background: var(--accent); }
.toggle-knob { width: 22px; height: 22px; border-radius: 50%; background: #fff; position: absolute; top: 2px; left: 2px; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle.on .toggle-knob { transform: translateX(18px); }

.weight-options, .design-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.option-pill { padding: 5px 10px; border-radius: 8px; font-size: 11px; background: var(--assistant-bubble); border: 1px solid var(--assistant-border); color: var(--text-secondary); cursor: pointer; transition: all 0.12s; font-family: var(--font-family); }
.option-pill.active { background: var(--accent); color: var(--user-text); border-color: var(--accent); }
.option-pill:active { transform: scale(0.95); }

.theme-list { margin-top: 12px; }
.theme-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; cursor: pointer; transition: background 0.12s; margin-bottom: 2px; }
.theme-row:active { background: rgba(128,128,128,0.1); }
.theme-row.active { background: rgba(128,128,128,0.06); }
.theme-swatches { display: flex; gap: 4px; }
.theme-swatch-dot { width: 16px; height: 16px; border-radius: 50%; }
.theme-row-name { font-size: 13px; flex: 1; }
.theme-row-check { color: var(--accent); opacity: 0; }
.theme-row.active .theme-row-check { opacity: 1; }

.font-list { display: flex; flex-direction: column; }
.font-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; }
.font-row.active { background: rgba(128,128,128,0.06); }
.font-row-check { color: var(--accent); opacity: 0; }
.font-row.active .font-row-check { opacity: 1; }

/* ============ TOAST ============ */
.toast { position: fixed; top: 52px; left: 50%; transform: translateX(-50%); padding: 8px 14px; border-radius: 20px; background: var(--sidebar); border: 1px solid rgba(52,199,89,0.2); box-shadow: 0 3px 8px rgba(0,0,0,0.15); font-size: 12px; font-weight: 500; z-index: 200; display: flex; align-items: center; gap: 6px; transition: opacity 0.3s, transform 0.3s; white-space: nowrap; }
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(-10px); pointer-events: none; }
.toast svg { color: #34c759; }

/* Compact mode */
.compact .messages { gap: 6px; }
.compact .msg-bubble { padding: 8px 12px; }
.compact .msg-avatar, .compact img.msg-avatar { width: 22px; height: 22px; }

.loading-spinner { width: 24px; height: 24px; border: 2px solid var(--assistant-border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-section { display: flex; align-items: center; justify-content: center; padding: 40px 16px; }

/* Login Screen */
.login-screen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg, #000);
}
.login-screen.hidden { display: none; }
.login-card {
  text-align: center; padding: 40px 32px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.login-card h2 { color: var(--text-primary, #fff); font-size: 22px; margin: 0; }
#login-form { display: flex; flex-direction: column; gap: 12px; width: 260px; }
#login-pass {
  padding: 12px 16px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08); color: var(--text-primary, #fff);
  font-size: 16px; text-align: center; outline: none;
}
#login-pass:focus { border-color: var(--accent, #598cff); }
#login-pass::placeholder { color: rgba(255,255,255,0.3); }
.login-btn {
  padding: 12px; border-radius: 12px; border: none;
  background: var(--accent, #598cff); color: #fff;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.login-btn:active { opacity: 0.8; }
.login-error { color: #ff6b6b; font-size: 13px; margin: 0; }
.login-error.hidden { display: none; }

/* ============ IMAGE ATTACHMENTS ============ */
.attach-previews {
  display: flex; gap: 8px; padding: 8px 12px 0;
  background: var(--sidebar); flex-wrap: wrap;
}
.attach-previews:empty { display: none; }
.attach-thumb {
  position: relative; width: 64px; height: 64px; border-radius: 10px;
  overflow: hidden; border: 1px solid var(--assistant-border); flex-shrink: 0;
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-thumb .remove-img {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,0.6); border: none; color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.msg-image { max-width: 220px; border-radius: 10px; margin-bottom: 4px; display: block; }
