:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --border: #e6e9f0;
  --text: #101828;
  --muted: #667085;
  --soft: #98a2b3;
  --primary: #3b6cf6;
  --primary-soft: #ebf0ff;
  --green: #12b76a;
  --green-soft: #e7f8f0;
  --red: #f04438;
  --red-soft: #fef0ef;
  --amber: #f79009;
  --amber-soft: #fff6e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font: 14px/1.45 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1440px; margin: 0 auto; padding: 24px; }

/* Top bar */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.topbar h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.seg { display: inline-flex; background: #e9ecf3; border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 8px;
  font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; transition: .15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.seg--sm button { padding: 5px 10px; font-size: 13px; }

.select, .input {
  height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); font: inherit; color: var(--text); outline: none;
}
.select:focus, .input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input { min-width: 220px; }

.btn {
  height: 36px; padding: 0 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); font: inherit; font-weight: 500; color: var(--text); cursor: pointer; transition: .15s;
}
.btn:hover { border-color: #cdd3df; background: #fafbfd; }
.btn--icon { width: 36px; padding: 0; font-size: 18px; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: #2f5ce0; border-color: #2f5ce0; }

/* Banners */
.banner { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; background: var(--amber-soft); color: #93370d; border: 1px solid #fedf89; }
.banner--error { background: var(--red-soft); color: #b42318; border-color: #fecdca; }
.banner a { color: inherit; font-weight: 600; cursor: pointer; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent, var(--primary)); }
.kpi__label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi__value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 6px 0 8px; }
.kpi__foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--soft); }

.delta { display: inline-flex; padding: 2px 7px; border-radius: 20px; font-weight: 600; font-size: 12px; }
.delta.up { background: var(--green-soft); color: #067647; }
.delta.down { background: var(--red-soft); color: #b42318; }
.delta.flat { background: #f2f4f7; color: var(--muted); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; font: inherit; font-weight: 500; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }

/* Cards / grid */
.panel { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2--right { grid-template-columns: 2fr 3fr; }
@media (max-width: 1100px) { .grid-2, .grid-2--right { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card__head h2 { font-size: 16px; font-weight: 600; }
.hint { color: var(--soft); font-size: 12px; }
.hint--block { margin: -6px 0 12px; }
.chart-box { position: relative; height: 300px; }
.empty { color: var(--soft); text-align: center; padding: 32px 0; }

/* Funnel */
.funnel { display: grid; gap: 6px; }
.fn-row, .fn-head { display: grid; grid-template-columns: 150px 1fr 70px 90px; gap: 12px; align-items: center; }
.fn-head { color: var(--soft); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding-bottom: 4px; }
.fn-row { padding: 4px 6px; margin: 0 -6px; border-radius: 8px; cursor: pointer; transition: background .15s; }
.fn-row:hover { background: #f6f8fc; }
.fn-name { font-weight: 500; font-size: 13px; line-height: 1.2; }
.fn-name small { display: block; color: var(--soft); font-weight: 400; font-size: 11px; margin-top: 2px; }
.fn-track { background: #f2f4f7; border-radius: 8px; height: 30px; overflow: hidden; }
.fn-bar {
  height: 100%; border-radius: 8px; display: flex; align-items: center; padding: 0 10px;
  color: #fff; font-weight: 600; font-size: 13px; min-width: 34px; transition: width .4s ease;
}
.fn-conv { font-weight: 600; text-align: right; }
.fn-conv small { display: block; color: var(--soft); font-weight: 400; font-size: 11px; }
.fn-time { text-align: right; color: var(--muted); font-size: 13px; }
.fn-sep { border-top: 1px dashed var(--border); margin: 6px 0; }

/* Stats under chart */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.stat__v { font-size: 20px; font-weight: 700; }
.stat__l { color: var(--muted); font-size: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 10px 12px;
  background: #f9fafb; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th:first-child { border-top-left-radius: 8px; }
.table th:last-child { border-top-right-radius: 8px; }
.table td { padding: 11px 12px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfd; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .total td { font-weight: 600; background: #f9fafb; }
.table .group td { font-weight: 600; }
.table .child td:first-child { padding-left: 28px; color: var(--muted); }
.table--compact td { padding: 8px 12px; }
.table tr.link { cursor: pointer; }
.table tr.link:hover td:first-child { color: var(--primary); }

.person { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: 11px; flex: none;
}

.plan { min-width: 120px; }
.plan__nums { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.plan__nums b { font-size: 13px; }
.plan__nums span { color: var(--soft); }
.plan__bar { height: 6px; background: #f2f4f7; border-radius: 6px; overflow: hidden; }
.plan__bar i { display: block; height: 100%; border-radius: 6px; }
.ok { background: var(--green); }
.warn { background: var(--amber); }
.bad { background: var(--red); }

.badge { display: inline-flex; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge--ok { background: var(--green-soft); color: #067647; }
.badge--late { background: var(--amber-soft); color: #b54708; }
.badge--missed { background: var(--red-soft); color: #b42318; }
.badge--wait { background: var(--primary-soft); color: #2f5ce0; }
.badge--unknown, .badge--stage { background: #f2f4f7; color: var(--muted); }
.badge--won { background: var(--green-soft); color: #067647; }
.badge--lost { background: var(--red-soft); color: #b42318; }

.share { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.share i { display: block; height: 6px; border-radius: 6px; background: var(--primary); opacity: .7; }

.wl-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Loading */
.loading { position: fixed; inset: 0; background: rgba(243, 245, 250, .6); display: grid; place-items: center; z-index: 50; backdrop-filter: blur(1px); }
.spinner { width: 36px; height: 36px; border: 3px solid #dbe3fb; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Denied */
.denied { min-height: 70vh; display: grid; place-items: center; padding: 24px; }
.denied__box { text-align: center; max-width: 380px; }
.denied__icon { font-size: 40px; margin-bottom: 12px; }
.denied h2 { margin-bottom: 8px; }
.denied p { color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(16, 24, 40, .4); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 60; overflow-y: auto; }
.modal__box { background: var(--surface); border-radius: 16px; width: 100%; max-width: 760px; padding: 24px; box-shadow: 0 20px 50px rgba(16, 24, 40, .2); }
.modal__box h2 { font-size: 18px; margin-bottom: 4px; }
.modal__box h3 { font-size: 14px; margin: 20px 0 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field .input, .field .select { width: 100%; min-width: 0; }
.users-box { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.users-box .table td { padding: 6px 12px; }
.users-box .table th { position: sticky; top: 0; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
