/* ── ClawMail Web — Full Mail Client ─────────────────── */
:root {
  --bg: #0a0f0a;
  --bg-card: #111a11;
  --bg-hover: #162016;
  --bg-input: #0d140d;
  --bg-sent: #0f1a16;
  --bg-received: #111a11;
  --border: #1a2e1a;
  --border-light: #243424;
  --accent: #7cf7c0;
  --accent-dim: rgba(124, 247, 192, 0.12);
  --accent-dark: #1a3a2a;
  --text: #e0e8e0;
  --text-dim: #8a9a8a;
  --text-muted: #556655;
  --danger: #ff6b6b;
  --danger-bg: rgba(255, 107, 107, 0.1);
  --blue: #64b5f6;
  --blue-dim: rgba(100, 181, 246, 0.1);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Login Page ──────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 30%, #0d1a0d 0%, var(--bg) 70%);
}
.login-container { width: 100%; max-width: 420px; padding: 1.5rem; }
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon { font-size: 3rem; display: block; margin-bottom: 0.5rem; }
.login-logo h1 { font-size: 1.6rem; color: var(--accent); font-weight: 700; }
.login-subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.3rem; font-family: monospace; }
.form-group { margin-bottom: 1.2rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.4rem; font-weight: 500; }
.password-wrapper { display: flex; }
.password-wrapper input {
  flex: 1; padding: 0.75rem 1rem; background: var(--bg-input);
  border: 1px solid var(--border); border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text); font-size: 1rem; outline: none;
  transition: border-color var(--transition);
}
.password-wrapper input:focus { border-color: var(--accent); }
.toggle-pw {
  background: var(--bg-input); border: 1px solid var(--border); border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 0 0.8rem; cursor: pointer; font-size: 1rem; color: var(--text-dim);
}
.toggle-pw:hover { color: var(--accent); }
.turnstile-wrapper { margin: 1.2rem 0; display: flex; justify-content: center; }
.error-msg {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid rgba(255,107,107,0.2); border-radius: var(--radius-sm);
  padding: 0.6rem 1rem; font-size: 0.85rem; margin-bottom: 1rem; text-align: center;
}
.btn-primary {
  width: 100%; padding: 0.75rem; background: var(--accent); color: #0a0f0a;
  border: none; border-radius: var(--radius-sm); font-size: 1rem; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  -webkit-appearance: none; appearance: none; position: relative; z-index: 10;
  touch-action: manipulation; -webkit-tap-highlight-color: rgba(124,247,192,0.3);
  transition: all var(--transition);
}
.btn-primary:hover:not(:disabled) { background: #9dffd6; }
.btn-primary:active:not(:disabled) { background: #6de0a8; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.login-footer { text-align: center; color: var(--text-muted); font-size: 0.75rem; margin-top: 1.5rem; }

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

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  width: 280px; min-width: 280px; background: var(--bg-card);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-header {
  padding: 0.8rem 1rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.4rem; font-weight: 700; color: var(--accent); font-size: 1rem; }
.sidebar-actions { display: flex; gap: 0.3rem; }
.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-dim); padding: 0.3rem 0.5rem; cursor: pointer; font-size: 0.85rem;
  transition: all var(--transition); touch-action: manipulation;
}
.icon-btn:hover, .icon-btn:active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

