:root {
  color-scheme: light;
  --ink: #161616;
  --muted: #6f716f;
  --soft: #f5f3ef;
  --line: #ded8ce;
  --panel: #ffffff;
  --shell: #15171c;
  --shell-2: #1d2027;
  --gold: #b68a45;
  --gold-dark: #8a652e;
  --danger: #b34838;
  --ok: #3f7a56;
  --blue: #406b9d;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--soft);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(21, 23, 28, 0.98), rgba(37, 38, 43, 0.95)),
    var(--shell);
}

.login-panel {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #101218;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.32);
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(182, 138, 69, 0.7);
  border-radius: 8px;
  color: #f4dfb9;
  background: rgba(182, 138, 69, 0.14);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand-name {
  color: #f7f1e6;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.brand-subtitle {
  margin-top: 2px;
  color: rgba(247, 241, 230, 0.62);
  font-size: 13px;
}

.login-form {
  margin-top: 34px;
  display: grid;
  gap: 16px;
}

.login-form h1 {
  margin: 0 0 4px;
  color: #f7f1e6;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px;
  line-height: 1;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: rgba(247, 241, 230, 0.68);
  font-size: 13px;
}

.login-form input,
.filters input,
.filters select,
.date-filters input,
.stack-form input,
.stack-form select,
.process-form input,
.process-form select,
.detail-panel input,
.detail-panel select,
.detail-panel textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

.login-form input {
  border-color: rgba(255, 255, 255, 0.16);
  background: #181b22;
  color: #f7f1e6;
}

.login-form input:focus,
.filters input:focus,
.filters select:focus,
.date-filters input:focus,
.stack-form input:focus,
.stack-form select:focus,
.process-form input:focus,
.process-form select:focus,
.detail-panel input:focus,
.detail-panel select:focus,
.detail-panel textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(182, 138, 69, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 9px 13px;
  font-size: 13px;
  font-weight: 700;
}

.primary-button {
  background: var(--gold);
  color: #1b1710;
}

.secondary-button {
  background: var(--shell);
  color: #fff;
}

.ghost-button {
  border-color: rgba(255, 255, 255, 0.16);
  background: transparent;
  color: rgba(255, 255, 255, 0.76);
}

.error-line {
  margin: 0;
  color: #ffb3a8;
  font-size: 13px;
}

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

.sidebar {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 20px 16px;
  background: var(--shell);
  color: #fff;
}

.sidebar-brand {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
}

.sidebar-brand strong,
.sidebar-brand small {
  display: block;
}

.sidebar-brand strong {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0.12em;
}

.sidebar-brand small {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.52);
  font-size: 12px;
}

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

.side-link {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.68);
  padding: 11px 12px;
  text-align: left;
  text-decoration: none;
  font-size: 14px;
}

.side-link.active {
  background: rgba(182, 138, 69, 0.14);
  color: #f4dfb9;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.session-user {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  line-height: 1.45;
}

.workspace {
  min-width: 0;
  padding: 18px;
  overflow: auto;
}

.view-panel {
  min-height: calc(100vh - 36px);
}

.leads-view {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(460px, 1.5fr);
  gap: 18px;
  align-items: end;
}

.topbar h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px;
  line-height: 1;
}

.topbar p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 150px 170px auto;
  gap: 8px;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(90px, 1fr));
  gap: 8px;
}

.stat-item {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
}

.stat-item strong,
.stat-item span {
  display: block;
}

.stat-item strong {
  font-size: 20px;
  line-height: 1;
}

.stat-item span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.content-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 14px;
}

.table-panel,
.detail-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.table-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
}

.leads-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

.leads-table th,
.leads-table td {
  padding: 11px 10px;
  border-bottom: 1px solid #eee9df;
  vertical-align: top;
  text-align: left;
}

.leads-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #faf8f4;
  color: #5b5c5b;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.leads-table tr {
  cursor: pointer;
}

.leads-table tr:hover,
.leads-table tr.is-selected {
  background: #fbf6ed;
}

.leads-table th:nth-child(1),
.leads-table td:nth-child(1) {
  width: 126px;
}

.leads-table th:nth-child(2),
.leads-table td:nth-child(2) {
  width: 128px;
}

.leads-table th:nth-child(3),
.leads-table td:nth-child(3),
.leads-table th:nth-child(6),
.leads-table td:nth-child(6) {
  width: 140px;
}

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

.cell-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.cell-sub {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eee8dc;
  color: #4e4b46;
  font-size: 12px;
  font-weight: 800;
}

.badge.status-new {
  background: #e8f0fb;
  color: var(--blue);
}

