/* SoldByMarvin Deal Pipeline — design tokens, built from Marvin's established brand palette
   (midnight blue / gold / ivory, per email-brand-template.html) */
:root {
  --bg: #efebe3;         /* page background */
  --surface: #ffffff;    /* card background */
  --surface-2: #f4f6f9;  /* soft panel */
  --text: #1e2a3a;       /* body text */
  --text-secondary: #5b6b82;
  --text-tertiary: #8a97a8;
  --border: #ddd6c5;
  --border-strong: #c7bda5;
  --accent: #c9a84c;         /* gold — fills, borders, icons, dots */
  --accent-text: #8a6d1e;    /* deep gold — small text/icons on light surfaces */
  --accent-contrast: #0a1730; /* midnight — text on a gold fill */
  --accent-soft: #f6edd3;
  --success: #2f6b46;
  --success-soft: #dcead9;
  --warning: #b36b12;
  --warning-soft: #f3e3c4;
  --danger: #a2432c;
  --danger-soft: #f4ddd4;
  --muted: #8a8f98;
  --muted-soft: #eceae4;
  --shadow-sm: 0 1px 2px rgba(10, 23, 48, 0.07);
  --shadow-lg: 0 12px 32px rgba(10, 23, 48, 0.14);
  --radius: 10px;
  --radius-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1730;         /* midnight blue — brand's own dark surface */
    --surface: #11213f;
    --surface-2: #16294a;
    --text: #f5f0e8;       /* ivory — brand's text-on-midnight */
    --text-secondary: #9fb0c7;
    --text-tertiary: #7c8ca3;
    --border: #23324f;
    --border-strong: #33456a;
    --accent: #c9a84c;
    --accent-text: #d9bd6f;
    --accent-contrast: #0a1730;
    --accent-soft: #2a2412;
    --success: #6fbf8b;
    --success-soft: #16301f;
    --warning: #e0ac57;
    --warning-soft: #332409;
    --danger: #e08267;
    --danger-soft: #35180f;
    --muted: #8891a0;
    --muted-soft: #1c2438;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #0a1730;
  --surface: #11213f;
  --surface-2: #16294a;
  --text: #f5f0e8;
  --text-secondary: #9fb0c7;
  --text-tertiary: #7c8ca3;
  --border: #23324f;
  --border-strong: #33456a;
  --accent: #c9a84c;
  --accent-text: #d9bd6f;
  --accent-contrast: #0a1730;
  --accent-soft: #2a2412;
  --success: #6fbf8b;
  --success-soft: #16301f;
  --warning: #e0ac57;
  --warning-soft: #332409;
  --danger: #e08267;
  --danger-soft: #35180f;
  --muted: #8891a0;
  --muted-soft: #1c2438;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand {
  font-family: "Fraunces", Georgia, serif;
  text-wrap: balance;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::placeholder { color: var(--text-tertiary); }

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

#app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 600;
  font-size: 20px;
  color: var(--text);
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.brand small {
  font-family: "Public Sans", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-text);
}

.search-box {
  flex: 1;
  max-width: 360px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}
.search-box svg {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-tertiary);
}

.stat-chip {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.stat-chip b {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-size: 13.5px;
}
.stat-chip.is-due b { color: var(--warning); }
.stat-chip.is-overdue b { color: var(--danger); }

.spacer { flex: 1; }

.view-nav {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}
.view-tab {
  padding: 6px 14px;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.view-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  transition: filter 0.12s ease, background 0.12s ease;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.account-menu { position: relative; }
.account-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 13px;
}
.avatar {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px;
}
.account-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  min-width: 200px; padding: 6px; z-index: 30;
}
.account-dropdown .email {
  padding: 8px 10px; font-size: 12.5px; color: var(--text-tertiary);
  border-bottom: 1px solid var(--border); margin-bottom: 4px; word-break: break-all;
}
.account-dropdown button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 6px; background: transparent; border: none;
  color: var(--text); font-size: 13px;
}
.account-dropdown button:hover { background: var(--surface-2); }

/* ---------- Board ---------- */

.board-wrap { flex: 1; overflow-x: auto; padding: 18px 20px 28px; }
.board {
  display: flex;
  gap: 14px;
  min-height: 60vh;
}

.column {
  flex: 0 0 268px;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-height: calc(100vh - 130px);
}

