/* ===== Two-column + Slide-in Detail Dashboard ===== */

.dashboard-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: calc(100vh - 66px);
  overflow: hidden;
  position: relative;
}

/* --- Shared panel styles --- */
.dash-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: #ffffff;
}

.dash-panel:last-child {
  border-right: none;
}

.dash-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(250, 250, 253, 0.92);
  flex-shrink: 0;
}

/* --- Mailbox header: compact buttons --- */
.dash-mb-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.08);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1;
}

.dash-mb-count-badge:empty {
  display: none;
}

.dash-compact-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 9px;
  border: 1px solid rgba(17, 17, 17, 0.08);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f7f7fa);
  color: var(--text-light);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 120ms ease;
  flex-shrink: 0;
}

.dash-compact-btn:hover {
  background: #ffffff;
  border-color: rgba(17, 17, 17, 0.14);
  color: var(--text);
}

.dash-compact-btn.is-primary {
  background: rgba(0, 122, 255, 0.06);
  border-color: rgba(0, 122, 255, 0.18);
  color: var(--primary);
}

.dash-compact-btn.is-primary:hover {
  background: rgba(0, 122, 255, 0.12);
  border-color: rgba(0, 122, 255, 0.26);
}

.dash-compact-btn.is-active {
  background: rgba(0, 122, 255, 0.08);
  border-color: rgba(0, 122, 255, 0.2);
  color: var(--primary);
}

.dash-compact-btn:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.dash-panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 28px;
}

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

.dash-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* --- Left panel: Mailbox list --- */
.dash-mailboxes {
  background: #fafafd;
}

.dash-search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.dash-search {
  width: 100%;
  box-sizing: border-box;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.dash-search:focus {
  border-color: rgba(0, 122, 255, 0.28);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.08);
}

.dash-mb-item {
  display: flex;
  align-items: flex-start;
  gap: 0;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(229, 229, 234, 0.5);
  cursor: pointer;
  transition: background 120ms ease;
  min-height: 0;
}

.dash-mb-item:hover {
  background: rgba(0, 122, 255, 0.04);
}

.dash-mb-item.is-active {
  background: rgba(0, 122, 255, 0.08);
  border-left: 3px solid var(--primary);
  padding-left: 11px;
}

.dash-mb-item.is-pinned {
  border-left: 3px solid rgba(255, 159, 10, 0.5);
  padding-left: 11px;
}

.dash-mb-item.is-pinned.is-active {
  border-left-color: var(--primary);
}

.dash-mb-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dash-mb-addr {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-mb-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 11px;
  color: var(--muted);
}

.dash-mb-meta-time {
  min-width: 0;
}

.dash-mb-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 14px;
  height: 14px;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(255, 59, 48, 0.12);
  color: #ff3b30;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.dash-mb-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 120ms ease;
}

.dash-mb-item:hover .dash-mb-actions {
  opacity: 1;
}

.dash-mb-actions {
  margin-top: -1px;
}

.dash-mb-actions .dash-icon-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 120ms ease;
}

.dash-mb-actions .dash-icon-btn:hover {
  background: rgba(0, 122, 255, 0.08);
  border-color: rgba(0, 122, 255, 0.14);
  color: var(--primary);
}

.dash-mb-actions .dash-icon-btn.is-danger:hover {
  background: rgba(255, 59, 48, 0.08);
  border-color: rgba(255, 59, 48, 0.14);
  color: var(--danger);
}

.dash-mb-actions .dash-icon-btn.is-pinned {
  color: #f59e0b;
}

.dash-mb-actions .dash-icon-btn svg {
  width: 14px;
  height: 14px;
}

/* --- Batch action bar --- */
.dash-batch-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 59, 48, 0.03);
  flex-shrink: 0;
}

.dash-batch-bar.is-visible {
  display: flex;
}

.dash-batch-select-all {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-light);
  cursor: pointer;
  user-select: none;
}

.dash-batch-select-all input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid rgba(0, 0, 0, 0.18);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  position: relative;
  transition: all 120ms ease;
}

.dash-batch-select-all input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.dash-batch-select-all input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 4.5px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.dash-batch-select-all input[type="checkbox"]:indeterminate {
  background: var(--primary);
  border-color: var(--primary);
}

