/* Общая стилистика: спокойная, современная, без ярких акцентов. */

:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1d212b;
    --border: #262b37;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --accent: #6ea8ff;
    --accent-2: #4a7fdb;
    --success: #3ecf8e;
    --warning: #f0b429;
    --danger: #ef5b5b;
    --row-hover: #1c2230;
    --row-open: #1a2030;
    --radius: 10px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любые display: flex/grid/… */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.4;
}

/* ---------- Верхняя панель ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: rgba(15, 17, 21, 0.85);
    backdrop-filter: saturate(140%) blur(8px);
    border-bottom: 1px solid var(--border);
}
.topbar__title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.topbar__actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
    user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: #323848; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #0b1220;
    font-weight: 600;
}
.btn--primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

.btn--ghost { background: transparent; }

.btn--icon {
    padding: 6px;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--text);
}
.btn--icon svg { display: block; }

/* ---------- Контейнер ---------- */
.container {
    max-width: none;
    margin: 0;
    padding: 20px 24px 60px;
}

/* Зона загрузки всё-таки не должна быть размером с монитор — ограничиваем по-мягкому. */
.upload {
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
}

/* ---------- Загрузка ---------- */
.upload {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
    width: 100%;
}
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    transition: border-color 0.15s, background 0.15s;
}
.dropzone--active {
    border-color: var(--accent);
    background: var(--surface-2);
    color: var(--text);
}
.dropzone__title {
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    margin: 10px 0 2px;
}
.dropzone__hint { font-size: 13px; margin-bottom: 12px; }
.dropzone__file { margin-top: 10px; font-size: 12px; color: var(--muted); }

.progress {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.progress__bar {
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}
.progress__fill {
    position: absolute;
    height: 100%;
    left: -40%;
    width: 40%;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    animation: slide 1.3s linear infinite;
}
@keyframes slide {
    from { left: -40%; }
    to   { left: 100%; }
}
.progress__text { color: var(--muted); font-size: 13px; }

.error {
    background: rgba(239, 91, 91, 0.12);
    border: 1px solid rgba(239, 91, 91, 0.4);
    color: #ffdede;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    white-space: pre-wrap;
}

/* ---------- Тулбар / статистика ---------- */
.results__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.input {
    flex: 1 1 300px;
    min-width: 200px;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    font: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); }
.results__stats {
    display: flex;
    gap: 16px;
    color: var(--muted);
    font-size: 13px;
    flex-wrap: wrap;
}
.results__stats span:empty { display: none; }

/* ---------- Таблица ---------- */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 500;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    z-index: 1;
}
.th--expand { width: 32px; }
.th--sortable { cursor: pointer; user-select: none; }
.th--sortable:hover { color: var(--text); }
.th__arrow {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    color: var(--accent);
}

/* Drag & drop заголовков */
.th--draggable { cursor: grab; }
.th--draggable:active { cursor: grabbing; }
.th--dragging { opacity: 0.45; }
.th--drop-before { box-shadow: inset 3px 0 0 0 var(--accent); }
.th--drop-after  { box-shadow: inset -3px 0 0 0 var(--accent); }

/* Ручка изменения ширины колонки (правый край th) */
.th__resize {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 2;
}
.th__resize:hover::after,
body.col-resizing .th__resize::after {
    content: '';
    position: absolute;
    top: 4px;
    bottom: 4px;
    right: 2px;
    width: 2px;
    background: var(--accent);
    border-radius: 2px;
}
body.col-resizing { cursor: col-resize; user-select: none; }
body.col-resizing * { cursor: col-resize !important; }
.row {
    cursor: pointer;
    transition: background 0.1s;
}
.row:hover { background: var(--row-hover); }
.row--open { background: var(--row-open); }
.td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.td--expand { width: 32px; text-align: center; color: var(--muted); }
.td--money {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--success);
    text-align: right;
}
.td--empty { text-align: center; color: var(--muted); padding: 20px; }

.chev {
    display: inline-block;
    transition: transform 0.15s;
    font-size: 10px;
    color: var(--muted);
}
.chev--muted { opacity: 0.35; }

/* ---------- Деталь (раскрытая строка) ---------- */
.row-detail > .td--detail {
    background: #12151c;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    max-width: none;
}
.detail { display: flex; flex-direction: column; gap: 10px; }
.detail__title { color: var(--muted); font-size: 12px; }
.detail__empty { color: var(--muted); font-style: italic; }
.detail__error {
    background: rgba(239, 91, 91, 0.12);
    border: 1px solid rgba(239, 91, 91, 0.4);
    color: #ffdede;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
}

.subtable {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    font-size: 12.5px;
}
.subtable__th {
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 500;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.subtable__td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.subtable__td--money {
    font-variant-numeric: tabular-nums;
    text-align: right;
}
.subtable tr:last-child .subtable__td { border-bottom: none; }

/* Бейджи статусов */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
    background: #2a2f3d;
    color: var(--muted);
    border: 1px solid var(--border);
}
.badge--dep    { background: rgba(62, 207, 142, 0.18); color: #7ee2b3; border-color: rgba(62, 207, 142, 0.4); }
.badge--redep  { background: rgba(110, 168, 255, 0.18); color: #9fc3ff; border-color: rgba(110, 168, 255, 0.4); }
.badge--reg    { background: rgba(240, 180, 41, 0.12);  color: #f5cf71; border-color: rgba(240, 180, 41, 0.35); }
.badge--lead   { background: rgba(110, 168, 255, 0.18); color: #9fc3ff; border-color: rgba(110, 168, 255, 0.4); }
.badge--sale   { background: rgba(62, 207, 142, 0.18); color: #7ee2b3; border-color: rgba(62, 207, 142, 0.4); }
.badge--contact, .badge--subscribe { background: #2a2f3d; }

/* ---------- Модалка ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
}
.modal__dialog {
    position: relative;
    width: min(460px, 92vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 24px 48px rgba(0,0,0,0.5);
    overflow: hidden;
}
.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.modal__title { margin: 0; font-size: 15px; font-weight: 600; }
.modal__body {
    padding: 12px 16px;
    overflow-y: auto;
}
.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.col-list { display: flex; flex-direction: column; gap: 6px; }
.col-list__hint {
    margin: 0 0 8px;
    font-size: 12px;
}
.col-list__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: grab;
    transition: background 0.1s;
    position: relative;
}
.col-list__item:active { cursor: grabbing; }
.col-list__item:hover { background: var(--surface-2); }
.col-list__item input { accent-color: var(--accent); cursor: pointer; }
.col-list__name { color: var(--text); }
.col-list__grip {
    color: var(--muted);
    font-size: 14px;
    letter-spacing: -2px;
    user-select: none;
    min-width: 14px;
    text-align: center;
}
.col-list__item--dragging { opacity: 0.45; }
.col-list__item--drop-before { box-shadow: inset 0 3px 0 0 var(--accent); }
.col-list__item--drop-after  { box-shadow: inset 0 -3px 0 0 var(--accent); }

.muted { color: var(--muted); }

/* ---------- Узкие экраны ---------- */
@media (max-width: 640px) {
    .topbar { padding: 12px 14px; }
    .container { padding: 16px 14px 40px; }
    .td { max-width: 200px; }
}