.compose-btn {
  margin: 0.8rem; padding: 0.6rem; background: var(--accent); color: #0a0f0a;
  border: none; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.9rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  touch-action: manipulation; transition: all var(--transition);
}
.compose-btn:hover { background: #9dffd6; }

/* Folders */
.folder-list { padding: 0.4rem 0; }
.folder-item {
  padding: 0.55rem 1rem; display: flex; align-items: center; gap: 0.6rem;
  cursor: pointer; color: var(--text-dim); font-size: 0.88rem;
  transition: all var(--transition); border-left: 3px solid transparent;
  touch-action: manipulation;
}
.folder-item:hover { background: var(--bg-hover); color: var(--text); }
.folder-item.active { background: var(--accent-dim); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.folder-icon { width: 1.2rem; text-align: center; }
.folder-count {
  margin-left: auto; font-size: 0.7rem; background: var(--accent-dim);
  color: var(--accent); padding: 0.1rem 0.4rem; border-radius: 999px; font-weight: 600;
}

.sidebar-divider { height: 1px; background: var(--border); margin: 0.4rem 1rem; }

/* Search */
.search-box { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%; padding: 0.45rem 0.7rem; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 0.82rem; outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-muted); }

/* Thread List */
.thread-list { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.thread-item {
  padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; gap: 0.7rem; align-items: flex-start;
  transition: background var(--transition); touch-action: manipulation;
}
.thread-item:hover { background: var(--bg-hover); }
.thread-item.active { background: var(--accent-dark); }
.thread-item.unread .thread-subject { font-weight: 700; color: var(--text); }
.thread-item.unread .thread-sender { font-weight: 700; }

.thread-avatar {
  width: 34px; height: 34px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-weight: 700;
  font-size: 0.8rem; flex-shrink: 0;
}
.thread-avatar.inbound { background: var(--accent-dim); color: var(--accent); }
.thread-avatar.outbound { background: var(--blue-dim); color: var(--blue); }

.thread-info { flex: 1; min-width: 0; }
.thread-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.4rem; }
.thread-sender { font-size: 0.82rem; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-date { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.thread-subject { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-meta { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.15rem; }
.thread-direction {
  font-size: 0.6rem; padding: 0.05rem 0.35rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}
.thread-direction.sent { background: var(--blue-dim); color: var(--blue); }
.thread-direction.received { background: var(--accent-dim); color: var(--accent); }
.thread-unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 0.35rem; }

.sidebar-footer {
  padding: 0.6rem 0.8rem; border-top: 1px solid var(--border);
  font-size: 0.7rem; color: var(--text-muted); text-align: center;
}

/* ── Main Content ────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.content-header {
  padding: 0.7rem 1.2rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-card); min-height: 48px;
}
.content-header-left { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.content-header h2 { font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content-header-actions { display: flex; gap: 0.3rem; }

.content-body { flex: 1; overflow-y: auto; padding: 1rem; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-muted); text-align: center; padding: 2rem;
}
.empty-state .empty-icon { font-size: 3.5rem; margin-bottom: 0.8rem; opacity: 0.5; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 0.4rem; color: var(--text-dim); }
.empty-state p { font-size: 0.85rem; max-width: 320px; }

/* ── Messages ────────────────────────────────────────── */
.message-card {
  border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 0.8rem;
  max-width: 85%; border: 1px solid var(--border);
}
.message-card.received {
  background: var(--bg-received); margin-right: auto;
  border-left: 3px solid var(--accent);
}
.message-card.sent {
  background: var(--bg-sent); margin-left: auto;
  border-right: 3px solid var(--blue);
}
.message-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; flex-wrap: wrap; gap: 0.3rem; }
.message-from { font-weight: 600; font-size: 0.85rem; display: flex; align-items: center; gap: 0.4rem; }
.message-from .direction-badge {
  font-size: 0.6rem; padding: 0.1rem 0.35rem; border-radius: 999px;
  text-transform: uppercase; font-weight: 700; letter-spacing: 0.05em;
}
.direction-badge.sent-badge { background: var(--blue-dim); color: var(--blue); }
.direction-badge.received-badge { background: var(--accent-dim); color: var(--accent); }
.from-email { color: var(--text-dim); font-weight: 400; font-size: 0.75rem; }
.message-time { font-size: 0.7rem; color: var(--text-muted); }
.message-to { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.message-body {
  font-size: 0.88rem; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}

/* ── Reply Bar ───────────────────────────────────────── */
.reply-bar {
  padding: 0.8rem 1rem; border-top: 1px solid var(--border);
  background: var(--bg-card); display: flex; gap: 0.6rem; align-items: flex-end;
}
.reply-bar textarea {
  flex: 1; resize: vertical; min-height: 40px; max-height: 180px;
  padding: 0.55rem 0.7rem; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 0.88rem; outline: none;
}
.reply-bar textarea:focus { border-color: var(--accent); }
.reply-bar textarea::placeholder { color: var(--text-muted); }
.btn-send {
  padding: 0.55rem 1rem; background: var(--accent); color: #0a0f0a;
  border: none; border-radius: var(--radius-sm); font-weight: 600;
  cursor: pointer; white-space: nowrap; touch-action: manipulation;
  transition: all var(--transition);
}
.btn-send:hover { background: #9dffd6; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Compose Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }

.compose-modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.5);
  transform: translateY(100%); transition: transform 0.3s ease;
}
.modal-overlay.active .compose-modal { transform: translateY(0); }

.compose-header {
  padding: 0.8rem 1.2rem; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
.compose-header h3 { font-size: 0.95rem; }
.compose-close { background: none; border: none; color: var(--text-dim); font-size: 1.5rem; cursor: pointer; padding: 0.2rem; }
.compose-close:hover { color: var(--danger); }
.compose-body { padding: 0.8rem 1.2rem; }
.compose-body .form-group { margin-bottom: 0.8rem; }
.compose-body label { display: block; font-size: 0.75rem; color: var(--text-dim); margin-bottom: 0.2rem; font-weight: 500; }
.compose-body input, .compose-body textarea {
  width: 100%; padding: 0.5rem 0.7rem; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 0.88rem; outline: none;
}
.compose-body input:focus, .compose-body textarea:focus { border-color: var(--accent); }
.compose-body textarea { resize: vertical; min-height: 140px; }
.compose-body input::placeholder, .compose-body textarea::placeholder { color: var(--text-muted); }
.compose-from {
  font-size: 0.8rem; color: var(--text-dim); padding: 0.4rem 0.7rem;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 0.8rem; font-family: monospace;
}
.compose-footer {
  padding: 0.8rem 1.2rem; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 0.5rem;
  position: sticky; bottom: 0; background: var(--bg-card);
}
.btn-cancel {
  padding: 0.5rem 1rem; background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-dim); cursor: pointer;
}
.btn-cancel:hover { border-color: var(--text-dim); color: var(--text); }

/* ── Toast ───────────────────────────────────────────── */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: 0.4rem; }
.toast {
  padding: 0.6rem 1rem; border-radius: var(--radius-sm); font-size: 0.82rem;
  box-shadow: var(--shadow); animation: toastIn 0.3s ease, toastOut 0.3s ease 3.7s forwards;
  max-width: 300px;
}
.toast.success { background: var(--accent-dark); color: var(--accent); border: 1px solid rgba(124,247,192,0.3); }
.toast.error { background: rgba(255,107,107,0.15); color: var(--danger); border: 1px solid rgba(255,107,107,0.3); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Loading ─────────────────────────────────────────── */
.loading-spinner { display: flex; align-items: center; justify-content: center; padding: 2rem; color: var(--text-muted); font-size: 0.85rem; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 0.6rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hamburger ───────────────────────────────────────── */
.hamburger {
  display: none; background: none; border: none; color: var(--accent);
  font-size: 1.3rem; cursor: pointer; padding: 0.2rem; touch-action: manipulation;
}
.mobile-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }

/* ── Mobile ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .hamburger { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    transform: translateX(-100%); width: 85%; max-width: 320px;
    transition: transform 0.3s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-overlay.active { display: block; }
  .content-header { padding: 0.6rem 0.8rem; }
  .content-body { padding: 0.7rem; }
  .reply-bar { padding: 0.6rem 0.7rem; }
  .message-card { max-width: 95%; padding: 0.8rem; }
  .compose-modal { max-width: 100%; border-radius: var(--radius) var(--radius) 0 0; }
  .thread-item { padding: 0.6rem 0.7rem; }
}

@media (max-width: 480px) {
  .login-card { padding: 2rem 1.2rem; }
  .message-card { max-width: 100%; }
  .content-body { padding: 0.5rem; }
}
