:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-strong: #f0f4f8;
  --line: #d8dee7;
  --text: #18212f;
  --muted: #667085;
  --teal: #0f766e;
  --blue: #2563eb;
  --green: #15803d;
  --amber: #b45309;
  --red: #b91c1c;
  --shadow: 0 10px 30px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  padding: 10px 20px;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-size: 13px;
}

.runtime-controls {
  display: flex;
  min-width: 0;
  align-items: end;
  gap: 10px;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

.api-control {
  width: min(42vw, 520px);
}

.icon-button,
.primary-button,
.secondary-button,
.stage-button,
.danger-button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 11px;
  font-weight: 700;
  white-space: nowrap;
}

.icon-button {
  width: 38px;
  padding: 8px;
  border-color: var(--line);
  background: #fff;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.secondary-button,
.stage-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.danger-button {
  border-color: #fecaca;
  background: #fff1f2;
  color: var(--red);
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.sidebar {
  position: sticky;
  top: 64px;
  align-self: start;
  display: grid;
  gap: 6px;
  height: calc(100vh - 64px);
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 14px;
}

.nav-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  text-align: left;
}

.nav-item.is-active {
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: 20px;
}

.view-root {
  display: grid;
  gap: 18px;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.view-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.notice {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.notice.is-error {
  border-left-color: var(--red);
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel,
.metric-card,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
}

.panel-title {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 14px;
}

.metric-card {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-value {
  font-size: 28px;
  font-weight: 800;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.table-wrap {
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

tr[data-id] {
  cursor: pointer;
}

tr[data-id]:hover {
  background: #f8fafc;
}

.muted {
  color: var(--muted);
}

.compact {
  font-size: 12px;
}

.pill,
.stage-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.pill {
  background: var(--surface-strong);
  color: var(--muted);
}

.stage-pill {
  background: #e0f2fe;
  color: #075985;
}

.stage-Contacted {
  background: #e0f7ef;
  color: #0f766e;
}

.stage-Demo {
  background: #eef2ff;
  color: #3730a3;
}

.stage-Proposal {
  background: #fef3c7;
  color: var(--amber);
}

.stage-Closed-Won {
  background: #dcfce7;
  color: var(--green);
}

.stage-Closed-Lost {
  background: #fee2e2;
  color: var(--red);
}

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(120px, 1.3fr) auto;
  align-items: center;
  gap: 10px;
}

.bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

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

.pipeline {
  display: grid;
  grid-template-columns: repeat(6, minmax(180px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.stage-column {
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stage-column header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  font-weight: 800;
}

.deal-card,
.queue-card {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 10px;
}

.deal-card:last-child,
.queue-card:last-child {
  border-bottom: 0;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stage-button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.detail-panel {
  align-self: start;
  overflow: hidden;
}

.detail-list {
  display: grid;
  gap: 8px;
}

.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.detail-list div:last-child {
  border-bottom: 0;
}

.inline-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

svg {
  width: 17px;
  height: 17px;
}

@media (max-width: 920px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .runtime-controls {
    width: 100%;
    align-items: end;
  }

  .api-control {
    width: 100%;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    display: flex;
    height: auto;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-item {
    width: auto;
    min-width: max-content;
  }

  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 14px;
  }

  .runtime-controls,
  .view-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .bar-row {
    grid-template-columns: 1fr;
  }

  .icon-button,
  .primary-button,
  .secondary-button,
  .danger-button {
    width: 100%;
  }
}
