/* Leadgen Cabinet — светлая тема (Refactoring UI principles)
   Scale: 4/8/12/16/24/32/48/64
   Type:  12/14/16/20/24/30
   Cool grays с лёгким blue tint
*/

:root {
  /* Neutral (cool grays with blue tint) */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Accent (blue) */
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;

  /* Semantic */
  --green-50:  #ecfdf5;
  --green-600: #059669;
  --green-700: #047857;
  --amber-50:  #fffbeb;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --red-50:    #fef2f2;
  --red-600:   #dc2626;
  --red-700:   #b91c1c;
  --orange-50: #fff7ed;
  --orange-600:#ea580c;
  --orange-700:#c2410c;

  /* Surface */
  --bg:       var(--gray-50);
  --surface:  #ffffff;
  --border:   var(--gray-200);
  --border-strong: var(--gray-300);

  /* Text */
  --text:           var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted:     var(--gray-500);
  --text-faint:     var(--gray-400);

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-md: 0 1px 3px 0 rgb(0 0 0 / 0.06), 0 1px 2px -1px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.06);

  /* Radii */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ========== Layout ========== */

.wrap { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap-narrow { max-width: 640px; margin: 0 auto; padding: 24px 16px 64px; }

/* ===== Admin shell (sidebar + main) ===== */

body.admin { background: var(--gray-100); }
body.admin .wrap, body.admin .wrap-narrow { max-width: none; padding: 0; margin: 0; }

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand {
  font-size: 12px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 4px 12px 16px;
}
.sidebar a, .sidebar .nav-section {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--r-sm);
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  text-decoration: none; line-height: 1.3;
}
.sidebar a:hover { background: var(--gray-100); color: var(--text); text-decoration: none; }
.sidebar a.active {
  background: var(--blue-50); color: var(--blue-700); font-weight: 600;
}
.sidebar a .badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--red-600); color: #fff; border-radius: 999px;
  padding: 1px 7px; line-height: 1.5;
}
.sidebar .sep {
  height: 1px; background: var(--border); margin: 10px 12px;
}
.sidebar .nav-section {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
  padding-top: 12px; padding-bottom: 4px;
}

.main { padding: 20px 24px 48px; min-width: 0; }
.main > .top { margin-bottom: 16px; }

/* Компактный режим для админ-страниц */
body.admin h1 { font-size: 18px; }
body.admin h2 { font-size: 14px; margin: 14px 0 8px;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }
body.admin .top { margin-bottom: 14px; }
body.admin .top h1 { line-height: 1.2; }
body.admin .crumb { font-size: 12px; margin-bottom: 2px; }
body.admin .card { padding: 12px 14px; margin-bottom: 6px; }
body.admin .card-section { padding: 14px 16px; }

/* Статы — плоская узкая полоса */
body.admin .stats {
  grid-template-columns: repeat(4, auto);
  gap: 0; margin-bottom: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 8px 4px; box-shadow: var(--shadow-sm);
  justify-content: start;
}
body.admin .stat {
  padding: 4px 18px; border: 0; border-radius: 0; box-shadow: none;
  background: transparent; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: center;
}
body.admin .stat:last-child { border-right: 0; }
body.admin .stat .num { font-size: 18px; line-height: 1.1; }
body.admin .stat .lbl { font-size: 10px; margin-top: 2px; }

body.admin .tabs { margin-bottom: 10px; }
body.admin .tabs a { padding: 6px 12px; font-size: 13px; }

/* Лиды — плотнее */
body.admin .lead { padding: 10px 12px; margin-bottom: 6px; }
body.admin .lead-name { font-size: 15px; }
body.admin .lead-meta { font-size: 12px; }
body.admin .lead-body { padding: 6px 10px; margin-top: 8px; font-size: 13px; line-height: 1.5; }
body.admin .lead-actions { margin-top: 8px; gap: 6px; }
body.admin .lead-actions .btn { padding: 5px 10px; font-size: 12px; min-height: auto; }
body.admin .lead-sla { font-size: 11px; }
body.admin .tag { font-size: 10px; padding: 2px 7px; }

