:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --amber-border: #fde68a;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.16);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans Thai", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
}

.text-green { color: var(--green); }
.text-blue { color: var(--primary); }
.text-red { color: var(--red); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 7px;
}

.btn-full {
  width: 100%;
  height: 40px;
  font-size: 14px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: #94a3b8;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: #e2e8f066;
  color: var(--text);
}

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: #fecaca;
}
.btn-danger:hover:not(:disabled) {
  background: #fee2e2;
}

.btn-amber {
  background: var(--amber);
  color: #fff;
}
.btn-amber:hover:not(:disabled) {
  background: #b45309;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: #e2e8f070;
  color: var(--text);
}

.icon-btn-xs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: all 0.12s ease;
}
.icon-btn-xs:hover {
  background: #e2e8f0;
  color: var(--text);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-slate { background: #f1f5f9; color: var(--text-secondary); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); border: 1px solid var(--amber-border); }

/* Login View */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #eff6ff 0%, #f4f6f9 60%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 32px 28px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  margin: -10px 0 22px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.login-field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.login-inline-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.login-inline-row input {
  flex: 1;
  min-width: 0;
}

.captcha-box {
  width: 122px;
  height: 42px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: #f8fafc;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.15s;
}

.captcha-box:hover {
  border-color: var(--primary);
}

.captcha-box img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
}

.captcha-loading {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-send-code {
  min-width: 112px;
  height: 42px;
  flex-shrink: 0;
  justify-content: center;
  white-space: nowrap;
}

.form-hint {
  color: #047857;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 8px;
  text-align: left;
  line-height: 1.45;
}

.login-footer-note {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  max-width: 220px;
  transition: background 0.15s, border-color 0.15s;
}

.user-chip:hover {
  background: var(--primary-soft);
  border-color: #bfdbfe;
  color: var(--primary);
}

.user-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  flex-shrink: 0;
}

.user-chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.security-info-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.security-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.security-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.login-sub {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input {
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-form input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-error {
  color: var(--red);
  font-size: 13px;
  text-align: left;
  background: var(--red-soft);
  padding: 8px 12px;
  border-radius: 8px;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Topbar */
.topbar {
  height: 56px;
  min-height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  z-index: 20;
}

.topbar-left, .topbar-center, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.batch-picker {
  display: flex;
  align-items: center;
  gap: 4px;
}

.select-pill {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  outline: none;
  max-width: 210px;
}
.select-pill:hover {
  border-color: var(--border-strong);
}

.topbar-center {
  flex: 1;
  max-width: 480px;
}

.search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 34px;
  padding: 0 28px 0 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-subtle);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: all 0.15s ease;
}
.search-box input:focus {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-clear {
  position: absolute;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: #cbd5e1;
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.toggle-chip.compact {
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
}
.toggle-chip input {
  margin: 0;
  accent-color: var(--primary);
}

/* Table View */
.table-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px 18px 18px;
  gap: 12px;
}

.stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.stats-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  color: var(--text-muted);
  font-size: 12px;
}

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  padding: 4px 10px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--primary);
  font-weight: 500;
}

.hint-pill {
  font-size: 12.5px;
  color: var(--text-muted);
}

.table-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.table-scroll {
  flex: 1;
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  z-index: 2;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background 0.1s ease;
}
.data-table tbody tr:hover {
  background: #f8fafc;
}

.col-check { width: 36px; text-align: center; }
.col-platform { width: 64px; }
.col-company { min-width: 180px; max-width: 260px; }
.col-email { min-width: 230px; }
.col-pwd { min-width: 135px; }
.col-status { width: 78px; }
.col-latest { min-width: 220px; max-width: 300px; }
.col-actions { width: 175px; white-space: nowrap; }

.cell-flex {
  display: flex;
  align-items: center;
  gap: 6px;
}

.company-text {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

.email-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin-left: -8px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  text-align: left;
}
.email-link:hover {
  background: var(--primary-soft);
  text-decoration: underline;
}

.token-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.token-dot.ok { background: var(--green); }
.token-dot.none { background: #cbd5e1; }
.token-dot.err { background: var(--red); }

.pwd-mask {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-secondary);
}

.latest-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
}
.latest-top {
  display: flex;
  align-items: center;
  gap: 6px;
}
.latest-subject {
  font-size: 12.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
}
.latest-time {
  font-size: 11.5px;
  color: var(--text-muted);
}
.latest-placeholder {
  font-size: 12px;
  color: #94a3b8;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 8px;
}
.empty-state h3 {
  margin: 6px 0 0;
  color: var(--text);
}
.empty-state p {
  margin: 0 0 12px;
  font-size: 13px;
}

/* ==========================================================================
   Mode 2: 3-Pane Split Webmail View
   ========================================================================== */
.mail-view {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 268px 365px 1fr;
  overflow: hidden;
  background: var(--surface);
}

