/* =========================================================================
   Mail Dashboard styles
   ========================================================================= */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f7f7f5;
  --surface:      #ffffff;
  --border:       #e7e5e4;
  --border-soft:  #f0eeec;
  --text:         #1c1917;
  --text-muted:   #78716c;
  --text-faint:   #a8a29e;

  --accent:       #c2410c;          /* burnt orange */
  --accent-soft:  #fef3ec;
  --ok:           #15803d;
  --err:          #b91c1c;

  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 2px rgba(28, 25, 23, 0.04);

  --font-sans:    -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
                  Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono:    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco,
                  "Cascadia Mono", Consolas, monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.page {
  min-height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 40px;
}

/* =========================================================================
   Top bar
   ========================================================================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 4px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  font-size: 18px;
  color: var(--accent);
  line-height: 1;
}
.brand-name { font-size: 13px; }

.nav { display: flex; gap: 4px; }
.nav-link {
  display: inline-block;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-decoration: none;
  color: var(--text-muted);
  transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--text); background: var(--border-soft); }
.nav-link.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border-soft); }

/* =========================================================================
   Page heading
   ========================================================================= */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 24px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}
.muted { color: var(--text-muted); font-size: 14px; }
.muted a { color: var(--accent); text-decoration: none; }
.muted a:hover { text-decoration: underline; }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary {
  background: var(--text);
  color: #fff;
}
.btn-primary:hover { background: #000; }
.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--border-soft); }
.refresh-icon { display: inline-block; font-size: 16px; }

/* =========================================================================
   Banners
   ========================================================================= */
.banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 14px;
  margin-bottom: 24px;
}
.banner-ok  { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }
.banner-err { background: #fef2f2; border-color: #fecaca; color: var(--err); }

/* =========================================================================
   Empty state
   ========================================================================= */
.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 56px 24px;
  text-align: center;
}
.empty h2 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.empty p { margin-bottom: 20px; }

/* =========================================================================
   Grid of account cards
   ========================================================================= */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--border); }

