/* ─── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 190px;
  --list-w: 310px;

  /* Sidebar */
  --sidebar-bg: #c8c8c8;
  --sidebar-hover: #b8b8bc;
  --sidebar-active-bg: #aaa9cf;
  --sidebar-text: #33334a;
  --sidebar-text-muted: #666677;
  --sidebar-border: #b4b4b4;

  /* Accent / brand */
  --accent: #34366f;
  --accent-hover: #292b5a;
  --accent-light: #aaa9cf;

  /* Content */
  --bg: #f4f4f4;
  --surface: #ffffff;
  --border: #d6d6d6;
  --border-light: #e8e8e8;
  --text-primary: #33334a;
  --text-secondary: #555566;
  --text-muted: #888899;

  /* Message list */
  --msg-hover: #ebebeb;
  --msg-active-bg: #eeedf7;
  --msg-active-border: #34366f;
  --msg-unread-weight: 600;

  /* Misc */
  --radius: 4px;
  --radius-sm: 3px;
  --radius-lg: 6px;
  --transition: 0.15s ease;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 2px 8px rgba(0,0,0,0.10);
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  color: var(--text-primary);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
img, svg { display: block; }


/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #33334a;
  color: #fff;
  padding: 10px 22px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 9999;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Loading overlay ────────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(51, 51, 74, 0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 9998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.loading-overlay.active { opacity: 1; pointer-events: all; }
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(170,169,207,0.35);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-overlay p { color: #ccc; font-size: 0.88rem; font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }


/* ═══════════════════════════════════════════════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════════════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  background: #eeeeee;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-logo-above {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.login-logo-above img {
  max-height: 120px;
  width: auto;
  object-fit: contain;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 38px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: fadeSlideUp 0.35s ease both;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-group .input-row {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
  transition: border-color var(--transition);
}
.form-group .input-row:focus-within { border-color: var(--accent); }
.form-group .input-row input {
  flex: 1;
  border: none;
  outline: none;
  padding: 10px 11px;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: transparent;
  min-width: 0;
}
.form-group .input-row input::placeholder { color: var(--text-muted); }
.domain-suffix {
  padding: 10px 11px 10px 0;
  font-size: 0.88rem;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
}
.form-group input[type="password"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 11px;
  font-size: 0.9rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
  background: #fff;
}
.form-group input[type="password"]:focus { border-color: var(--accent); }
.form-group input[type="password"]::placeholder { color: var(--text-muted); }

.error-msg {
  background: #fff5f5;
  border: 1px solid #f5c6c6;
  color: #9b1c1c;
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 0.82rem;
  display: none;
  margin-bottom: 12px;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%,75%  { transform: translateX(-5px); }
  50%      { transform: translateX(5px); }
}

.btn-login {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 11px;
  font-size: 0.9rem;
  font-weight: 700;
  transition: background var(--transition);
  margin-top: 6px;
}
.btn-login:hover { background: var(--accent-hover); }

.login-footer {
  text-align: center;
  margin-top: 16px;
}
.login-footer a {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 500;
}
.login-footer a:hover { text-decoration: underline; }


/* ═══════════════════════════════════════════════════════════════════════════════
   3-PANEL MAILBOX LAYOUT
═══════════════════════════════════════════════════════════════════════════════ */
.mailbox-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 200;
  transition: transform 0.28s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 14px 14px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-logo img {
  max-height: 60px;
  width: auto;
  object-fit: contain;
}

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 12px 12px 8px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}
.compose-btn svg { width: 14px; height: 14px; }
.compose-btn:hover { background: var(--accent-hover); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 10px;
  font-size: 0.72rem;
  color: var(--sidebar-text-muted);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-user svg { width: 13px; height: 13px; flex-shrink: 0; }
.sidebar-user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.65; }
.nav-item span.label { flex: 1; }
.nav-item:hover:not(.disabled) { background: var(--sidebar-hover); }
.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--accent);
  font-weight: 700;
}
.nav-item.active svg { opacity: 1; }
.nav-item.disabled { opacity: 0.38; cursor: default; }

.badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  line-height: 1.5;
}

.sidebar-bottom {
  padding: 8px 0 4px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-icons-row {
  display: flex;
  gap: 2px;
  padding: 4px 10px 2px;
}
.sidebar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text-muted);
  transition: background var(--transition), color var(--transition);
}
.sidebar-icon-btn svg { width: 15px; height: 15px; }
.sidebar-icon-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  color: var(--sidebar-text);
  font-size: 0.8rem;
  font-weight: 500;
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  transition: background var(--transition);
}
.logout-btn svg { width: 14px; height: 14px; opacity: 0.6; }
.logout-btn:hover { background: var(--sidebar-hover); }

