/* MailSure dashboard design system */

:root {
  --color-bg: #f5f6fa;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-border-strong: #d1d5db;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-text-faint: #9ca3af;

  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-soft: #eef2ff;
  --color-primary-text: #4338ca;

  --color-success: #15803d;
  --color-success-soft: #dcfce7;
  --color-danger: #b91c1c;
  --color-danger-soft: #fee2e2;
  --color-warning: #a16207;
  --color-warning-soft: #fef3c7;
  --color-purple: #7c3aed;
  --color-purple-soft: #f3e8ff;
  --color-gray: #4b5563;
  --color-gray-soft: #f3f4f6;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 4px 12px rgba(17, 24, 39, 0.08);
  --shadow-lg: 0 12px 32px rgba(17, 24, 39, 0.12);

  --nav-height: 60px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

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

h1, h2, h3, h4 {
  line-height: 1.25;
  margin: 0 0 0.5rem;
  letter-spacing: -0.01em;
}

h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }

p { margin: 0 0 0.6rem; }
a { color: var(--color-primary); }
a:hover { color: var(--color-primary-hover); }

small, .text-muted { color: var(--color-text-muted); }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.page-header p {
  margin: 0.15rem 0 0;
  color: var(--color-text-muted);
}

/* ---------- Top navigation ---------- */

.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--nav-height);
  padding: 0 1rem;
  background: #111827;
  box-shadow: var(--shadow-md);
}

.topnav .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  padding: 0.5rem 0;
  margin-right: 0.25rem;
}

.topnav .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.nav-toggle-checkbox {
  display: none;
}

.nav-toggle-btn {
  display: none;
  margin-left: auto;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: #e5e7eb;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-toggle-icon,
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.nav-toggle-icon::before { content: ""; margin-bottom: 5px; }
.nav-toggle-icon::after { content: ""; margin-top: 5px; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.topnav a:not(.brand) {
  color: #cbd5e1;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.topnav a:not(.brand):hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.topnav a.active {
  color: #fff;
  background: rgba(99, 102, 241, 0.35);
}

.topnav a.right {
  margin-left: auto;
}

.topnav a.logout-link {
  border: 1px solid rgba(255, 255, 255, 0.18);
}

@media (max-width: 820px) {
  .nav-toggle-btn { display: flex; }

  .nav-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.1rem;
    background: #111827;
    padding: 0.5rem;
    box-shadow: var(--shadow-lg);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.2s ease, opacity 0.15s ease;
  }

  .topnav a.right { margin-left: 0; }

  .nav-toggle-checkbox:checked ~ .nav-links {
    max-height: 70vh;
    opacity: 1;
    overflow-y: auto;
  }

  .nav-toggle-checkbox:checked ~ .nav-toggle-btn .nav-toggle-icon::before {
    transform: translateY(7px) rotate(45deg);
  }
  .nav-toggle-checkbox:checked ~ .nav-toggle-btn .nav-toggle-icon {
    opacity: 0;
  }
  .nav-toggle-checkbox:checked ~ .nav-toggle-btn .nav-toggle-icon::after {
    transform: translateY(-7px) rotate(-45deg);
  }

  .topnav a:not(.brand) {
    padding: 0.7rem 0.75rem;
  }
}

/* ---------- Layout ---------- */

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

@media (max-width: 560px) {
  .container { padding: 1.25rem 0.85rem 2.5rem; }
}

/* ---------- Cards ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.1rem;
}

.card > h3:first-child,
.card > h2:first-child {
  margin-bottom: 0.9rem;
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.5rem;
}

.card.auth-card {
  max-width: 380px;
  margin: 0 auto;
}

/* ---------- Grid / stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.stat-tile {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  background: var(--color-bg);
}

.stat-tile .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-tile .stat-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-tile.valid .stat-value { color: var(--color-success); }
.stat-tile.invalid .stat-value { color: var(--color-danger); }
.stat-tile.catch_all .stat-value { color: var(--color-warning); }
.stat-tile.disposable .stat-value { color: var(--color-purple); }
.stat-tile.unknown .stat-value { color: var(--color-gray); }

/* ---------- Tables ---------- */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 0.6rem 0.65rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr:hover { background: var(--color-bg); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Status badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-valid, .badge.status-valid { color: var(--color-success); background: var(--color-success-soft); }
.status-invalid, .badge.status-invalid { color: var(--color-danger); background: var(--color-danger-soft); }
.status-catch_all, .badge.status-catch_all { color: var(--color-warning); background: var(--color-warning-soft); }
.status-disposable, .badge.status-disposable { color: var(--color-purple); background: var(--color-purple-soft); }
.status-unknown, .badge.status-unknown { color: var(--color-gray); background: var(--color-gray-soft); }
.status-pending, .badge.status-pending { color: var(--color-primary-text); background: var(--color-primary-soft); }
.status-processing, .badge.status-processing { color: var(--color-primary-text); background: var(--color-primary-soft); }
.status-completed, .badge.status-completed { color: var(--color-success); background: var(--color-success-soft); }
.status-failed, .badge.status-failed { color: var(--color-danger); background: var(--color-danger-soft); }

/* bare status text (no badge wrapper) keeps color only */
td > .status-valid, td > .status-invalid, td > .status-catch_all,
td > .status-disposable, td > .status-unknown, td > .status-pending {
  font-weight: 600;
}

.badge.revoked { color: var(--color-text-muted); background: var(--color-gray-soft); }

.status-qualified, .badge.status-qualified { color: var(--color-success); background: var(--color-success-soft); }
.status-needs_review, .badge.status-needs_review { color: var(--color-warning); background: var(--color-warning-soft); }
.status-rejected, .badge.status-rejected { color: var(--color-danger); background: var(--color-danger-soft); }
.status-draft, .badge.status-draft,
.status-clarifying, .badge.status-clarifying,
.status-ready, .badge.status-ready,
.status-planning, .badge.status-planning,
.status-discovering, .badge.status-discovering,
.status-triaging, .badge.status-triaging,
.status-enriching, .badge.status-enriching,
.status-auditing, .badge.status-auditing,
.status-finding_people, .badge.status-finding_people,
.status-finding_emails, .badge.status-finding_emails,
.status-qualifying, .badge.status-qualifying { color: var(--color-primary-text); background: var(--color-primary-soft); }
.status-done, .badge.status-done { color: var(--color-success); background: var(--color-success-soft); }
.status-timed_out, .badge.status-timed_out { color: var(--color-warning); background: var(--color-warning-soft); }
.status-stopped, .badge.status-stopped { color: var(--color-gray); background: var(--color-gray-soft); }

/* ---------- Problem / fact-kind chips ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--color-gray-soft);
  color: var(--color-gray);
  margin: 0.1rem 0.25rem 0.1rem 0;
}

.chip.severity-high { background: var(--color-danger-soft); color: var(--color-danger); }
.chip.severity-medium { background: var(--color-warning-soft); color: var(--color-warning); }
.chip.severity-low { background: var(--color-gray-soft); color: var(--color-gray); }

.kind-tag {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.4rem;
}

.kind-tag.kind-fact { background: var(--color-success-soft); color: var(--color-success); }
.kind-tag.kind-estimate { background: var(--color-warning-soft); color: var(--color-warning); }
.kind-tag.kind-ai_assessment { background: var(--color-purple-soft); color: var(--color-purple); }

.evidence-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
}

.evidence-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.evidence-list li:last-child { border-bottom: none; }

.evidence-source {
  display: block;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 0.15rem;
  overflow-wrap: anywhere;
}

/* ---------- Forms ---------- */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--color-text);
}

