/* ═══════════════════════════════════════════════════════════
   style.css — Material Design 3 тёмная тема, КП ОМПК v2.0
   ═══════════════════════════════════════════════════════════ */

/* ─── CSS-переменные ──────────────────────────────────────── */
:root {
    --md-bg:          #0f0f23;
    --md-surface:     #16213e;
    --md-surface-2:   #1a1a2e;
    --md-surface-3:   #1f2744;
    --md-outline:     #1f3460;
    --md-primary:     #e94560;
    --md-primary-dim: #c81e45;
    --md-on-primary:  #ffffff;
    --md-secondary:   #0984e3;
    --md-success:     #00b894;
    --md-warning:     #fdcb6e;
    --md-error:       #d63031;
    --md-text:        #e0e0e0;
    --md-text-dim:    #aaaaaa;
    --md-text-muted:  #666688;
    --md-transition:  0.2s cubic-bezier(0.2, 0, 0, 1);
    --md-radius:      12px;
    --md-radius-sm:   8px;
    --md-radius-xs:   6px;
}

/* ─── Сброс и база ────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    background: var(--md-bg);
    color: var(--md-text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--md-secondary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
code { background: var(--md-surface-3); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }

/* ─── Top App Bar ─────────────────────────────────────────── */
.top-app-bar {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; justify-content: space-between;
    height: 56px; padding: 0 16px;
    background: var(--md-surface);
    border-bottom: 2px solid var(--md-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.top-app-bar__left { display: flex; align-items: center; gap: 8px; }
.top-app-bar__title {
    font-size: 18px; font-weight: 700; color: var(--md-text);
    text-decoration: none; white-space: nowrap;
}
.top-app-bar__title:hover { color: var(--md-primary); text-decoration: none; }
.top-app-bar__actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ─── Контент ─────────────────────────────────────────────── */
.main-content { padding: 20px; max-width: 1920px; margin: 0 auto; }

/* ─── Карточки (elevation 1-3) ────────────────────────────── */
.card {
    background: var(--md-surface);
    border-radius: var(--md-radius);
    border: 1px solid var(--md-outline);
    padding: 20px;
}
.elevation-1 { box-shadow: 0 1px 3px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.15); }
.elevation-2 { box-shadow: 0 3px 6px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.2); }
.elevation-3 { box-shadow: 0 6px 12px rgba(0,0,0,0.3), 0 4px 8px rgba(0,0,0,0.22); }

/* ─── Кнопки ──────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border: none; border-radius: var(--md-radius-sm);
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: all var(--md-transition);
    overflow: hidden; position: relative;
    white-space: nowrap; text-decoration: none;
    line-height: 1.4;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--md-primary); color: var(--md-on-primary); }
.btn-primary:hover { background: var(--md-primary-dim); }

.btn-tonal { background: var(--md-surface-3); color: var(--md-text); }
.btn-tonal:hover { background: var(--md-outline); }

.btn-outlined {
    background: transparent; color: var(--md-primary);
    border: 1px solid var(--md-primary);
}
.btn-outlined:hover { background: rgba(233,69,96,0.1); }

.btn-success { background: var(--md-success); color: #fff; }
.btn-success:hover { background: #00a381; }

.btn-error { background: var(--md-error); color: #fff; }
.btn-error:hover { background: #b82828; }

.btn-icon {
    width: 36px; height: 36px; padding: 0;
    border-radius: 50%; background: transparent; color: var(--md-text);
    border: none; cursor: pointer; font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background var(--md-transition);
}
.btn-icon:hover { background: var(--md-surface-3); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--md-radius-xs); }

/* ─── Ripple ──────────────────────────────────────────────── */
.ripple {
    position: absolute; border-radius: 50%;
    background: rgba(255,255,255,0.3);
    transform: scale(0); animation: ripple-anim 0.6s ease-out;
    pointer-events: none;
}
@keyframes ripple-anim { to { transform: scale(4); opacity: 0; } }

