:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --hover: #f1f5f9;
  --active-bg: #eff6ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Login */
.login-container {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-brand h1 {
  margin: 0;
  font-size: 18px;
}

.login-brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

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

.brand-icon.small {
  width: 28px;
  height: 28px;
  font-size: 14px;
  border-radius: 7px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

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

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--hover);
}

.btn-danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.btn-danger:hover {
  background: #fef2f2;
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 6px;
}

.btn-ghost:hover {
  background: var(--hover);
  color: var(--text);
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--hover);
}

.full-width {
  width: 100%;
  margin-top: 14px;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
}

/* Shell */
.app-shell {
  display: grid;
  grid-template-columns: 220px 340px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 14px;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
}

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item,
.mailbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.nav-item:hover,
.mailbox-item:hover {
  background: var(--hover);
}

.nav-item.active,
.mailbox-item.active {
  background: var(--active-bg);
  color: var(--primary);
  font-weight: 600;
}

.badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
}

.badge.muted {
  background: #e2e8f0;
  color: var(--muted);
}

.mailbox-section {
  margin-top: 20px;
  flex: 1;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  padding: 0 10px 6px;
}

.mailbox-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mailbox-item {
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

/* List Pane */
.list-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.list-toolbar {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}

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

.email-row {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.email-row:hover {
  background: var(--hover);
}

.email-row.active {
  background: var(--active-bg);
}

.email-row.unread .email-subject,
.email-row.unread .email-sender {
  font-weight: 700;
}

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

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

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

.email-sender {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-time {
  font-size: 11.5px;
  color: var(--muted);
  flex-shrink: 0;
}

.email-subject {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  padding: 0 2px;
}

.star-btn.starred {
  color: #eab308;
}

/* Detail Pane */
.detail-pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  padding: 24px;
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 8px;
  opacity: 0.5;
}

.detail-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--surface);
}

.detail-toolbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}

.btn-tab {
  background: #fff;
  border: none;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
}

.btn-tab.active {
  background: var(--active-bg);
  color: var(--primary);
  font-weight: 600;
}

.detail-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
}

.detail-header h2 {
  margin: 0 0 10px;
  font-size: 19px;
}

.detail-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  gap: 12px;
  flex-wrap: wrap;
}

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

.meta-arrow {
  margin: 0 6px;
}

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

.att-chip {
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text);
}

.detail-body-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#detail-html-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

#detail-text-body {
  flex: 1;
  margin: 0;
  padding: 20px 24px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.form-row {
  margin-bottom: 12px;
}

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

.warning-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 12.5px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.mobile-only {
  display: none;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .detail-pane {
    display: none;
  }
  .app-shell.mobile-detail .list-pane {
    display: none;
  }
  .app-shell.mobile-detail .detail-pane {
    display: flex;
  }
  .mobile-only {
    display: inline-block;
  }
}
