/* ========== ЦВЕТОВЫЕ ПЕРЕМЕННЫЕ (СВЕТЛАЯ ТЕМА) ========== */
:root {
    --bg-main: #f4f6f9;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-input: #f9fafc;
    --bg-hover: #f0f4fe;
    --bg-active: #e6f0ff;
    --bg-result: #f8faff;
    --border: #e6eaef;
    --border-light: #eef2f6;
    --text-main: #1e293b;
    --text-secondary: #6c7a8a;
    --text-muted: #94a3b8;
    --accent: #0066cc;
    --accent-hover: #0052a3;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 24px rgba(0, 102, 204, 0.12);
}

/* ========== ТЁМНАЯ ТЕМА ========== */
body.dark-theme {
    --bg-main: #0f1419;
    --bg-card: #1a2028;
    --bg-sidebar: #151b22;
    --bg-input: #1f2630;
    --bg-hover: #252d38;
    --bg-active: #1e3a5f;
    --bg-result: #1a2a3f;
    --border: #2a3441;
    --border-light: #222a35;
    --text-main: #e8eef5;
    --text-secondary: #8fa0b3;
    --text-muted: #6a7a8f;
    --accent: #4d9fff;
    --accent-hover: #66b3ff;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 24px rgba(77, 159, 255, 0.2);
}

/* ========== ОБЩИЕ СБРОСЫ ========== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ========== ЛЕВАЯ КОЛОНКА: КАТАЛОГ ========== */
.catalog-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 18px 12px 18px;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-header h2 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 10px;
}

.sidebar-header input {
    width: 100%;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 30px;
    font-size: 14px;
    outline: none;
    transition: 0.15s;
    background: var(--bg-input);
    color: var(--text-main);
}

.sidebar-header input:focus {
    border-color: var(--accent);
    background: var(--bg-card);
}

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

.btn-refresh {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 30px;
    transition: 0.15s;
    color: var(--text-secondary);
}

.btn-refresh:hover {
    background: var(--bg-hover);
    color: var(--accent);
    transform: rotate(90deg);
    transition: 0.3s;
}

.catalog-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px 20px 12px;
}

.catalog-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    border-radius: 8px;
    margin-bottom: 2px;
    cursor: pointer;
    transition: 0.15s;
    background: transparent;
}

.catalog-item:hover {
    background: var(--bg-hover);
}

.catalog-item .name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
}

.catalog-item .id {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-hover);
    padding: 2px 10px;
    border-radius: 30px;
}

.catalog-item.active {
    background: var(--bg-active);
    border-left: 3px solid var(--accent);
}

.catalog-item.active .name {
    color: var(--accent);
    font-weight: 600;
}

/* ========== ПРАВАЯ КОЛОНКА ========== */
.calculator-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    padding: 20px 30px 30px 30px;
    background: var(--bg-main);
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.top-header h1 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-main);
}

.deal-id {
    background: var(--bg-hover);
    padding: 4px 16px;
    border-radius: 30px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* ========== КНОПКА СМЕНЫ ТЕМЫ ========== */
.theme-toggle {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: all 0.25s ease;
    padding: 0;
}

.theme-toggle:hover {
    background: var(--bg-active);
    transform: rotate(20deg) scale(1.1);
}

.theme-toggle:active {
    transform: rotate(20deg) scale(0.95);
}

/* ========== СЕТКА ========== */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin: 12px 0 20px 0;
}

.grid-card {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 20px 16px 18px;
    border: 1px solid var(--border);
    transition: all 0.25s ease;
    cursor: pointer;
    text-align: center;
    user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
    overflow: hidden;
}

.grid-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), #66a3ff);
    opacity: 0;
    transition: opacity 0.25s;
}

.grid-card:hover::before {
    opacity: 1;
}

.grid-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px);
}

.grid-card:active {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.card-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 6px;
    transition: transform 0.25s;
}

/* ===== Картинка товара (превью из Аксиомы) ===== */
.card-image {
    width: 100%;
    height: 130px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-hover);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.grid-card:hover .card-image img {
    transform: scale(1.06);
}

.card-icon-fallback {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.grid-card:hover .card-icon {
    transform: scale(1.1);
}

.grid-card h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    line-height: 1.35;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.grid-card .grid-id {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    font-weight: 500;
}

.empty-msg {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 0;
}

/* ========== ЗАГОЛОВОК КАЛЬКУЛЯТОРА ========== */
.calc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    padding: 0 4px;
}

.calc-title {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.calc-title h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

.axioma-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 1px dashed var(--accent);
    transition: 0.15s;
}

.axioma-link:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-hover);
}

/* ========== ПАНЕЛЬ ПАРАМЕТРОВ ========== */
.params-panel {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px 28px 28px 28px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

/* ========== ГРУППЫ ПАРАМЕТРОВ ========== */
.param-group {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.param-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.param-group-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 14px;
    padding: 6px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--bg-active);
}

.params-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.params-grid .form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.params-grid label {
    font-weight: 500;
    font-size: 14px;
    color: var(--text-main);
}

.params-grid select,
.params-grid input[type="number"] {
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text-main);
    transition: 0.15s;
    width: 100%;
}

.params-grid select:focus,
.params-grid input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-card);
}

/* ========== КНОПКИ-ВАРИАНТЫ ========== */
.options-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.options-buttons .option-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    font-size: 13px;
    cursor: pointer;
    transition: 0.15s;
    color: var(--text-main);
}

.options-buttons .option-btn:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.options-buttons .option-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.2);
}

.options-select select {
    width: 100%;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-input);
    color: var(--text-main);
}

/* ========== ЦВЕТНОСТЬ ========== */
.color-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.color-group input {
    width: auto;
    flex: 1;
    min-width: 60px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-input);
    color: var(--text-main);
}

