:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-soft: #f2f4f7;
  --line: #d9dee7;
  --line-strong: #aeb7c5;
  --text: #151922;
  --muted: #667085;
  --accent: #002fa7;
  --accent-dark: #001f70;
  --accent-soft: #e8eefc;
  --green: #067647;
  --green-soft: #e7f6ee;
  --amber: #b54708;
  --amber-soft: #fff4e5;
  --red: #b42318;
  --red-soft: #fdecec;
}

body.dark {
  --bg: #080b10;
  --surface: #111722;
  --surface-soft: #1a2331;
  --line: #344055;
  --line-strong: #59677e;
  --text: #f4f7fb;
  --muted: #c1cad8;
  --accent: #7aa2ff;
  --accent-dark: #9ab8ff;
  --accent-soft: #1f2d50;
  --green: #58d68d;
  --green-soft: #153626;
  --amber: #ffcf66;
  --amber-soft: #3a2a10;
  --red: #ff8a80;
  --red-soft: #3a1715;
}

* {
  box-sizing: border-box;
}

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

body.dark {
  background:
    linear-gradient(90deg, rgba(122, 162, 255, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(122, 162, 255, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 48px 48px;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(0, 47, 167, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(0, 47, 167, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 48px 48px;
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

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

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  padding: 10px 16px;
  font-weight: 700;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  transform: translateY(-1px);
}

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

button:disabled:hover {
  background: var(--accent);
  border-color: var(--accent);
}

button.secondary,
#cancelPreview,
#clearFilters {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

#cancelPreview {
  border-color: var(--line-strong);
}

button.secondary:hover,
#cancelPreview:hover,
#clearFilters:hover {
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  min-height: 138px;
  resize: vertical;
  line-height: 1.45;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.top-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(34px, 4.6vw, 58px);
  line-height: 0.95;
  font-weight: 800;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
  font-weight: 800;
}

.today {
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  text-align: right;
  background: var(--surface);
}

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

.today strong {
  color: var(--accent);
  font-size: 20px;
}

.entry-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(360px, 0.88fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  min-width: 0;
}

.entry-panel,
.guided-panel,
.preview,
.filters,
.table-panel {
  padding: 18px;
}

.entry-panel {
  align-self: start;
}

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

.hint {
  color: var(--muted);
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.5;
}

.free-phone-alert {
  margin-top: 12px;
  border: 1px solid var(--red);
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.35;
}

.free-phone-alert strong {
  display: block;
  color: var(--red);
  font-size: 16px;
  margin-bottom: 3px;
}

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

.guided-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.free-actions button {
  min-width: 180px;
}

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

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

[hidden] {
  display: none !important;
}

.full {
  margin-top: 11px;
}

.preview,
.decision-panel {
  margin-top: 16px;
  border-color: var(--accent);
  background: color-mix(in srgb, var(--surface) 94%, var(--accent-soft));
}

.import-panel {
  margin-top: 16px;
  padding: 18px;
}

.import-source {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.import-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.import-stats span {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 800;
}

.import-stats strong {
  color: var(--text);
  font-size: 18px;
}

.import-report {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  max-height: 160px;
  overflow: auto;
}

.import-report p {
  margin: 0 0 8px;
}

.import-report p:last-child {
  margin-bottom: 0;
}

.import-report ul {
  margin: 0;
  padding-left: 18px;
}

#guidedPreviewSlot .decision-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#guidedPreviewSlot .decision-panel.blocked {
  border-color: var(--red);
  background: color-mix(in srgb, var(--surface) 90%, var(--red-soft));
}

#decisionSummary {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  font-weight: 700;
}

.duplicate-choice {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

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

.existing {
  margin-top: 12px;
  border: 1px solid var(--amber);
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--amber);
  padding: 11px 13px;
  font-size: 13px;
  line-height: 1.45;
}

.existing:empty {
  display: none;
}

.existing-title {
  margin: 0 0 10px;
  font-weight: 800;
}

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

.existing-link {
  width: 100%;
  min-height: 38px;
  border-color: color-mix(in srgb, var(--amber) 55%, var(--line));
  background: color-mix(in srgb, var(--surface) 88%, var(--amber-soft));
  color: var(--text);
  text-align: left;
  font-size: 13px;
  font-weight: 800;
  padding: 9px 11px;
}

.existing-link:hover {
  background: var(--surface);
  border-color: var(--amber);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0;
}

.tab {
  min-height: 42px;
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.tab:hover {
  background: var(--surface-soft);
  border-color: var(--line-strong);
}

.tab.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.workarea {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.filters {
  align-self: start;
  display: grid;
  gap: 14px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 100%;
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 720px;
  table-layout: fixed;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  font-size: 15px;
  line-height: 1.35;
  background: var(--surface);
  overflow-wrap: anywhere;
}

th:nth-child(1),
td:nth-child(1) {
  width: 18%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 12%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 17%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 13%;
}

th:nth-child(5),
td:nth-child(5) {
  width: 16%;
}

th:nth-child(6),
td:nth-child(6) {
  width: 10%;
}

th:nth-child(7),
td:nth-child(7) {
  width: 14%;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr {
  cursor: pointer;
}

tr:hover td {
  background: var(--surface-soft);
}

tr.selected td {
  background: var(--accent-soft);
  box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 4px 8px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 800;
  max-width: 100%;
  white-space: nowrap;
  overflow-wrap: normal;
}

.pill.review {
  color: var(--amber);
  border-color: var(--amber);
  background: var(--amber-soft);
}

.pill.client {
  color: var(--green);
  border-color: var(--green);
  background: var(--green-soft);
}

.pill.priority-very-hot {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-soft);
}

.pill.priority-hot {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
}

body:not(.dark) .pill.priority-hot {
  color: #ffffff;
}

.pill.priority-warm {
  color: var(--amber);
  border-color: var(--amber);
  background: var(--amber-soft);
}

.pill.priority-cold {
  color: var(--muted);
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.pill.priority-reschedule,
.pill.schedule-pre {
  color: var(--amber);
  border-color: var(--amber);
  background: var(--amber-soft);
}

.pill.schedule-done {
  color: var(--green);
  border-color: var(--green);
  background: var(--green-soft);
}

.queue-label,
.phone-text {
  font-weight: 800;
}

.detail-panel {
  position: sticky;
  top: 14px;
  padding: 18px;
}

.detail-id,
.save-status {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-top: 5px;
}

.save-status {
  color: var(--accent);
  margin-top: 0;
}

.detail-empty {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

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

.detail-panel textarea {
  min-height: 116px;
}

#detailForm.saving {
  opacity: 0.74;
}

#detailForm.save-error input,
#detailForm.save-error select,
#detailForm.save-error textarea {
  border-color: var(--red);
}

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

@media (max-width: 1180px) {
  .workarea {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .detail-panel {
    position: static;
    grid-column: 1 / -1;
  }

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

@media (max-width: 920px) {
  .topbar,
  .top-actions,
  .entry-grid,
  .workarea {
    grid-template-columns: 1fr;
    display: grid;
  }

  .today {
    text-align: left;
  }

  .fields,
  .detail-grid,
  .duplicate-choice,
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .shell {
    padding: 14px;
  }

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

  .guided-actions,
  .panel-head button,
  .free-actions button,
  .actions,
  .actions button {
    width: 100%;
  }

  .guided-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  h1 {
    font-size: 38px;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(126px, 42%) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    min-height: 44px;
    padding: 10px 12px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }
}