.card-head { display: flex; flex-direction: column; gap: 4px; }
.card-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-email {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.status-dot[data-status="loading"] {
  background: var(--text-faint);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-dot[data-status="ok"]    { background: var(--ok); }
.status-dot[data-status="error"] { background: var(--err); }

@keyframes pulse {
  0%, 100% { opacity: .35; }
  50%      { opacity: 1;   }
}

/* =========================================================================
   Stats row
   ========================================================================= */
.card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border-soft);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.stat {
  background: var(--surface);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 500;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
}
.stat-accent .stat-value { color: var(--accent); }

/* =========================================================================
   Recent messages
   ========================================================================= */
.card-recent { display: flex; flex-direction: column; gap: 8px; }
.recent-head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 500;
}
.recent-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.recent-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border-soft);
}
.recent-from {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-subject {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-empty {
  font-size: 13px;
  color: var(--text-faint);
  font-style: italic;
  padding: 8px 10px;
}

/* =========================================================================
   Card footer
   ========================================================================= */
.card-foot {
  border-top: 1px solid var(--border-soft);
  padding-top: 6px;
}
.card-status {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

/* =========================================================================
   Skeleton loaders
   ========================================================================= */
.skeleton-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border-soft);
}
.skeleton {
  display: block;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(90deg, #ececea 0%, #f5f5f3 50%, #ececea 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
.skeleton-line { height: 9px; }
.w50 { width: 50%; }
.w60 { width: 60%; }
.w70 { width: 70%; }
.w80 { width: 80%; }
.w90 { width: 90%; }
@keyframes shimmer {
  0%   { background-position:  200% 0; }
  100% { background-position: -200% 0; }
}

/* =========================================================================
   Settings form
   ========================================================================= */
.config-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.config-row {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 1.2fr 1.5fr 1.2fr;
  gap: 14px;
  box-shadow: var(--shadow);
}
.config-row legend {
  grid-column: 1 / -1;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field input {
  height: 38px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  font-family: var(--font-sans);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-row { display: flex; gap: 12px; }
.field-narrow { flex: 0 0 100px; }

.advanced {
  grid-column: 1 / -1;
  font-size: 13px;
}
.advanced summary {
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
  padding: 4px 0;
}
.advanced summary:hover { color: var(--text); }
.advanced[open] summary { margin-bottom: 12px; }

.pill {
  display: inline-block;
  padding: 1px 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #ecfdf5;
  color: var(--ok);
  border-radius: 999px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.footnote {
  margin-top: 28px;
  font-size: 12px;
  line-height: 1.6;
}
.footnote code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--border-soft);
  padding: 1px 6px;
  border-radius: 3px;
}

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 700px) {
  .page { padding: 0 18px 48px; }
  .topbar { margin-bottom: 28px; }
  .page-head h1 { font-size: 22px; }
  .config-row { grid-template-columns: 1fr; }
}

/* =========================================================================
   Refresh control (countdown + button)
   ========================================================================= */
.refresh-control {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.auto-hint {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  min-width: 86px;
  text-align: right;
}

/* =========================================================================
   Nav lock pill
   ========================================================================= */
.nav-lock {
  margin-left: 4px;
  font-size: 12px;
  color: var(--text-faint);
}
.nav-lock:hover { color: var(--err); }

/* =========================================================================
   Lock screen (PIN entry)
   ========================================================================= */
.lock-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 0%, #faf5f0 0%, transparent 40%),
    radial-gradient(circle at 80% 100%, #f5efe9 0%, transparent 40%),
    var(--bg);
}
.lock-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 36px 32px 28px;
  box-shadow:
    0 1px 2px rgba(28, 25, 23, 0.04),
    0 8px 32px rgba(28, 25, 23, 0.05);
  text-align: center;
}
.lock-mark {
  font-size: 36px;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 18px;
}
.lock-card h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.lock-card p { font-size: 13px; margin-bottom: 22px; }
.lock-card .banner { text-align: left; margin-bottom: 18px; }

.lock-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
}
.pin-input {
  height: 52px;
  padding: 0 16px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 22px;
  letter-spacing: 0.5em;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.pin-input::placeholder {
  letter-spacing: 0.4em;
  color: var(--text-faint);
}
.pin-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.pin-input:disabled { opacity: 0.5; cursor: not-allowed; }

.lock-form .btn {
  height: 44px;
  justify-content: center;
}

.lock-back {
  display: inline-block;
  font-size: 13px;
  text-decoration: none;
  color: var(--text-muted);
  transition: color .15s;
}
.lock-back:hover { color: var(--text); }

@media (max-width: 480px) {
  .auto-hint { display: none; }
  .lock-card { padding: 28px 22px 22px; }
}

/* =========================================================================
   New-mail alerts — looping animations while a card is "alerting"
   Click the card to dismiss.
   ========================================================================= */

/* Cards need positioned context for the badge */
.card { position: relative; }

/* Cards in the alerting state become clickable to acknowledge */
.card.has-new-mail {
  cursor: pointer;
  border-color: var(--accent);
  animation: card-loop 2.6s ease-in-out infinite;
}
@keyframes card-loop {
  0%, 100% { box-shadow: 0 0 0 0 rgba(194, 65, 12, 0.0), var(--shadow); }
  50%      { box-shadow: 0 0 0 6px rgba(194, 65, 12, 0.28), var(--shadow); }
}

/* Unread number gently pulses while alerting */
.card.has-new-mail .stat-accent .stat-value {
  display: inline-block;
  animation: number-loop 2.6s ease-in-out infinite;
}
@keyframes number-loop {
  0%, 100% { transform: scale(1);    }
  50%      { transform: scale(1.12); }
}

/* Persistent badge that gently pulses (no fade-out) */
.new-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(194, 65, 12, 0.35);
  pointer-events: none;
  animation: badge-loop 2.6s ease-in-out infinite;
  z-index: 2;
}
@keyframes badge-loop {
  0%, 100% { transform: scale(1);    box-shadow: 0 2px 8px rgba(194, 65, 12, 0.35); }
  50%      { transform: scale(1.08); box-shadow: 0 4px 14px rgba(194, 65, 12, 0.5); }
}

/* Full-screen edge flash — soft vignette that pulses while ANY card is alerting */
.screen-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  box-shadow: inset 0 0 120px 30px rgba(194, 65, 12, 0.55);
}
.screen-flash.is-active {
  animation: screen-loop 2.6s ease-in-out infinite;
}
@keyframes screen-loop {
  0%, 100% { opacity: 0;    }
  50%      { opacity: 0.55; }
}

/* Respect reduced-motion preference: keep the indication, drop the motion */
@media (prefers-reduced-motion: reduce) {
  .card.has-new-mail,
  .card.has-new-mail .stat-accent .stat-value,
  .new-badge,
  .screen-flash.is-active {
    animation: none;
  }
  .card.has-new-mail { box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.25), var(--shadow); }
  .screen-flash.is-active { opacity: 0.3; }
}
