:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #20242a;
  --muted: #687182;
  --line: #dde3ea;
  --line-strong: #c7d0db;
  --blue: #2463d1;
  --blue-soft: #e9f0ff;
  --green: #167348;
  --green-soft: #e5f5ee;
  --amber: #946200;
  --amber-soft: #fff3d6;
  --red: #a23632;
  --red-soft: #fde8e7;
  --violet: #5b50b6;
  --violet-soft: #eeeafd;
  --cyan: #147285;
  --cyan-soft: #e4f5f7;
  --dark: #111820;
  --shadow: 0 18px 42px rgba(23, 31, 42, 0.10);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1160px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  user-select: none;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

.sidebar {
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--dark);
  color: #f7f9fb;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #f0c23d;
  color: var(--dark);
  font-weight: 850;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
}

.brand-subtitle {
  color: rgba(247, 249, 251, 0.72);
  font-size: 12px;
}

.tabs {
  display: grid;
  gap: 6px;
}

.tab {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(247, 249, 251, 0.74);
  text-align: left;
  padding: 0 12px;
  cursor: pointer;
}

.tab:hover,
.tab.is-active {
  background: rgba(255, 255, 255, 0.10);
  color: #ffffff;
}

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

.view {
  display: none;
}

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

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

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.muted,
.small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

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

.button,
.icon-button,
.drawer-close {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.button {
  padding: 0 12px;
}

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

.button-danger {
  border-color: #d9a19e;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 750;
}

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

.icon-button,
.drawer-close {
  width: 38px;
  font-size: 18px;
}

.button:hover,
.icon-button:hover,
.drawer-close:hover {
  border-color: var(--line-strong);
  box-shadow: 0 2px 10px rgba(32, 36, 42, 0.08);
}

.button:disabled,
.icon-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

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

.stat-card,
.task-summary-card {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.task-summary-card.task-overdue {
  background: var(--red-soft);
  border-color: #f0b8b5;
}

.task-summary-card.task-today {
  background: var(--amber-soft);
  border-color: #f0d08b;
}

.task-summary-card.task-planned {
  background: var(--blue-soft);
  border-color: #b8cafa;
}

.task-summary-card.task-done {
  background: var(--green-soft);
  border-color: #acd9c3;
}

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

.stat-value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 800;
}

.filters {
  display: grid;
  grid-template-columns: minmax(320px, 1.6fr) minmax(170px, 0.7fr) minmax(200px, 0.9fr);
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.tasks-toolbar {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(260px, 360px);
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.task-filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.task-filter {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 0 12px;
  cursor: pointer;
  font-weight: 750;
}

.task-filter:hover,
.task-filter.is-active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

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

.task-page-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) max-content;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
  box-shadow: 0 2px 9px rgba(23, 31, 42, 0.05);
}

.task-page-item.task-overdue {
  border-left: 4px solid var(--red);
}

.task-page-item.task-today {
  border-left: 4px solid #d59319;
}

.task-page-item.task-planned {
  border-left: 4px solid var(--blue);
}

.task-page-item.task-done {
  opacity: 0.72;
}

.task-page-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.task-page-title {
  font-size: 15px;
  font-weight: 800;
}

.task-page-side {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.link-button {
  width: fit-content;
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0;
  cursor: pointer;
  text-align: left;
  font-weight: 750;
}

.link-button:hover {
  text-decoration: underline;
}

.board-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: -2px 0 10px;
}

.board-nav-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

input,
select {
  min-height: 38px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  min-height: 78px;
  padding: 10px;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 2px solid var(--blue-soft);
  border-color: var(--blue);
}

.pipeline-board {
  display: grid;
  grid-auto-columns: 306px;
  grid-auto-flow: column;
  gap: 12px;
  min-height: calc(100vh - 238px);
  overflow-x: auto;
  padding-bottom: 12px;
}

.bulk-toolbar {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 6px 10px;
}

.bulk-select-all {
  display: flex;
  align-items: center;
  grid-template-columns: none;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.bulk-select-all input,
.card-select {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--blue);
}

.bulk-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.pipeline-column {
  display: flex;
  min-height: 560px;
  flex-direction: column;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 8px;
  background: #eef2f6;
}

.pipeline-column.is-drop-target {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px var(--blue-soft);
}

.column-violet {
  border-top-color: var(--violet);
}

.column-amber {
  border-top-color: #d59319;
}

.column-green,
.column-emerald {
  border-top-color: var(--green);
}

.column-cyan {
  border-top-color: var(--cyan);
}

.column-red {
  border-top-color: var(--red);
}

.column-gray {
  border-top-color: #828b98;
}

.column-header {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.column-header h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.25;
}

.column-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.delete-expired-leads {
  width: 100%;
  min-height: 32px;
  margin-top: 10px;
  font-size: 12px;
}

.column-body {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 10px;
}

.deal-card {
  display: grid;
  gap: 7px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
  box-shadow: 0 2px 9px rgba(23, 31, 42, 0.06);
  cursor: grab;
  overflow: hidden;
}

.deal-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 8px 20px rgba(23, 31, 42, 0.10);
}

.deal-card.is-dragging {
  opacity: 0.55;
}

.deal-card.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-soft), 0 8px 20px rgba(23, 31, 42, 0.10);
}

.card-select-wrap {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  cursor: pointer;
}

