.fdm-relief-frontend {
    --fdm-primary: #2271b1;
    --fdm-primary-hover: #135e96;
    --fdm-success: #00a32a;
    --fdm-error: #d63638;
    --fdm-border: #c3c4c7;
    --fdm-bg: #f6f7f7;
    --fdm-text: #1d2327;
    --fdm-text-light: #646970;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 600px;
    margin: 0 auto;
}

.fdm-relief-form-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.fdm-relief-form {
    padding: 24px;
}

/* Upload Area */
.fdm-upload-wrapper {
    margin-bottom: 20px;
}

.fdm-upload-area {
    position: relative;
    border: 2px dashed var(--fdm-border);
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--fdm-bg);
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.fdm-upload-area:hover,
.fdm-upload-area.dragover {
    border-color: var(--fdm-primary);
    background: #f0f6fc;
}

.fdm-upload-area svg {
    color: #a7aaad;
    margin-bottom: 12px;
}

.fdm-upload-area .upload-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--fdm-text);
    margin: 0 0 4px;
}

.fdm-upload-area .upload-hint {
    font-size: 13px;
    color: var(--fdm-text-light);
    margin: 0;
}

.fdm-upload-area input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.fdm-upload-area #preview-image {
    display: none;
    max-width: 100%;
    max-height: 250px;
    border-radius: 8px;
}

.fdm-upload-area.has-image #preview-image {
    display: block;
}

.fdm-upload-area.has-image .upload-placeholder {
    display: none;
}

.fdm-upload-area .remove-image {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
}

.fdm-upload-area.has-image .remove-image {
    display: block;
}

.fdm-upload-area .remove-image:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Model Selection */
.fdm-model-selection {
    margin-bottom: 20px;
}

.fdm-model-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--fdm-text);
    margin-bottom: 10px;
}

.fdm-model-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.fdm-model-options-3 {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.fdm-model-options-4 {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.fdm-model-option {
    cursor: pointer;
}

.fdm-model-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.fdm-model-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 8px;
    background: var(--fdm-bg);
    border: 2px solid var(--fdm-border);
    border-radius: 10px;
    transition: all 0.2s;
    text-align: center;
    position: relative;
    min-height: 100px;
}

.fdm-model-option input[type="radio"]:checked + .fdm-model-card {
    border-color: var(--fdm-primary);
    background: #f0f6fc;
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.15);
}

.fdm-model-card:hover {
    border-color: var(--fdm-primary);
}

.fdm-model-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 50%;
    margin-bottom: 6px;
    color: var(--fdm-primary);
}

.fdm-model-icon svg {
    width: 20px;
    height: 20px;
}

.fdm-model-option input[type="radio"]:checked + .fdm-model-card .fdm-model-icon {
    background: var(--fdm-primary);
    color: #fff;
}

.fdm-model-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--fdm-text);
    margin-bottom: 2px;
}

.fdm-model-desc {
    font-size: 10px;
    color: var(--fdm-text-light);
    line-height: 1.3;
}

.fdm-model-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    border-radius: 10px;
    text-transform: uppercase;
}

.fdm-badge-recommended {
    background: var(--fdm-success);
    color: #fff;
}

.fdm-badge-fast {
    background: #6c5ce7;
    color: #fff;
}

.fdm-badge-balanced {
    background: #f0ad4e;
    color: #fff;
}

.fdm-badge-quality {
    background: #e84393;
    color: #fff;
}

.fdm-badge-slow {
    background: #636e72;
    color: #fff;
}

.fdm-badge-stable {
    background: #00b894;
    color: #fff;
}

.fdm-badge-metric {
    background: #0984e3;
    color: #fff;
}

.fdm-badge-apple {
    background: #2d3436;
    color: #fff;
}