.column-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.stage-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.column-title { font-weight: 700; font-size: 13px; letter-spacing: 0.01em; flex: 1; }
.column-count {
  font-variant-numeric: tabular-nums;
  font-size: 12px; color: var(--text-tertiary);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 7px;
}

.column-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.column-empty {
  color: var(--text-tertiary);
  font-size: 12.5px;
  padding: 10px 4px;
  line-height: 1.5;
}

.add-in-column {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 2px;
}
.add-in-column:hover { background: var(--surface); color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card:hover { border-color: var(--border-strong); }

.card-name { font-weight: 700; font-size: 13.5px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }

.tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--surface-2);
  white-space: nowrap;
}

.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill-overdue { background: var(--danger-soft); color: var(--danger); }
.pill-today { background: var(--warning-soft); color: var(--warning); }
.pill-upcoming { background: var(--muted-soft); color: var(--text-secondary); }
.pill-none { background: transparent; color: var(--text-tertiary); border: 1px dashed var(--border); }
.pill-won { background: var(--success-soft); color: var(--success); }

.card-foot {
  display: flex; align-items: center; justify-content: flex-end;
}
.advance-btn {
  background: var(--accent-soft);
  color: var(--accent-text);
  border: none;
  border-radius: 7px;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
}
.advance-btn:hover { filter: brightness(0.96); }

/* ---------- Slide-over panel ---------- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(16, 20, 30, 0.38);
  z-index: 40;
  display: flex; justify-content: flex-end;
}

.panel {
  width: min(420px, 100vw);
  height: 100%;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 19px; flex: 1; }
.icon-btn {
  background: transparent; border: none; color: var(--text-tertiary);
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.panel-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.field label {
  display: block;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
}
.field textarea { min-height: 84px; resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.panel-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}

/* ---------- Auth screen ---------- */

.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 28px 26px;
}
.auth-card .brand { justify-content: center; margin-bottom: 4px; font-size: 24px; }
.auth-tagline {
  text-align: center; color: var(--text-secondary);
  font-size: 13px; margin: 0 0 22px;
}
.auth-tabs {
  display: flex; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 3px; margin-bottom: 18px;
}
.auth-tabs button {
  flex: 1; background: transparent; border: none; border-radius: 7px;
  padding: 7px 0; font-weight: 700; font-size: 13px; color: var(--text-secondary);
}
.auth-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form .field input { padding: 10px 11px; }
.auth-submit { width: 100%; justify-content: center; padding: 10px 0; font-size: 14px; }
.auth-note { text-align: center; font-size: 12px; color: var(--text-tertiary); margin-top: 14px; }
.auth-note button { background: none; border: none; color: var(--accent-text); font-weight: 700; padding: 0; }
.auth-error {
  background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius); padding: 9px 11px; font-size: 12.5px;
}
.auth-success {
  background: var(--success-soft); color: var(--success);
  border-radius: var(--radius); padding: 9px 11px; font-size: 12.5px;
}
.auth-forgot { text-align: right; }
.auth-forgot button { background: none; border: none; color: var(--text-tertiary); font-size: 12px; padding: 0; }
.auth-forgot button:hover { color: var(--accent-text); }

.loading-screen {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); font-size: 13px;
}

.banner {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* ---------------------------------------------------------------- */
/* AI Assistant view                                                  */
/* ---------------------------------------------------------------- */

.ai-wrap {
  display: grid;
  grid-template-columns: minmax(320px, 460px) 1fr;
  gap: 20px;
  padding: 24px 28px 40px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: start;
}
.ai-form-card, .ai-result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px 22px;
  box-shadow: var(--shadow-sm);
}
.ai-form-card h2, .ai-result-card h2 {
  font-size: 16px;
  margin: 0 0 4px;
}
.ai-sub {
  font-size: 12.5px;
  color: var(--text-tertiary);
  margin: 0 0 16px;
}
.field-optional {
  font-weight: 400;
  color: var(--text-tertiary);
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
}
.field-row-3 { display: flex; gap: 10px; }
.field-row-3 .field { flex: 1; }
.ai-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.ai-result-card {
  position: sticky;
  top: 82px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}
.ai-output {
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  flex: 1;
}
.ai-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

@media (max-width: 640px) {
  .search-box { display: none; }
  .stat-chip { display: none; }
  .panel { width: 100%; }
  .brand small { display: none; }
  .ai-wrap { grid-template-columns: 1fr; padding: 16px; }
  .ai-result-card { position: static; }
}