label { cursor: pointer; }

input[type="email"],
input[type="text"],
input[type="password"],
input[type="file"],
select {
  display: block;
  width: 100%;
  max-width: 420px;
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="email"]:focus,
input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

input[type="file"] {
  padding: 0.5rem;
  background: var(--color-bg);
  border-style: dashed;
  cursor: pointer;
}

/* Default Django form.as_p rendering */
form p {
  margin: 0 0 1rem;
}

form p label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.errorlist {
  list-style: none;
  margin: 0.3rem 0 0;
  padding: 0;
  color: var(--color-danger);
  font-size: 0.82rem;
}

.mode-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}

.mode-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
}

.mode-option:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.mode-option input { margin-top: 0.2rem; flex-shrink: 0; }
.mode-option .mode-option-desc {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-top: 0.1rem;
}

/* ---------- Buttons ---------- */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  transition: background 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

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

button:focus-visible, .btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

button:disabled, .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover { background: var(--color-bg); }

.btn-danger {
  background: var(--color-surface);
  color: var(--color-danger);
  border-color: #fecaca;
}
.btn-danger:hover { background: var(--color-danger-soft); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }

form.inline-form { display: inline; }

/* ---------- Key display ---------- */

.key-display {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  background: #111827;
  color: #86efac;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: nowrap;
}

.callout {
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  padding: 1rem 1.1rem;
}

.callout-success {
  background: var(--color-success-soft);
  border-color: #bbf7d0;
}

.callout-warning {
  background: var(--color-warning-soft);
  border-color: #fde68a;
}

.callout-danger {
  background: var(--color-danger-soft);
  border-color: #fecaca;
}

/* ---------- Progress bar ---------- */

.progress-bar {
  height: 10px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #4f46e5);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-bar.indeterminate .fill {
  width: 40% !important;
  animation: indeterminate-slide 1.2s ease-in-out infinite;
}

@keyframes indeterminate-slide {
  0% { margin-left: 0; }
  50% { margin-left: 60%; }
  100% { margin-left: 0; }
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

/* ---------- Score meter ---------- */

.score-meter {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0 0.7rem;
}

.score-meter .progress-bar {
  flex: 1;
  margin: 0;
}

.score-meter .score-value {
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 3.2rem;
  text-align: right;
}

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-text-muted);
}

/* ---------- Auth page ---------- */

.auth-shell {
  min-height: calc(100vh - var(--nav-height) - 3rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card-header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.auth-card-header .brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 0.6rem;
}

.auth-card-header h2 { margin-bottom: 0.2rem; }
.auth-card-header p { color: var(--color-text-muted); font-size: 0.9rem; }

.auth-card form button[type="submit"] {
  width: 100%;
  margin-top: 0.25rem;
}

/* ---------- Misc helpers ---------- */

.mt-0 { margin-top: 0; }
.text-right { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 1rem; }
}
