/* ============================================================
   Friday — White-label AI Assistant
   Dark/light theme, mobile-first, accent via CSS var
   ============================================================ */

:root {
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-dark: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.15);

  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #242833;
  --bg-hover: #2a2e3a;

  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border: #2d3344;
  --border-light: #1e2230;

  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8f9fc;
    --bg-card: #ffffff;
    --bg-input: #f1f3f9;
    --bg-hover: #eef0f6;
    --text: #1a1a2e;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  }
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   SETUP WIZARD
   ============================================================ */

.setup-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

.setup-container {
  width: 100%;
  max-width: 420px;
}

.setup-progress {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
  border-radius: 2px;
}

.setup-step-label {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 32px;
}

.setup-step {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.setup-step.active {
  display: flex;
}

.step-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.setup-step h1 {
  font-size: 24px;
  font-weight: 700;
}

.setup-step p {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 300px;
}

.setup-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  text-align: center;
  transition: border-color 0.2s;
}

.setup-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.setup-input::placeholder {
  color: var(--text-muted);
}

.pin-input {
  font-size: 24px;
  letter-spacing: 8px;
  max-width: 200px;
}

.setup-error {
  font-size: 13px;
  color: var(--red);
  min-height: 18px;
}

.name-suggestions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.suggestion {
  padding: 6px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.suggestion:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.setup-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  margin-top: 8px;
}

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

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

.setup-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.setup-btn-secondary {
  padding: 14px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.setup-btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.setup-nav {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}

.setup-nav .setup-btn-secondary {
  flex: 1;
}

.setup-nav .setup-btn {
  flex: 2;
  margin-top: 0;
}

/* --- Color & Emoji pickers --- */

.look-section {
  width: 100%;
  text-align: left;
}

.look-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.color-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.color-btn.selected {
  border-color: var(--text);
  transform: scale(1.15);
}

.color-btn:hover {
  transform: scale(1.1);
}

.emoji-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.emoji-btn {
  width: 48px;
  height: 48px;
  font-size: 24px;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.emoji-btn:hover {
  background: var(--bg-hover);
}

/* --- Icon Upload --- */

.icon-upload-section {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.or-divider {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.icon-upload-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.icon-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.icon-upload-btn.uploaded {
  border-color: var(--green);
  color: var(--green);
  border-style: solid;
}

.preview-icon-img {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

/* --- Claude Connection --- */

.claude-instructions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  margin: 8px 0;
}

.instruction-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}

.instruction-step .num {
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.instruction-step code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  word-break: break-all;
}

.setup-btn-test {
  width: 100%;
  padding: 12px;
  background: var(--bg-input);
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.setup-btn-test:hover {
  background: var(--accent-glow);
}

.setup-btn-test:disabled {
  opacity: 0.5;
  cursor: default;
}

.test-result {
  font-size: 13px;
  min-height: 20px;
  word-break: break-word;
}

.test-result.success {
  color: var(--green);
}

.test-result.error {
  color: var(--red);
}

/* ============================================================
   LOGIN SCREEN (PIN)
   ============================================================ */

#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  gap: 24px;
  text-align: center;
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.login-logo .icon {
  font-size: 56px;
}

.login-logo h1 {
  font-size: 28px;
  font-weight: 700;
}

.login-logo p {
  font-size: 15px;
  color: var(--text-secondary);
}

.pin-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 240px;
}

.pin-form .setup-input {
  font-size: 28px;
  letter-spacing: 10px;
}

.login-btn {
  width: 100%;
  max-width: 240px;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

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

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

.login-error {
  font-size: 13px;
  color: var(--red);
  min-height: 18px;
}

/* ============================================================
   APP SCREEN
   ============================================================ */

#app-screen {
  display: none;
  flex-direction: column;
  height: 100dvh;
  max-width: 700px;
  margin: 0 auto;
  position: relative;
}

/* ---- Header ---- */

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

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

.header-left .logo-icon {
  font-size: 24px;
}

.header-left h2 {
  font-size: 18px;
  font-weight: 700;
}

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

.header-btn {
  padding: 6px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.header-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ---- Conversations Sidebar ---- */

.conversations-drawer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
}

.conversations-drawer.open {
  display: flex;
}

.drawer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.drawer-panel {
  position: relative;
  width: 280px;
  max-width: 80vw;
  height: 100%;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1;
}

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

.drawer-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.drawer-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
}

.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  gap: 8px;
}

.conv-item:hover {
  background: var(--bg-hover);
}

.conv-item.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.conv-title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

.conv-delete:hover {
  color: var(--red);
  background: rgba(239, 68, 68, 0.1);
}

/* ---- Drawer Tabs ---- */

.drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.drawer-tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-family: inherit;
}

