:root {
  color-scheme: light;
  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --surface-strong: #122023;
  --text: #132326;
  --muted: #64747a;
  --line: #dce5e7;
  --line-strong: #c8d4d7;
  --teal: #0f8f83;
  --teal-dark: #0a665f;
  --blue: #315f9c;
  --green: #237a57;
  --red: #b94a48;
  --amber: #b06a20;
  --ink-shadow: 0 18px 50px rgba(18, 32, 35, 0.10);
  --soft-shadow: 0 8px 24px rgba(18, 32, 35, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 18% -8%, rgba(15, 143, 131, 0.14), transparent 34%),
    linear-gradient(180deg, #f8fbfb 0%, var(--bg) 360px);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

select[multiple] {
  min-height: 54px;
  padding: 6px 8px;
}

button,
a,
input,
select {
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background 160ms ease;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.app-header {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 30px clamp(16px, 4vw, 48px) 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand-block,
.header-actions,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark,
.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.brand-mark {
  display: grid;
  place-items: center;
  background: var(--surface-strong);
  color: #ffffff;
  font-size: 15px;
  font-weight: 900;
}

.brand-logo {
  display: block;
  object-fit: contain;
  background: #ffffff;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.period-chip,
.status-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: var(--soft-shadow);
}

.status-pill.ok {
  border-color: rgba(35, 122, 87, 0.28);
  background: #edf8f2;
  color: var(--green);
}

.status-pill.fail {
  border-color: rgba(185, 74, 72, 0.28);
  background: #fff1f1;
  color: var(--red);
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 48px) 48px;
}

.tabs {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 14px;
  padding: 5px;
  border: 1px solid rgba(220, 229, 231, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--soft-shadow);
}

.tab-button {
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tab-button.active {
  background: var(--surface-strong);
  color: #ffffff;
}

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid rgba(220, 229, 231, 0.86);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(12px);
}

.meta-toolbar {
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

input::placeholder {
  color: #95a1a6;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(15, 143, 131, 0.13);
}

button,
.button-secondary {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 15px;
  background: var(--surface-strong);
  color: #ffffff;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

button:hover,
.button-secondary:hover {
  transform: translateY(-1px);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metrics-four {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric,
.panel,
.table-panel {
  border: 1px solid rgba(220, 229, 231, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--soft-shadow);
}

.metric {
  position: relative;
  min-height: 108px;
  display: grid;
  align-content: space-between;
  gap: 18px;
  overflow: hidden;
  padding: 16px;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--blue);
}

.metric-total::before {
  background: var(--surface-strong);
}

.metric-won::before {
  background: var(--green);
}

.metric-lost::before {
  background: var(--red);
}

.metric-net::before {
  background: var(--teal);
}

.metric span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  min-height: 16px;
}

.metric strong {
  font-size: clamp(22px, 2vw, 30px);
  line-height: 1;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error-banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(185, 74, 72, 0.28);
  border-radius: 8px;
  background: #fff1f1;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

.alert-banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(176, 106, 32, 0.32);
  border-radius: 8px;
  background: #fff8ec;
  color: var(--amber);
  font-size: 13px;
  font-weight: 900;
}

.is-loading .metric strong,
.is-loading .line-chart,
.is-loading .bar-list,
.is-loading .cohort-list,
.is-loading .mix-chart,
.is-loading tbody {
  position: relative;
}

.is-loading .metric strong::after,
.is-loading .line-chart::after,
.is-loading .bar-list::after,
.is-loading .cohort-list::after,
.is-loading .mix-chart::after,
.is-loading tbody::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(233, 239, 241, 0.55), rgba(255, 255, 255, 0.92), rgba(233, 239, 241, 0.55));
  background-size: 240% 100%;
  animation: skeleton 1.1s linear infinite;
  pointer-events: none;
}

@keyframes skeleton {
  from {
    background-position: 100% 0;
  }

  to {
    background-position: -100% 0;
  }
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.75fr) minmax(280px, 0.75fr);
  gap: 12px;
  margin-bottom: 16px;
}

.meta-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.75fr) minmax(280px, 0.75fr);
}

.panel-wide {
  grid-row: span 2;
}

.panel {
  min-height: 270px;
  padding: 16px;
}

.panel-head,
.table-head,
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-head span,
.table-head p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.line-chart {
  height: 320px;
  margin-top: 16px;
}

.line-chart svg {
  width: 100%;
  height: 100%;
  display: block;
}

.empty-state {
  height: 100%;
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.bar-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) minmax(120px, 1.1fr) minmax(48px, auto);
  gap: 10px;
  align-items: center;
  min-height: 30px;
}

.bar-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.bar-track {
  height: 10px;
  border-radius: 7px;
  background: #e9eff1;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.bar-row:nth-child(3n) .bar-fill {
  background: var(--teal);
}

.bar-row:nth-child(3n + 2) .bar-fill {
  background: var(--amber);
}

.bar-row.is-won .bar-fill {
  background: var(--green);
}

.bar-row.is-lost .bar-fill {
  background: var(--red);
}

.bar-row.is-open .bar-fill {
  background: var(--blue);
}

.bar-value {
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  text-align: right;
}

.table-panel {
  overflow: hidden;
}

.table-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfd 100%);
}

.pager {
  display: inline-grid;
  grid-template-columns: 40px minmax(58px, auto) 40px;
  align-items: center;
  gap: 8px;
}

.pager button,
.drawer-head button {
  width: 40px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
  font-size: 22px;
}

#pageLabel,
#metaPageLabel {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
}