.mail-rail {
  border-right: 1px solid var(--border);
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rail-header {
  height: 44px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rail-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rail-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.rail-count {
  font-size: 11.5px;
  color: var(--text-muted);
  background: #e2e8f0;
  padding: 1px 7px;
  border-radius: 999px;
}

.rail-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.rail-search input {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font-size: 12.5px;
  outline: none;
}
.rail-search input:focus {
  border-color: var(--primary);
}

.rail-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rail-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s ease;
  position: relative;
}
.rail-item:hover {
  background: #eef2f7;
}
.rail-item.active {
  background: var(--primary-soft);
  border-color: var(--primary-border);
}
.rail-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.rail-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.rail-company {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-email {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-pill {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* Middle Pane */
.mail-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
}

.shop-mini-card {
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shop-mini-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.shop-mini-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.shop-mini-company {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.shop-mini-company:hover {
  color: var(--primary);
}

.shop-mini-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.shop-mini-creds {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.cred-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11.5px;
  cursor: pointer;
  max-width: 100%;
  transition: border-color 0.12s, background 0.12s;
}
.cred-chip:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.cred-k {
  color: var(--text-muted);
  font-size: 11px;
}
.cred-v {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 210px;
}

.folder-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.folder-tabs::-webkit-scrollbar { display: none; }

.folder-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s;
}
.folder-tab:hover {
  background: #f1f5f9;
  color: var(--text);
}
.folder-tab.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.folder-badge {
  font-size: 11px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--text-secondary);
}
.folder-tab.active .folder-badge {
  background: var(--primary);
  color: #fff;
}

.mail-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.mail-search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.mail-search-wrap input {
  width: 100%;
  height: 30px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12.5px;
  outline: none;
}
.mail-search-wrap input:focus {
  border-color: var(--primary);
}
.mail-search-wrap .icon-btn-xs {
  position: absolute;
  right: 3px;
}

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

.msg-item {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.msg-item:hover {
  background: #f8fafc;
}
.msg-item.active {
  background: var(--primary-soft);
}
.msg-item.unread .msg-sender,
.msg-item.unread .msg-subject {
  font-weight: 700;
  color: var(--text);
}

.msg-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.msg-sender-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.msg-sender {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-time {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.msg-subject {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.msg-preview {
  font-size: 12px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
}

.msg-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.mail-pagination {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

/* Right Pane: Email Reader */
.mail-reader-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
}

.reader-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 10px;
}

.reader-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reader-header {
  flex-shrink: 0;
  padding: 16px 22px 14px;
  border-bottom: 1px solid var(--border);
  background: #fbfcfe;
}

.reader-subject-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.reader-subject {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}

.reader-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.reader-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-label {
  color: var(--text-muted);
  width: 44px;
  flex-shrink: 0;
}

.meta-dim {
  color: var(--text-secondary);
  font-size: 12px;
}

.meta-spacer { flex: 1; }

.meta-time {
  color: var(--text-muted);
  font-size: 12px;
}

.otp-banner {
  margin-top: 12px;
  padding: 9px 14px;
  background: var(--amber-soft);
  border: 1px solid var(--amber-border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.otp-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.otp-tag {
  background: var(--amber);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
}

.otp-code {
  font-size: 20px;
  letter-spacing: 0.14em;
  color: #92400e;
}

.attachments-bar {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  transition: all 0.12s;
}
.att-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.reader-body-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.reader-body-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
}

.reader-iframe-host {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.reader-iframe {
  display: block;
  width: 100%;
  height: 100%;
  flex: 1;
  min-height: 0;
  border: none;
  background: #fff;
}

.reader-text {
  flex: 1;
  margin: 0;
  padding: 20px 24px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-lg { max-width: 720px; }
.modal-sm { max-width: 440px; }

.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: #f8fafc;
}

.modal-footer-inline {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.modal-footer-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.btn-group {
  display: flex;
  gap: 8px;
}

/* Forms */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-field, .form-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label, .form-row label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-field input,
.form-field textarea,
.form-row input,
.form-row select,
#importTextArea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  outline: none;
}
.form-field input:focus,
.form-field textarea:focus,
.form-row input:focus,
.form-row select:focus,
#importTextArea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  cursor: pointer;
}
.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Import Modal */
.tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.tab-btn {
  padding: 6px 12px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.file-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  padding: 28px 20px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  background: #fafbfd;
}
.file-dropzone:hover, .file-dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.dropzone-title {
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.dropzone-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.text-preview-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.preview-box {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.preview-summary {
  padding: 9px 12px;
  background: #f0fdf4;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: #166534;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.preview-warn {
  color: var(--amber);
  font-size: 12px;
}

.preview-table-wrap {
  max-height: 190px;
  overflow: auto;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.mini-table th, .mini-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
  white-space: nowrap;
}
.mini-table th {
  background: #f8fafc;
  color: var(--text-muted);
  position: sticky;
  top: 0;
}

.import-options {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Global Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(37, 99, 235, 0.16);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.drop-overlay-box {
  background: var(--surface);
  border: 2px dashed var(--primary);
  border-radius: 18px;
  padding: 44px 56px;
  text-align: center;
  color: var(--primary);
  box-shadow: var(--shadow-lg);
}
.drop-overlay-box h3 { margin: 12px 0 4px; color: var(--text); }
.drop-overlay-box p { margin: 0; color: var(--text-muted); font-size: 13px; }

/* Spinner & State Cards */
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.pane-state {
  padding: 36px 18px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.pane-error {
  color: var(--red);
  background: var(--red-soft);
  margin: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: left;
  word-break: break-word;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 360px;
}
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

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

/* Responsive */
@media (max-width: 1100px) {
  .mail-view {
    grid-template-columns: 220px 300px 1fr;
  }
  .hint-pill { display: none; }
}

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .topbar-center { order: 3; width: 100%; max-width: none; }
  .mail-view { grid-template-columns: 1fr; }
  .mail-rail { max-height: 180px; border-right: none; border-bottom: 1px solid var(--border); }
  .mail-list-pane { max-height: 320px; border-right: none; border-bottom: 1px solid var(--border); }
  .import-options, .form-row-2 { grid-template-columns: 1fr; }
}