.drawer-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.drawer-tab:hover {
  color: var(--text);
}

/* ---- Drawer Footer ---- */

.drawer-footer {
  display: flex;
  gap: 8px;
  padding: 8px 12px 12px;
  align-items: center;
}

.drawer-new-btn {
  flex: 1;
  padding: 10px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.drawer-new-btn:hover {
  background: var(--accent-dark);
}

.drawer-settings-btn {
  width: 38px;
  height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.drawer-settings-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ---- Drawer Settings ---- */

.drawer-settings {
  display: none;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-direction: column;
  gap: 10px;
}

.drawer-settings.open {
  display: flex;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.settings-toggle:hover {
  background: var(--accent-glow);
}

/* ---- Conv Item Archive Button ---- */

.conv-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.2s;
}

.conv-item:hover .conv-actions {
  opacity: 1;
}

.conv-archive {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}

.conv-archive:hover {
  color: var(--yellow);
  background: rgba(245, 158, 11, 0.1);
}

/* ---- Chat Direction (top = newest at top) ---- */

.chat-area.chat-top #messages-list {
  display: flex;
  flex-direction: column-reverse;
}

.chat-area.chat-top #empty-state {
  justify-content: flex-end;
}

/* ---- Chat Area ---- */

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 48px 24px;
}

#empty-state .empty-icon {
  font-size: 48px;
  opacity: 0.5;
}

#empty-state p {
  font-size: 15px;
}

/* ---- Chat Bubbles ---- */

.message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

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

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

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

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

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

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

.message.user .message-meta {
  text-align: right;
}

.message-photo {
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  margin-bottom: 6px;
  cursor: pointer;
}

/* ---- Typing indicator ---- */

.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 4px;
}

.typing-indicator.active {
  display: flex;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

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

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ---- Input Bar ---- */

.input-bar {
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  resize: none;
  min-height: 42px;
  max-height: 150px;
  line-height: 1.4;
  transition: border-color 0.2s;
}

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

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

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

.action-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.action-btn svg {
  width: 20px;
  height: 20px;
}

#send-btn {
  background: var(--accent);
  color: white;
}

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

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

#send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

#photo-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

#photo-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ---- Photo Preview ---- */

#photo-preview {
  display: none;
  padding: 8px 16px 0;
  position: relative;
}

#photo-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 2px solid var(--accent);
}

.photo-remove-btn {
  position: absolute;
  top: 4px;
  left: 72px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  border: none;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ---- Mic Button ---- */

#mic-btn {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

#mic-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

#mic-btn.recording {
  background: var(--red);
  color: white;
  border-color: var(--red);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ---- Recording Indicator ---- */

#recording-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(239, 68, 68, 0.08);
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
  border-top: 1px solid rgba(239, 68, 68, 0.15);
}

.rec-dot {
  width: 8px;
  height: 8px;
  background: var(--red);
  border-radius: 50%;
  animation: blink 1s infinite;
}

/* ---- Upload Indicator ---- */

#upload-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  border-top: 1px solid rgba(99, 102, 241, 0.15);
}

/* ---- Photo Modal ---- */

.photo-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  cursor: pointer;
}

.photo-modal img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

/* ---- Toast ---- */

.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s;
  white-space: nowrap;
}

.toast.success { background: var(--green); color: white; }
.toast.error { background: var(--red); color: white; }
.toast.info { background: var(--accent); color: white; }

/* ---- Spinner ---- */

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

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

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ---- Responsive ---- */

@media (min-width: 640px) {
  #app-screen {
    max-width: 700px;
  }
}