@media (max-width: 500px) {
    .fdm-model-options,
    .fdm-model-options-3,
    .fdm-model-options-4 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 350px) {
    .fdm-model-options,
    .fdm-model-options-3,
    .fdm-model-options-4 {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 501px) and (max-width: 700px) {
    .fdm-model-options-3 {
        grid-template-columns: 1fr 1fr;
    }
    .fdm-model-options-3 .fdm-model-option:last-child {
        grid-column: span 2;
    }
    .fdm-model-options-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 701px) {
    .fdm-model-options-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Settings Panel */
.fdm-settings-panel {
    margin-bottom: 20px;
}

.fdm-settings-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: var(--fdm-bg);
    border: 1px solid var(--fdm-border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--fdm-text);
    transition: all 0.2s;
}

.fdm-settings-toggle:hover {
    background: #eee;
}

.fdm-settings-content {
    display: none;
    padding: 16px 20px;
    border: 1px solid var(--fdm-border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    background: #fafafa;
}

.fdm-settings-content.open {
    display: block;
}

/* Settings Grid - Clean 2-column layout */
.fdm-settings-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px 20px;
    align-items: center;
}

.fdm-settings-grid > label {
    font-size: 14px;
    font-weight: 500;
    color: var(--fdm-text);
    white-space: nowrap;
}

.fdm-setting-input {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}

.fdm-setting-input input[type="number"] {
    width: 70px;
    padding: 8px 10px;
    border: 1px solid var(--fdm-border);
    border-radius: 6px;
    text-align: center;
    font-size: 14px;
    background: #fff;
}

.fdm-setting-input input[type="number"]:focus {
    border-color: var(--fdm-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15);
}

.fdm-setting-input .fdm-unit {
    font-size: 13px;
    color: var(--fdm-text-light);
    width: 24px;
    text-align: left;
}

.fdm-setting-input select {
    padding: 8px 12px;
    border: 1px solid var(--fdm-border);
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    color: var(--fdm-text);
    min-width: 100px;
}

.fdm-setting-input select:focus {
    border-color: var(--fdm-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15);
}

.fdm-setting-input input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--fdm-primary);
    cursor: pointer;
}

.fdm-setting-hint {
    font-size: 11px;
    color: var(--fdm-text-light);
    font-style: italic;
}

/* Slider Input */
.fdm-slider-input {
    display: flex;
    align-items: center;
    gap: 12px;
}

.fdm-slider-input input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 120px;
    height: 6px;
    background: var(--fdm-border);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.fdm-slider-input input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--fdm-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.fdm-slider-input input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(34, 113, 177, 0.3);
}

.fdm-slider-input input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--fdm-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.fdm-slider-value {
    min-width: 24px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--fdm-text);
}

/* Border Settings (conditional display) */
.fdm-border-settings {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px 20px;
    align-items: center;
    margin-top: 8px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid var(--fdm-border);
}

.fdm-border-settings > label {
    font-size: 14px;
    font-weight: 500;
    color: var(--fdm-text);
    white-space: nowrap;
}

/* Mobile: keep grid but adjust */
@media (max-width: 400px) {
    .fdm-settings-grid {
        gap: 10px 12px;
    }

    .fdm-setting-input input[type="number"] {
        width: 60px;
        padding: 6px 8px;
    }

    .fdm-setting-input select {
        min-width: 80px;
        padding: 6px 8px;
    }
}

/* Generate Button */
.fdm-generate-btn {
    width: 100%;
    padding: 16px 24px;
    background: var(--fdm-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.fdm-generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Progress */
.fdm-progress {
    display: none;
    padding: 40px 24px;
    text-align: center;
}

.fdm-progress.active {
    display: block;
}

.fdm-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--fdm-bg);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 16px;
}

.fdm-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--fdm-primary), var(--fdm-primary-hover));
    border-radius: 3px;
    animation: progress-indeterminate 1.5s infinite ease-in-out;
}

@keyframes progress-indeterminate {
    0% { width: 0%; margin-left: 0%; }
    50% { width: 60%; margin-left: 20%; }
    100% { width: 0%; margin-left: 100%; }
}

.fdm-progress-text {
    color: var(--fdm-text-light);
    font-size: 14px;
    margin: 0;
}

/* Result */
.fdm-result {
    display: none;
    padding: 24px;
}

.fdm-result.active {
    display: block;
}

.fdm-result-header {
    text-align: center;
    margin-bottom: 20px;
}

.fdm-result-header h3 {
    color: var(--fdm-success);
    font-size: 20px;
    margin: 0 0 8px;
}

.fdm-result-header p {
    color: var(--fdm-text-light);
    font-size: 14px;
    margin: 0;
}

/* 3D Viewer */
.fdm-3d-viewer-container {
    position: relative;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
}

#fdm-3d-viewer {
    width: 100%;
    height: 350px;
    cursor: grab;
}

#fdm-3d-viewer:active {
    cursor: grabbing;
}

.fdm-viewer-controls {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
}

.fdm-viewer-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
}

.fdm-viewer-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.fdm-viewer-btn svg {
    width: 18px;
    height: 18px;
}

/* Model Info */
.fdm-model-info {
    background: var(--fdm-bg);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
}

.fdm-model-info-item {
    text-align: center;
}

.fdm-model-info-item .label {
    font-size: 12px;
    color: var(--fdm-text-light);
    display: block;
    margin-bottom: 4px;
}

