/* DSMail design system - a warm, calm, Claude-inspired look. */

:root {
  --bg: #faf9f7;
  --bg-elevated: #ffffff;
  --bg-subtle: #f3f1ee;
  --bg-hover: #ede9e4;
  --border: #e7e3dd;
  --text: #24211d;
  --text-muted: #6f6a63;
  --text-faint: #a39c92;
  --accent: #b45f2e;
  --accent-hover: #9a4f24;
  --accent-soft: #f2e4d8;
  --accent-contrast: #ffffff;
  --danger: #c2402c;
  --success: #3f7d5c;
  --unread-dot: #b45f2e;
  --shadow-sm: 0 1px 2px rgba(30, 25, 18, 0.06);
  --shadow-md: 0 4px 16px rgba(30, 25, 18, 0.08);
  --shadow-lg: 0 12px 40px rgba(30, 25, 18, 0.14);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --sidebar-w: 260px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --bg-elevated: #262320;
    --bg-subtle: #2b2825;
    --bg-hover: #33302b;
    --border: #3a3631;
    --text: #ece7e0;
    --text-muted: #a89f93;
    --text-faint: #766e63;
    --accent: #e08a55;
    --accent-hover: #f0a06e;
    --accent-soft: #3a2b1f;
    --accent-contrast: #241a10;
    --danger: #e0705c;
    --success: #6fbb92;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

button { font-family: inherit; }

::selection { background: var(--accent-soft); }

/* Layout */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 20px;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #d68a4a);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  margin-bottom: 18px;
}

.compose-btn:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); transform: translateY(-1px); }

.nav-section { margin-bottom: 18px; }

.nav-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 0 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item svg { flex-shrink: 0; opacity: 0.85; }

.nav-item .badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
}
.nav-item.active .badge, .nav-item .badge.unread { color: var(--accent); }

.nav-item .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

/* Main content */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

.search-box {
  flex: 1;
  max-width: 520px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  color: var(--text-muted);
}
.search-box:focus-within { border-color: var(--accent); }
.search-box input { flex: 1; }

.content-scroll { flex: 1; overflow-y: auto; }

/* Thread list */
.thread-list { display: flex; flex-direction: column; }

.thread-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease;
}
.thread-row:hover { background: var(--bg-subtle); }
.thread-row.unread { font-weight: 600; }
.thread-row.unread::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--unread-dot);
  flex-shrink: 0;
}
.thread-row:not(.unread)::before { content: ""; width: 8px; flex-shrink: 0; }

.thread-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 13px; flex-shrink: 0;
}

.thread-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.thread-participants { font-size: 13.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-subject-line { font-size: 13.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-subject-line .subject { color: var(--text); }

.thread-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.thread-time { font-size: 12px; color: var(--text-faint); }

.star-btn { background: none; border: none; cursor: pointer; padding: 2px; color: var(--text-faint); }
.star-btn.starred { color: var(--accent); }
.star-btn svg { display: block; }

.attach-badge { color: var(--text-faint); }

/* Thread detail */
.thread-detail-wrap { max-width: 860px; margin: 0 auto; padding: 24px 24px 80px; }
.thread-header { margin-bottom: 20px; }
.thread-header h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 10px; }
.thread-actions { display: flex; gap: 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; transition: all 0.12s ease;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.message-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.message-card-header {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 16px 20px; cursor: pointer;
}

.message-from { font-weight: 600; font-size: 14px; }
.message-to { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.message-time { font-size: 12.5px; color: var(--text-faint); flex-shrink: 0; }

.message-body {
  padding: 0 20px 20px 62px;
  font-size: 14.5px;
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.message-body img { max-width: 100%; border-radius: 8px; }
.message-body blockquote { color: var(--text-muted); }
.message-body a { color: var(--accent); text-decoration: underline; }

.attachments-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.attachment-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg-subtle); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 12.5px; color: var(--text-muted);
}
.attachment-chip:hover { background: var(--bg-hover); color: var(--text); }

.quick-actions { display: flex; gap: 10px; margin-top: 4px; }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text); font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: all 0.12s ease;
}
.pill-btn:hover { background: var(--bg-hover); }
.pill-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.pill-btn.primary:hover { background: var(--accent-hover); }

/* Compose modal */
.compose-overlay {
  position: fixed; inset: 0; background: rgba(20, 16, 10, 0.35);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  backdrop-filter: blur(2px);
}
.compose-panel {
  width: min(680px, 96vw); max-height: 90vh; display: flex; flex-direction: column;
  background: var(--bg-elevated); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border); border-bottom: none;
  overflow: hidden;
}
.compose-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px;
}
.compose-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.compose-field-row { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 8px; gap: 10px; }
.compose-field-row label { font-size: 13px; color: var(--text-faint); width: 44px; flex-shrink: 0; }
.compose-field-row input, .compose-field-row select { border: none; background: transparent; flex: 1; font-size: 14px; color: var(--text); outline: none; }
.compose-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }

/* Forms (auth + account settings) */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-md); }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p.subtitle { color: var(--text-muted); font-size: 13.5px; margin: 0 0 24px; }
.field-group { margin-bottom: 14px; }
.field-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }
.field-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.form-actions { margin-top: 20px; }
.btn-block { width: 100%; padding: 11px; border-radius: var(--radius-md); border: none; background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; }
.btn-block:hover { background: var(--accent-hover); }
.auth-switch { margin-top: 18px; text-align: center; font-size: 13px; color: var(--text-muted); }
.auth-switch a { color: var(--accent); font-weight: 500; }

.settings-shell { max-width: 720px; margin: 0 auto; padding: 32px 24px 80px; }
.settings-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.account-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.account-row:last-child { border-bottom: none; }
.account-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.account-info { flex: 1; }
.account-info .email { font-weight: 600; font-size: 14px; }
.account-info .meta { font-size: 12px; color: var(--text-faint); }
.status-pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.status-pill.ok { background: #e2f1e8; color: var(--success); }
.status-pill.error { background: #fbe3df; color: var(--danger); }
.status-pill.pending, .status-pill.syncing { background: var(--bg-subtle); color: var(--text-faint); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 80px 20px; color: var(--text-faint); text-align: center; gap: 10px; }
.empty-state svg { opacity: 0.5; margin-bottom: 6px; }

.toast-stack { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-elevated); border: 1px solid var(--border); box-shadow: var(--shadow-md); border-radius: var(--radius-md); padding: 12px 16px; font-size: 13.5px; max-width: 320px; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

.mobile-topbar { display: none; }
.mobile-menu-btn { background: none; border: none; color: var(--text); cursor: pointer; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; height: 100%; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .mobile-topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .thread-detail-wrap { padding: 16px 14px 60px; }
  .message-body { padding-left: 20px; }
  .form-grid { grid-template-columns: 1fr; }
}

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { opacity: 0; transition: opacity 0.15s ease; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