/* ─── Формы ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block; margin-bottom: 4px;
    font-size: 12px; font-weight: 600; color: var(--md-text-dim);
    text-transform: uppercase; letter-spacing: 0.5px;
}
.form-input, .form-textarea, .form-select {
    width: 100%; padding: 10px 12px;
    background: var(--md-surface-2); color: var(--md-text);
    border: 1px solid var(--md-outline); border-radius: var(--md-radius-sm);
    font-size: 14px; font-family: inherit;
    transition: border-color var(--md-transition);
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none; border-color: var(--md-primary);
    box-shadow: 0 0 0 2px rgba(233,69,96,0.2);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { cursor: pointer; }
.form-select option { background: var(--md-surface-2); color: var(--md-text); }

.form-input::placeholder, .form-textarea::placeholder {
    color: var(--md-text-muted);
}

/* ─── Чипы ────────────────────────────────────────────────── */
.chips-container {
    display: flex; flex-wrap: wrap; gap: 6px;
    min-height: 24px; margin-top: 8px;
}
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px 4px 12px;
    background: var(--md-surface-3); color: var(--md-text);
    border-radius: 20px; font-size: 12px;
    border: 1px solid var(--md-outline);
    animation: chip-in 0.2s ease-out;
}
@keyframes chip-in { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.chip__code { font-weight: 700; color: var(--md-secondary); }
.chip__name { color: var(--md-text-dim); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__remove {
    width: 18px; height: 18px; border-radius: 50%; border: none;
    background: var(--md-error); color: #fff; font-size: 11px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background var(--md-transition); line-height: 1; padding: 0;
}
.chip__remove:hover { background: #ff4757; }

/* ─── Snackbar ────────────────────────────────────────────── */
.snackbar {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    padding: 12px 24px; border-radius: var(--md-radius-sm);
    font-size: 14px; font-weight: 500; z-index: 1000;
    display: none; align-items: center; gap: 12px;
    max-width: 90vw; min-width: 280px;
    animation: snackbar-in 0.3s ease-out;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.snackbar.show { display: flex; }
.snackbar-success { background: var(--md-success); color: #fff; }
.snackbar-error { background: var(--md-error); color: #fff; }
.snackbar-warning { background: #e67e22; color: #fff; }
.snackbar-info { background: var(--md-secondary); color: #fff; }
.snackbar__action {
    background: transparent; border: 1px solid rgba(255,255,255,0.5);
    color: #fff; padding: 4px 10px; border-radius: 4px; cursor: pointer;
    font-size: 12px; font-weight: 600;
}
@keyframes snackbar-in {
    from { transform: translateX(-50%) translateY(40px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ─── Диалог / Модалка ────────────────────────────────────── */
.dialog-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fade-in 0.2s;
}
@keyframes fade-in { from { opacity: 0; } }
.dialog {
    background: var(--md-surface);
    border-radius: var(--md-radius); border: 1px solid var(--md-outline);
    max-width: 600px; width: 100%; max-height: 80vh;
    display: flex; flex-direction: column;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
    animation: dialog-in 0.25s ease-out;
}
@keyframes dialog-in { from { transform: scale(0.9); opacity: 0; } }
.dialog__header {
    padding: 20px 24px 12px;
    font-size: 18px; font-weight: 700;
    border-bottom: 1px solid var(--md-outline);
    display: flex; justify-content: space-between; align-items: center;
}
.dialog__body { padding: 16px 24px; overflow-y: auto; flex: 1; }
.dialog__footer {
    padding: 12px 24px 16px;
    display: flex; justify-content: flex-end; gap: 8px;
    border-top: 1px solid var(--md-outline);
}
.dialog.fullscreen {
    position: fixed; inset: 0; z-index: 300;
    max-width: none; max-height: none;
    border-radius: 0; border: none;
}
.dialog.fullscreen .dialog__body { padding: 16px; }

/* ─── Linear Progress ─────────────────────────────────────── */
.progress-bar {
    width: 100%; height: 4px; border-radius: 2px;
    background: var(--md-surface-3); overflow: hidden;
    margin: 12px 0;
}
.progress-bar__fill {
    height: 100%; border-radius: 2px;
    background: linear-gradient(90deg, var(--md-primary), var(--md-secondary));
    transition: width 0.3s;
    width: 0%;
}
.progress-bar.indeterminate .progress-bar__fill {
    width: 40%;
    animation: progress-indeterminate 1.2s infinite ease-in-out;
}
@keyframes progress-indeterminate {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

/* ─── Navigation Tabs ─────────────────────────────────────── */
.tabs { display: flex; border-bottom: 1px solid var(--md-outline); margin-bottom: 20px; overflow-x: auto; }
.tab {
    padding: 12px 20px; font-size: 13px; font-weight: 600;
    color: var(--md-text-dim); cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all var(--md-transition);
    white-space: nowrap; background: transparent; border-top: none; border-left: none; border-right: none;
}
.tab:hover { color: var(--md-text); background: var(--md-surface-3); }
.tab.active { color: var(--md-primary); border-bottom-color: var(--md-primary); }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fade-in 0.2s; }

/* ─── Skeleton loading ────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--md-surface-3) 25%, var(--md-surface-2) 50%, var(--md-surface-3) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--md-radius-xs);
    min-height: 20px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── Статистические карточки ─────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
    background: var(--md-surface-2); border-radius: var(--md-radius-sm);
    padding: 16px; text-align: center; border: 1px solid var(--md-outline);
}
.stat-card__value { font-size: 28px; font-weight: 800; color: var(--md-primary); }
.stat-card__label { font-size: 12px; color: var(--md-text-dim); margin-top: 4px; }

/* ─── Таблицы (общие) ─────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 8px 10px; text-align: left;
    border-bottom: 1px solid var(--md-outline);
    font-size: 13px;
}
.data-table th {
    background: var(--md-surface-3); color: var(--md-text-dim);
    font-weight: 600; font-size: 11px; text-transform: uppercase;
    letter-spacing: 0.5px; position: sticky; top: 0; z-index: 1;
}
.data-table tr:hover { background: rgba(233,69,96,0.05); }

/* ─── Пагинация ───────────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 16px; }
.pagination__btn {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--md-surface-3); color: var(--md-text); border: none;
    cursor: pointer; font-size: 13px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--md-transition);
}
.pagination__btn:hover { background: var(--md-outline); }
.pagination__btn.active { background: var(--md-primary); color: #fff; }
.pagination__btn:disabled { opacity: 0.3; cursor: default; }

/* ═══════════════════════════════════════════════════════════
   ТАБЛИЦА КП
   ═══════════════════════════════════════════════════════════ */
.kp-table-container { overflow: visible; margin-top: 16px; }
.kp-table-scroll { overflow-x: auto; border: 1px solid var(--md-outline); border-radius: var(--md-radius-sm); }

.kp-table {
    width: max-content; min-width: 100%;
    border-collapse: collapse; font-size: 12px;
}
.kp-table th, .kp-table td {
    padding: 4px 5px; border: 1px solid rgba(255,255,255,0.06);
    white-space: nowrap; vertical-align: middle;
    height: 32px;
}
/* Заголовки блоков (строка 1) */
.kp-hdr-ompk    { background: #c0392b; color: #fff; font-weight: 700; text-align: center; font-size: 13px; }
.kp-hdr-compare { background: #2980b9; color: #fff; font-weight: 700; text-align: center; font-size: 13px; }
.kp-hdr-comp    { background: #27ae60; color: #fff; font-weight: 700; text-align: center; font-size: 13px; }
.kp-hdr-extra   { background: #8e44ad; color: #fff; font-weight: 700; text-align: center; font-size: 13px; }
/* Подзаголовки (строка 2) */
.kp-sub-hdr { background: #34495e; color: #fff; font-weight: 600; text-align: center; font-size: 11px; }
/* Заголовки колонок (строка 3) */
.kp-col-hdr {
    background: var(--md-surface-3); color: var(--md-text-dim);
    font-weight: 600; text-align: center; font-size: 10px;
    text-transform: uppercase; cursor: pointer;
    user-select: none; position: sticky; top: 0; z-index: 2;
}
.kp-col-hdr:hover { background: var(--md-outline); }
.kp-col-hdr .sort-icon { font-size: 10px; margin-left: 2px; opacity: 0.5; }
.kp-col-hdr .sort-icon.active { opacity: 1; color: var(--md-primary); }

/* Разделитель типа продукции */
.kp-type-row td {
    background: #2c3e50; color: #fff; font-weight: 700;
    font-size: 13px; padding: 6px 10px;
}

/* Ячейки данных */
.kp-table td { background: var(--md-surface); }
.kp-table .kp-data-row:hover td { background: var(--md-surface-2); }

/* Типы ячеек */
.cell-calc     { color: var(--md-success) !important; font-weight: 600; }
.cell-manual   { color: var(--md-warning) !important; }
.cell-autofill { color: #74b9ff !important; }
.cell-readonly { color: var(--md-text-muted) !important; }

/* Подсветка дельты */
.delta-pos { background: rgba(0,184,148,0.12) !important; }
.delta-neg { background: rgba(214,48,49,0.12) !important; }

/* Инпуты в ячейках */
.kp-table input.cell-input {
    width: 100%; padding: 2px 4px; border: none;
    background: transparent; color: inherit; font-size: 12px;
    font-family: inherit; text-align: right;
    outline: none; min-width: 50px;
}
.kp-table input.cell-input:focus {
    background: var(--md-surface-3);
    box-shadow: inset 0 0 0 1px var(--md-primary);
    border-radius: 3px;
}
.kp-table input.cell-input.cell-text { text-align: left; min-width: 100px; }

/* Фото в ячейке */
.cell-photo { width: 45px; height: 45px; object-fit: cover; border-radius: 4px; cursor: pointer; }
.cell-photo-placeholder { width: 45px; height: 45px; background: var(--md-surface-3); border-radius: 4px; display: flex; align-items: center; justify-content: center; color: var(--md-text-muted); font-size: 16px; }

/* Строка конкурента (дочерняя) */
.kp-comp-row td { background: var(--md-surface-2) !important; }
.kp-comp-row .ompk-hidden { background: var(--md-surface-3) !important; color: var(--md-text-muted); }

/* Кнопки в строке */
.kp-row-actions { display: flex; gap: 4px; }
.kp-row-actions button {
    padding: 2px 6px; font-size: 11px; border-radius: 4px;
    border: none; cursor: pointer; white-space: nowrap;
    transition: background var(--md-transition);
}
.btn-add-comp { background: #27ae60; color: #fff; }
.btn-add-comp:hover { background: #2ecc71; }
.btn-del-row { background: var(--md-error); color: #fff; }
.btn-del-row:hover { background: #ff4757; }

/* Панель фильтров */
.kp-filters {
    display: none; gap: 12px; align-items: center;
    padding: 12px 16px; background: var(--md-surface-2);
    border-radius: var(--md-radius-sm); margin-bottom: 12px;
    flex-wrap: wrap;
}
.kp-filters.show { display: flex; }
.kp-filters .form-input, .kp-filters .form-select {
    width: auto; min-width: 150px; padding: 6px 10px; font-size: 12px;
}

/* ═══════════════════════════════════════════════════════════
   ПРЕДПРОСМОТР
   ═══════════════════════════════════════════════════════════ */
.preview-table {
    width: 100%; border-collapse: collapse; font-size: 11px;
    background: #fff; color: #333;
}
.preview-table th, .preview-table td {
    border: 1px solid #ccc; padding: 3px 5px;
    text-align: center; vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════════
   ПАНЕЛЬ ВВОДА (index.php)
   ═══════════════════════════════════════════════════════════ */
.input-panel { margin-bottom: 16px; }
.input-panel__row { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.input-panel__left { flex: 1; min-width: 280px; }
.input-panel__right { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }

/* Автокомплит */
.autocomplete-wrapper { position: relative; }
.autocomplete-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
    background: var(--md-surface); border: 1px solid var(--md-outline);
    border-radius: 0 0 var(--md-radius-sm) var(--md-radius-sm);
    max-height: 300px; overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    display: none;
}
.autocomplete-dropdown.show { display: block; }
.ac-item {
    padding: 8px 12px; cursor: pointer; font-size: 13px;
    border-bottom: 1px solid var(--md-outline);
    display: flex; justify-content: space-between; gap: 8px;
    transition: background 0.1s;
}
.ac-item:hover, .ac-item.active { background: var(--md-surface-3); }
.ac-item__code { font-weight: 700; color: var(--md-secondary); min-width: 60px; }
.ac-item__name { flex: 1; color: var(--md-text); }
.ac-item__type { color: var(--md-text-muted); font-size: 11px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.ac-item mark { background: rgba(233,69,96,0.3); color: var(--md-text); border-radius: 2px; padding: 0 1px; }

/* ═══════════════════════════════════════════════════════════
   АДМИН-ПАНЕЛЬ
   ═══════════════════════════════════════════════════════════ */
.admin-login {
    max-width: 360px; margin: 80px auto;
    text-align: center;
}
.admin-login h2 { margin-bottom: 20px; }

/* Модалка редактирования */
.edit-modal .form-group { margin-bottom: 10px; }
.edit-modal .form-label { font-size: 11px; }
.edit-modal .form-input { padding: 6px 8px; font-size: 13px; }

/* Парсинг картинок */
.parsed-images-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px; margin-top: 12px;
}
.parsed-image-card {
    border: 2px solid var(--md-outline); border-radius: var(--md-radius-sm);
    overflow: hidden; cursor: pointer;
    transition: border-color var(--md-transition);
    aspect-ratio: 1;
}
.parsed-image-card:hover { border-color: var(--md-primary); }
.parsed-image-card img { width: 100%; height: 100%; object-fit: cover; }

/* Формулы */
.formula-group { margin-bottom: 20px; }
.formula-group__title {
    font-size: 14px; font-weight: 700;
    padding: 8px 12px; background: var(--md-surface-3);
    border-radius: var(--md-radius-xs); margin-bottom: 8px;
}
.formula-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; border-bottom: 1px solid var(--md-outline);
}
.formula-row__key { min-width: 180px; font-weight: 600; color: var(--md-secondary); font-size: 12px; }
.formula-row__label { min-width: 200px; font-size: 12px; }
.formula-row__input { flex: 1; }
.formula-row__input input {
    width: 100%; padding: 4px 8px; background: var(--md-surface-2);
    border: 1px solid var(--md-outline); border-radius: 4px;
    color: var(--md-text); font-family: monospace; font-size: 12px;
}
.formula-row__input input:focus {
    outline: none; border-color: var(--md-primary);
}

/* ─── Утилиты ─────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .top-app-bar { height: auto; flex-wrap: wrap; padding: 8px; }
    .top-app-bar__actions { width: 100%; justify-content: flex-start; overflow-x: auto; }
    .main-content { padding: 10px; }
    .input-panel__row { flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .btn { font-size: 12px; padding: 6px 10px; }
}

/* ─── Скроллбар ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--md-surface-2); }
::-webkit-scrollbar-thumb { background: var(--md-outline); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--md-text-muted); }