:root {
    --bg-color: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #eef4fb;
    --surface-muted: #e5edf6;
    --border: #d6e0ec;
    --primary: #3158d4;
    --primary-hover: #2547b9;
    --secondary: #087f5b;
    --secondary-hover: #066d4e;
    --danger: #c92a2a;
    --danger-soft: #fff0f0;
    --text-primary: #172033;
    --text-secondary: #506079;
    --text-muted: #78869b;
    --focus: rgba(49, 88, 212, 0.2);
    --radius-sm: 6px;
    --radius-md: 8px;
    --shadow: 0 18px 40px rgba(27, 39, 63, 0.11);
    --transition: 160ms ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: #182337;
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand .icon-lg {
    color: #8dd7bd;
    font-size: 2rem;
}

.brand h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.brand p,
.status-note {
    color: #adbad0;
    font-size: 0.88rem;
}

.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 28px 36px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.eyebrow {
    color: var(--secondary);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1 {
    max-width: 780px;
    font-size: 2rem;
    line-height: 1.18;
    letter-spacing: 0;
}

.content-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 28px 36px 40px;
}

.w-full {
    width: 100%;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    color: var(--text-primary);
    background: var(--surface);
    cursor: pointer;
    font-weight: 700;
    transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

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

.btn-secondary {
    background: var(--secondary);
    color: #ffffff;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
}

.btn-outline {
    border-color: var(--border);
    background: var(--surface);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-icon {
    width: 40px;
    min-height: 40px;
    padding: 0;
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.btn-ghost-danger {
    background: transparent;
    color: var(--danger);
}

.empty-state {
    display: flex;
    min-height: 360px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 48px 24px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
}

.empty-icon {
    display: grid;
    width: 64px;
    height: 64px;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--primary);
    font-size: 2.1rem;
}

.empty-state h2 {
    font-size: 1.45rem;
}

.empty-state p {
    max-width: 520px;
    color: var(--text-secondary);
}

.pset-container {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.pset-card,
.preview-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
}

.pset-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--border);
}

.pset-title-group {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
}

.step-badge {
    display: grid;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
}

.pset-card-body {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 22px;
}

.form-grid {
    display: grid;
    grid-template-columns: minmax(170px, 0.7fr) minmax(280px, 2fr);
    gap: 22px;
}

.field-stack {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 8px;
}

.field-stack label {
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

.input-ghost,
.input-standard {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-ghost {
    min-height: 42px;
    padding: 9px 12px;
    font-size: 1.08rem;
    font-weight: 700;
}

.input-standard {
    min-height: 40px;
    padding: 8px 10px;
}

.input-ghost:focus,
.input-standard:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus);
}

.is-invalid {
    border-color: var(--danger);
}

.field-error {
    display: none;
    color: var(--danger);
    font-size: 0.78rem;
}

.field-error.is-visible {
    display: block;
}

.radio-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.radio-label input {
    position: absolute;
    opacity: 0;
}

.radio-label span {
    display: flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 800;
}

.radio-label input:checked + span {
    border-color: var(--primary);
    background: #edf1ff;
    color: var(--primary);
}

.chip-list,
.selected-elements {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip,
.selected-tag {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-secondary);
    padding: 7px 10px;
    cursor: pointer;
    font-size: 0.86rem;
    font-weight: 700;
}

.chip.is-selected {
    border-color: var(--primary);
    background: #edf1ff;
    color: var(--primary);
}

.selected-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-soft);
    color: var(--text-primary);
}

.custom-class-row {
    display: flex;
    gap: 8px;
}

.properties-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.properties-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.properties-header h3 {
    font-size: 1.05rem;
}

.properties-header p {
    color: var(--text-secondary);
    font-size: 0.86rem;
}

.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.properties-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.properties-table th,
.properties-table td {
    border-bottom: 1px solid var(--border);
    padding: 12px;
    text-align: left;
    vertical-align: top;
}

.properties-table th {
    background: var(--surface-soft);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.properties-table tr:last-child td {
    border-bottom: 0;
}

.actions-col {
    width: 54px;
    text-align: center;
}

.preview-section {
    margin-top: 22px;
    overflow: hidden;
}

.preview-section summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    cursor: pointer;
    font-weight: 800;
}

.preview-section summary::marker {
    color: var(--primary);
}

.preview-section summary span:first-child {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

#previewSummary {
    color: var(--text-secondary);
    font-size: 0.86rem;
    font-weight: 700;
}

.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--surface-soft);
}

.preview-toolbar p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.code-block {
    max-height: 420px;
    overflow: auto;
    padding: 20px;
    background: #111827;
    color: #dbeafe;
    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 0.86rem;
    white-space: pre-wrap;
    tab-size: 4;
}

.fade-in {
    animation: fadeIn 180ms ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
    }

    .sidebar-actions {
        width: min(430px, 100%);
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .status-note {
        grid-column: 1 / -1;
    }

    .main-header {
        padding: 22px 20px;
    }

    #mobileAddPsetBtn {
        display: none;
    }

    .content-scroll {
        padding: 20px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 620px) {
    h1 {
        font-size: 1.55rem;
    }

    .sidebar,
    .main-header,
    .properties-header,
    .preview-toolbar,
    .custom-class-row {
        align-items: stretch;
        flex-direction: column;
    }

    .sidebar-actions {
        width: 100%;
        grid-template-columns: 1fr;
    }

    .pset-card-header {
        padding: 16px;
    }

    .pset-card-body {
        padding: 16px;
    }

    .properties-table,
    .properties-table thead,
    .properties-table tbody,
    .properties-table tr,
    .properties-table td {
        display: block;
        min-width: 0;
        width: 100%;
    }

    .properties-table thead {
        display: none;
    }

    .properties-table tr {
        border-bottom: 1px solid var(--border);
        padding: 10px;
    }

    .properties-table tr:last-child {
        border-bottom: 0;
    }

    .properties-table td {
        border: 0;
        padding: 8px 0;
    }

    .properties-table td::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 5px;
        color: var(--text-secondary);
        font-size: 0.76rem;
        font-weight: 800;
        text-transform: uppercase;
    }

    .properties-table .actions-col {
        text-align: left;
    }

    .properties-table .actions-col::before {
        content: "";
        display: none;
    }
}
