/* ── Top Bar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border), 0 2px 8px rgba(0,0,0,.04);
}
.topbar-left  { display: flex; align-items: center; gap: 10px; width: var(--sidebar-w); flex-shrink: 0; }
.topbar-center { flex: 1; max-width: 480px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.brand-icon-wrap {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #1a56db, #0ea5e9);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 13px; font-weight: 800; color: var(--text); letter-spacing: -.2px; }
.brand-sub  { font-size: 10px; color: var(--text-muted); font-weight: 500; }

/* Search */
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within {
  border-color: #1a56db;
  box-shadow: 0 0 0 3px rgba(26,86,219,.08);
}
.search-box input { border: none; background: none; outline: none; width: 100%; color: var(--text); font-size: 13px; }
.search-box input::placeholder { color: var(--text-muted); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }

/* Topbar refresh button — with spin animation */
.topbar-refresh { position: relative; }
.topbar-refresh #refresh-svg { transition: transform .15s; }
.topbar-refresh:hover #refresh-svg { transform: rotate(30deg); }
.topbar-refresh.spinning #refresh-svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* User menu */
.user-email-label { font-size: 12px; color: var(--text-secondary); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main layout ─────────────────────────────────────────────────────────── */
.main-layout {
  display: flex;
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0; bottom: 0;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px 8px;
  gap: 4px;
  transition: transform .2s ease;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

.btn-compose {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, #1a56db, #0ea5e9);
  color: #fff;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-weight: 700; font-size: 13px;
  margin-bottom: 10px;
  width: 100%;
  box-shadow: 0 2px 8px rgba(26,86,219,.28);
  transition: opacity .15s, box-shadow .15s;
}
.btn-compose:hover { opacity: .92; box-shadow: 0 4px 12px rgba(26,86,219,.36); }

.folder-list { display: flex; flex-direction: column; gap: 2px; }
.folder-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  transition: background .1s;
  user-select: none;
}
.folder-item:hover { background: var(--bg-hover); color: var(--text); }
.folder-item.active { background: #eff6ff; color: #1a56db; font-weight: 600; }
[data-theme="dark"] .folder-item.active { background: #1e2f55; color: #60a5fa; }
.folder-item .folder-name { display: flex; align-items: center; gap: 8px; }
.folder-item .badge {
  background: #1a56db; color: white;
  border-radius: 10px; font-size: 10px;
  padding: 1px 6px; font-weight: 700;
}

/* ── Message List ────────────────────────────────────────────────────────── */
.message-list-pane {
  width: var(--list-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--bg-panel);
  overflow: hidden;
}
.pane-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.pane-title { font-weight: 700; font-size: 13px; color: var(--text); }
.toolbar-actions { display: flex; gap: 2px; }

#message-list { flex: 1; overflow-y: auto; }

/* Skeleton loading */
.msg-skeleton {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  display: flex; flex-direction: column; gap: 7px;
}
.skel { background: var(--border); border-radius: 4px; animation: shimmer 1.4s ease infinite; }
.skel-sm  { height: 10px; width: 40%; }
.skel-md  { height: 11px; width: 70%; }
.skel-lg  { height: 11px; width: 90%; }
@keyframes shimmer {
  0%,100% { opacity: 1; } 50% { opacity: .4; }
}

.msg-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px 14px 10px 18px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background .1s;
  position: relative;
}
.msg-item:hover { background: var(--bg-hover); }
.msg-item.active { background: var(--bg-active); }
.msg-item.unread .msg-from { font-weight: 700; color: var(--text); }
.msg-item.unread .msg-subject { font-weight: 600; }
.msg-item.unread::before {
  content: '';
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
  width: 5px; height: 5px; border-radius: 50%;
  background: #1a56db;
}
.msg-from    { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-subject { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.msg-meta    { display: flex; justify-content: space-between; margin-top: 1px; }
.msg-date    { font-size: 11px; color: var(--text-muted); }
.msg-flags   { display: flex; gap: 4px; }
.msg-flags .flag-star { color: #f59e0b; font-size: 11px; }
.msg-flags .flag-att  { font-size: 11px; }

.pagination {
  padding: 7px 12px;
  display: flex; justify-content: center; gap: 6px;
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}
.page-btn {
  padding: 4px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); color: var(--text-secondary);
  font-size: 12px; background: var(--bg-input); cursor: pointer;
}
.page-btn:hover { background: var(--bg-hover); }
.page-btn.active { background: #1a56db; color: white; border-color: #1a56db; }

/* ── Message Reader ──────────────────────────────────────────────────────── */
.message-reader-pane { flex: 1; overflow-y: auto; background: var(--bg); display: flex; flex-direction: column; }
#message-reader { flex: 1; padding: 24px; max-width: 860px; margin: 0 auto; width: 100%; }

.reader-header { margin-bottom: 20px; }
.reader-subject { font-size: 20px; font-weight: 700; margin-bottom: 12px; line-height: 1.3; }
.reader-meta { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-secondary); }
.reader-meta .meta-row { display: flex; gap: 8px; }
.reader-meta .meta-label { font-weight: 600; min-width: 34px; color: var(--text-muted); flex-shrink: 0; }
.reader-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.reader-body { line-height: 1.7; font-size: 14px; }
.reader-body-text { white-space: pre-wrap; font-family: inherit; }
.reader-body iframe { width: 100%; border: none; min-height: 200px; }
.reader-attachments { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.reader-attachments h4 { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; font-weight: 600; }
.attachment-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 12px;
  cursor: pointer; transition: background .1s; text-decoration: none; color: var(--text);
}
.attachment-chip:hover { background: var(--bg-hover); }

/* Empty / loading states */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; height: 100%; min-height: 200px;
  color: var(--text-muted); font-size: 14px;
}
.reader-empty { min-height: 60vh; }
.folder-loading { padding: 12px 10px; color: var(--text-muted); font-size: 13px; }

/* ── PWA install banner ──────────────────────────────────────────────────── */
#pwa-banner {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: white;
  border-radius: 12px;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: 999;
  max-width: calc(100vw - 32px);
}
#pwa-install-btn {
  background: linear-gradient(135deg,#1a56db,#0ea5e9);
  color: white; border: none; border-radius: 7px;
  padding: 6px 14px; font-size: 12px; font-weight: 700;
  cursor: pointer; flex-shrink: 0;
}
#pwa-dismiss-btn {
  background: none; border: none; color: rgba(255,255,255,.5);
  cursor: pointer; font-size: 16px; flex-shrink: 0; padding: 0 2px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) { :root { --list-w: 260px; } }
@media (max-width: 700px) {
  .brand-sub, .user-email-label { display: none; }
  :root { --list-w: 240px; }
}
@media (max-width: 580px) {
  .message-list-pane { display: none; }
  .message-list-pane.mobile-visible { display: flex; position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0; z-index: 50; width: 100%; }
  .sidebar { position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 60; }
  .sidebar.collapsed { transform: translateX(-100%); }
}
