:root {
  --accent: #0d5ea6;
  --accent-soft: #e7f0f9;
  --bg: #f3f5f8;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --ok: #16a34a;
  --sidebar: #0f1b2d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0b4f8c; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fef2f2; border-color: #fecaca; }
.btn:disabled { opacity: .6; cursor: default; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=tel],
select, textarea {
  width: 100%; height: 36px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; font-weight: 600; color: #334155; }
.field small { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.form-actions .spacer { flex: 1; }
.hint { font-size: 13px; padding: 8px 10px; border-radius: 8px; }
.hint.info { background: var(--accent-soft); color: #0b4f8c; }
.hint:empty { display: none; }
.req { color: var(--danger); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; padding: 28px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }
.login-card .btn { width: 100%; justify-content: center; height: 40px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; padding: 18px 12px;
  background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 18px; font-weight: 700; color: #fff; padding: 0 10px; }
.brand b { color: #5fb0f5; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block; padding: 9px 12px; border-radius: 8px;
  color: #cbd5e1; text-decoration: none;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .1); }
.me-name { color: #fff; font-weight: 600; }
.me-role { font-size: 12px; color: #94a3b8; margin-bottom: 8px; }
.me button {
  display: block; padding: 4px 0; border: 0; background: none;
  color: #94a3b8; cursor: pointer;
}
.me button:hover { color: #fff; }

main { flex: 1; min-width: 0; padding: 24px 28px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 12px; margin-bottom: 16px;
}
.page-head h1 { font-size: 22px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-head input[type=search] { width: 260px; }
.page-head select { width: auto; min-width: 160px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #f8fafc; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafc; }
td.wrap { white-space: normal; min-width: 160px; }
.t-name { font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #f1f5f9; color: #475569;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.off { background: #fef2f2; color: var(--danger); }

/* ---------- Kanban ---------- */
.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(280px, 1fr);
  gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: start;
}
.column { background: #e9edf2; border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 130px); }
.col-head { padding: 12px 12px 8px; }
.col-title { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.col-title .dot { width: 10px; height: 10px; border-radius: 50%; }
.col-title .count { margin-left: auto; font-weight: 600; color: var(--muted); font-size: 13px; }
.col-sum { font-size: 12px; color: var(--muted); margin-top: 2px; padding-left: 18px; }
.col-body { padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 80px; flex: 1; }
.col-body.over { background: rgba(13, 94, 166, .06); border-radius: 0 0 var(--radius) var(--radius); }
.lead-card {
  background: #fff; border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow);
  cursor: grab; border-left: 3px solid transparent;
}
.lead-card:hover { box-shadow: 0 2px 6px rgba(15, 23, 42, .12); }
.lead-card.dragging { opacity: .4; }
.lc-product { font-weight: 600; margin-bottom: 2px; overflow-wrap: anywhere; }
.lc-customer { font-size: 13px; color: #334155; }
.lc-customer .phone { color: var(--muted); }
.lc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--muted); }
.lc-foot .amount { color: var(--text); font-weight: 600; }
.avatar {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700;
}
.drop-marker { height: 3px; border-radius: 2px; background: var(--accent); margin: -2px 0; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; overflow-y: auto;
}
.modal { width: 100%; max-width: 520px; background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 18px 20px 20px; }
.icon-btn { border: 0; background: none; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.icon-btn:hover { color: var(--text); }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.split h4 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; justify-content: space-between; }
.lead-list { display: flex; flex-direction: column; gap: 8px; }
.lead-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.lead-row:hover { border-color: #cbd5e1; background: #f8fafc; }
.lead-row .top { display: flex; justify-content: space-between; gap: 8px; }
.meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.customer-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 100; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 10px; color: #fff; background: #0f172a;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2); animation: toast-in .2s ease-out;
}
.toast.ok { background: #166534; }
.toast.err { background: #b91c1c; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

.import-result { margin-top: 8px; font-size: 13px; }
.import-result ul { margin: 6px 0 0; padding-left: 18px; max-height: 160px; overflow: auto; color: var(--danger); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: auto; height: auto; position: static; flex-direction: row; align-items: center;
    flex-wrap: wrap; gap: 8px 14px; padding: 10px 16px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { padding: 6px 10px; }
  .me { margin: 0 0 0 auto; padding: 0; border: 0; display: flex; gap: 10px; align-items: center; }
  .me-name, .me-role { display: none; }
  main { padding: 16px; }
  .page-head input[type=search] { width: 100%; }
  .page-head .actions { width: 100%; }
  .split, .grid-2 { grid-template-columns: 1fr; }
  .column { max-height: none; }
  .board { grid-auto-columns: minmax(260px, 85vw); }
}
