/* RedMint CRM — светлая тема, плотный рабочий интерфейс */

:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #fafbfa;
  --line: #e0e4e2;
  --line-strong: #c9d0cc;
  --ink: #14181a;
  --ink-2: #5c6a64;
  --ink-3: #8a9791;
  --accent: #0f8a63;
  --accent-ink: #0a6d4e;
  --accent-wash: #e8f5ef;
  --won: #0f8a63;
  --lost: #b3261e;
  --warn: #a8600a;
  --warn-wash: #fdf3e4;
  --focus: #0f8a63;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-1: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  --shadow-2: 0 2px 4px rgba(20, 30, 25, .08), 0 8px 24px rgba(20, 30, 25, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-wash); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid var(--bg);
  border-radius: 6px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

a { color: var(--accent-ink); text-decoration-color: rgba(15, 138, 99, .35); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--accent); }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; text-wrap: balance; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ——— Каркас ——— */

.app { display: grid; grid-template-columns: 208px 1fr; min-height: 100vh; }

.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo {
  font-size: 17px; font-weight: 600; letter-spacing: -0.02em;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line);
}
.logo span { color: var(--accent); }

.nav { padding: 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); }
.nav svg { width: 16px; height: 16px; flex: none; stroke-width: 1.7; }

.me {
  border-top: 1px solid var(--line); padding: 12px;
  display: flex; align-items: center; gap: 10px;
}
.me .avatar { width: 30px; height: 30px; }
.me-name { font-weight: 500; font-size: 13px; line-height: 1.3; }
.me-role { color: var(--ink-3); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar .grow { flex: 1; }

.content { padding: 20px; flex: 1; min-width: 0; }

/* ——— Элементы ——— */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 500; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; stroke-width: 1.8; }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }

.btn-danger { color: var(--lost); border-color: transparent; background: transparent; }
.btn-danger:hover { background: #fdeceb; border-color: #f3c9c6; }

.btn-sm { padding: 4px 9px; font-size: 13px; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg a {
  padding: 6px 12px; text-decoration: none; color: var(--ink-2);
  font-weight: 500; background: var(--surface);
}
.seg a + a { border-left: 1px solid var(--line); }
.seg a:hover { background: var(--surface-2); color: var(--ink); }
.seg a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=date], input[type=number], input[type=search], input[type=datetime-local],
select, textarea {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit;
  caret-color: var(--accent);
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-3); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 138, 99, .14);
}
::placeholder { color: var(--ink-3); }
textarea { min-height: 76px; resize: vertical; line-height: 1.55; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 8l3-3.5' fill='none' stroke='%235c6a64' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

label { display: block; font-weight: 500; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }

.field { margin-bottom: 14px; }
.row { display: grid; gap: 14px; }
.row > .field { min-width: 0; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: 1fr 1fr 1fr; }

.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check label { margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
}
.card-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.card-body { padding: 16px; }

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

/* ——— Таблица ——— */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 500; font-size: 12px; letter-spacing: .02em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }

/* ——— Канбан ——— */

.board { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 8px; }

.column {
  flex: 0 0 272px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 150px);
}
.column-head {
  padding: 11px 13px; border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 8px;
}
.column-head .name { font-weight: 600; font-size: 13px; }
.column-head .count {
  font-size: 12px; color: var(--ink-3); background: var(--surface-2);
  padding: 1px 6px; border-radius: 10px;
}
.column-head .sum { margin-left: auto; font-size: 12px; color: var(--ink-2); }
.column[data-kind="won"] .name { color: var(--won); }
.column[data-kind="lost"] .name { color: var(--lost); }

.column-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 80px; }
.column-body.over { background: var(--accent-wash); }

.deal-card {
  display: block; padding: 10px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: inherit; cursor: grab;
  box-shadow: var(--shadow-1);
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s cubic-bezier(.2,.8,.3,1);
}
.deal-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.deal-card.dragging { opacity: .45; cursor: grabbing; }
.deal-card .who { font-weight: 600; margin-bottom: 3px; }
.deal-card .meta { color: var(--ink-3); font-size: 12px; line-height: 1.45; }
.deal-card .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.deal-card .amount { font-weight: 600; color: var(--accent-ink); margin-top: 6px; }

/* ——— Мелочи ——— */

.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: var(--accent-wash); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px; flex: none; border: 1px solid var(--line);
}

