:root {
  --bg-body: #09090b;
  --bg-sidebar: #111113;
  --bg-card: #18181b;
  --bg-card-hover: #1f1f23;
  --bg-input: #0d0d0f;

  --text-primary: #f4f4f5;
  --text-secondary: #71717a;
  --text-muted: #52525b;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.1);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --success: #22c55e;

  --border: #27272a;
  --border-soft: #1f1f23;
  --radius: 10px;
  --radius-sm: 6px;

  --sidebar-width: 220px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================
   LAYOUT
   ========================================== */
.layout {
  display: flex;
  height: 100vh;
}

/* ==========================================
   SIDEBAR
   ========================================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.menu {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  text-align: left;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  width: 100%;
  position: relative;
}

.menu-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.menu-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-info {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0;
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  width: 100%;
}

.btn-logout:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

/* ==========================================
   MAIN CONTENT
   ========================================== */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  padding: 28px 32px 0;
  margin-bottom: 20px;
}

header h2 {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.4px;
  margin-bottom: 4px;
}

header p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.tab-pane {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.2s ease;
}

.tab-pane.active { display: flex; }

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

/* Scrollable section for settings/accounts */
.tab-pane.scrollable { overflow-y: auto; }

/* ==========================================
   STATS BAR
   ========================================== */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 14px 20px;
  margin: 16px 20px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 20px;
}

.stat-item:first-child { padding-left: 8px; }

.stat-value {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-divider {
  width: 1px;
  height: 32px;
  background: var(--border);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}

.status-dot.active {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
  50%       { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.1); }
}

/* ==========================================
   EMAIL SPLIT VIEW
   ========================================== */
.email-split-view {
  display: flex;
  flex: 1;
  gap: 0;
  padding: 0 20px 20px;
  min-height: 0;
}

.email-list-panel {
  width: 340px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.email-detail-panel {
  flex: 1;
  margin-left: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.btn-icon:hover { color: var(--text-primary); background: var(--bg-card-hover); }

/* Email List */
.email-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.email-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background 0.12s;
}

.email-item:hover { background: var(--bg-card-hover); }
.email-item.active { background: var(--accent-soft); border-left: 2px solid var(--accent); }
.email-item:last-child { border-bottom: none; }

.email-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
  border: 1px solid rgba(59,130,246,0.2);
}

.email-item-body { flex: 1; min-width: 0; }

.email-item-row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.email-sender {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.email-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.email-subject-line {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.email-snippet-line {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Email Detail */
.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
}

.detail-empty p { font-size: 0.9rem; color: var(--text-secondary); }

.detail-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.detail-subject {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 14px;
  line-height: 1.4;
}

.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.detail-meta-row {
  display: flex;
  gap: 8px;
  font-size: 0.8rem;
}

.detail-meta-key {
  color: var(--text-muted);
  width: 32px;
  flex-shrink: 0;
}

.detail-meta-val { color: var(--text-secondary); }

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.detail-body-text {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-body-html {
  width: 100%;
  border: none;
  background: white;
  border-radius: var(--radius-sm);
  min-height: 300px;
}

.detail-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.detail-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  font-family: inherit;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.detail-tab:hover { background: var(--bg-card-hover); color: var(--text-secondary); }
.detail-tab.active { background: var(--accent-soft); color: var(--accent); }

/* ==========================================
   CARDS (Accounts & Settings)
   ========================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.825rem;
  margin-bottom: 14px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.card-header h3 { margin-bottom: 0; }

/* Auth Link Box */
.auth-link-box {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border: 1px dashed rgba(59,130,246,0.3);
  border-radius: var(--radius-sm);
}

.auth-link-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.auth-link-desc { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 10px; }

.auth-link-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.mono-input {
  flex: 1;
  font-family: monospace;
  font-size: 0.75rem;
  padding: 8px 10px;
  background: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

/* Account List */
.account-list { list-style: none; }

.account-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
}

.account-item:last-child { border-bottom: none; }

.account-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.account-info { flex: 1; }
.account-email { font-size: 0.875rem; font-weight: 500; }
.account-status { font-size: 0.75rem; color: var(--success); display: flex; align-items: center; gap: 4px; }

/* Filters */
.filter-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.filter-item {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-item select {
  width: 140px;
  flex-shrink: 0;
}

/* Action Bar */
.action-bar {
  display: flex;
  justify-content: flex-end;
  padding: 0 20px 20px;
}

/* ==========================================
   INPUTS & FORMS
   ========================================== */
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input, select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

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

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-card-hover); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border: none; }
.btn-danger:hover { background: var(--danger); color: white; }

/* ==========================================
   EMPTY STATE
   ========================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state p { font-size: 0.875rem; color: var(--text-secondary); }
.empty-state span { font-size: 0.8rem; color: var(--text-muted); }
.empty-state.sm { padding: 24px; }

/* ==========================================
   LOGIN OVERLAY
   ========================================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.login-card {
  background: var(--bg-card);
  padding: 36px 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 380px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.25s ease-out;
}

.login-logo {
  margin-bottom: 16px;
}

.login-card h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.input-group { margin-bottom: 16px; }

.login-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 6px;
  display: none;
}

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

/* ==========================================
   SCROLLBAR
   ========================================== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ==========================================
   ACCOUNTS & SETTINGS SCROLL WRAPPER
   ========================================== */
.scroll-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
}

/* ==========================================
   MOBILE BOTTOM NAV
   ========================================== */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 0;
  height: 56px;
}

