/* === Шрифты === */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Manrope:wght@400;500;600;700&display=swap');

/* === Переменные === */
:root {
    --bg-dark: #0d1117;
    --bg-card: #161b22;
    --bg-hover: #21262d;
    --border-color: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-purple: #a371f7;
    --accent-pink: #f778ba;
    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-orange: #d29922;
    --accent-red: #f85149;
    --gradient-primary: linear-gradient(135deg, #a371f7 0%, #f778ba 100%);
    --gradient-bg: linear-gradient(180deg, #0d1117 0%, #161b22 100%);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(163, 113, 247, 0.2);
}

/* === Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gradient-bg);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Декоративный фон */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse 80% 50% at 20% -10%, rgba(163, 113, 247, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(247, 120, 186, 0.1) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* === Container === */
.container {
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* === Header === */
header {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 2rem 0;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* === Cards === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-card);
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-card), var(--shadow-glow);
}

.card h2 {
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.hint {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

/* === Forms === */
.form-row {
    margin-bottom: 1rem;
}

.form-row label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-row input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-row input:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(163, 113, 247, 0.15);
}

.form-row input::placeholder {
    color: var(--text-muted);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
}

.form-group input {
    padding: 0.75rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(163, 113, 247, 0.15);
}

.form-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-family: 'Manrope', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 2px 12px rgba(163, 113, 247, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(163, 113, 247, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    border-color: var(--text-muted);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === Status === */
.status {
    font-size: 0.85rem;
    font-weight: 500;
}

.status.loading {
    color: var(--accent-orange);
}

.status.success {
    color: var(--accent-green);
}

.status.error {
    color: var(--accent-red);
}

/* === Cards List (Table) === */
.cards-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.cards-count strong {
    color: var(--accent-purple);
}

.cards-list {
    margin-top: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    overflow-x: auto;
}

.cards-list table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1rem;
}

.cards-list th,
.cards-list td {
    padding: 1.25rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.cards-list th {
    background: var(--bg-dark);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 1.05rem;
    position: sticky;
    top: 0;
    z-index: 1;
}

.cards-list tr:hover {
    background: var(--bg-hover);
}

.cards-list tr.selected {
    background: rgba(163, 113, 247, 0.15);
}

.cards-list .nm-id {
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-blue);
    font-size: 1.1rem;
    font-weight: 600;
}

.cards-list td {
    font-size: 1rem;
    vertical-align: middle;
}

.cards-list td img {
    display: block;
    margin: 0 auto;
    transition: transform 0.2s;
}

.cards-list td img:hover {
    transform: scale(1.1);
    cursor: pointer;
}

/* Ввод себестоимости в таблице */
.cost-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.cost-input {
    width: 140px;
    padding: 0.75rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 500;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.cost-input:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(163, 113, 247, 0.15);
}

.cost-input::placeholder {
    color: var(--text-muted);
}

.cost-status {
    font-size: 1rem;
    min-width: 1.5rem;
    font-weight: 600;
}

.cost-status.loading {
    color: var(--accent-orange);
}

.cost-status.success {
    color: var(--accent-green);
}

.cost-status.error {
    color: var(--accent-red);
}

/* === Result Section === */
.result-section {
    border: 2px solid var(--accent-purple);
    background: linear-gradient(135deg, rgba(163, 113, 247, 0.05) 0%, rgba(247, 120, 186, 0.05) 100%);
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.metric .label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.metric .value {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
}

.metric.highlight {
    background: var(--gradient-primary);
    border: none;
}

.metric.highlight .label {
    color: rgba(255, 255, 255, 0.8);
}

.metric.highlight .value {
    color: white;
    font-size: 1.5rem;
}

/* === Selected NM IDs === */
.selected-nm-ids {
    margin-top: 1rem;
}

.nm-ids-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.nm-id-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.nm-id-value {
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-blue);
    font-weight: 600;
}

.nm-id-title {
    color: var(--text-secondary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-nm-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0;
    width: 1.2rem;
    height: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.remove-nm-btn:hover {
    background: var(--accent-red);
    color: white;
}

/* === Results Table === */
.results-table-wrapper {
    overflow-x: auto;
    margin-top: 1rem;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.results-table th,
.results-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.results-table th {
    background: var(--bg-dark);
    color: var(--text-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.results-table th.highlight,
.results-table td.highlight {
    background: rgba(163, 113, 247, 0.1);
    font-weight: 600;
}

.results-table tbody tr:hover {
    background: var(--bg-hover);
}

.results-table td {
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
}

.results-table .totals-row {
    background: rgba(163, 113, 247, 0.15);
    border-top: 2px solid var(--accent-purple);
}

.results-table .totals-row:hover {
    background: rgba(163, 113, 247, 0.2);
}

.results-table .totals-cell {
    font-weight: 700;
    font-size: 1rem;
}

.results-table .totals-cell strong {
    color: var(--accent-purple);
}

/* Управление столбцами */
#column-controls {
    font-size: 0.875rem;
}

#column-checkboxes label {
    user-select: none;
}

#column-checkboxes input[type="checkbox"] {
    cursor: pointer;
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent-purple);
}

/* === Result JSON === */
.result-json {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.result-json h3 {
    margin-bottom: 0.75rem;
}

.result-json pre {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-height: 300px;
}

.result-json button {
    margin-top: 0.75rem;
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* === Modal === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-card);
    width: 100%;
}

.card-item {
    background: var(--bg-dark);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.card-item:hover {
    border-color: var(--accent-purple);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(163, 113, 247, 0.3);
}

.card-item.selected {
    border-color: var(--accent-purple);
    background: rgba(163, 113, 247, 0.1);
}

.card-item img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.card-item .card-title {
    font-size: 0.85rem;
    text-align: center;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.3;
    max-height: 2.6em;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.card-item .card-nm-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--accent-blue);
    font-weight: 600;
}

.selected-card-item {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin: 0.5rem;
    transition: all 0.2s;
}

.selected-card-item:hover {
    border-color: var(--accent-purple);
    background: var(--bg-hover);
}

.selected-card-item img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.selected-card-item .card-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.selected-card-item .card-nm-id {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: var(--accent-blue);
    font-weight: 600;
}

.selected-card-item .card-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-card-item .remove-card-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.25rem;
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
    margin-left: 0.5rem;
}

.selected-card-item .remove-card-btn:hover {
    background: var(--accent-red);
    color: white;
}

/* === Responsive === */
@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 1.75rem;
    }
    
    .card {
        padding: 1.25rem;
    }
    
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .btn {
        width: 100%;
    }
    
    .cards-list {
        font-size: 0.8rem;
    }
}

/* Группы товаров */
.group-item {
    transition: background 0.2s, border-color 0.2s;
}

.group-item:hover {
    background: var(--bg-hover) !important;
    border-color: var(--accent-purple) !important;
}

.btn-sm {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
}

.select-group-btn {
    transition: all 0.2s;
}

.select-group-btn:hover {
    background: var(--accent-purple);
    color: white;
    transform: translateY(-1px);
}

/* Drag-and-drop для столбцов */
.draggable-column {
    transition: all 0.2s;
}

.draggable-column:hover {
    background: var(--bg-hover);
}

.draggable-column.dragging {
    opacity: 0.5;
}

.drag-handle {
    display: inline-block;
    cursor: grab;
}

.drag-handle:active {
    cursor: grabbing;
}

/* Ползунок для выбора диапазона дат */
#funnel-range-from,
#funnel-range-to {
    -webkit-appearance: none;
    appearance: none;
}

#funnel-range-from::-webkit-slider-thumb,
#funnel-range-to::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-purple);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
}

#funnel-range-from::-webkit-slider-thumb:hover,
#funnel-range-to::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 6px rgba(163, 113, 247, 0.4);
}

#funnel-range-from::-moz-range-thumb,
#funnel-range-to::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent-purple);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
}

#funnel-range-from::-moz-range-thumb:hover,
#funnel-range-to::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 6px rgba(163, 113, 247, 0.4);
}

#funnel-range-from::-webkit-slider-runnable-track,
#funnel-range-to::-webkit-slider-runnable-track {
    height: 6px;
    background: transparent;
}

#funnel-range-from::-moz-range-track,
#funnel-range-to::-moz-range-track {
    height: 6px;
    background: transparent;
}

/* Контролы дат воронки в результатах */
#funnel-date-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

#funnel-date-controls input[type="date"] {
    transition: all 0.2s;
}

#funnel-date-controls input[type="date"]:hover {
    border-color: var(--accent-purple);
}

#funnel-date-controls input[type="date"]:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(163, 113, 247, 0.2);
    outline: none;
}

#funnel-recalc-status {
    transition: opacity 0.3s, color 0.3s;
    font-family: 'JetBrains Mono', monospace;
}

