/* ── Symdy PWA — Companion-first UI ────────────────────────────────── */
:root {
  --bg: #0a0a12;
  --bg-raised: #111120;
  --bg-higher: #1a1a2e;
  --text: #e0e0e8;
  --text-dim: #8888a0;
  --text-muted: #606078;
  --accent: #7c8cf8;
  --accent-dim: #5a6ad6;
  --accent-glow: #9cabff;
  --error: #f05050;
  --success: #50c878;
  --border: #1e1e34;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; width: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ───────────────────────────────────────────────────── */
#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg);
}

/* ── Header ────────────────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  background: var(--bg);
}

#header-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

#header-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online { background: var(--success); box-shadow: 0 0 6px rgba(80,200,120,0.4); }
.status-dot.offline { background: var(--text-muted); }
.status-dot.error { background: var(--error); }

#header-actions {
  display: flex;
  gap: 4px;
  -webkit-app-region: no-drag;
}

.header-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* ── Sleep Banner ──────────────────────────────────────────────────── */
#sleep-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px;
  background: #1a1a2e;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-dim);
  flex-shrink: 0;
}

#sleep-banner.hidden { display: none; }

#wake-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 4px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}

#wake-btn:hover { background: var(--accent-glow); }

/* ── Welcome ───────────────────────────────────────────────────────── */
#welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 24px;
}

#welcome.hidden { display: none; }

.welcome-message {
  max-width: 420px;
  text-align: center;
}

.welcome-icon {
  font-size: 40px;
  color: var(--accent);
  margin-bottom: 20px;
  opacity: 0.8;
}

.welcome-message p {
  font-size: 17px;
  line-height: 1.7;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.welcome-message .welcome-prompt {
  color: var(--text);
  font-size: 18px;
  font-weight: 500;
  margin-top: 8px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 20px;
}

.btn-primary:hover { background: var(--accent-glow); transform: translateY(-1px); }

/* ── Messages ──────────────────────────────────────────────────────── */
#messages {
  flex: 1 1 0%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

#messages:empty { display: none; }

.message {
  max-width: 85%;
  animation: msgIn 0.25s ease-out;
}

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

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

.msg-user .msg-content {
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 16px 16px 4px 16px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
}

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

.msg-assistant .msg-content {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 16px 16px 16px 4px;
  font-size: 15px;
  line-height: 1.6;
  word-wrap: break-word;
  color: var(--text);
}

.msg-assistant .msg-content p {
  margin-bottom: 8px;
}

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

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

.msg-assistant .msg-content pre {
  background: var(--bg-higher);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
}

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

.msg-assistant .msg-content li {
  margin-left: 20px;
  margin-bottom: 4px;
}

.msg-copy-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 4px;
  transition: all var(--transition);
}

.msg-assistant:hover .msg-copy-btn {
  display: inline-block;
}

.msg-copy-btn:hover {
  background: var(--bg-higher);
  color: var(--text);
}

/* ── Typing ────────────────────────────────────────────────────────── */
#typing {
  padding: 8px 16px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-start;
  flex-shrink: 0;
}

#typing.hidden { display: none; }

.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(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* ── Input Area ────────────────────────────────────────────────────── */
#input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
  z-index: 10;
}

#input {
  flex: 1;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: 120px;
  transition: border-color var(--transition);
  -webkit-user-select: text;
  user-select: text;
}

#input:focus {
  border-color: var(--accent-dim);
}

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

#send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

#send-btn:disabled {
  background: var(--bg-higher);
  color: var(--text-muted);
  cursor: not-allowed;
}

#send-btn:not(:disabled):hover {
  background: var(--accent-glow);
  transform: scale(1.05);
}

/* ── Panels ────────────────────────────────────────────────────────── */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.4);
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.panel.hidden { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}

.panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.panel-close:hover { color: var(--text); }

#memory-content,
#settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Settings ──────────────────────────────────────────────────────── */
.setting-group {
  margin-bottom: 20px;
}

.setting-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.setting-group input[type="text"],
.setting-group input[type="password"],
.setting-group input[type="time"],
.setting-group select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
}

.setting-group input:focus,
.setting-group select:focus {
  border-color: var(--accent-dim);
}

.setting-group select {
  appearance: auto;
}

.setting-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.setting-info {
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

.setting-info a {
  color: var(--accent);
  text-decoration: none;
}

.setting-info a:hover {
  text-decoration: underline;
}

/* ── Memory Categories ─────────────────────────────────────────────── */
.memory-cat {
  margin-bottom: 16px;
}

.memory-cat-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.memory-item {
  padding: 8px 12px;
  margin-bottom: 4px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}

.memory-item .confidence {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 6px;
}

/* ── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Loading ──────────────────────────────────────────────────────── */
#loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  animation: fadeIn 0.3s ease-out;
}

#loading.hidden { display: none; }

#loading p {
  color: var(--text-dim);
  font-size: 15px;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  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); } }
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Connection Banner ────────────────────────────────────────────── */
#conn-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(240, 80, 80, 0.15);
  border-bottom: 1px solid rgba(240, 80, 80, 0.3);
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}

#conn-banner.hidden { display: none; }

#retry-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 3px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
}

#retry-btn:hover { background: var(--accent-glow); }

/* ── Messages Container ───────────────────────────────────────────── */
#messages.hidden,
#input-area.hidden { display: none; }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .panel { width: 100vw; }
  .message { max-width: 90%; }
  #input { font-size: 16px; }
}