body.admin .thread-msg { padding: 6px 10px; }
body.admin .thread-msg-head { font-size: 10px; margin-bottom: 2px; }
body.admin .thread-msg-reason { font-size: 13px; margin: 0; }
body.admin .thread-msg-text { font-size: 13px; }

/* Пакеты-карточки */
body.admin .pkg { padding: 12px 14px; margin-bottom: 6px; }
body.admin .pkg-title { font-size: 15px; }
body.admin .pkg-period { font-size: 12px; }
body.admin .pkg-progress .big { font-size: 18px; }
body.admin .pkg-progress .big .sep { font-size: 14px; }
body.admin .pkg-progress .lbl { font-size: 10px; }
body.admin .pkg-metrics { margin-top: 8px; gap: 14px; font-size: 12px; }
body.admin .pkg-metrics .item .v { font-size: 13px; }
body.admin .pkg-metrics .item .k { font-size: 10px; }

/* Таблицы — плотнее */
body.admin th { padding: 6px 12px; font-size: 10px; }
body.admin td { padding: 6px 12px; font-size: 13px; }

/* Empty state — поменьше */
body.admin .empty { padding: 24px 16px; }
body.admin .empty h3 { font-size: 14px; }

/* На мобиле sidebar превращается в горизонтальную полосу сверху */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 10;
    height: auto; flex-direction: row; gap: 4px;
    padding: 8px 8px; border-right: 0; border-bottom: 1px solid var(--border);
    overflow-x: auto; overflow-y: hidden; white-space: nowrap;
    box-shadow: var(--shadow-sm);
  }
  .sidebar .brand { display: none; }
  .sidebar .sep, .sidebar .nav-section { display: none; }
  .sidebar a {
    padding: 6px 10px; font-size: 13px; white-space: nowrap; flex-shrink: 0;
  }
  .main { padding: 12px 12px 48px; }
}

.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
}
.top .crumb { color: var(--text-muted); font-size: 13px; margin-bottom: 4px; display: block; }
.top .crumb:hover { color: var(--text-secondary); }

/* ========== Typography ========== */

h1 { font-size: 24px; line-height: 1.25; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 18px; line-height: 1.3;  font-weight: 600; margin: 24px 0 12px; letter-spacing: -0.005em; }
h3 { font-size: 16px; line-height: 1.4;  font-weight: 600; margin: 0 0 6px; }

p  { margin: 0 0 12px; }
a  { color: var(--blue-600); text-decoration: none; }
a:hover { color: var(--blue-700); text-decoration: underline; }

.text-sm   { font-size: 14px; }
.text-xs   { font-size: 12px; }
.text-lg   { font-size: 18px; }
.text-xl   { font-size: 20px; }
.muted     { color: var(--text-secondary); }
.faint     { color: var(--text-muted); }
.mono      { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
}

/* ========== Surfaces ========== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  margin: 0 0 12px;
  box-shadow: var(--shadow-sm);
}
.card-interactive { cursor: pointer; transition: box-shadow .12s, border-color .12s, transform .12s; }
.card-interactive:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card-interactive:active { transform: translateY(1px); }

.card-section { padding: 24px; }

/* ========== Buttons ========== */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 9px 16px; border-radius: var(--r-md);
  background: var(--blue-600); color: #fff; border: 1px solid var(--blue-600);
  font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; line-height: 1.2;
  box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, box-shadow .12s, transform .06s;
}
.btn:hover { background: var(--blue-700); border-color: var(--blue-700); color:#fff; text-decoration: none; }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.secondary {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn.secondary:hover { background: var(--gray-50); border-color: var(--gray-400); color: var(--text); }

.btn.ghost {
  background: transparent; color: var(--text-secondary); border-color: transparent;
  box-shadow: none;
}
.btn.ghost:hover { background: var(--gray-100); color: var(--text); }

.btn.danger {
  background: var(--red-600); border-color: var(--red-600); color: #fff;
}
.btn.danger:hover { background: var(--red-700); border-color: var(--red-700); }

.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.lg { padding: 12px 20px; font-size: 15px; }
.btn.block { width: 100%; }

/* ========== Forms ========== */

input, select, textarea {
  width: 100%; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  color: var(--text); font: inherit; font-size: 15px;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.15);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

label.field {
  display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-secondary);
  margin: 16px 0 6px;
}
label.field:first-child { margin-top: 0; }