.tag {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2); white-space: nowrap;
}
.tag-accent { background: var(--accent-wash); border-color: transparent; color: var(--accent-ink); }
.tag-warn { background: var(--warn-wash); border-color: transparent; color: var(--warn); }
.tag-lost { background: #fdeceb; border-color: transparent; color: var(--lost); }

.muted { color: var(--ink-3); }
.small { font-size: 13px; }

.flash {
  padding: 9px 14px; border-radius: var(--radius-sm); margin-bottom: 16px;
  background: var(--accent-wash); color: var(--accent-ink); font-weight: 500;
}

.empty { padding: 48px 24px; text-align: center; color: var(--ink-2); }
.empty h2 { margin-bottom: 6px; color: var(--ink); }

.feed { display: flex; flex-direction: column; gap: 0; }
.feed-item { padding: 11px 0; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: none; }
.feed-meta { color: var(--ink-3); font-size: 12px; margin-bottom: 3px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; }

.task-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: none; }
.task-row.overdue .due { color: var(--lost); font-weight: 500; }
.task-row.done .title { color: var(--ink-3); text-decoration: line-through; }

/* ——— Вход ——— */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 368px; }
.auth-logo { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-bottom: 4px; }
.auth-logo span { color: var(--accent); }
.auth-sub { color: var(--ink-2); margin: 0 0 22px; }
.auth-error {
  background: #fdeceb; color: var(--lost); padding: 9px 12px;
  border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px;
}

@media (max-width: 900px) {
  /* Одна колонка: шапка по содержимому, остальное — контенту.
     Без grid-template-rows строки делят высоту поровну и шапка растягивается. */
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side {
    position: sticky; top: 0; z-index: 30;
    height: auto; min-height: 0;
    flex-direction: row; align-items: center; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .logo { border-bottom: none; border-right: 1px solid var(--line); white-space: nowrap; }
  .nav { flex-direction: row; flex: 1; }
  .nav a span { display: none; }
  .me { border-top: none; border-left: 1px solid var(--line); margin-left: auto; }
  .me-name, .me-role { display: none; }
  .logo { padding: 12px 14px; }
  .nav { padding: 8px; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 12px 14px; top: 55px; }
  .topbar h1 { font-size: 18px; }
  .content { padding: 14px; }
  .column { flex-basis: 84vw; max-height: none; }
  .filters .field { min-width: 0; flex: 1 1 140px; }
  .grid-2 { grid-template-columns: 1fr; }
  .row-2, .row-3 { grid-template-columns: 1fr; }
}

/* ——— Цвет этапа, правка названия, палитра ——— */

.column { position: relative; overflow: hidden; }
.column::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--stage-color, var(--ink-3));
}
.column-head { padding-top: 13px; }

.column-head[draggable="true"] { cursor: grab; }
.column-head[draggable="true"]:active { cursor: grabbing; }
.column.col-dragging { opacity: .5; }
.column.col-target { outline: 2px dashed var(--accent); outline-offset: -2px; }

.column-head .name {
  border-radius: 4px; padding: 1px 4px; margin-left: -4px;
  transition: background .12s ease;
}
.column-head .name[contenteditable]:hover { background: var(--surface-2); }
.column-head .name[contenteditable]:focus {
  outline: none; background: var(--surface-2);
  box-shadow: 0 0 0 2px rgba(15, 138, 99, .35);
}
.column-head .name.saved { background: var(--accent-wash); }

.swatch-btn {
  width: 14px; height: 14px; border-radius: 50%; padding: 0; flex: none;
  border: 1px solid rgba(0, 0, 0, .12); background: var(--stage-color, var(--ink-3));
  cursor: pointer; opacity: 0; transition: opacity .12s ease, transform .12s ease;
}
.column:hover .swatch-btn, .swatch-btn:focus-visible { opacity: 1; }
.swatch-btn:hover { transform: scale(1.15); }

.palette {
  position: absolute; z-index: 50; display: flex; gap: 6px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-2);
}
/* display:flex перебивает атрибут hidden, поэтому скрываем явно */
.palette[hidden] { display: none; }
.swatch {
  width: 20px; height: 20px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 1px solid rgba(0, 0, 0, .12);
  transition: transform .1s ease;
}
.swatch:hover { transform: scale(1.15); }
.swatch-reset {
  background: var(--surface);
  background-image: linear-gradient(45deg, transparent 44%, var(--lost) 44%, var(--lost) 56%, transparent 56%);
}

.dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  border: 1px solid rgba(0, 0, 0, .12);
}