.mobile-nav-items {
  display: flex;
  height: 100%;
}

.mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
  padding: 0;
  position: relative;
}

.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item svg { flex-shrink: 0; }

.mobile-badge {
  position: absolute;
  top: 6px; right: calc(50% - 18px);
  background: var(--accent);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  width: 14px; height: 14px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

/* Mobile email detail — full screen overlay */
.email-detail-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-body);
  z-index: 200;
  flex-direction: column;
  animation: slideInRight 0.25s ease-out;
}

.email-detail-overlay.open { display: flex; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.mobile-detail-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 0;
}

.mobile-detail-title {
  font-size: 0.875rem;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-detail-body {
  flex: 1;
  overflow-y: auto;
}

/* ==========================================
   RESPONSIVE — TABLET (≤ 900px)
   ========================================== */
@media (max-width: 900px) {
  :root { --sidebar-width: 180px; }

  .email-list-panel { width: 280px; }

  .stats-bar { padding: 10px 16px; margin: 12px 16px 10px; }
  .stat-item { padding: 0 12px; }
  .stat-value { font-size: 1rem; }

  .email-split-view { padding: 0 16px 16px; }
  .scroll-wrapper { padding: 0 16px 16px; }
  header { padding: 20px 16px 0; }
}

/* ==========================================
   RESPONSIVE — MOBILE (≤ 640px)
   ========================================== */
@media (max-width: 640px) {

  body { overflow: auto; }

  /* Hide desktop sidebar */
  .sidebar { display: none; }

  /* Show mobile bottom nav */
  .mobile-nav { display: block; }

  /* Layout becomes vertical, full height minus bottom nav */
  .layout {
    flex-direction: column;
    height: calc(100vh - 56px);
  }

  .content {
    height: 100%;
    overflow: hidden;
  }

  /* Stats bar: horizontal scroll */
  .stats-bar {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0;
    margin: 10px 12px 8px;
    padding: 10px 12px;
    scrollbar-width: none;
  }
  .stats-bar::-webkit-scrollbar { display: none; }
  .stat-item { padding: 0 14px; white-space: nowrap; }
  .stat-item:first-child { padding-left: 0; }
  .stat-value { font-size: 0.95rem; }

  /* Email split → single column, full list */
  .email-split-view {
    flex-direction: column;
    padding: 0 0 0;
    gap: 0;
    flex: 1;
    min-height: 0;
  }

  .email-list-panel {
    width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    flex: 1;
    min-height: 0;
  }

  /* Hide desktop detail panel on mobile */
  .email-detail-panel { display: none; }

  /* Larger touch targets for email items */
  .email-item { padding: 16px 14px; }
  .email-avatar { width: 38px; height: 38px; font-size: 0.85rem; }

  /* Login card */
  .login-card { padding: 28px 20px; margin: 16px; max-width: 100%; }

  /* Accounts & Settings scroll wrapper */
  .scroll-wrapper { padding: 0 12px 80px; } /* 80px for bottom nav clearance */

  header { padding: 16px 12px 0; }
  header h2 { font-size: 1.2rem; }

  .action-bar { padding: 0 12px 80px; }

  /* Filter item wrapping */
  .filter-item { flex-wrap: wrap; }
  .filter-item select { width: 100%; }

  /* Auth link box */
  .auth-link-row { flex-wrap: wrap; }
  .mono-input { width: 100%; }

  /* Card padding */
  .card { padding: 16px; border-radius: 8px; }
}