/* ─── Sidebar Overlay (mobile) ───────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}
.sidebar-overlay.open { display: block; }

/* ─── List panel ─────────────────────────────────────────────────────────────── */
.list-panel {
  width: var(--list-w);
  flex-shrink: 0;
  background: #f8f8f8;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: #f4f4f4;
}
.list-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}
.list-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.message-list {
  flex: 1;
  overflow-y: auto;
}

.message-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background var(--transition);
  position: relative;
}
.message-item:hover { background: var(--msg-hover); }
.message-item.active {
  background: var(--msg-active-bg);
  border-left: 3px solid var(--msg-active-border);
  padding-left: 11px;
}
.message-item.active .msg-sender { color: var(--accent); }

/* Avatar */
.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Message content */
.msg-content { flex: 1; min-width: 0; }
.msg-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
}
.msg-sender {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.msg-subject {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.msg-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-attach-icon { color: var(--text-muted); margin-top: 3px; flex-shrink: 0; }
.msg-attach-icon svg { width: 13px; height: 13px; }

/* ─── Detail panel ───────────────────────────────────────────────────────────── */
.detail-panel {
  flex: 1;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: var(--text-muted);
}
.detail-empty svg { width: 48px; height: 48px; opacity: 0.25; }
.detail-empty p { font-size: 0.85rem; }

/* Toolbar */
.detail-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
  flex-shrink: 0;
}
.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.toolbar-btn svg { width: 14px; height: 14px; }
.toolbar-btn:hover { background: var(--border-light); color: var(--text-primary); }
.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}
.toolbar-spacer { flex: 1; }
.toolbar-more {
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
}
.toolbar-more:hover { background: var(--border-light); }

/* Detail content */
.detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 40px;
}

.email-subject {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  line-height: 1.3;
}

.email-meta {
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 0;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.email-meta-row {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
}
.email-meta-label {
  color: var(--text-muted);
  font-weight: 600;
  min-width: 48px;
  flex-shrink: 0;
}
.email-meta-value { color: var(--text-secondary); }
.email-meta-value strong { color: var(--text-primary); font-weight: 600; }
.email-link { color: var(--accent); }

/* Seen-by banner */
.seen-by-banner {
  background: #fff8f8;
  border: 1px solid #f5c6c6;
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8b1c1c;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 20px;
}
.seen-by-banner svg { width: 15px; height: 15px; flex-shrink: 0; color: #dc2626; }

/* Body */
.email-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Attachment section */
.attachment-wrap {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border-light);
}
.attachment-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.attachment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.attachment-icon {
  width: 38px;
  height: 38px;
  background: #dc2626;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.attachment-icon svg { width: 20px; height: 20px; color: #fff; }
.attachment-info { flex: 1; min-width: 0; }
.attachment-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-type { font-size: 0.72rem; color: var(--text-muted); }
.attachment-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition);
}
.attachment-btn svg { width: 13px; height: 13px; }
.attachment-btn:hover { background: var(--accent-hover); }
.pdf-preview {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.pdf-preview iframe {
  width: 100%;
  height: 460px;
  border: none;
  display: block;
}

/* Mobile topbar */
.topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.hamburger {
  background: none;
  border: none;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--sidebar-text);
  border-radius: 2px;
}
.topbar-logo img {
  max-height: 28px;
  width: auto;
  object-fit: contain;
}

/* Mobile folder quick-tabs */
.folder-tabs {
  display: none;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.folder-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--sidebar-text);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.folder-tab:hover {
  background: var(--sidebar-hover);
  color: var(--accent);
}
.folder-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.folder-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
}
.folder-tab.active .folder-tab-count {
  background: var(--accent);
}

/* ─── Single-column email.html (mobile fallback + standalone) ────────────────── */
.email-page-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.email-page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}
.email-page-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 40px;
}
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 18px;
  padding: 5px 0;
  border: none;
  background: none;
  cursor: pointer;
  transition: opacity var(--transition);
}
.back-btn svg { width: 14px; height: 14px; }
.back-btn:hover { opacity: 0.7; }


/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 960px) {
  :root { --list-w: 270px; }
}

@media (max-width: 720px) {
  /* Hide sidebar by default on mobile */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { display: flex; }
  .folder-tabs { display: flex; }

  /* On mobile mailbox: list takes full width, detail hidden */
  .mailbox-layout {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .list-panel {
    width: 100%;
    height: auto;
    border-right: none;
    overflow: visible;
  }
  .message-list { overflow: visible; }
  .detail-panel { display: none !important; }

  /* Email.html on mobile: full page */
  .email-page-layout { flex-direction: column; height: auto; }
  .email-page-main { overflow: visible; }
  .email-page-content { overflow: visible; }
  .pdf-preview iframe { height: 280px; }
}

@media (max-width: 480px) {
  .login-card { padding: 32px 22px 28px; }
  .msg-preview { display: none; }
  .toolbar-btn span { display: none; }
  .toolbar-btn { padding: 5px 7px; }
}
