/* ============================================================
   MailFlow design system
   ============================================================ */
:root {
  --bg-1: #f3faf8; --bg-2: #e8f4f0; --bg-3: #d4ede5;
  --surface: #ffffff; --surface-dim: #f1f7f5; --surface-hover: #e2efea;
  --text: #1a1a1a; --text-secondary: #5a5a5a; --text-muted: #94978f; --text-on-dark: #ffffff;
  --border: rgba(0,0,0,0.06); --border-strong: rgba(0,0,0,0.1);
  --primary: #1a1a1a; --primary-soft: #eaf2ef; --primary-text: #ffffff;
  --accent: #0d9488; --accent-soft: #ccfbf1; --accent-text: #ffffff;
  --success: #5cb874; --success-soft: #e2f5e7;
  --danger: #e57373; --danger-soft: #fde8e8;
  --info: #4a90c2; --info-soft: #e8f1f9;
  --purple: #7c4dbd; --purple-soft: #f0e7f9;
  --warn-soft: #fff4c2; --warn-text: #8b6914;
  --shadow-card: 0 4px 20px rgba(15, 60, 55, 0.06);
  --shadow-lg: 0 8px 24px rgba(15, 60, 55, 0.09);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.2);
  --radius: 14px; --radius-lg: 20px; --radius-pill: 999px;
  --topbar-h: 76px;
  --font-body: "Hanken Grotesk", system-ui, -apple-system, sans-serif;
}
[data-theme="dark"] {
  --bg-1: #0d1614; --bg-2: #111c1a; --bg-3: #16221f;
  --surface: #1c2723; --surface-dim: #131e1b; --surface-hover: #243530;
  --text: #e6efeb; --text-secondary: #9aa39e; --text-muted: #6e7773;
  --border: rgba(255,255,255,0.06); --border-strong: rgba(255,255,255,0.1);
  --primary: #e6efeb; --primary-soft: #243530; --primary-text: #0d1614;
  --accent: #14b8a6; --accent-soft: #134e4a; --accent-text: #0d1614;
  --success: #7dd396; --success-soft: #1f3525;
  --danger: #ef8a8a; --danger-soft: #3a1f1f;
  --info: #7fb3d9; --info-soft: #1a2a3a;
  --purple: #b09cd0; --purple-soft: #2a1f3a;
  --warn-soft: #3a3320; --warn-text: #ffd93d;
  --shadow-card: 0 4px 20px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 14px; line-height: 1.5;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 40%, var(--bg-3) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
input, select, textarea { font-family: inherit; }
h1:focus { outline: none; }

/* === TOPBAR === */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h); display: flex; align-items: center;
  padding: 0 28px; gap: 16px; z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; cursor: pointer; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-weight: 800; font-size: 19px;
  position: relative; transform: rotate(-3deg);
}
.brand-logo::after {
  content: ""; position: absolute; width: 14px; height: 14px;
  background: var(--accent); border-radius: 50%;
  top: -4px; right: -4px; border: 3px solid var(--bg-2);
}
.brand-name { font-weight: 800; font-size: 18px; color: var(--text); letter-spacing: -0.03em; }

.topnav-wrap { flex: 1; display: flex; justify-content: center; min-width: 0; }
.topnav {
  display: flex; align-items: center;
  background: var(--surface); border-radius: var(--radius-pill);
  padding: 5px; box-shadow: var(--shadow-card);
  gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: var(--radius-pill);
  font-size: 13.5px; font-weight: 500;
  color: var(--text-secondary); white-space: nowrap;
  transition: all 0.18s cubic-bezier(0.4,0,0.2,1);
}
.topnav a:hover { color: var(--text); background: var(--surface-hover); }
.topnav a.active { color: var(--primary-text); background: var(--primary); font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.action-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 18px; background: var(--surface);
  border-radius: var(--radius-pill); box-shadow: var(--shadow-card);
  font-size: 13.5px; font-weight: 500; color: var(--text);
  transition: all 0.18s ease;
}
.action-pill:hover { background: var(--surface-hover); transform: translateY(-1px); }
.org-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px; background: var(--accent-soft); color: var(--accent);
  border-radius: var(--radius-pill); box-shadow: var(--shadow-card);
  font-size: 13px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
