:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1b1f29;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 15px; }

.screen { min-height: 100vh; }

/* ---------- Login ---------- */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1d4ed8, #0f172a);
}
.login-box {
  background: var(--surface);
  padding: 32px 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
.login-box h1 { font-size: 19px; margin: 0 0 8px; text-align: center; }
.login-box input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
}
.login-box .error { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-weight: 600; font-size: 16px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.current-user { font-size: 13px; color: var(--text-muted); }

.btn-primary, .btn-ghost {
  border: none; border-radius: 8px; padding: 8px 14px; font-size: 14px; font-weight: 500;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }

/* ---------- Tab navigation ---------- */
.tabbar {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky; top: 49px; z-index: 9;
}
.tab-btn {
  border: none; background: transparent; color: var(--text-muted);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 500;
  white-space: nowrap;
}
.tab-btn.active { background: #e0e7ff; color: var(--primary-dark); }
.tab-btn:hover { background: var(--bg); }

.view { padding: 14px; }

/* ---------- Dashboard ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.stat-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px;
}
.stat-tile .stat-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-tile .stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-tile.warn .stat-value { color: #b45309; }
.stat-tile.danger .stat-value { color: var(--danger); }
.stat-tile.good .stat-value { color: #15803d; }

.dash-section { margin-bottom: 20px; }
.dash-section h3 {
  font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em;
  margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center;
}
.dash-list { display: flex; flex-direction: column; gap: 6px; }
.dash-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; font-size: 14px;
}
.dash-item:hover { box-shadow: var(--shadow); }
.dash-item .dash-item-main { display: flex; flex-direction: column; gap: 2px; }
.dash-item .dash-item-sub { font-size: 12px; color: var(--text-muted); }
.dash-item.overdue { border-color: #fecaca; background: #fef2f2; }
.dash-empty { color: var(--text-muted); font-size: 13px; padding: 10px 0; }

/* ---------- Tasks view ---------- */
.task-group { margin-bottom: 18px; }
.task-group h3 {
  font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; margin: 0 0 8px;
}
.task-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; margin-bottom: 6px;
}
.task-row.overdue { border-color: #fecaca; background: #fef2f2; }
.task-row .task-title { font-size: 14px; flex: 1; cursor: pointer; }
.task-row .task-sub { font-size: 12px; color: var(--text-muted); }

/* ---------- Analytics ---------- */
.funnel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.funnel-label { width: 140px; font-size: 13px; flex-shrink: 0; }
.funnel-bar-track { flex: 1; background: var(--bg); border-radius: 6px; height: 20px; overflow: hidden; }
.funnel-bar-fill { background: var(--primary); height: 100%; border-radius: 6px; }
.funnel-count { width: 36px; text-align: right; font-size: 13px; font-weight: 600; flex-shrink: 0; }

/* ---------- Avito reply box ---------- */
.reply-box { display: flex; gap: 6px; margin-top: 8px; }
.reply-box textarea { flex: 1; min-height: 44px; resize: vertical; }

/* ---------- Board toolbar / search ---------- */
.board-toolbar { padding: 10px 14px 0; }
#board-search {
  width: 100%; max-width: 320px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}

/* ---------- Small confirm modal ---------- */
.modal-small { max-width: 360px; }
.modal-small h3 { margin: 0 0 6px; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- Activity log ---------- */
.activity-item { font-size: 12px; color: var(--text-muted); padding: 4px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.call-btn { font-size: 12px; padding: 4px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); margin-left: 6px; }
.phone-link { color: var(--primary); text-decoration: none; }

/* ---------- Board ---------- */
.board {
  display: flex;
  gap: 12px;
  padding: 14px;
  overflow-x: auto;
  height: calc(100vh - 102px);
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.column {
  background: var(--surface);
  border-radius: var(--radius);
  min-width: 260px;
  max-width: 280px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  scroll-snap-align: start;
  border: 1px solid var(--border);
  max-height: 100%;
}
.column-header {
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
}
.column-count {
  background: var(--bg); color: var(--text-muted); font-size: 12px;
  padding: 1px 7px; border-radius: 10px;
}
.column-body {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  display: flex; flex-direction: column; gap: 8px;
}
.column.drop-hover { outline: 2px dashed var(--primary); outline-offset: -2px; }

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.card:hover { box-shadow: var(--shadow); }
.card.dragging { opacity: .4; }
.card-name { font-weight: 600; font-size: 14px; margin-bottom: 3px; }
.card-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.card-badge {
  display: inline-block; font-size: 11px; background: #e0e7ff; color: #3730a3;
  padding: 1px 6px; border-radius: 6px; margin-top: 4px;
}
.card-footer {
  display: flex; justify-content: space-between; align-items: center; margin-top: 6px;
}
.card-move-select { font-size: 11px; border: 1px solid var(--border); border-radius: 6px; padding: 2px 4px; background: #fff; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 24px 12px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 560px; padding: 22px; position: relative;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute; top: 12px; right: 14px; border: none; background: none;
  font-size: 22px; line-height: 1; color: var(--text-muted);
}

.form { display: flex; flex-direction: column; gap: 10px; }
.form h2 { margin: 0 0 6px; font-size: 17px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.form input, .form select, .form textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 14px; color: var(--text);
}

.detail-section { margin-top: 16px; }
.detail-section h3 { font-size: 13px; color: var(--text-muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: .03em; }
.field-row { display: flex; gap: 10px; margin-bottom: 8px; }
.field-row label { flex: 1; display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-muted); }
.field-row input, .field-row select { padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; font-size: 14px; }

.note-item, .msg-item, .task-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px;
}
.note-meta, .msg-meta { color: var(--text-muted); font-size: 11px; margin-bottom: 3px; }
.msg-item.out { background: #eef2ff; margin-left: 20px; }
.msg-item.in { background: var(--bg); margin-right: 20px; }
.task-item.done { opacity: .5; text-decoration: line-through; }
.task-item { display: flex; align-items: center; gap: 8px; }

.add-note-form { display: flex; gap: 6px; margin-top: 8px; }
.add-note-form textarea { flex: 1; min-height: 40px; resize: vertical; }
.add-note-form button, .add-task-form button { align-self: flex-end; }
.add-task-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.add-task-form input[type=text] { flex: 1; min-width: 120px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px;
  opacity: 0; transition: all .25s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
  .topbar-title { font-size: 14px; }
  .column { min-width: 85vw; }
  .modal { padding: 16px; }
  .field-row { flex-direction: column; }
}
