:root {
    --gap: 10px;
    --fg: #222;
    --muted: #666;
    --bg: #f5f5f5;
    --card: #fff;
    --bd: #ddd;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font: 15px/1.5 system-ui, Arial, sans-serif;
    color: var(--fg);
    background: var(--bg);
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-lang {
    padding: 6px 16px;
    font-size: 14px;
    font-weight: 600;
    background: #f0f4f8;
    border: 2px solid #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    color: #334155;
    transition: background 0.15s, border-color 0.15s;
}

.btn-lang:hover {
    background: #e2e8f0;
    border-color: #64748b;
}

header {
    padding: 16px;
    border-bottom: 2px solid var(--bd);
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

h1 {
    margin: 0 0 8px 0;
    font-size: 22px;
    color: #111;
}

.progress-bar {
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--info));
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 13px;
    color: var(--muted);
    margin-top: 4px;
}

main {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.block {
    background: var(--card);
    border: 1px solid var(--bd);
    padding: 20px;
    border-radius: 10px;
    margin: 16px 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.block h2 {
    margin: 0 0 16px 0;
    font-size: 18px;
    color: #111;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 8px;
}

.card {
    background: #fafafa;
    border: 1px solid #e5e7eb;
    padding: 16px;
    border-radius: 8px;
    margin: 12px 0;
}

.card.step {
    background: #fff;
    border-left: 4px solid var(--info);
}

/* Part cards — blue left border */
.card.entity {
    background: #eff6ff;
    border-left: 3px solid var(--info);
}

/* Auxiliary Medium cards — amber left border */
.card.entity.medium {
    border-left: 3px solid #f59e0b;
    background: #fffbeb;
}

/* Auxiliary Tool cards — orange left border */
.card.entity.tool {
    border-left: 3px solid #f97316;
    background: #fff7ed;
}

/* Inherited Part cards — teal left border */
.card.entity.inherited {
    border-left: 3px solid #0d9488;
    background: #f0fdfa;
}

/* Part ID badge — small grey pill */
.part-id-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    padding: 1px 7px;
    letter-spacing: 0.03em;
}

/* Inherited origin tag — teal italic */
.part-origin {
    font-size: 11px;
    color: #0d9488;
    font-style: italic;
}

/* Entity section subheadings */
.entity-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 14px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #f0f0f0;
}

.entity-section-header h4 {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin: 8px 0;
}

.grid-2,
.grid-3,
.grid-4 {
    display: grid;
    gap: var(--gap);
}

.grid-2 {
    grid-template-columns: 1fr 1fr;
}

.grid-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.grid-4 {
    grid-template-columns: 2fr 1fr 1fr auto;
    align-items: end;
}

.subs-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-remove {
    padding: 8px 12px;
    background: #fee;
    color: #dc2626;
}

label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    font-weight: 500;
}

input,
select,
textarea,
button {
    font: inherit;
    padding: 10px;
    border: 1px solid var(--bd);
    border-radius: 6px;
    background: #fff;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--info);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea {
    resize: vertical;
}

button {
    cursor: pointer;
    background: #f6f6f6;
    font-weight: 500;
    transition: all 0.2s;
}

button:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
}

button.primary {
    background: var(--info);
    color: white;
    border: none;
}

button.primary:hover {
    background: #2563eb;
}

.step-toolbar {
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-move-up,
.btn-move-down {
    padding: 4px 10px;
    font-size: 12px;
    background: #f0f4f8;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    cursor: pointer;
    color: #475569;
}

.btn-move-up:disabled,
.btn-move-down:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-move-up:hover:not(:disabled),
.btn-move-down:hover:not(:disabled) {
    background: #e2e8f0;
}

.btn-remove-step {
    background: #fee;
    color: #dc2626;
    border-color: #fca5a5;
}

.btn-add {
    background: #f0f9ff;
    border-color: var(--info);
    color: var(--info);
}

/* Interface Groups */
.interface-group {
    margin: 20px 0;
}

.interface-group h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.interface-group.always {
    border-left: 3px solid var(--success);
    padding-left: 12px;
}

.interface-group.always h4::before {
    content: "✓";
    color: var(--success);
    font-weight: bold;
}

.interface-group.conditional {
    border-left: 3px solid var(--info);
    padding-left: 12px;
}

.interface-group.conditional h4::before {
    content: "🔵";
}

.interface-group.optional {
    border-left: 3px solid var(--warning);
    padding-left: 12px;
    opacity: 0.85;
}

.interface-group.optional h4::before {
    content: "⚠";
}

/* Validation Badges */
.validation-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

.validation-badge.success {
    background: #d1fae5;
    color: #065f46;
}

.validation-badge.warning {
    background: #fef3c7;
    color: #92400e;
}

.validation-badge.error {
    background: #fee2e2;
    color: #991b1b;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    border-left: 4px solid;
}

.alert.info {
    background: #dbeafe;
    border-color: var(--info);
    color: #1e40af;
}

.alert.warning {
    background: #fef3c7;
    border-color: var(--warning);
    color: #92400e;
}

.alert.error {
    background: #fee2e2;
    border-color: var(--error);
    color: #991b1b;
}

.step-title {
    margin: 0;
    font-size: 16px;
}

.kpi-block {
    margin-top: 14px;
}

.kpi-block h4 {
    margin-bottom: 10px;
}

footer {
    text-align: center;
    padding: 24px;
    color: var(--muted);
    font-size: 13px;
}

.tooltip {
    position: relative;
    cursor: help;
    border-bottom: 1px dotted var(--muted);
}

#validation-summary {
    position: sticky;
    top: 100px;
    z-index: 5;
}