.meta-table {
  min-width: 980px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f6faf9;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #f8fbfb;
}

.person-name,
.date-cell {
  display: block;
  line-height: 1.25;
}

.subtle {
  display: block;
  max-width: 240px;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.money {
  font-weight: 900;
  white-space: nowrap;
}

.money-won {
  color: var(--green);
}

.money-lost {
  color: var(--red);
}

.reason-cell {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag,
.status-badge {
  display: inline-flex;
  max-width: 220px;
  min-height: 26px;
  align-items: center;
  border-radius: 7px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  background: #eaf5f3;
  color: var(--teal-dark);
}

.source-tag {
  margin: 2px 4px 2px 0;
  background: #edf4fb;
  color: var(--blue);
}

.channel-tag {
  background: #f1f6ee;
  color: var(--green);
}

.mix-chart {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.mix-meter {
  display: flex;
  width: 100%;
  height: 18px;
  overflow: hidden;
  border-radius: 7px;
  background: #e9eff1;
}

.mix-fill.direct {
  background: var(--green);
}

.mix-fill.campaign {
  background: var(--amber);
}

.mix-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.mix-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.mix-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.mix-card strong {
  font-size: 26px;
  line-height: 1;
}

.mix-card small {
  color: var(--muted);
  font-weight: 800;
}

.mix-card.direct strong {
  color: var(--green);
}

.mix-card.campaign strong {
  color: var(--amber);
}

.cohort-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.cohort-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1.4fr) minmax(150px, auto);
  gap: 12px;
  align-items: center;
  min-height: 44px;
}

.cohort-row strong,
.cohort-row span,
.cohort-row small {
  display: block;
}

.cohort-row span,
.cohort-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.cohort-stack {
  display: flex;
  height: 14px;
  overflow: hidden;
  border-radius: 7px;
  background: #e9eff1;
}

.cohort-stack i {
  display: block;
  min-width: 3px;
}

.cohort-stack .won {
  background: var(--green);
}

.cohort-stack .lost {
  background: var(--red);
}

.cohort-stack .open {
  background: var(--blue);
}

.plan-note {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 180px;
  margin-top: 18px;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
}

.plan-note p {
  color: var(--muted);
  line-height: 1.5;
}

.status-badge.is-won {
  background: #e9f7ef;
  color: var(--green);
}

.status-badge.is-lost {
  background: #fff0ef;
  color: var(--red);
}

.status-badge.is-open {
  background: #edf4fb;
  color: var(--blue);
}

.status-badge.is-neutral {
  background: #f1f4f5;
  color: var(--muted);
}

.row-action {
  min-height: 34px;
  padding: 0 11px;
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  justify-content: flex-end;
  background: rgba(18, 32, 35, 0.42);
}

.drawer.open {
  display: flex;
}

.drawer-panel {
  width: min(580px, 100%);
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  box-shadow: -20px 0 48px rgba(18, 32, 35, 0.18);
}

.drawer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.details {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.details dl {
  margin: 0;
}

.lead-timeline {
  display: grid;
  gap: 12px;
  margin-bottom: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.lead-timeline h3 {
  margin: 0;
  font-size: 14px;
}

.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  top: 18px;
  bottom: -12px;
  left: 7px;
  width: 2px;
  background: var(--line);
}

.timeline-item:last-child::before {
  display: none;
}

.timeline-item > span {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border: 3px solid #ffffff;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 1px rgba(15, 143, 131, 0.28);
}

.timeline-item strong {
  display: block;
  font-size: 12px;
}

.timeline-item p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.detail-row {
  display: grid;
  gap: 5px;
  padding: 0 0 13px;
  border-bottom: 1px solid var(--line);
}

.detail-row dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-row dd {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.skeleton-row td {
  padding: 16px;
}

.skeleton-line,
.skeleton-card span {
  display: block;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(220, 229, 231, 0.75), rgba(255, 255, 255, 0.95), rgba(220, 229, 231, 0.75));
  background-size: 240% 100%;
  animation: skeleton 1.1s linear infinite;
}

.skeleton-line {
  width: 44%;
  margin-top: 8px;
}

.skeleton-line.wide {
  width: 72%;
  margin-top: 0;
}

.skeleton-card {
  display: grid;
  gap: 14px;
  min-height: 180px;
  margin-top: 18px;
  padding: 16px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.skeleton-card span:nth-child(1) {
  width: 70%;
}

.skeleton-card span:nth-child(2) {
  width: 92%;
}

.skeleton-card span:nth-child(3) {
  width: 54%;
}

@media (max-width: 1220px) {
  .toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions > * {
    flex: 1;
  }

  .search-field {
    grid-column: span 2;
  }

  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }

  .panel-wide {
    grid-column: span 2;
    grid-row: auto;
  }
}

@media (max-width: 860px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    align-items: stretch;
  }

  .period-chip,
  .status-pill {
    flex: 1;
  }

  .tabs,
  .toolbar,
  .metrics,
  .dashboard-grid,
  .cohort-row {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: grid;
    width: 100%;
  }

  .search-field,
  .panel-wide {
    grid-column: auto;
  }

}

@media (max-width: 560px) {
  .brand-mark,
  .brand-logo {
    width: 42px;
    height: 42px;
  }

  .brand-block {
    align-items: flex-start;
  }

  .header-actions,
  .toolbar-actions {
    flex-direction: column;
  }

  .period-chip,
  .status-pill,
  .toolbar-actions > * {
    width: 100%;
  }

  .metric {
    min-height: 94px;
  }

  .line-chart {
    height: 250px;
  }
}
