:root {
  --bg: #FFFFFF;
  --text: #00142e;
  --text-muted: #5b6b80;
  --action: #f71685;
  --action-dark: #d40f6f;
  --border: #e7eaf0;
  --card-bg: #ffffff;
  --card-unread-bg: #e9fbf1;
  --card-unread-border: #1fbf6b;
  --shadow: 0 1px 2px rgba(0,20,46,0.06), 0 8px 24px rgba(0,20,46,0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--action); }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Auth pages ---------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}
.auth-logo img { height: 52px; }

.auth-card h1 {
  font-size: 20px;
  margin: 0 0 6px;
  text-align: center;
}
.auth-card p.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--action);
  box-shadow: 0 0 0 3px rgba(247,22,133,0.12);
}
.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-weight: 700;
  font-size: 14px;
  transition: background 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--action); color: #fff; }
.btn-primary:hover { background: var(--action-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-block { width: 100%; }
.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: #cfd6e2; }
.btn-ghost {
  background: transparent;
  color: var(--text);
}
.btn-danger { background: #fff; color: #d64545; border: 1px solid #f3c9c9; }
.btn-danger:hover { background: #fff5f5; }

.auth-footer {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

.alert {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-error { background: #fdecec; color: #a12727; border: 1px solid #f3c9c9; }
.alert-success { background: #e9fbf1; color: #106b3f; border: 1px solid #b7ebcf; }
.alert-info { background: #eef3fb; color: #1c4a8a; border: 1px solid #c9dcf3; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.topbar .logo img { height: 42px; display: block; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar .user-email { font-size: 13px; color: var(--text-muted); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  font-size: 13px;
}
.icon-btn:hover { background: #f4f6f9; color: var(--text); }

.main {
  padding: 28px;
  max-width: none;
  margin: 0 auto;
}

.main-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}
.main-header h1 { font-size: 20px; margin: 0; }
.main-header p { color: var(--text-muted); font-size: 13px; margin: 4px 0 0; }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.empty-state h2 { color: var(--text); font-size: 18px; margin-bottom: 8px; }
.empty-state .btn { margin-top: 16px; }

/* ---------- Dashboard layout: grid + expanded split ---------- */
.dashboard {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(390px, 1fr));
  gap: 18px;
  flex: 1 1 auto;
  min-width: 0;
  transition: flex-basis 0.2s ease;
}

.dashboard.expanded .card-grid {
  flex: 1 1 50%;
  max-width: 50%;
}

.mailbox-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  height: 190px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
  overflow: hidden;
}
.mailbox-card:hover { transform: translateY(-2px); }
.mailbox-card.active { border-color: var(--action); box-shadow: 0 0 0 2px rgba(247,22,133,0.18); }

.mailbox-card.unread {
  background: var(--card-unread-bg);
  border-color: var(--card-unread-border);
}

.mailbox-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.mailbox-card-title {
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  flex: none; margin-top: 4px;
  background: #cfd6e2;
}
.status-dot.ok { background: #1fbf6b; }
.status-dot.error { background: #e2453f; }
.status-dot.pending { background: #f2b705; }

.unread-badge {
  background: var(--card-unread-border);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  flex: none;
}

.mailbox-card-emails {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}

.email-row {
  font-size: 12.5px;
  line-height: 1.3;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
  overflow: hidden;
}
.email-row:last-child { border-bottom: none; }
.email-row .from {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-row .subject {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-row.unread .from { color: var(--text); }
.email-row.unread::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--action);
  margin-right: 5px;
}

.mailbox-card-empty {
  color: var(--text-muted);
  font-size: 12.5px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.mailbox-card-footer {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ---------- Expanded panel ---------- */
.expand-panel {
  flex: 1 1 50%;
  max-width: 50%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 84px;
}

.expand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.expand-header-title { min-width: 0; }
.expand-header-title h2 {
  font-size: 16px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.expand-header-title span {
  font-size: 12px;
  color: var(--text-muted);
}
.expand-header-actions { display: flex; gap: 6px; flex: none; }

.expand-body {
  flex: 1;
  overflow: auto;
  display: flex;
}

.email-list {
  width: 320px;
  flex: none;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.email-list-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.email-list-item:hover { background: #fbfbfd; }
.email-list-item.selected { background: #fef1f8; border-left: 3px solid var(--action); padding-left: 13px; }
.email-list-item .from {
  font-weight: 700;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.email-list-item .from time { font-weight: 400; color: var(--text-muted); font-size: 11px; flex: none; }
.email-list-item .subject { font-size: 12.5px; margin-top: 2px; }
.email-list-item .snippet { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-list-item.unread .from, .email-list-item.unread .subject { color: var(--text); font-weight: 700; }
.email-list-item.unread .subject { font-weight: 600; }
.email-list-item:not(.unread) .from { font-weight: 600; color: var(--text); }

.email-reader {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 20px 24px;
}
.email-reader .subject { font-size: 17px; font-weight: 700; margin: 0 0 6px; }
.email-reader .meta { font-size: 12.5px; color: var(--text-muted); margin-bottom: 18px; }
.email-reader .meta strong { color: var(--text); }
.email-reader iframe {
  width: 100%;
  border: none;
  min-height: 300px;
}
.email-reader pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
}
.email-reader-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 60px 20px;
  font-size: 13.5px;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,20,46,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,20,46,0.3);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 17px; margin: 0; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.modal-footer .spacer { flex: 1; }

.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }

.select-wrap { position: relative; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 40px; }
.password-toggle {
  position: absolute;
  right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); font-size: 12px; padding: 4px 6px;
}

.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.section-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,20,46,0.25);
  max-width: 320px;
}
.toast.error { background: #a12727; }
.toast.success { background: #106b3f; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner.dark { border-color: rgba(0,20,46,0.2); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-muted); gap: 10px; font-size: 13px; }

@media (max-width: 900px) {
  .dashboard.expanded { flex-direction: column; }
  .dashboard.expanded .card-grid,
  .expand-panel { max-width: 100%; }
  .expand-panel { position: static; }
  .expand-body { flex-direction: column; }
  .email-list { width: auto; max-height: 260px; border-right: none; border-bottom: 1px solid var(--border); }
}