/* ── Step indicator badge ────────────────────────────────── */
.step-indicator {
    display: inline-flex;
    align-items: center;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    background: var(--info);
    color: #fff;
    letter-spacing: 0.3px;
}

/* ── Step 1 layout ───────────────────────────────────────── */
.step1-main {
    padding: 20px;
    max-width: 860px;
    margin: 0 auto;
}

.step1-main .block {
    margin: 16px 0;
}

.step1-main label {
    margin-bottom: 10px;
}

.req {
    color: var(--error);
    font-weight: 700;
    margin-left: 2px;
}

.muted {
    color: var(--muted);
    font-size: 12px;
}

/* Success state */
.step1-success {
    border-left: 4px solid var(--success);
    background: #f0fdf4;
}

.step1-success h2 {
    color: #065f46;
    border-bottom-color: #bbf7d0;
}

/* Back button in Step 2 header */
.btn-back {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    background: #f0f4f8;
    border: 2px solid #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    color: #334155;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.btn-back:hover {
    background: #e2e8f0;
    border-color: #64748b;
}

/* Responsive */
@media (max-width: 768px) {

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* ── Entity Register Panel ────────────────────────────────────────────────── */

.entity-register {
    background: #f8faff;
    border: 1px solid #dbeafe;
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

/* Tab bar */
.reg-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid #dbeafe;
    background: #eff6ff;
}

.reg-tab {
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 600;
    background: transparent;
    border: none;
    border-right: 1px solid #dbeafe;
    cursor: pointer;
    color: var(--muted);
    transition: background 0.12s, color 0.12s;
}

.reg-tab:last-child { border-right: none; }

.reg-tab:hover:not(:disabled) {
    background: #dbeafe;
    color: #1e40af;
}

.reg-tab.active {
    background: #fff;
    color: #1d4ed8;
    border-bottom: 2px solid #3b82f6;
    margin-bottom: -1px;
}

.reg-tab:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Panel body */
.reg-body {
    padding: 10px 14px 12px;
}

.reg-empty {
    font-size: 13px;
    color: var(--muted);
    font-style: italic;
    margin: 6px 0;
}

/* Compact register table */
.reg-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 8px;
}

.reg-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 8px;
    border-bottom: 1px solid #e5e7eb;
}

.reg-table td {
    padding: 5px 8px;
    border-bottom: 1px solid #f0f4f8;
    vertical-align: middle;
}

.reg-table tr:last-child td { border-bottom: none; }

.reg-table tr.reg-part-row:hover td { background: #f0f6ff; }

/* Icon action buttons in the table */
.reg-btn-edit,
.reg-btn-delete {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.1s;
}

.reg-btn-edit:hover  { background: #dbeafe; }
.reg-btn-delete:hover:not(:disabled) { background: #fee2e2; }
.reg-btn-delete:disabled { opacity: 0.3; cursor: not-allowed; }

/* Inline form row */
.reg-form-row td {
    background: #fefce8;
    border: 1px solid #fde68a;
    padding: 10px 12px;
}

.reg-inline-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.reg-inline-form label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.reg-inline-form input {
    font-size: 13px;
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    min-width: 120px;
}

.reg-form-btns {
    display: flex;
    gap: 8px;
    align-items: center;
    padding-bottom: 1px;
}

/* Add row at bottom of panel */
.reg-add-row {
    margin-top: 4px;
}

.reg-add-row button {
    font-size: 13px;
    padding: 5px 14px;
}

/* ── Part Selector (Step 3) ──────────────────────────────────────────────── */

/* Wrapper inside the part card — replaces old attribute grid */
.part-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

/* Register dropdown row */
.part-selector-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.part-selector-row label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    margin: 0;
}

.part-selector-row select {
    flex: 1;
    font-size: 13px;
}

/* Compact badge: "PART_001 — housing | S235 | 42g" */
.part-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 13px;
    line-height: 1.3;
    flex-wrap: wrap;
}

.part-badge-id {
    font-weight: 700;
    color: #1d4ed8;
    font-size: 12px;
    letter-spacing: 0.03em;
}

.part-badge-sep {
    color: #94a3b8;
    font-size: 12px;
}

.part-badge-attr {
    color: #374151;
}

.part-badge-none {
    color: var(--muted);
    font-style: italic;
    font-size: 13px;
    padding: 4px 0;
}

/* Override toggle button */
.btn-override {
    font-size: 12px;
    padding: 4px 10px;
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: 4px;
    cursor: pointer;
    color: #92400e;
    align-self: flex-start;
    transition: background 0.12s;
}

.btn-override:hover { background: #fef9c3; }
.btn-override.active { background: #fef08a; border-color: #f59e0b; }

/* Override panel — hidden by default, shown when .open */
.override-panel {
    display: none;
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: 6px;
    padding: 10px 12px;
    margin-top: 2px;
}

.override-panel.open { display: block; }

.override-panel-footer {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.btn-override-reset {
    font-size: 12px;
    padding: 3px 10px;
    background: transparent;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    color: var(--muted);
}

.btn-override-reset:hover { background: #f3f4f6; }