.drawer-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.deal-card h3 {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.32;
  min-height: 34px;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card-topline,
.card-footer,
.card-facts,
.drawer-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.card-topline {
  min-width: 0;
  flex-wrap: nowrap;
  justify-content: space-between;
}

.card-topline .badge {
  flex: 0 0 auto;
}

.card-date-row {
  display: flex;
  min-width: 0;
}

.card-keyline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
  align-items: center;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
}

.card-keyline span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-keyline strong {
  color: var(--text);
  font-size: 12px;
}

.card-customer {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-facts span,
.source-chip,
.date-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: #edf1f5;
  color: #4c5665;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-chip {
  flex: 0 1 auto;
}

.date-chip {
  background: #f6f8fb;
  color: #3f4855;
}

.date-fresh {
  background: var(--green-soft);
  color: var(--green);
}

.date-recent {
  background: var(--amber-soft);
  color: var(--amber);
}

.date-old {
  background: #eceff3;
  color: #596170;
}

.card-footer {
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

.task-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.task-overdue {
  background: var(--red-soft);
  color: var(--red);
}

.task-today {
  background: var(--amber-soft);
  color: var(--amber);
}

.task-planned {
  background: var(--blue-soft);
  color: var(--blue);
}

.task-empty {
  background: #edf1f5;
  color: var(--muted);
}

.drop-hint {
  display: grid;
  min-height: 86px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.badge-hot {
  background: var(--red-soft);
  color: var(--red);
}

.badge-warm {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-watch {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge-low {
  background: #eceff3;
  color: #596170;
}

.badge-active {
  background: var(--green-soft);
  color: var(--green);
}

.table-panel,
.settings-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

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

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

td {
  font-size: 13px;
}

.settings-panel {
  padding: 14px;
}

.add-stage-form {
  display: grid;
  grid-template-columns: minmax(280px, 420px) max-content;
  gap: 10px;
  align-items: end;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.stage-settings-list {
  display: grid;
  gap: 8px;
  padding-top: 14px;
}

.stage-setting-row {
  display: grid;
  grid-template-columns: 42px minmax(260px, 1fr) 130px max-content;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.stage-order {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 800;
}

.stage-count {
  color: var(--muted);
  font-size: 13px;
}

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

.deal-drawer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 540px);
  max-width: 100vw;
  opacity: 0;
  transition: opacity 160ms ease;
}

.deal-drawer.is-open {
  pointer-events: auto;
  opacity: 1;
}

.drawer-backdrop {
  background: rgba(17, 24, 32, 0.24);
}

.drawer-panel {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--panel);
  box-shadow: -18px 0 42px rgba(23, 31, 42, 0.18);
}

.drawer-close {
  position: sticky;
  top: 12px;
  left: calc(100% - 50px);
  z-index: 2;
  background: var(--panel);
}

.drawer-content {
  min-width: 0;
  padding: 0 18px 24px;
}

.drawer-header {
  display: grid;
  gap: 10px;
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.amo-status-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: end;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.quick-action {
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 11px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-action:hover {
  border-color: var(--line-strong);
  background: var(--blue-soft);
}

.drawer-tabs {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.drawer-tab {
  min-height: 42px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 750;
}

.drawer-tab:hover,
.drawer-tab.is-active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.drawer-tab-panel {
  display: none;
}

.drawer-tab-panel.is-active {
  display: block;
}

.drawer-section {
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}

.drawer-section:last-child {
  border-bottom: 0;
}

.drawer-section h3 {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 7px 10px;
  font-size: 13px;
}

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

.kv dd {
  margin: 0;
}

.stack {
  display: grid;
  gap: 8px;
}

.line-item,
.timeline-item,
.note-item {
  border-left: 3px solid var(--line);
  padding-left: 10px;
  font-size: 13px;
}

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

.task-form {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 9px;
}

.task-form .button {
  grid-column: 1 / -1;
}

.comment-form {
  display: grid;
  gap: 8px;
}

.task-item,
.comment-item,
.activity-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.task-item {
  grid-template-columns: 34px 1fr max-content;
  align-items: center;
}

.task-overdue {
  border-color: #f0b8b5;
}

.task-today {
  border-color: #f0d08b;
}

.task-marker {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  background: var(--panel);
  color: var(--blue);
  font-weight: 850;
}

.task-done-button {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--green);
  cursor: pointer;
  font-weight: 900;
}

.task-done-button:hover {
  border-color: var(--green);
  background: var(--green-soft);
}

.task-done-label {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.comment-item {
  background: #fffdf7;
}

.activity-item {
  grid-template-columns: 14px 1fr;
  border: 0;
  border-left: 2px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.activity-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--blue);
}

.activity-comment .activity-dot {
  background: var(--green);
}

.activity-task .activity-dot {
  background: var(--amber);
}

.activity-stage .activity-dot {
  background: var(--violet);
}

.empty-mini {
  display: grid;
  min-height: 72px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-shell,
  .filters,
  .stats,
  .task-summary,
  .tasks-toolbar,
  .task-page-item,
  .add-stage-form,
  .stage-setting-row,
  .amo-status-row,
  .task-form,
  .deal-drawer {
    grid-template-columns: 1fr;
  }

  .pipeline-board {
    grid-auto-columns: minmax(280px, 86vw);
  }

  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
