:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;

    --background: #f8fafc;
    --surface: #ffffff;
    --surface-muted: #f1f5f9;

    --text: #334155;
    --text-muted: #64748b;

    --border: #cbd5e1;
    --border-light: #e2e8f0;

    --radius: 10px;

    --history-height: 220px;
    --history-height: min(220px, 35dvh);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* MAIN CONTAINER */

.main_container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 24px;
}

/* SETTINGS CARD */

.generate_container {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 14px;
    padding: 24px;

    box-shadow: 0 3px 16px rgba(15, 23, 42, 0.04);
}

/* PRESETS */

.preset-group {
    margin-bottom: 12px;
}

/* TWO-COLUMN GRID */

.general-settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px 24px;
}

.row_container {
    display: contents;
}

/* FIELD GROUPS */

.simple_combo_group,
.label-input-item-div,
.number-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* LABELS */

.simple_combo_group > label,
.label-input-item-div > label,
.number-field > span {
    font-size: 13px;
    font-weight: 600;
    color: #475569;
}

/* INPUTS AND SELECTS */

input[type="number"],
input[type="text"],
select {
    width: 100%;
    min-width: 0;
    height: 42px;

    padding: 0 12px;

    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;

    color: var(--text);
    font-family: inherit;
    font-size: 14px;

    outline: none;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background 0.2s ease;
}

/* HOVER */

input[type="number"]:hover,
input[type="text"]:hover,
select:hover {
    border-color: #94a3b8;
}

/* FOCUS */

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* DISABLED */

input:disabled,
select:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

/* SELECT */

select {
    cursor: pointer;
}

/* CHECKBOX GROUP */

.choice {
    display: flex;
    align-items: center;
    gap: 10px;

    padding: 10px 12px;
    min-height: 42px;

    background: #f8fafc;
    border: 1px solid var(--border-light);
    border-radius: 8px;

    color: var(--text);
    font-size: 14px;

    cursor: pointer;
    user-select: none;

    transition:
        background 0.2s ease,
        border-color 0.2s ease;
}

.choice:hover {
    background: #f1f5f9;
    border-color: var(--border);
}

/* COMPACT CHECKBOXES */

.field-heading.field-heading-with-checkbox {
    align-items: center;
    gap: 2px 8px;
}

.field-heading-with-checkbox > .choice.inline-checkbox,
.result-actions > .choice {
    display: inline-flex;
    align-items: center;
    gap: 5px;

    width: auto;
    min-height: 10px;
    margin: 0;
    padding: 0;

    border: 0;
    background: transparent;
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
}

/* CHECKBOX INPUT */

input[type="checkbox"] {
    width: 17px;
    height: 17px;
    margin: 0;
    flex-shrink: 0;

    accent-color: var(--primary);
    cursor: pointer;
}

input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

/* TABS SECTION */

.types {
    grid-column: 1 / -1;
    min-width: 0;

    padding-top: 18px;
    border-top: 1px solid var(--border-light);
}

/* TABS CONTAINER */

.tab-list {
    display: flex;
    gap: 6px;
    padding: 5px;

    background: var(--surface-muted);
    border-radius: var(--radius);
}

/* TAB BUTTON */

.tab {
    flex: 1;
    min-width: 0;
    padding: 11px 16px;

    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;

    color: var(--text-muted);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;

    cursor: pointer;

    transition:
        background 0.2s ease,
        color 0.2s ease,
        box-shadow 0.2s ease;
}

/* TAB HOVER */

.tab:hover:not([aria-selected="true"]) {
    background: #e2e8f0;
    color: var(--text);
}

/* ACTIVE TAB */

.tab[aria-selected="true"] {
    background: var(--primary);
    color: #ffffff;
    font-weight: 600;

    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

.tab:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

/* TAB PANELS */

.tab-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px 24px;
    margin-top: 20px;
}

.tab-panel[hidden] {
    display: none;
}

.options-stack {
    display: contents;
}

/* GENERATE BUTTON */

.generate_btn {
    display: block;
    width: 100%;
    min-height: 52px;

    margin: 0 0 20px;
    padding: 12px 24px;

    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius);

    color: #ffffff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;

    cursor: pointer;

    transition:
        background 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.15s ease;
}

.generate_btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.18);
}

.generate_btn:active {
    transform: scale(0.99);
}

.generate_btn:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 3px;
}

.generate_btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* RESULT ACTIONS */

.result-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.result-actions button {
    padding: 7px 12px;
    border: 1px solid #d5dae3;
    border-radius: 6px;
    background: #f7f8fa;
    color: #374151;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.result-actions button:hover {
    background: #e9edf3;
}

.result-actions button:focus-visible {
    outline: 2px solid #557cff;
    outline-offset: 2px;
}

#result-action-status {
    color: #737b88;
    font-size: 12px;
}

/* RESULT PREVIEW */

.result_preview {
    width: 100%;
    min-height: 120px;
    max-height: 300px;

    padding: 24px;
    margin-bottom: 16px;

    background: var(--surface-muted);
    border: 1px solid var(--border-light);
    border-radius: 12px;

    color: var(--text);
    font-family: Consolas, Monaco, monospace;
    font-size: min(var(--preview-font-size, 48px), 9vw);
    font-weight: 500;
    line-height: 1.5;
    text-align: center;

    align-content: center;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    overflow-y: auto;

    transition: font-size 0.2s ease;
}

#result-preview {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

#result-preview.multiple-results {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    max-height: 360px;
    overflow-y: auto;
    align-content: start;
    padding: 12px;
}

.result-cell {
    display: block;
    min-width: 0;
    padding: 6px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

#result-preview.multiple-results .result-cell {
    border-radius: 6px;
    background: rgb(128 128 128 / 8%);
}

/* ERROR LABEL */

.error-label {
    display: block;
    padding: 12px 14px;
    margin-bottom: 16px;

    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;

    color: #dc2626;
    font-size: 13px;
    font-weight: 500;
}

.error-label:empty {
    display: none;
}

/* GENERATION HISTORY */

.generation-history:empty {
    display: none;
}

/* Позволяет прокрутить нижние поля выше фиксированной панели. */
body.history-visible {
    padding-bottom: calc(var(--history-height) + 20px);
}

.history-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;

    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    height: var(--history-height);
    padding-bottom: env(safe-area-inset-bottom);

    background: #fff;
    color: #232936;
    border-top: 1px solid #dfe3e9;
    box-shadow: 0 -4px 18px rgb(0 0 0 / 8%);
    text-align: left;
}

.history-panel[hidden] {
    display: none;
}

.history-header {
    flex-shrink: 0;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
}

.history-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding: 8px 16px;
}

.history-panel .generation-history {
    margin: 0;
    padding-left: 28px;
    text-align: left;
}

.history-panel .generation-history li {
    padding: 6px 0;
    border-bottom: 1px solid #eef0f3;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* MOBILE */

@media (max-width: 600px) {
    .main_container {
        padding: 14px;
    }

    .generate_container {
        padding: 16px;
    }

    .general-settings-grid,
    .tab-panel {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .types {
        padding-top: 16px;
    }

    .tab {
        padding: 10px 12px;
        font-size: 14px;
    }

    .generate_btn {
        min-height: 48px;
    }

    .result_preview {
        min-height: 100px;
        padding: 16px;
    }

    input[type="number"],
    input[type="text"],
    select {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    #result-preview.multiple-results {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 6px;
    }
}

/* REDUCED MOTION */

@media (prefers-reduced-motion: reduce) {
    .tab,
    .generate_btn,
    .result_preview,
    .choice,
    input,
    select {
        transition: none;
    }
}