.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; }

.field-help {
  font-size: 12px; color: var(--text-muted); margin-top: 4px;
}

/* ========== Tables ========== */

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; vertical-align: middle; }
th {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted);
  background: var(--gray-50); border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--gray-50); }

/* ========== Tags / Status badges ========== */

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.02em; line-height: 1.4; border: 1px solid transparent;
  white-space: nowrap;
}
.tag::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  flex-shrink: 0;
}

.tag.pending  { background: var(--amber-50);  color: var(--amber-700);  border-color: #fde68a; }
.tag.disputed { background: var(--orange-50); color: var(--orange-700); border-color: #fed7aa; }
.tag.accepted, .tag.auto_accepted { background: var(--green-50); color: var(--green-700); border-color: #a7f3d0; }
.tag.rejected { background: var(--red-50); color: var(--red-700); border-color: #fecaca; }
.tag.active   { background: var(--green-50); color: var(--green-700); border-color: #a7f3d0; }
.tag.closed   { background: var(--gray-100); color: var(--text-muted); border-color: var(--border); }

/* ========== Stats grid ========== */

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin: 0 0 24px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 16px; box-shadow: var(--shadow-sm);
}
.stat .num { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; color: var(--text); }
.stat .num.accent { color: var(--blue-600); }
.stat .num.success { color: var(--green-700); }
.stat .num.danger  { color: var(--red-700); }
.stat .lbl {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted); margin-top: 8px;
}

/* ========== Tabs ========== */

.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  margin: 0 0 16px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 10px 16px; color: var(--text-muted); font-size: 14px; font-weight: 500;
  border-bottom: 2px solid transparent; white-space: nowrap; line-height: 1.4;
  text-decoration: none;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--blue-700); border-bottom-color: var(--blue-600); font-weight: 600; }
.tabs .grow { margin-left: auto; }

/* ========== Notice ========== */

.notice {
  padding: 12px 16px; border-radius: var(--r-md); margin: 0 0 12px;
  font-size: 14px; line-height: 1.5; border: 1px solid;
}
.notice.error { background: var(--red-50);   color: var(--red-700);   border-color: #fecaca; }
.notice.ok    { background: var(--green-50); color: var(--green-700); border-color: #a7f3d0; }
.notice.info  { background: var(--blue-50);  color: var(--blue-700);  border-color: #bfdbfe; }

/* ========== Dialog ========== */

.dialog-bg {
  position: fixed; inset: 0; background: rgb(17 24 39 / 0.4);
  display: none; align-items: center; justify-content: center; z-index: 100;
  padding: 16px; backdrop-filter: blur(2px);
}
.dialog-bg.open { display: flex; }
.dialog {
  background: var(--surface); border-radius: var(--r-lg);
  padding: 24px; max-width: 520px; width: 100%;
  max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-xl);
}
.dialog h2 { margin-top: 0; }

/* ========== Lead card (специализированный компонент) ========== */

.lead {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 16px; margin: 0 0 10px; box-shadow: var(--shadow-sm);
}
.lead-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.lead-name { font-size: 17px; font-weight: 600; color: var(--text); letter-spacing: -0.005em; }
.lead-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.lead-phone { color: var(--blue-600); font-variant-numeric: tabular-nums; }
.lead-body {
  margin-top: 12px; padding: 12px 14px; background: var(--gray-50);
  border-radius: var(--r-sm); font-size: 15px; line-height: 1.6;
  white-space: pre-wrap; color: var(--gray-800);
}
.lead-actions { margin-top: 14px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.lead-sla { font-size: 12px; color: var(--text-muted); }
.lead-sla.urgent { color: var(--amber-700); font-weight: 500; }

/* Переписка по спору */
.thread { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.thread-msg {
  border-left: 3px solid var(--border);
  padding: 8px 12px; background: var(--gray-50); border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.thread-msg.from-client { border-left-color: var(--orange-600); }
.thread-msg.from-arthur { border-left-color: var(--blue-500); background: var(--blue-50); }
.thread-msg-head { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.thread-msg-reason { font-weight: 600; font-size: 14px; margin: 2px 0; }
.thread-msg-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; color: var(--gray-800); }
.thread-msg-attach { margin-top: 6px; font-size: 13px; }

/* ========== Package card ========== */

.pkg {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 20px; margin: 0 0 12px; cursor: pointer; text-decoration: none; color: var(--text);
  display: block; box-shadow: var(--shadow-sm);
  transition: box-shadow .12s, border-color .12s, transform .12s;
}
.pkg:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); text-decoration: none; color: var(--text); }
.pkg:active { transform: translateY(1px); }
.pkg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.pkg-title { font-size: 18px; font-weight: 600; letter-spacing: -0.005em; }
.pkg-period { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.pkg-progress {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.pkg-progress .big { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.pkg-progress .big .sep { color: var(--text-faint); font-weight: 400; font-size: 18px; }
.pkg-progress .lbl { font-size: 11px; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }

.pkg-metrics { display: flex; gap: 20px; margin-top: 16px; flex-wrap: wrap; font-size: 13px; }
.pkg-metrics .item { display: flex; flex-direction: column; }
.pkg-metrics .item .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pkg-metrics .item .v.green  { color: var(--green-700); }
.pkg-metrics .item .v.amber  { color: var(--amber-700); }
.pkg-metrics .item .v.orange { color: var(--orange-700); }
.pkg-metrics .item .v.red    { color: var(--red-700); }
.pkg-metrics .item .k { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; font-weight: 600; }

/* ========== Свёрнутый раздел (закрытые пакеты) ========== */

details.collapsed {
  margin: 16px 0 0;
}
details.collapsed > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
}
details.collapsed > summary::-webkit-details-marker { display: none; }
details.collapsed > summary::before {
  content: "›";
  display: inline-block;
  font-size: 16px;
  transition: transform .15s;
  color: var(--text-faint);
  width: 12px;
}
details.collapsed[open] > summary::before { transform: rotate(90deg); }
details.collapsed > summary .line {
  flex: 1; height: 1px; background: var(--border);
}
details.collapsed > summary:hover { color: var(--text); }

/* ========== Empty state ========== */

.empty {
  text-align: center; padding: 48px 24px; background: var(--surface);
  border: 1px dashed var(--border-strong); border-radius: var(--r-md);
  color: var(--text-muted);
}
.empty .icon { font-size: 32px; margin-bottom: 12px; }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ========== Login ========== */

.login-wrap {
  max-width: 380px; margin: 80px auto 0; padding: 0 16px;
}
.login-brand {
  text-align: center; color: var(--text-muted);
  font-size: 12px; font-weight: 600; letter-spacing: 0.16em;
  text-transform: uppercase; margin-bottom: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 32px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { text-align: center; margin: 0 0 24px; font-size: 22px; }

/* ========== Responsive ========== */

@media (max-width: 640px) {
  body { font-size: 15px; }
  .wrap { padding: 16px 12px 64px; }
  h1 { font-size: 20px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px; }
  .stat .num { font-size: 22px; }
  .field-row { flex-direction: column; gap: 0; }
  .pkg { padding: 16px; }
  .pkg-title { font-size: 16px; }
  .pkg-progress .big { font-size: 20px; }
  .pkg-metrics { gap: 14px; }
  th, td { padding: 8px 10px; font-size: 13px; }
  .login-wrap { margin-top: 32px; }
  .login-card { padding: 24px 20px; }
}

/* tap-friendly targets on mobile */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn.sm { min-height: 36px; }
}