.badge.status-in_progress,
.badge.status-contacted,
.badge.status-qualified,
.badge.status-proposal {
  background: #fff2d9;
  color: var(--gold-dark);
}

.badge.status-won {
  background: #e3f2e8;
  color: var(--ok);
}

.badge.status-lost,
.badge.status-spam {
  background: #f7e4df;
  color: var(--danger);
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  font-size: 14px;
}

.detail-panel {
  min-height: 0;
  overflow: auto;
}

.detail-placeholder {
  height: 100%;
  min-height: 360px;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.detail-placeholder span {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
}

.detail-content {
  display: grid;
  gap: 18px;
  padding: 18px;
}

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

.detail-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  line-height: 1.05;
}

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

.detail-section {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid #eee9df;
}

.detail-section h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.kv-grid {
  display: grid;
  gap: 9px;
}

.kv-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.kv-row span:first-child {
  color: var(--muted);
}

.kv-row a {
  color: var(--gold-dark);
}

.detail-form {
  display: grid;
  gap: 10px;
}

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

.detail-form label,
.note-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.detail-form textarea,
.note-form textarea {
  min-height: 96px;
  resize: vertical;
}

.check-row {
  display: inline-grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.check-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
}

.check-row span {
  line-height: 1.35;
}

.note-form {
  display: grid;
  gap: 10px;
}

.timeline {
  display: grid;
  gap: 9px;
}

.timeline-item {
  border-left: 2px solid #e5dccd;
  padding-left: 10px;
}

.timeline-item strong,
.timeline-item time,
.timeline-item p {
  display: block;
}

.timeline-item strong {
  font-size: 13px;
}

.timeline-item time {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.timeline-item p {
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(340px, calc(100vw - 40px));
  border-radius: 8px;
  background: var(--shell);
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
  font-size: 13px;
}

.reports-view,
.settings-view {
  display: grid;
  gap: 14px;
  align-content: start;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.section-head h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 34px;
  line-height: 1;
}

.section-head p,
.panel-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.date-filters {
  display: grid;
  grid-template-columns: 150px 150px auto;
  gap: 8px;
  align-items: end;
}

.date-filters label,
.stack-form label,
.process-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.reports-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

.metric-card,
.report-panel,
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-card {
  min-height: 76px;
  padding: 14px;
}

.metric-card strong {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.metric-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

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

.report-panel,
.settings-panel {
  min-width: 0;
  padding: 16px;
}

.report-panel h2,
.settings-panel h2 {
  margin: 0;
  font-size: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(420px, 1.2fr);
  gap: 14px;
}

.settings-panel-wide {
  grid-column: 1 / -1;
}

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

.stack-form,
.process-form {
  display: grid;
  gap: 12px;
}

.checkbox-fieldset {
  min-width: 0;
  margin: 0;
  border: 1px solid #eee9df;
  border-radius: 8px;
  padding: 10px;
}

.checkbox-fieldset legend {
  color: var(--muted);
  font-size: 12px;
}

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

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #eee9df;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.compact-scroll {
  max-height: 520px;
}

.users-table {
  min-width: 680px;
}

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

.text-button {
  border: 0;
  background: transparent;
  color: var(--gold-dark);
  padding: 0;
  font-size: 13px;
  font-weight: 700;
}

.process-stages {
  display: grid;
  gap: 10px;
}

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

.ops-card {
  min-height: 86px;
  border: 1px solid #eee9df;
  border-radius: 8px;
  background: #fcfaf6;
  padding: 14px;
}

.ops-card strong,
.ops-card span,
.ops-card small {
  display: block;
}

.ops-card strong {
  font-size: 18px;
}

.ops-card span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.ops-card small {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.ops-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.stage-row {
  display: grid;
  grid-template-columns: 150px minmax(160px, 1fr) 120px minmax(220px, 1.1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid #eee9df;
  border-radius: 8px;
  padding: 12px;
  background: #fcfaf6;
}

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

@media (max-width: 1180px) {
  .topbar,
  .content-grid,
  .reports-grid,
  .settings-grid,
  .stage-row {
    grid-template-columns: 1fr;
  }

  .settings-panel-wide {
    grid-column: auto;
  }

  .detail-panel {
    min-height: 520px;
  }

  .stats-strip {
    grid-template-columns: repeat(4, minmax(100px, 1fr));
  }
}

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

  .sidebar {
    min-height: auto;
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .workspace {
    padding: 12px;
  }

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

  .date-filters,
  .reports-summary,
  .ops-grid,
  .directions-checks,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .stats-strip {
    grid-template-columns: repeat(2, minmax(100px, 1fr));
  }

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