/* UI tokens inspired by clean dashboard patterns (e.g. Tabler-style cards, soft elevation) */
:root {
  --bg: #f0f2f6;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --text: #0f1419;
  --muted: #5b6675;
  --border: #e8ecf1;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --danger: #dc2626;
  --success: #059669;
  --warn: #d97706;
  --chip: #f1f4f9;
  --shadow: 0 1px 2px rgba(15, 20, 25, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 20, 25, 0.08);
  --radius: 12px;
  --radius-lg: 16px;
  --font-display: "DM Sans", "Inter", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0c0e12;
  --surface: #14181f;
  --surface-elevated: #1a1f2a;
  --text: #f0f3f8;
  --muted: #8b95a8;
  --border: #2a3140;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.15);
  --danger: #f87171;
  --success: #34d399;
  --warn: #fbbf24;
  --chip: #1e2430;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.65rem 1.25rem;
  background: var(--surface-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.topbar-brand {
  flex-shrink: 0;
  min-width: 0;
}

.topbar .project-nav {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  margin-left: auto;
}

.project-nav .tab {
  margin-right: 0.35rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.project-nav .tab:hover {
  color: var(--text);
  background: var(--chip);
}

.project-nav .tab.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.topbar nav a {
  margin-right: 1rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
}

.topbar nav a:hover {
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
}

.btn:hover {
  border-color: var(--muted);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--muted);
  background: var(--chip);
}

.btn-icon svg {
  display: block;
}

.btn-icon.danger:hover {
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.35);
}

.btn.btn-icon.btn-primary {
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border-radius: 10px;
  color: #fff;
}

.input,
select.input {
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
}

textarea.input {
  min-height: 72px;
  resize: vertical;
}

main.container {
  flex: 1;
  padding: 1.25rem 1.5rem 2rem;
  max-width: 1480px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

.pipeline-shell {
  position: relative;
}

.pipeline-loading-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover), var(--accent));
  background-size: 200% 100%;
  animation: pipeline-shimmer 1s linear infinite;
  border-radius: 2px;
  z-index: 5;
  pointer-events: none;
}

@keyframes pipeline-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.pipeline-dim {
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.summary-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent));
  opacity: 0.65;
}

.summary-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-card .value {
  font-size: 1.35rem;
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar-rail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.toolbar-rail .grow {
  flex: 1;
  min-width: 200px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 520px;
}

.search-wrap .search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-wrap .input {
  padding-left: 2.5rem;
  padding-right: 2.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  min-height: 2.5rem;
}

.search-wrap .input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 1rem;
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.filter-panel .input,
.filter-panel select.input {
  max-width: 170px;
  border-radius: 10px;
}

.toolbar .grow {
  flex: 1;
  min-width: 160px;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.investor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}

.investor-card:hover {
  box-shadow: var(--shadow-md);
}

.investor-card.follow-due {
  border-left: 4px solid var(--warn);
}

.investor-card.replied {
  border-left: 4px solid var(--success);
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.card-head-rich {
  flex-wrap: wrap;
  align-items: flex-start;
  padding-bottom: 1rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.card-head-left {
  flex: 1 1 180px;
  min-width: 0;
}

.card-subid {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  margin-top: 0.2rem;
}

.card-head-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: flex-end;
  flex: 2 1 320px;
  justify-content: flex-end;
  min-width: 0;
}

.card-head-meta .field {
  flex: 1 1 110px;
  min-width: 0;
  max-width: 11rem;
}

.card-hint {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Full pipeline grid: fixed column counts so desktop never collapses to one skinny column */
.pipeline-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 0.6rem 0.85rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 640px) {
  .pipeline-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .pipeline-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .pipeline-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

.pipeline-grid > * {
  min-width: 0;
}

.pipeline-grid-notes {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .pipeline-grid-notes {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pipeline-grid-notes .field.field-wide:last-child {
    grid-column: 1 / -1;
  }
}

.card-title {
  font-weight: 600;
  font-size: 1.05rem;
}

.card-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.card-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.card-section:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.card-section-title {
  margin: 0 0 0.65rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1.1rem;
}

/* Desktop: more columns so every pipeline field is visible without horizontal scroll illusion */
@media (min-width: 900px) {
  .card-grid-dense {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .card-grid-dense {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .card-grid:not(.card-grid-dense):not(.card-grid-stack) {
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  }
}

.card-grid-stack {
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.field.field-wide {
  grid-column: 1 / -1;
}

.field--compact .k {
  font-size: 0.62rem;
  margin-bottom: 0.08rem;
}

.field--compact .v {
  min-height: 1.2rem;
  padding: 0.12rem 0.25rem;
}

.field--compact .input,
.field--compact select.input {
  padding: 0.32rem 0.45rem;
  font-size: 0.82rem;
  min-height: 2rem;
}

@media (max-width: 768px) {
  .card-grid-dense {
    grid-template-columns: 1fr;
  }

  .card-head-meta {
    flex-basis: 100%;
    justify-content: flex-start;
  }

  .card-head-meta .field {
    max-width: none;
    flex: 1 1 calc(50% - 0.5rem);
  }
}

/* Expand drawer: mobile only — desktop shows full card */
.card-actions .btn-expand-only {
  display: none;
}

@media (max-width: 768px) {
  .card-actions .btn-expand-only {
    display: inline-flex;
  }
}

.field {
  font-size: 0.88rem;
}

.field .k {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.15rem;
}

.field .v {
  min-height: 1.35rem;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  cursor: default;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.field .v a {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  vertical-align: top;
}

.field.field--saving {
  position: relative;
  opacity: 0.92;
}

.field.field--saving::after {
  content: "";
  position: absolute;
  right: 0.35rem;
  top: 1.65rem;
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: field-spin 0.65s linear infinite;
}

@keyframes field-spin {
  to {
    transform: rotate(360deg);
  }
}

.rule-visual .rule-block {
  padding: 0.85rem 1rem;
  background: var(--chip);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.rule-block-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

.rule-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.rule-row .input {
  max-width: 200px;
}

.rule-row-actions .input {
  max-width: 180px;
}

.rule-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.rule-arrow,
.rule-muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.field .v.editable:hover {
  background: var(--chip);
  outline: 1px dashed var(--border);
}

.chip {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  background: var(--chip);
  color: var(--text);
}

.chip-tier-1 {
  background: rgba(34, 197, 94, 0.18);
}
.chip-tier-2 {
  background: rgba(59, 130, 246, 0.18);
}
.chip-tier-3 {
  background: rgba(234, 179, 8, 0.2);
}

.save-state {
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: 0.5rem;
}

.save-state.saving {
  color: var(--warn);
}
.save-state.saved {
  color: var(--success);
}
.save-state.error {
  color: var(--danger);
}

.login-wrap {
  max-width: 400px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.login-wrap h1 {
  margin-top: 0;
}

.project-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.project-card {
  padding: 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  display: block;
  box-shadow: var(--shadow);
}

.project-card:hover {
  border-color: var(--accent);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10000;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, 100%);
  height: 100%;
  max-height: 100vh;
  background: var(--surface);
  color: var(--text);
  z-index: 10001;
  padding: 1rem 1.25rem;
  overflow: auto;
  overflow-x: hidden;
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
}

.drawer .card-grid {
  position: relative;
  z-index: 1;
}

.field-date .input[type="date"] {
  min-height: 2.5rem;
  cursor: pointer;
}

@media (max-width: 640px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}