[data-theme="dark"] .org-pill { color: var(--text); }

/* === LAYOUT === */
.app { padding: calc(var(--topbar-h) + 4px) 28px 28px; max-width: 1420px; margin: 0 auto; }

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-title { font-size: 40px; font-weight: 700; color: var(--text); letter-spacing: -0.035em; line-height: 1; }
.page-subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 8px; }
.page-header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* === ANIMATIONS === */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.page-anim > * { animation: fadeUp 0.4s ease backwards; }
.page-anim > *:nth-child(1) { animation-delay: 0.05s; }
.page-anim > *:nth-child(2) { animation-delay: 0.1s; }
.page-anim > *:nth-child(3) { animation-delay: 0.15s; }
.page-anim > *:nth-child(4) { animation-delay: 0.2s; }
.page-anim > *:nth-child(5) { animation-delay: 0.25s; }

/* === CARDS === */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 22px; }
.card-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.card-title { font-size: 18px; font-weight: 700; letter-spacing: -0.015em; }
.card-sub { font-size: 12.5px; color: var(--text-secondary); }

/* === STAT STRIP === */
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.stat-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 18px 20px; }
.stat-label { font-size: 11.5px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; margin-top: 6px; }
.stat-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* === BADGES === */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: var(--radius-pill); font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.gray { background: var(--surface-dim); color: var(--text-muted); }
.badge.yellow { background: var(--warn-soft); color: var(--warn-text); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.blue { background: var(--info-soft); color: var(--info); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.badge.teal { background: var(--accent-soft); color: var(--accent); }
[data-theme="dark"] .badge.teal { color: var(--text); }

/* === BUTTONS === */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 18px; border-radius: var(--radius-pill); font-size: 13.5px; font-weight: 600; cursor: pointer; transition: all 0.15s ease; white-space: nowrap; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none !important; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: #2a2a2a; transform: translateY(-1px); }
[data-theme="dark"] .btn-primary:hover:not(:disabled) { background: #fff; }
.btn-accent { background: var(--accent); color: var(--accent-text); }
.btn-accent:hover:not(:disabled) { background: #0b7d72; transform: translateY(-1px); }
.btn-ghost { background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 13px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }

/* === TOOLBAR / SEARCH === */
.table-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.search-pill { flex: 1; min-width: 200px; max-width: 380px; display: flex; align-items: center; gap: 8px; padding: 9px 16px; background: var(--surface); border-radius: var(--radius-pill); box-shadow: var(--shadow-card); }
.search-pill input { flex: 1; border: none; background: none; outline: none; color: var(--text); font-size: 13.5px; }
.search-pill input::placeholder { color: var(--text-muted); }
.toolbar-count { font-size: 12.5px; color: var(--text-secondary); margin-left: auto; }

/* === DATA TABLE === */
.data-table-wrap { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; padding: 14px 18px; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px dashed var(--border-strong); white-space: nowrap; }
.data-table td { padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.15s ease; }
.data-table tbody tr:hover { background: var(--surface-dim); }
.row-name { font-weight: 600; color: var(--text); font-size: 13.5px; }
.row-meta { font-size: 11.5px; color: var(--text-muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; opacity: 0; transition: opacity 0.15s; }
.data-table tbody tr:hover .row-actions { opacity: 1; }
.cell-num { font-weight: 600; }

/* === PROGRESS === */
.progress-track { min-width: 130px; height: 20px; border-radius: var(--radius-pill); background: var(--surface-dim); overflow: hidden; position: relative; }
.progress-fill { height: 100%; background: var(--accent); border-radius: var(--radius-pill); transition: width 0.4s ease; }
.progress-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--text); }

/* === PAGINATION === */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 18px; }
.page-btn { min-width: 32px; height: 32px; padding: 0 8px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 500; cursor: pointer; transition: all 0.15s; background: var(--surface); color: var(--text); box-shadow: var(--shadow-card); }
.page-btn:hover { background: var(--surface-hover); }
.page-btn.active { background: var(--primary); color: var(--primary-text); }

/* === FORMS === */
.form-row { margin-bottom: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; } }
.form-label { display: block; font-size: 11px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 11px 16px; background: var(--surface-dim); border: 1.5px solid transparent; border-radius: var(--radius-pill); font-size: 14px; color: var(--text); outline: none; transition: all 0.15s ease; }
.form-input:focus, .form-select:focus, .form-textarea:focus { background: var(--surface); border-color: var(--accent); }
.form-textarea { border-radius: var(--radius); min-height: 90px; resize: vertical; padding: 12px 16px; }
.form-textarea.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.form-select { appearance: none; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%235a5a5a" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>'); background-repeat: no-repeat; background-position: right 16px center; padding-right: 40px; cursor: pointer; }
[data-theme="dark"] .form-select { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%23a8a39a" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>'); }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-secondary); cursor: pointer; }
.form-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* === ALERTS === */
.alert { display: flex; align-items: center; gap: 8px; padding: 11px 18px; border-radius: var(--radius); font-size: 13.5px; font-weight: 500; margin-bottom: 16px; animation: fadeUp 0.25s ease; }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

/* === CARDS GRID === */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.entity-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); padding: 22px; transition: transform 0.2s ease, box-shadow 0.2s; }
.entity-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.entity-icon { width: 48px; height: 48px; border-radius: 14px; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; font-size: 21px; }
.entity-icon.teal { background: var(--accent-soft); }
.entity-icon.purple { background: var(--purple-soft); }
.entity-icon.blue { background: var(--info-soft); }
.entity-name { font-size: 18px; font-weight: 700; letter-spacing: -0.015em; }
.entity-meta { font-size: 12.5px; color: var(--text-secondary); margin-top: 4px; }
.entity-stats { display: flex; gap: 22px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.entity-stat-num { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.entity-stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.entity-actions { display: flex; gap: 8px; margin-top: 16px; }

/* === EDITOR GRID === */
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .editor-grid { grid-template-columns: 1fr; } }
.mf-preview { width: 100%; height: 480px; border: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); background: #fff; display: block; }
.preview-card { padding: 0; overflow: hidden; }
.preview-card .card-header-row { padding: 18px 22px 0; margin-bottom: 12px; }

/* === AUTH === */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; padding: 36px; }
.auth-brand { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 6px; }
.auth-title { text-align: center; font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.auth-sub { text-align: center; font-size: 13.5px; color: var(--text-secondary); margin: 4px 0 24px; }
.auth-alt { text-align: center; font-size: 13px; color: var(--text-secondary); margin-top: 18px; }
.auth-alt a { color: var(--accent); font-weight: 600; }

/* === STUB / EMPTY === */
.empty { padding: 60px 30px; text-align: center; }
.empty-icon { width: 72px; height: 72px; border-radius: 22px; background: var(--surface); display: flex; align-items: center; justify-content: center; margin: 0 auto 22px; box-shadow: var(--shadow-card); font-size: 30px; }
.empty h3 { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 8px; letter-spacing: -0.025em; }
.empty p { font-size: 14px; max-width: 380px; margin: 0 auto; color: var(--text-secondary); }

/* === UTILITIES === */
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 14px; } .mt-4 { margin-top: 20px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 14px; } .mb-4 { margin-bottom: 20px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; }
.text-break { word-break: break-all; }
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* === BLAZOR CHROME === */
.loading-progress { position: absolute; display: block; width: 8rem; height: 8rem; inset: 20vh 0 auto 0; margin: 0 auto; }
.loading-progress circle { fill: none; stroke: var(--surface-hover); stroke-width: 0.6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child { stroke: #0d9488; stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; transition: stroke-dasharray 0.05s ease-in-out; }
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 3.25rem) 0 auto 0.2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

#blazor-error-ui { color-scheme: light only; background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,0.2); box-sizing: border-box; display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem; position: fixed; width: 100%; z-index: 1000; color: #1a1a1a; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; border-radius: var(--radius); }
.blazor-error-boundary::after { content: "An error has occurred."; }

.valid.modified:not([type=checkbox]) { outline: none; }
.invalid { outline: 1px solid var(--danger); }
.validation-message { color: var(--danger); font-size: 12px; }

@media (max-width: 1024px) {
  .app { padding-inline: 14px; }
  .page-title { font-size: 30px; }
  .topbar { padding-inline: 14px; }
  .topnav a span.nav-label { display: none; }
  .action-pill span { display: none; }
  .org-pill { max-width: 120px; }
}