.dash-batch-select-all input[type="checkbox"]:indeterminate::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 3px;
  width: 8px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
}

.dash-batch-select-all input[type="checkbox"]:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.08);
}

.dash-compact-btn.is-danger {
  border-color: rgba(255, 59, 48, 0.18);
  color: var(--danger);
  background: rgba(255, 59, 48, 0.04);
}

.dash-compact-btn.is-danger:hover {
  background: rgba(255, 59, 48, 0.1);
  border-color: rgba(255, 59, 48, 0.28);
}

/* --- Mailbox item checkbox (hidden unless in selection mode) --- */
.dash-mb-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 0;
  height: 16px;
  margin: 1px 0 0;
  padding: 0;
  border: 1.5px solid rgba(0, 0, 0, 0.18);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: width 150ms ease, opacity 150ms ease, margin 150ms ease;
  opacity: 0;
  pointer-events: none;
  position: relative;
  overflow: hidden;
}

.dash-mb-checkbox:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.dash-mb-checkbox:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 4.5px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.dash-mb-checkbox:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.08);
}

/* Selection mode: checkboxes slide in */
.dash-mb-list-selecting .dash-mb-checkbox {
  width: 16px;
  opacity: 1;
  pointer-events: auto;
  margin-right: 8px;
}

/* --- Create mailbox overlay --- */
.dash-create-wrap {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 122, 255, 0.02);
  display: none;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.dash-create-wrap.is-open {
  display: flex;
}



.dash-create-row {
  display: flex;
  gap: 6px;
}

.dash-create-input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.dash-create-input:focus {
  border-color: rgba(0, 122, 255, 0.28);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.08);
}

.dash-create-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(0, 122, 255, 0.16);
  border-radius: 10px;
  background: rgba(0, 122, 255, 0.08);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 120ms ease;
}

.dash-create-btn:hover {
  background: rgba(0, 122, 255, 0.12);
}

.dash-domain-select {
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  min-width: 0;
  flex: 1;
}

/* --- Middle panel: Email list --- */
.dash-emails {
  background: #ffffff;
}

.dash-email-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(229, 229, 234, 0.5);
  cursor: pointer;
  transition: background 120ms ease;
  position: relative;
}

.dash-email-item.is-new {
  animation: dash-email-enter 220ms ease-out;
}

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

.dash-email-item:hover {
  background: rgba(0, 122, 255, 0.03);
}

.dash-email-item.is-active {
  background: rgba(0, 122, 255, 0.07);
  border-left: 3px solid var(--primary);
  padding-left: 13px;
}

.dash-email-item.is-unread .dash-email-subject {
  font-weight: 700;
  color: var(--text);
}

.dash-email-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.dash-email-sender {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.dash-email-time-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.dash-email-time {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.dash-email-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #ff3b30;
  box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.14);
  flex: 0 0 auto;
}