/* ========== КНОПКИ ДЕЙСТВИЙ ========== */
.actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.btn {
    padding: 10px 24px;
    border: none;
    border-radius: 30px;
    font-size: 15px;
    cursor: pointer;
    font-weight: 500;
    transition: 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #1e7e34;
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--bg-active);
}

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

/* ========== РЕЗУЛЬТАТ ========== */
.result-box {
    margin-top: 24px;
    padding: 18px 22px;
    background: var(--bg-result);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.result-box .total {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
}

.total-row {
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

/* ========== ЛОАДЕР ========== */
.loader {
    display: none;
    text-align: center;
    padding: 24px;
}

.loader.active {
    display: block;
}

.spinner {
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ========== СТАТУС ========== */
.status-msg {
    padding: 12px 18px;
    border-radius: 10px;
    margin: 12px 0;
    font-size: 14px;
}

.status-msg.success {
    background: #e3f5e9;
    color: #0d5e2a;
    border: 1px solid #c1e6d0;
}

.status-msg.error {
    background: #fde8e8;
    color: #9e1f1f;
    border: 1px solid #f8d0d0;
}

body.dark-theme .status-msg.success {
    background: #143b22;
    color: #7ee8a2;
    border-color: #1e7e34;
}

body.dark-theme .status-msg.error {
    background: #3b1414;
    color: #ff8a8a;
    border-color: #9e1f1f;
}

/* ========== КНОПКА НАЗАД ========== */
.back-btn {
    padding: 8px 18px;
    background: var(--bg-hover);
    border: none;
    border-radius: 30px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-main);
    transition: 0.15s;
}

.back-btn:hover {
    background: var(--bg-active);
}

/* ========== АДАПТИВ ========== */
@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
        height: auto;
    }
    .catalog-sidebar {
        width: 100%;
        min-width: unset;
        height: 280px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .calculator-main {
        height: auto;
        padding: 16px;
    }
    .calc-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ========== ТОСТЫ (всплывающие уведомления) ========== */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    min-width: 280px;
    max-width: 420px;
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: white;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    animation: toast-in 0.35s cubic-bezier(0.21, 1.02, 0.73, 1);
    word-break: break-word;
}

.toast.success { background: linear-gradient(135deg, #28a745, #1e7e34); }
.toast.error   { background: linear-gradient(135deg, #dc3545, #b02a37); }
.toast.info    { background: linear-gradient(135deg, #0066cc, #0052a3); }
.toast.warning { background: linear-gradient(135deg, #ffc107, #e0a800); color: #1e293b; }

.toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    line-height: 1.4;
}

@keyframes toast-in {
    from {
        transform: translateX(120%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.hide {
    animation: toast-out 0.35s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
}

@keyframes toast-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(120%);
        opacity: 0;
    }
}

/* Адаптив для мобильных */
@media (max-width: 768px) {
    #toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }
    .toast {
        min-width: unset;
        max-width: unset;
        width: 100%;
    }
}

/* ===== Кнопка копирования результата ===== */
.copy-result-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-main);
    cursor: pointer;
    transition: 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.copy-result-btn:hover {
    background: var(--bg-active);
    border-color: var(--accent);
    color: var(--accent);
}

.copy-result-btn.copied {
    background: #28a745;
    color: white;
    border-color: #28a745;
}

.copy-result-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ===== Подсказка под параметром (Description значения) ===== */
.param-help {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
    padding: 6px 10px;
    background: var(--bg-hover);
    border-left: 2px solid var(--accent);
    border-radius: 4px;
}

.param-help:empty {
    display: none;
}

/* ===== Детали расчёта ===== */
.details-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    padding: 8px 0;
    font-weight: 600;
    color: var(--text-main);
    transition: color 0.15s;
}

.details-header:hover {
    color: var(--accent);
}

.details-toggle-icon {
    font-size: 12px;
    transition: transform 0.2s ease;
    color: var(--text-muted);
}

.details-header.collapsed .details-toggle-icon {
    transform: rotate(-90deg);
}

.details-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    opacity: 1;
}

.details-content.collapsed {
    max-height: 0;
    opacity: 0;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 3px 0;
    align-items: flex-start;
}

.detail-label {
    color: var(--text-muted);
    flex-shrink: 0;
}

.detail-value {
    color: var(--text-main);
    text-align: right;
    max-width: 65%;
    word-break: break-word;
}

.detail-layer {
    margin-bottom: 12px;
}

.detail-layer-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 6px;
    padding: 2px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-separator {
    border-top: 1px dashed var(--border);
    margin: 10px 0;
}

.detail-total-postpress {
    padding-top: 8px;
    margin-top: 8px;
    border-top: 2px solid var(--border);
}

/* Карточка виртуального калькулятора */
.custom-calc-card {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 2px solid #fbbf24;
}

body.dark-theme .custom-calc-card {
    background: linear-gradient(135deg, #3d2e0a 0%, #2d2007 100%);
    border-color: #f59e0b;
}

.custom-calc-card:hover {
    border-color: #f59e0b;
    box-shadow: 0 10px 24px rgba(245, 158, 11, 0.2);
}

/* Адаптив для формы багета */
@media (max-width: 768px) {
    .param-group-title {
        font-size: 13px;
    }
}

/* ===== Утилитарные сетки для кастомных форм ===== */
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.form-grid-4 {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 12px;
}

.form-grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

@media (max-width: 900px) {
    .form-grid-3, .form-grid-4, .form-grid-5 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .form-grid-2, .form-grid-3, .form-grid-4, .form-grid-5 {
        grid-template-columns: 1fr;
    }
}