.fdm-model-info-item .value {
    font-size: 16px;
    font-weight: 600;
    color: var(--fdm-text);
}

/* Order Section */
.fdm-order-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#order-buttons-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.fdm-no-buttons {
    color: var(--fdm-text-light);
    font-style: italic;
    margin: 0;
}

.fdm-order-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 16px 32px;
    background: linear-gradient(135deg, var(--fdm-success) 0%, #00852a 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(0, 163, 42, 0.3);
}

.fdm-order-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 163, 42, 0.4);
}

.fdm-order-btn svg {
    transition: transform 0.2s;
}

.fdm-order-btn:hover svg {
    transform: translateX(4px);
}

.fdm-new-btn {
    padding: 10px 20px;
    background: transparent;
    color: var(--fdm-primary);
    border: 1px solid var(--fdm-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.fdm-new-btn:hover {
    background: var(--fdm-primary);
    color: #fff;
}

/* Error */
.fdm-error {
    display: none;
    padding: 40px 24px;
    text-align: center;
}

.fdm-error.active {
    display: block;
}

.fdm-error svg {
    color: var(--fdm-error);
    margin-bottom: 16px;
}

.fdm-error p {
    color: var(--fdm-error);
    margin: 0 0 20px;
}

.fdm-retry-btn {
    padding: 12px 24px;
    background: var(--fdm-error);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.fdm-retry-btn:hover {
    background: #b32d2e;
}

/* Hide form when processing/done */
.fdm-relief-form.hidden {
    display: none;
}

/* Progress hint */
.fdm-progress-hint {
    font-size: 12px;
    color: var(--fdm-text-light);
    margin: 8px 0 0;
    opacity: 0.7;
}

/* Info Box */
.fdm-info-box {
    margin-top: 24px;
    padding: 20px;
    background: #f0f6fc;
    border-radius: 12px;
    border: 1px solid #c5d9ed;
}

.fdm-info-box h4 {
    margin: 0 0 12px;
    color: var(--fdm-primary);
    font-size: 16px;
}

.fdm-info-box ol {
    margin: 0;
    padding-left: 20px;
}

.fdm-info-box li {
    margin-bottom: 8px;
    color: var(--fdm-text);
    font-size: 14px;
    line-height: 1.5;
}

.fdm-info-box li:last-child {
    margin-bottom: 0;
}

.fdm-info-box strong {
    color: var(--fdm-primary);
}

/* Generate button with icon */
.fdm-generate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.fdm-generate-btn .btn-icon {
    display: flex;
    align-items: center;
}

.fdm-generate-btn .btn-icon svg {
    width: 20px;
    height: 20px;
}

/* Debug Button */
.fdm-debug-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--fdm-border);
    background: var(--fdm-bg);
    color: var(--fdm-text-light);
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-left: 8px;
}

.fdm-debug-btn:hover {
    background: var(--fdm-primary);
    color: white;
    border-color: var(--fdm-primary);
}

/* Debug Modal */
.fdm-debug-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.fdm-debug-modal.active {
    display: flex;
}

.fdm-debug-modal-content {
    background: white;
    border-radius: 12px;
    max-width: 90%;
    max-height: 90%;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.fdm-debug-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--fdm-border);
}

.fdm-debug-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--fdm-text);
}

.fdm-debug-modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    color: var(--fdm-text-light);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.fdm-debug-modal-close:hover {
    background: var(--fdm-bg);
    color: var(--fdm-text);
}

.fdm-debug-modal-body {
    padding: 20px;
    overflow: auto;
    max-height: calc(90vh - 80px);
}

.fdm-debug-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
}

.fdm-debug-loading .fdm-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--fdm-border);
    border-top-color: var(--fdm-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.fdm-debug-loading p {
    margin-top: 16px;
    color: var(--fdm-text-light);
}

#debug-image {
    display: none;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid var(--fdm-border);
}

#debug-image.loaded {
    display: block;
}

.fdm-debug-legend {
    display: none;
    margin-top: 16px;
    padding: 16px;
    background: var(--fdm-bg);
    border-radius: 8px;
}

.fdm-debug-legend.visible {
    display: block;
}

.fdm-debug-legend h4 {
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--fdm-text);
}

.fdm-debug-legend ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.fdm-debug-legend li {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--fdm-text);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-yellow {
    background: #d4a84a;
}

.legend-green {
    background: #4caf50;
}

.legend-red {
    background: #e57373;
}

.legend-blue {
    background: #64b5f6;
}
