/* Emanuel Chat PWA - Mobile-First Dark Theme */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #111;
  --bg-secondary: #1a1a1a;
  --bg-elevated: #222;
  --text: #eee;
  --text-secondary: #888;
  --accent: #f90;
  --user-bubble: #2563eb;
  --assistant-bubble: #262626;
  --error: #f44;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

/* Screen management */
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

/* ===== PIN Screen ===== */
.pin-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 12px;
}

.pin-icon {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: var(--accent);
  color: #000;
  font-size: 40px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.pin-container h1 {
  font-size: 1.5em;
  font-weight: 600;
}

.pin-sub {
  color: var(--text-secondary);
  font-size: 0.9em;
}

#pin-input {
  width: 200px;
  text-align: center;
  font-size: 1.5em;
  letter-spacing: 8px;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid #444;
  border-radius: 12px;
  color: var(--text);
  outline: none;
}
#pin-input:focus {
  border-color: var(--accent);
}

.btn-primary {
  padding: 12px 32px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 12px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.btn-primary:active {
  opacity: 0.8;
}

.error-text {
  color: var(--error);
  font-size: 0.85em;
  min-height: 1.2em;
}

/* ===== Thread List Screen ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--bg);
  border-bottom: 1px solid #222;
}

.app-header h1 {
  font-size: 1.3em;
  font-weight: 600;
}

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.3em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active {
  opacity: 0.7;
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  padding-bottom: var(--safe-bottom);
}

.thread-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #1e1e1e;
  cursor: pointer;
  transition: background 0.15s;
}
.thread-item:active {
  background: var(--bg-elevated);
}

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

.thread-title {
  font-size: 1em;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-preview {
  font-size: 0.85em;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.thread-date {
  font-size: 0.75em;
  color: var(--text-secondary);
  margin-left: 12px;
  white-space: nowrap;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  text-align: center;
}
.empty-state .sub {
  font-size: 0.85em;
  margin-top: 4px;
}

/* ===== Chat Screen ===== */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + var(--safe-top));
  background: var(--bg);
  border-bottom: 1px solid #222;
}

.chat-header h2 {
  flex: 1;
  font-size: 1em;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.delete-btn {
  font-size: 1.5em;
  color: var(--text-secondary);
  background: transparent;
}

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.95em;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

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

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

.message .msg-time {
  font-size: 0.7em;
  color: rgba(255,255,255,0.5);
  margin-top: 4px;
  text-align: right;
}

.message.assistant .msg-time {
  color: var(--text-secondary);
}

/* Tool indicator */
.tool-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 0.85em;
  color: var(--accent);
}
.tool-indicator.hidden {
  display: none;
}

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

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

/* Input bar */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid #222;
}

#message-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid #333;
  border-radius: 22px;
  color: var(--text);
  font-size: 1em;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}
#message-input:focus {
  border-color: #555;
}

.mic-btn {
  color: var(--text-secondary);
}
.mic-btn.recording {
  color: var(--error);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.send-btn {
  color: var(--accent);
}
.send-btn:disabled {
  color: var(--text-secondary);
  opacity: 0.5;
}

/* Streaming cursor */
.streaming-cursor::after {
  content: '|';
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
}
@keyframes blink {
  50% { opacity: 0; }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 2px;
}