.dash-email-subject {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-email-preview {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-email-code {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0 5px;
  min-height: 18px;
  border: 1px solid rgba(52, 199, 89, 0.18);
  border-radius: 999px;
  background: rgba(52, 199, 89, 0.08);
  color: #166534;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  flex-shrink: 0;
  cursor: pointer;
  font: inherit;
}

.dash-email-code:hover {
  background: rgba(52, 199, 89, 0.16);
  border-color: rgba(22, 101, 52, 0.28);
}

/* --- Right panel: Slide-in detail --- */
.dash-detail {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(580px, 50vw);
  background: #ffffff;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(15, 23, 42, 0.08);
  z-index: 20;
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dash-detail.is-open {
  transform: translateX(0);
}

.dash-detail .dash-panel-body {
  padding: 0;
}

.dash-detail-close {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 120ms ease;
  flex-shrink: 0;
}

.dash-detail-close:hover {
  background: rgba(255, 59, 48, 0.08);
  border-color: rgba(255, 59, 48, 0.14);
  color: var(--danger);
}

.dash-detail-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.dash-detail-subject {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.dash-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dash-detail-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8f8fb;
  font-size: 12px;
}

.dash-detail-chip-label {
  color: var(--text-light);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.dash-detail-chip-value {
  color: var(--text);
  font-weight: 500;
}

.dash-detail-chip-code {
  border-color: rgba(52, 199, 89, 0.22);
  background: rgba(52, 199, 89, 0.06);
  cursor: pointer;
}

.dash-detail-chip-code:hover {
  background: rgba(52, 199, 89, 0.12);
}

.dash-detail-chip-code .dash-detail-chip-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  color: #166534;
  letter-spacing: 0.06em;
}

.dash-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.dash-detail-body .detail-body {
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

/* --- Backdrop when detail is open (optional dim) --- */
.dash-detail-backdrop {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 19;
  background: rgba(15, 23, 42, 0.06);
}

.dash-detail-backdrop.is-visible {
  display: block;
}

/* --- Custom confirm modal --- */
.dash-confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

.dash-confirm-overlay.is-open {
  display: flex;
}

.dash-confirm-box {
  width: min(400px, calc(100vw - 40px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  animation: dash-confirm-in 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes dash-confirm-in {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.dash-confirm-body {
  padding: 24px 24px 18px;
  text-align: center;
}

.dash-confirm-icon {
  display: none;
}

.dash-confirm-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
}

.dash-confirm-msg {
  margin: 0;
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.6;
  white-space: pre-line;
}

.dash-confirm-msg:empty {
  display: none;
}

.dash-confirm-actions {
  display: flex;
  border-top: 1px solid var(--border);
}

.dash-confirm-btn {
  flex: 1;
  height: 48px;
  padding: 0 16px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease;
}

.dash-confirm-btn:first-child {
  border-right: 1px solid var(--border);
  color: var(--text-light);
}

.dash-confirm-btn:first-child:hover {
  background: rgba(0, 0, 0, 0.03);
}

.dash-confirm-btn:last-child {
  color: var(--danger);
}

.dash-confirm-btn:last-child:hover {
  background: rgba(255, 59, 48, 0.05);
}

/* --- Empty states --- */
.dash-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  gap: 8px;
  height: 100%;
}

.dash-empty-icon {
  font-size: 36px;
  opacity: 0.5;
}

.dash-empty-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
}

.dash-empty-sub {
  font-size: 12px;
  color: var(--muted);
}

/* --- Toolbar buttons --- */
.dash-toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(17, 17, 17, 0.08);
  border-radius: 9px;
  background: linear-gradient(180deg, #ffffff, #f7f7fa);
  color: var(--text-light);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 120ms ease;
}

.dash-toolbar-btn:hover {
  background: #ffffff;
  border-color: rgba(17, 17, 17, 0.12);
  color: var(--text);
}

.dash-toolbar-btn:disabled {
  pointer-events: none;
}

.dash-toolbar-btn.is-primary {
  background: rgba(0, 122, 255, 0.08);
  border-color: rgba(0, 122, 255, 0.16);
  color: var(--primary);
}

.dash-toolbar-btn.is-primary:hover {
  background: rgba(0, 122, 255, 0.12);
}

.dash-toolbar-btn.is-danger {
  color: var(--danger);
}

.dash-toolbar-btn.is-danger:hover {
  background: rgba(255, 59, 48, 0.06);
  border-color: rgba(255, 59, 48, 0.14);
}

.dash-toolbar-btn svg {
  width: 14px;
  height: 14px;
}

/* --- Loading states --- */
.dash-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
  gap: 8px;
}

.dash-loading .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0, 122, 255, 0.14);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* --- Refresh indicator --- */
.dash-refresh-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  height: 28px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: #2563eb;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* --- Pager --- */
.dash-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
}

.dash-pager button {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-light);
  font-size: 12px;
  cursor: pointer;
}

.dash-pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

.dash-pager button:not(:disabled):hover {
  background: rgba(0, 122, 255, 0.05);
  border-color: rgba(0, 122, 255, 0.14);
  color: var(--primary);
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .dashboard-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .dash-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .dash-mailboxes .dash-panel-body {
    max-height: 300px;
  }

  .dash-emails .dash-panel-body {
    max-height: 50vh;
  }

  .dash-mb-actions {
    opacity: 1;
  }

  .dash-detail {
    width: 100%;
    box-shadow: none;
    border-left: none;
  }
}

@media (min-width: 901px) and (max-width: 1100px) {
  .dashboard-layout {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .dash-detail {
    width: min(480px, 55vw);
  }
}