:root {
  --bg: #141b30;
  --bg-2: #182140;
  --panel: rgba(255,255,255,0.05);
  --panel-border: rgba(255,255,255,0.1);
  --panel-2: rgba(255,255,255,0.07);
  --text: #e8ecf7;
  --text-dim: #8892a8;
  --text-dimmer: #5c6480;
  --accent: #5b8cff;
  --accent-2: #7ea8ff;
  --accent-glow: rgba(91,140,255,0.35);
  --green: #3ddc97;
  --yellow: #ffc857;
  --red: #ff6b6b;
  --radius: 16px;
  --radius-sm: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: radial-gradient(1200px 800px at 15% 0%, #23305c 0%, var(--bg) 45%, #0f1526 100%);
  color: var(--text);
  min-height: 100vh;
}

body {
  font-size: 14px;
}

a { color: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- Login ---------- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 32px;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-logo {
  width: 44px; height: 44px; border-radius: 12px;
  object-fit: cover; margin-bottom: 18px;
  box-shadow: 0 8px 24px var(--accent-glow);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--text-dim); margin: 0 0 24px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; margin-top: 14px; }
.login-card input { width: 100%; }
.login-card button.primary { width: 100%; margin-top: 22px; }
.login-error { color: var(--red); font-size: 12.5px; margin-top: 12px; min-height: 16px; }
.login-hint { color: var(--text-dimmer); font-size: 11.5px; margin-top: 18px; text-align: center; }

button.primary {
  background: linear-gradient(135deg, var(--accent), #7a63ff);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: 0 8px 20px var(--accent-glow);
}
button.secondary {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13px;
}
button.ghost {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 6px 8px;
}
button.danger { color: var(--red); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- App shell ---------- */
#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: rgba(20,27,48,0.55);
  border-right: 1px solid var(--panel-border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 22px;
}
.brand .mark {
  width: 32px; height: 32px; border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 6px 18px var(--accent-glow);
}
.brand .name { font-weight: 700; font-size: 14.5px; }
.brand .sub { font-size: 10.5px; color: var(--text-dimmer); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
}
.nav-item .ico { width: 16px; text-align: center; opacity: 0.85; }
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(91,140,255,0.18), rgba(122,99,255,0.10));
  color: var(--text);
  border-color: rgba(91,140,255,0.35);
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--panel-border);
}
.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px 4px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #5b8cff, #7a63ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700;
}
.user-chip .who { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip .who .n { font-size: 12.5px; font-weight: 600; }
.user-chip .who .r { font-size: 10.5px; color: var(--text-dimmer); }
.logout-btn { margin-top: 8px; width: 100%; text-align: left; font-size: 12px; }

.main {
  padding: 24px 28px 60px;
  overflow-x: hidden;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
}
.topbar h1 { font-size: 21px; margin: 0; }
.topbar .breadcrumb { color: var(--text-dimmer); font-size: 12px; margin-top: 3px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.card.tight { padding: 14px 16px; }

.stat-card .label { font-size: 12px; color: var(--text-dim); display: flex; justify-content: space-between; align-items: center; }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 8px; }
.stat-card .delta { font-size: 11.5px; margin-top: 6px; }
.stat-card .delta.up { color: var(--green); }
.stat-card .delta.down { color: var(--red); }

.card h3 { font-size: 14px; margin: 0 0 14px; font-weight: 600; }
.card .card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card .card-head h3 { margin: 0; }

.section { margin-bottom: 20px; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  text-align: left; color: var(--text-dimmer); font-weight: 500;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 8px 10px; border-bottom: 1px solid var(--panel-border);
}
tbody td { padding: 11px 10px; border-bottom: 1px solid rgba(255,255,255,0.04); }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody tr { cursor: pointer; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 100px;
  font-size: 11px; font-weight: 600;
}
.badge.lead { background: rgba(255,200,87,0.15); color: var(--yellow); }
.badge.contacted { background: rgba(91,140,255,0.15); color: var(--accent-2); }
.badge.negotiation { background: rgba(122,99,255,0.15); color: #b09bff; }
.badge.enrolled { background: rgba(61,220,151,0.15); color: var(--green); }
.badge.training { background: rgba(61,220,151,0.15); color: var(--green); }
.badge.exam { background: rgba(255,140,87,0.15); color: #ff9d5c; }
.badge.finished { background: rgba(255,255,255,0.1); color: var(--text-dim); }
.badge.lost { background: rgba(255,107,107,0.15); color: var(--red); }
.badge.pending { background: rgba(255,200,87,0.15); color: var(--yellow); }
.badge.passed { background: rgba(61,220,151,0.15); color: var(--green); }
.badge.failed { background: rgba(255,107,107,0.15); color: var(--red); }

/* ---------- Pipeline board ---------- */
.pipeline {
  display: grid; grid-auto-flow: column; grid-auto-columns: 250px; gap: 14px;
  overflow-x: auto; overflow-y: hidden; padding-bottom: 12px;
  max-height: calc(100vh - 300px); min-height: 320px;
}
.pipeline-col {
  background: rgba(255,255,255,0.02); border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 12px; min-height: 200px; transition: background 0.15s, border-color 0.15s;
  display: flex; flex-direction: column; max-height: 100%;
}
.pipeline-col.drag-over { background: rgba(91,140,255,0.08); border-color: var(--accent); }
.pipeline-col .col-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 10px; flex-shrink: 0; }
.pipeline-col-body { min-height: 40px; overflow-y: auto; flex: 1; padding-right: 4px; }
.pipeline-card {
  background: linear-gradient(150deg, rgba(91,140,255,0.16) 0%, rgba(122,99,255,0.07) 55%, rgba(255,255,255,0.02) 100%);
  border: 1px solid rgba(91,140,255,0.28); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 8px; font-size: 12.5px; cursor: grab;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
}
.pipeline-card:hover { box-shadow: 0 4px 16px rgba(91,140,255,0.18); transform: translateY(-1px); }
.pipeline-card.dragging { opacity: 0.4; cursor: grabbing; }
.pipeline-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.pipeline-card .name { font-weight: 600; margin-bottom: 3px; }
.pipeline-card .meta { color: var(--text-dimmer); font-size: 11px; }
.avatar-circle {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #7a63ff);
  color: white; font-size: 9.5px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.mini-pill-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.mini-pill { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 100px; border: 1px solid; white-space: nowrap; }
.mini-check { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 600; color: var(--text-dim); cursor: pointer; }
.mini-check input[type=checkbox] { width: 13px; height: 13px; accent-color: var(--green); cursor: pointer; }

/* ---------- InfoCar result box ---------- */
.infocar-result {
  margin-top: 10px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: linear-gradient(150deg, rgba(91,140,255,0.16) 0%, rgba(122,99,255,0.07) 55%, rgba(255,255,255,0.02) 100%);
  border: 1px solid rgba(91,140,255,0.28);
  transition: background 0.15s, border-color 0.15s;
}
.infocar-result .t2 { color: var(--text-dimmer); font-size: 11px; margin-bottom: 3px; }
.infocar-result .t1 { font-weight: 600; font-size: 13px; }
.infocar-result.empty { background: var(--panel-2); border-color: var(--panel-border); }
.infocar-result.empty .t1 { color: var(--text-dimmer); font-weight: 500; }
.infocar-result.error { background: rgba(255,107,107,0.12); border-color: rgba(255,107,107,0.4); }
.infocar-result.error .t1 { color: var(--red); }

/* ---------- progress bar ---------- */
.progress-track { height: 6px; border-radius: 4px; background: rgba(255,255,255,0.08); overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #8a5bff); border-radius: 4px; }

/* ---------- list rows (tasks / activity) ---------- */
.list-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid rgba(255,255,255,0.04); font-size: 12.5px; }
.list-row:last-child { border-bottom: none; }
.list-row .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.list-row .txt { flex: 1; }
.list-row .txt .t1 { font-weight: 500; }
.list-row .txt .t2 { color: var(--text-dimmer); font-size: 11px; }
.list-row input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- inline auto-save fields (картка клієнта) ---------- */
.inline-input { width: 100%; margin-top: 4px; padding: 7px 10px; font-size: 12.5px; }
.tag-row .inline-input { width: auto; margin-top: 0; padding: 3px 10px; font-size: 11px; border-radius: 100px; }
textarea.inline-input { resize: vertical; }
.inline-input.saving { opacity: 0.6; }
.inline-input.saved-ok, input.inline-check.saved-ok { border-color: var(--green) !important; box-shadow: 0 0 0 2px rgba(61,220,151,0.3); transition: box-shadow 0.2s, border-color 0.2s; }

/* ---------- forms / modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4,6,12,0.65);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px);
}
.modal {
  width: 480px; max-height: 86vh; overflow-y: auto;
  background: #0e1424; border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal h2 { margin: 0 0 18px; font-size: 17px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 11.5px; color: var(--text-dim); margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea { width: 100%; }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar input[type=search] { min-width: 220px; }

.empty-state { color: var(--text-dimmer); font-size: 12.5px; padding: 30px 0; text-align: center; }

.pill-tabs { display: flex; gap: 6px; background: rgba(255,255,255,0.03); border: 1px solid var(--panel-border); border-radius: 100px; padding: 4px; width: fit-content; }
.pill-tab { padding: 6px 14px; border-radius: 100px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.pill-tab.active { background: linear-gradient(135deg, var(--accent), #7a63ff); color: white; }

.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.detail-header h2 { margin: 0 0 4px; font-size: 19px; }
.tag-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.chip { font-size: 11px; color: var(--text-dim); background: rgba(255,255,255,0.05); border: 1px solid var(--panel-border); padding: 3px 10px; border-radius: 100px; }

.integration-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.integration-row:last-child { border-bottom: none; }
.switch { width: 38px; height: 22px; border-radius: 100px; background: rgba(255,255,255,0.12); position: relative; cursor: pointer; flex-shrink: 0; }
.switch.on { background: linear-gradient(135deg, var(--accent), #7a63ff); }
.switch .knob { width: 18px; height: 18px; border-radius: 50%; background: white; position: absolute; top: 2px; left: 2px; transition: left 0.15s; }
.switch.on .knob { left: 18px; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; }
}
