:root {
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-2: #eef3ea;
  --ink: #1f2a24;
  --muted: #65736b;
  --line: #dbe3d7;
  --green: #287a4c;
  --green-dark: #185f39;
  --teal: #19747e;
  --amber: #b45f06;
  --red: #ad343e;
  --blue: #315c9b;
  --shadow: 0 18px 50px rgba(31, 42, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hidden {
  display: none !important;
}

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

button {
  cursor: pointer;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(140deg, #183428 0%, #287a4c 48%, #f5f7f3 48%);
}

.auth-card {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: 25px;
}

.auth-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-card p {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
}

.auth-brand {
  color: var(--ink);
}

.auth-brand span {
  color: var(--muted);
}

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

.sidebar {
  background: #183428;
  color: white;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #a3d65c;
  color: #173125;
  font-weight: 800;
  border-radius: 8px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-note span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.sidebar-note {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding-top: 18px;
  display: grid;
  gap: 6px;
  line-height: 1.45;
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 32px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  margin-bottom: 0;
}

.topbar-actions,
.toolbar,
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search {
  min-width: min(390px, 100%);
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
}

.search input {
  border: 0;
  outline: 0;
  width: 100%;
  background: transparent;
}

.primary-button,
.ghost-button,
.icon-button,
menu button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 13px;
  background: var(--surface);
  color: var(--ink);
}

.primary-button {
  border-color: var(--green);
  background: var(--green);
  color: white;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--green-dark);
}

.ghost-button:hover,
menu button:hover {
  border-color: var(--green);
}

.danger-button {
  color: var(--red);
  border-color: #f0c8cc;
}

.danger-button:hover {
  border-color: var(--red);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 22px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.7fr);
  gap: 18px;
}

.dashboard-grid > *,
.lead-layout > * {
  min-width: 0;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  min-height: 38px;
  padding: 8px 10px;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

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

.date-filter {
  width: 155px;
}

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

.segmented button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  min-height: 36px;
  padding: 0 10px;
}

.segmented button.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

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

.pipe-column {
  min-width: 145px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.pipe-column h3 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
}

.lead-card,
.task-card,
.activity-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.lead-card {
  display: grid;
  gap: 8px;
  width: 100%;
  text-align: left;
}

.lead-card.active,
.lead-card:hover {
  border-color: var(--green);
}

.lead-card strong,
.task-card strong {
  overflow-wrap: anywhere;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #e8efe5;
  color: #275038;
  font-size: 12px;
  font-weight: 700;
}

.badge.hot {
  background: #fff1d6;
  color: var(--amber);
}

.badge.won {
  background: #dff3e7;
  color: var(--green-dark);
}

.badge.lost {
  background: #fde3e5;
  color: var(--red);
}

.lead-layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.call-layout {
  max-width: 980px;
}

.call-panel {
  position: static;
  max-height: none;
}

.call-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.call-form textarea {
  min-height: 130px;
}

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

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

.lead-detail {
  position: sticky;
  top: 18px;
  align-self: start;
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-height: 520px;
  box-shadow: var(--shadow);
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.field-box {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px;
}

.field-box span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 5px;
}

.field-box a,
.meta-row a {
  color: var(--teal);
  font-weight: 700;
  text-decoration: none;
}

.field-box a:hover,
.meta-row a:hover {
  text-decoration: underline;
}

.notes-box {
  white-space: pre-wrap;
  line-height: 1.5;
}

.activity-list,
.task-list,
.task-board,
.timeline {
  display: grid;
  gap: 10px;
}

.task-board {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.task-card {
  display: grid;
  gap: 10px;
}

.task-top {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
}

.task-card.done {
  opacity: 0.62;
}

.activity-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
}

.activity-icon {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--teal);
  font-weight: 800;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 22px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.65);
  text-align: center;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(780px, calc(100vw - 28px));
  box-shadow: 0 24px 80px rgba(24, 52, 40, 0.25);
}

dialog::backdrop {
  background: rgba(24, 52, 40, 0.42);
}

.dialog-form {
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

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

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.import-help {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  line-height: 1.45;
  padding: 12px;
  margin-bottom: 12px;
}

.import-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.import-actions span {
  color: var(--muted);
  font-size: 13px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.inline-check input {
  min-height: auto;
}

.import-area {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.import-area textarea {
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  color: var(--ink);
  font-weight: 400;
}

.span-2 {
  grid-column: 1 / -1;
}

menu {
  margin: 18px 0 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 12px;
    gap: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(4, 1fr);
  }

  .sidebar-note {
    display: none;
  }

  .metrics,
  .dashboard-grid,
  .lead-layout {
    grid-template-columns: 1fr;
  }

  .lead-detail {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .toolbar,
  .toolbar-actions,
  .panel-head,
  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    min-width: 0;
    width: 100%;
  }

  .nav-item {
    justify-content: center;
    padding: 10px 8px;
    font-size: 13px;
    min-width: 0;
  }

  .nav-item span {
    display: none;
  }

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