:root {
    --machine-primary: #0f62d6;
    --machine-complete: #0f766e;
    --machine-surface: #f5f8fc;
    --machine-text: #172033;
    --machine-muted: #5f6b7a;
}

.machine-setup-modal .machine-setup-content {
    width: min(720px, calc(100vw - 24px));
    max-height: min(90vh, 820px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 22px;
}

.machine-setup-progress {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 18px;
    padding: 0;
    list-style: none;
    color: #64748b;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.machine-setup-progress li {
    min-width: 0;
    padding: 8px 4px;
    border-bottom: 3px solid #cbd5e1;
}

.machine-setup-progress li.active,
.machine-setup-progress li[aria-current="step"] {
    color: #075fdf;
    border-color: #0b6cff;
}

.machine-setup-step h3 {
    margin: 0 0 14px;
    color: #172033;
    font-size: 17px;
}

.machine-setup-step {
    min-width: 0;
}

.machine-setup-group,
.machine-monitor-card {
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid #dbe4ef;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(15, 35, 65, 0.05);
}

.machine-group-heading {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.machine-group-heading > span {
    display: grid;
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 9px;
    background: #eaf2ff;
    color: var(--machine-primary);
    font-size: 12px;
    font-weight: 900;
}

.machine-group-heading strong,
.machine-group-heading small {
    display: block;
}

.machine-group-heading strong {
    color: var(--machine-text);
    font-size: 14px;
}

.machine-group-heading small,
.machine-reusable-panel small {
    margin-top: 3px;
    color: var(--machine-muted);
    font-size: 12px;
    line-height: 1.45;
}

.machine-choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.machine-choice-grid button,
.machine-reusable-suggestion,
.machine-add-reusable {
    min-height: 44px;
    border: 1px solid currentColor;
    border-radius: 10px;
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.machine-choice-grid button {
    position: relative;
    padding: 8px 10px;
    opacity: 0.78;
}

.machine-choice-grid button.selected,
.machine-choice-grid button[aria-checked="true"] {
    opacity: 1;
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--machine-primary);
}

.machine-choice-grid button[aria-checked="true"]::after {
    content: "✓";
    margin-left: 6px;
}

.machine-reusable-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 4px 0 10px;
}

.machine-reusable-suggestions[hidden] {
    display: none;
}

.machine-reusable-suggestion {
    max-width: 100%;
    min-height: 38px;
    padding: 7px 10px;
    overflow-wrap: anywhere;
    text-align: left;
}

.machine-add-reusable {
    width: 100%;
    padding: 8px 12px;
    border-style: dashed;
    border-color: #75a7eb;
    background: #f8fbff;
    color: #075fdf;
}

.machine-reusable-panel {
    margin-top: 9px;
    padding: 11px;
    border: 1px solid #93c5fd;
    border-radius: 11px;
    background: #eff6ff;
}

.machine-reusable-panel[hidden] {
    display: none;
}

.machine-reusable-panel > label {
    display: block;
    margin-bottom: 6px;
    color: #334155;
    font-size: 13px;
    font-weight: 800;
}

.machine-reusable-error {
    margin-top: 7px;
    color: #b42318;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.45;
}

.machine-reusable-error[hidden] {
    display: none;
}

.machine-field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.machine-new-department,
.machine-new-type {
    margin-top: 8px;
    padding: 10px;
    border: 1px solid #93c5fd;
    border-radius: 10px;
    background: #eff6ff;
}

.machine-type-control {
    min-width: 0;
}

.machine-type-help {
    display: block;
    margin-top: 5px;
    color: #64748b;
    font-size: 12px;
    line-height: 1.45;
}

.machine-type-error {
    margin-top: 7px;
    color: #b91c1c;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.45;
}

.machine-type-error[hidden],
.machine-new-type[hidden] {
    display: none;
}

.machine-inline-action,
.machine-range-group > div {
    display: flex;
    align-items: center;
    gap: 8px;
}

.machine-inline-action input,
.machine-range-group input {
    min-width: 0;
    flex: 1;
}

.machine-inline-action button,
.machine-apply-recommendation {
    min-height: 44px;
    border: 1px solid #0b6cff;
    border-radius: 9px;
    background: #fff;
    color: #075fdf;
    font-weight: 700;
    cursor: pointer;
}

.machine-inline-action button[data-machine-cancel-type] {
    border-color: #94a3b8;
    color: #475569;
}

.m-type-tag {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    padding: 3px 9px;
    border: 1px solid currentColor;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.25;
    text-overflow: ellipsis;
    vertical-align: middle;
    white-space: nowrap;
}

.tag-lathe { background: #dbeafe; color: #1d4ed8; }
.tag-milling { background: #dcfce7; color: #15803d; }
.tag-grinding { background: #cffafe; color: #0e7490; }
.tag-machining-center { background: #e0e7ff; color: #4338ca; }
.tag-other { background: #e2e8f0; color: #475569; }
.tag-custom { background: #f5f3ff; color: #5b21b6; }

.classification-tag {
    display: inline-block;
    max-width: 100%;
    margin: 2px 0 2px 6px;
    padding: 3px 8px;
    border: 1px solid currentColor;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.25;
    overflow-wrap: anywhere;
    vertical-align: middle;
}

.machine-card-meta-block {
    display: grid;
    min-width: 0;
    margin: 0 0 10px 12px;
    gap: 7px;
}

.machine-card-primary-tags {
    display: flex;
    min-width: 0;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.machine-card-primary-tags .m-dept,
.machine-card-primary-tags .m-type-tag {
    margin: 0;
}

.machine-card-classification-list {
    display: grid;
    min-width: 0;
    gap: 5px;
}

.machine-card-classification-line {
    display: grid;
    min-width: 0;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
}

.machine-card-classification-kind {
    color: #64748b;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.machine-card-classification-name {
    min-width: 0;
    color: #334155;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.machine-card-classification-line .classification-tag {
    margin: 0;
    white-space: normal;
}

@media (max-width: 420px) {
    .machine-card-meta-block {
        margin-left: 0;
    }

    .machine-card-classification-line {
        grid-template-columns: 32px minmax(0, 1fr) auto;
    }
}

.material-general { background: #f1f5f9; color: #475569; }
.material-aluminum { background: #dbeafe; color: #1d4ed8; }
.material-copper { background: #f3e8ff; color: #7e22ce; }
.material-cast-iron { background: #fef3c7; color: #92400e; }
.material-stainless { background: #ccfbf1; color: #0f766e; }
.material-other { background: #e2e8f0; color: #475569; }
.oil-full-synthetic { background: #cffafe; color: #0e7490; }
.oil-semi-synthetic { background: #e0e7ff; color: #4338ca; }
.oil-emulsifiable { background: #ccfbf1; color: #0f766e; }
.oil-other { background: #e2e8f0; color: #475569; }

.machine-range-group {
    margin-bottom: 14px;
}

.machine-range-group > span {
    display: block;
    margin-bottom: 6px;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
}

.machine-range-group small {
    display: block;
    margin-top: 5px;
    color: #64748b;
    line-height: 1.5;
}

.machine-recommendation {
    margin-bottom: 8px;
    padding: 10px 12px;
    border-left: 4px solid #22c55e;
    border-radius: 8px;
    background: #f0fdf4;
    color: #166534;
    font-size: 12px;
    line-height: 1.55;
}

.machine-apply-recommendation {
    width: 100%;
    margin-bottom: 14px;
    padding: 7px 10px;
}

.machine-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 44px;
    margin: 4px 0 10px;
    font-weight: 700;
    cursor: pointer;
}

.machine-toggle input {
    width: 20px;
    height: 20px;
}

.machine-review {
    padding: 14px;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    background: #f8fbff;
    color: #334155;
    font-size: 13px;
    line-height: 1.75;
}

.machine-setup-error {
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 2px solid #e11d48;
    border-radius: 9px;
    background: #fff1f2;
    color: #9f1239;
    font-size: 13px;
    font-weight: 700;
}

.machine-setup-actions {
    position: sticky;
    bottom: -22px;
    display: flex;
    gap: 10px;
    margin: 20px -22px -22px;
    padding: 12px 22px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid #e2e8f0;
    background: rgba(255, 255, 255, 0.98);
}

.machine-setup-actions button {
    flex: 1;
    min-height: 46px;
    margin: 0;
    border-radius: 10px;
    font-weight: 800;
}

.machine-setup-actions .btn-primary,
.machine-setup-actions .btn-save {
    border: 0;
    background: #0b6cff;
    color: #fff;
}

.machine-setup-actions .btn-secondary {
    border: 1px solid #94a3b8;
    background: #fff;
    color: #334155;
}

[data-machine-setup-form] [aria-invalid="true"] {
    border-color: #e11d48 !important;
    box-shadow: 0 0 0 2px rgba(225, 29, 72, 0.14);
}

[data-machine-setup-form] :focus-visible {
    outline: 3px solid #f59e0b;
    outline-offset: 2px;
}

@media (max-width: 480px) {
    .machine-setup-modal .machine-setup-content {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
        padding: 18px 14px;
    }

    .machine-field-grid {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .machine-setup-group,
    .machine-monitor-card {
        padding: 12px;
    }

    .machine-choice-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .machine-inline-action {
        flex-wrap: wrap;
    }

    .machine-inline-action input {
        flex-basis: 100%;
    }

    .machine-inline-action button {
        flex: 1;
    }

    .machine-setup-progress {
        font-size: 11px;
    }

    .machine-setup-actions {
        bottom: -18px;
        margin: 18px -14px -18px;
        padding-right: 14px;
        padding-left: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .machine-setup-modal *,
    .machine-setup-modal *::before,
    .machine-setup-modal *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
