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

:root {
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --nav-h: 60px;
  --header-h: 52px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border: #334155;
  --accent-light: #1e3a5f;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

/* ─── Auth Screen ─── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.auth-card {
  text-align: center;
  padding: 48px 32px;
  max-width: 360px;
  width: 100%;
}
.auth-logo {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
}
.auth-logo span { color: var(--accent); }
.auth-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 8px 0 32px;
}
.auth-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 16px;
  min-height: 20px;
}

/* ─── Header ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
.logo {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.logo span { color: var(--accent); }
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.status-dots {
  display: flex;
  gap: 6px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.4;
}
.status-dot.active {
  background: var(--success);
  opacity: 1;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.icon-btn:hover { background: var(--bg-input); }

/* ─── Pages ─── */
.page {
  display: none;
  height: calc(100vh - var(--header-h) - var(--nav-h));
  overflow-y: auto;
  padding: 16px;
}
.page.active { display: flex; flex-direction: column; }
.page-heading {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
}

/* ─── Chat ─── */
.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}
.chat-welcome {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.chat-welcome h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.chat-welcome p { font-size: 0.9rem; }
.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 0.9rem;
  line-height: 1.5;
  border-radius: var(--radius);
  word-wrap: break-word;
}
.chat-bubble.user { white-space: pre-wrap; }
.chat-bubble.user {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 2px;
}
.chat-bubble.ai {
  margin-right: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 2px;
}
.chat-bubble.ai.loading {
  color: var(--text-muted);
  font-style: italic;
}
.chat-bubble.ai p { margin-bottom: 6px; }
.chat-bubble.ai p:last-child { margin-bottom: 0; }
.chat-bubble.ai ul { margin: 6px 0; padding-left: 18px; list-style: disc; }
.chat-bubble.ai li { margin-bottom: 4px; }
.chat-bubble.ai li:last-child { margin-bottom: 0; }
.chat-bubble.ai strong { font-weight: 600; }
.chat-bubble.ai em { font-style: italic; }
.chat-bubble.ai br { display: block; content: ''; margin-top: 4px; }
.chat-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
  max-height: 120px;
  outline: none;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { opacity: 0.4; cursor: default; }

/* ─── Inbox ─── */
.inbox-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-chips { display: flex; gap: 6px; }
.chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
}
.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.inbox-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.inbox-card:hover { border-color: var(--accent); }
.inbox-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.inbox-source {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 3px;
}
.inbox-source.email { color: var(--accent); background: var(--accent-light); }
.inbox-source.teams { color: #7c3aed; background: #ede9fe; }
.inbox-source.asana { color: #ea580c; background: #fff7ed; }
[data-theme="dark"] .inbox-source.teams { background: #2e1065; }
[data-theme="dark"] .inbox-source.asana { background: #431407; }
.inbox-time { font-size: 0.75rem; color: var(--text-muted); }
.inbox-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 2px; }
.inbox-preview { font-size: 0.8rem; color: var(--text-secondary); }

/* ─── Priority Sections ─── */
.inbox-priority-section { margin-bottom: 16px; }
.inbox-priority-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 0 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.inbox-priority-count {
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-secondary);
  padding: 1px 6px;
  border-radius: 8px;
}
.priority-high { color: var(--danger); }
.priority-medium { color: var(--warning); }
.priority-low { color: var(--text-muted); }
.priority-tasks { color: #ea580c; }

/* ─── Task Groups ─── */
.inbox-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.inbox-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
}
.inbox-group-header:hover { background: var(--bg-input); }
.inbox-group-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.inbox-group-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inbox-group-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.inbox-group-count {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 10px;
}
.inbox-group-chevron {
  font-size: 0.65rem;
  color: var(--text-muted);
}
.inbox-group-tasks {
  border-top: 1px solid var(--border);
}
.inbox-task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 8px 24px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
}
.inbox-task-row:last-child { border-bottom: none; }
.inbox-task-row:hover { background: var(--bg-input); }
.inbox-task-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inbox-task-due {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 12px;
}

/* ─── Settings ─── */
.settings-group { margin-bottom: 24px; }
.settings-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-actions { display: flex; gap: 6px; flex-shrink: 0; }
.setting-name { font-size: 0.9rem; font-weight: 500; }
.setting-detail { font-size: 0.8rem; color: var(--text-muted); }
.ical-url-input {
  width: 100%;
  margin-top: 6px;
  padding: 6px 8px;
  font-size: 0.75rem;
  font-family: monospace;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-secondary);
  outline: none;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg-input); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }

/* ─── Bottom Nav ─── */
.bottom-nav {
  display: flex;
  height: var(--nav-h);
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-family: inherit;
  cursor: pointer;
  position: relative;
  padding: 0;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }
.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  font-weight: 600;
}

/* ─── Modal ─── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
}
.modal-body { padding: 16px; }
.detail-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.detail-content {
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 16px;
}

/* ─── Forms ─── */
.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg-input);
  color: var(--text);
  resize: vertical;
  min-height: 80px;
  outline: none;
}
.textarea:focus { border-color: var(--accent); }
.draft-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 8px;
  white-space: pre-wrap;
}

/* ─── Empty & Loading ─── */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.loading { text-align: center; padding: 24px; }
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto 8px;
}
.loading p { font-size: 0.8rem; color: var(--text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive ─── */
@media (min-width: 640px) {
  .page { padding: 24px; max-width: 640px; margin: 0 auto; width: 100%; }
  .modal { border-radius: 16px; margin: auto; }
  .modal-overlay { align-items: center; }
}
