/* ===== CSS Variables ===== */
:root {
    --primary: #c8102e;
    --primary-hover: #a00d24;
    --bg: #f5f5f5;
    --bg-panel: #ffffff;
    --text: #333333;
    --text-secondary: #666666;
    --border: #ddd;
    --border-focus: #c8102e;
    --error: #d32f2f;
    --warning: #f57c00;
    --success: #388e3c;
    --radius: 6px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --input-panel-width: 380px;
    --header-height: 56px;
}

/* ===== Reset ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', 'Meiryo', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.app-header {
    height: var(--header-height);
    background: #fff;
    border-bottom: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: var(--shadow);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    height: 32px;
    width: auto;
}

.header-left h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.toggle-group {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.toggle-btn {
    padding: 4px 12px;
    border: none;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.toggle-btn.active {
    background: var(--primary);
    color: #fff;
}

.toggle-btn:hover:not(.active) {
    background: #f0f0f0;
}

/* ===== Main Layout ===== */
.app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== Input Panel (Left) ===== */
.input-panel {
    width: var(--input-panel-width);
    min-width: var(--input-panel-width);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.step-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.step-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-num {
    background: var(--primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 10px;
}

/* ===== Process Image (STEP2 icon) ===== */
.process-image {
    text-align: center;
    margin-bottom: 12px;
}
.process-image .process-icon {
    max-width: 100%;
    max-height: 140px;
    object-fit: contain;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* ===== Mount Type Images (STEP3) ===== */
.mount-type-images {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* ===== Process Type Images (STEP1) ===== */
.process-type-images {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.process-type-card,
.mount-type-card {
    flex: 1;
    text-align: center;
    padding: 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    opacity: 0.55;
    transition: border-color 0.2s, opacity 0.2s, box-shadow 0.2s;
    background: var(--surface);
}
.process-type-card:hover,
.mount-type-card:hover {
    opacity: 0.85;
}
.process-type-card.active,
.mount-type-card.active {
    border-color: var(--accent);
    opacity: 1;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
.process-type-card img,
.mount-type-card img {
    max-width: 100%;
    max-height: 108px;
    object-fit: contain;
}
.process-type-label,
.mount-type-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
    color: var(--text-secondary);
}
.process-type-card.active .process-type-label,
.mount-type-card.active .mount-type-label {
    color: var(--accent);
}

.mount-type-card.disabled {
    opacity: 0.25;
    cursor: not-allowed;
    pointer-events: auto;
    border-color: var(--border);
    box-shadow: none;
}

.mount-type-card.disabled:hover {
    opacity: 0.25;
    box-shadow: none;
}

.form-group > label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.input-with-unit {
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-with-unit input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.input-with-unit input:focus {
    border-color: var(--border-focus);
}

.input-with-unit input.has-error {
    border-color: var(--error);
    background: #fff5f5;
}

.unit-label {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 28px;
}

select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    background: #fff;
}

select:focus {
    border-color: var(--border-focus);
}

/* ===== Radio / Checkbox ===== */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.radio-group.horizontal {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
}

.radio-label, .checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.radio-label input, .checkbox-label input {
    accent-color: var(--primary);
}

/* ===== Error Messages ===== */
.error-msg {
    font-size: 12px;
    color: var(--error);
    margin-top: 3px;
    min-height: 16px;
}

/* ===== Field Hints (DC min / Z max guidance) ===== */
.field-hint {
    font-size: 11px;
    color: var(--primary);
    margin-top: 2px;
    min-height: 0;
    line-height: 1.4;
    padding-left: 2px;
    transition: opacity 0.2s;
}

.field-hint:empty {
    display: none;
}

.field-note {
    font-size: 11px;
    color: #e65100;
    margin-bottom: 4px;
    line-height: 1.4;
    padding-left: 2px;
}

/* ===== Standard R Chip Buttons ===== */
.standard-r-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 4px;
    min-height: 0;
    transition: opacity 0.3s;
}

.standard-r-chips:empty {
    display: none;
}

.standard-r-chips .chip-label {
    font-size: 11px;
    color: var(--text-secondary);
    width: 100%;
    margin-bottom: 1px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.standard-r-chips .chip-label .chip-icon {
    display: inline-block;
    width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    background: var(--success);
    color: #fff;
    border-radius: 50%;
    font-size: 9px;
    font-weight: 700;
    flex-shrink: 0;
}

.chip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 500;
    border: 1.5px solid var(--success);
    border-radius: 14px;
    background: #fff;
    color: var(--success);
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.2;
}

.chip-btn:hover {
    background: var(--success);
    color: #fff;
    box-shadow: 0 1px 4px rgba(56, 142, 60, 0.3);
}

.chip-btn.active {
    background: var(--success);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(56, 142, 60, 0.3);
}

/* ===== Standard Cutter Recommend (TungMiniSlit) ===== */
.recommend-section {
    background: #fffbe6;
    border: 1.5px solid #ffc107;
    border-radius: 8px;
    padding: 8px 10px;
    margin: -2px 0 6px 0;
}

.recommend-section.hidden {
    display: none;
}

.recommend-label {
    font-size: 11.5px;
    color: #795548;
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.recommend-icon {
    color: #ffc107;
    font-size: 14px;
}

.recommend-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.recommend-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border: 1.5px solid #ff9800;
    border-radius: 14px;
    background: #fff;
    color: #e65100;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.3;
    white-space: nowrap;
}

.recommend-chip:hover {
    background: #ff9800;
    color: #fff;
    box-shadow: 0 1px 4px rgba(255, 152, 0, 0.35);
}

.recommend-chip.active {
    background: #ff9800;
    color: #fff;
    font-weight: 600;
    box-shadow: 0 1px 4px rgba(255, 152, 0, 0.35);
}

/* ===== Buttons ===== */
.btn-primary {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-secondary {
    padding: 8px 16px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #f0f0f0;
}

.btn-action {
    padding: 8px 16px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-action:hover:not(:disabled) {
    background: #f0f0f0;
    border-color: var(--primary);
}

.btn-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* PDF Export Button — 目立つ赤ボタン */
.btn-pdf-export {
    padding: 10px 28px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(200, 16, 46, 0.3);
}

.btn-pdf-export:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(200, 16, 46, 0.4);
    transform: translateY(-1px);
}

.btn-pdf-export:disabled {
    background: #ccc;
    color: #888;
    cursor: not-allowed;
    box-shadow: none;
}

/* ===== Result Panel (Right) ===== */
.result-panel {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

/* ===== Result Summary ===== */
.result-summary {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}

.result-summary h3 {
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--primary);
}

.summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
}

.summary-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.summary-label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 100px;
}

.summary-value {
    font-size: 14px;
    font-weight: 600;
    font-family: 'Consolas', 'Courier New', monospace;
    word-break: break-all;
}

.dimension-summary {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    font-family: 'Consolas', 'Courier New', monospace;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ===== Candidate Selection ===== */
.candidate-selection {
    background: #fff8e1;
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    padding: 14px;
}

.candidate-selection h4 {
    font-size: 13px;
    color: var(--warning);
    margin-bottom: 8px;
}

.candidate-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
}

.candidate-option .recommended-badge {
    font-size: 11px;
    background: var(--warning);
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
}

/* ===== Result Error ===== */
.result-error {
    background: #ffebee;
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.error-icon {
    font-size: 20px;
    line-height: 1;
}

.error-content {
    font-size: 13px;
    line-height: 1.5;
}

/* ===== Drawing Preview ===== */
.drawing-preview {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.preview-placeholder {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.svg-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.svg-container svg {
    max-width: 100%;
    max-height: 100%;
    border: 1px solid #eee;
    background: #fff;
}

/* ===== Action Buttons ===== */
.action-buttons {
    display: flex;
    gap: 10px;
}

/* ===== Footer ===== */
.app-footer {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== Dialog Overlay ===== */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.dialog-box {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.dialog-icon {
    font-size: 36px;
    margin-bottom: 12px;
}

.dialog-message {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.dialog-actions .btn-primary {
    width: auto;
    padding: 8px 24px;
}

/* ===== Utility ===== */
.hidden {
    display: none !important;
}

/* ===== Drawing Tabs ===== */
.drawing-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 0;
}

.tab-btn {
    padding: 8px 20px;
    border: 1px solid var(--border);
    border-bottom: none;
    background: #f5f5f5;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius) var(--radius) 0 0;
    transition: all 0.2s;
    position: relative;
    top: 2px;
}

.tab-btn.active {
    background: #fff;
    color: var(--primary);
    font-weight: 600;
    border-color: var(--border);
    border-bottom: 2px solid #fff;
    z-index: 1;
}

.tab-btn:hover:not(.active) {
    background: #eee;
}

/* ===== Standard Product Badge ===== */
.standard-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    background: var(--success);
    color: #fff;
    padding: 2px 8px;
    border-radius: 3px;
    margin-left: 8px;
    vertical-align: middle;
    letter-spacing: 0.5px;
}

/* ===== Standard Product Drawing Stamp ===== */
.standard-stamp {
    font-size: 14px;
    font-weight: bold;
    fill: #388e3c;
}

.standard-stamp-box {
    stroke: #388e3c;
    stroke-width: 1.5;
    fill: #e8f5e9;
    rx: 3;
    ry: 3;
}

/* ===== Responsive: Tablet (≤ 900px) ===== */
@media (max-width: 900px) {
    :root {
        --input-panel-width: 320px;
    }
}

/* ===== Responsive: Mobile (≤ 768px) ===== */
@media (max-width: 768px) {
    /* Header */
    .app-header {
        padding: 0 12px;
        flex-wrap: wrap;
        height: auto;
        min-height: var(--header-height);
        gap: 4px;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .header-left h1 {
        font-size: 13px;
    }

    .logo {
        height: 26px;
    }

    .header-right {
        gap: 8px;
    }

    .toggle-btn {
        padding: 3px 10px;
        font-size: 12px;
    }

    /* Body: allow natural document flow on mobile */
    body {
        display: block;
        min-height: 0;
        height: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Main Layout: vertical stack, no overflow clipping */
    .app-main {
        display: flex;
        flex-direction: column;
        flex: none;
        overflow: visible;
        height: auto;
    }

    /* Input Panel: full width */
    .input-panel {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: none;
        overflow-y: visible;
        padding: 12px;
    }

    /* Result Panel: full width, no internal scroll */
    .result-panel {
        flex: none;
        padding: 12px;
        min-height: auto;
        height: auto;
        overflow-y: visible;
    }

    /* Drawing Preview: auto height to fit SVG fully */
    .drawing-preview {
        flex: none;
        min-height: 0;
        max-height: none;
        height: auto;
        overflow: visible;
        align-items: flex-start;
    }

    /* SVG container: show full drawing */
    .svg-container {
        height: auto;
        display: block;
    }

    .svg-container svg {
        max-width: 100%;
        max-height: none;
        width: 100%;
        height: auto !important;
        display: block;
    }

    /* Action Buttons: stack if needed */
    .action-buttons {
        flex-wrap: wrap;
    }

    .btn-pdf-export {
        flex: 1;
        min-width: 140px;
        padding: 10px 16px;
        font-size: 14px;
    }

    .btn-action {
        flex: 1;
        min-width: 100px;
    }

    /* Mount type images: keep visible */
    .mount-type-images {
        flex-wrap: wrap;
    }

    .process-type-images {
        flex-wrap: wrap;
    }

    .process-type-card,
    .mount-type-card {
        min-width: 80px;
    }

    /* Footer */
    .app-footer {
        height: auto;
        padding: 8px;
    }
}

/* ===== Responsive: Small Mobile (≤ 480px) ===== */
@media (max-width: 480px) {
    .app-header {
        padding: 6px 8px;
    }

    .header-left h1 {
        font-size: 11px;
    }

    .logo {
        height: 22px;
    }

    .header-left {
        gap: 6px;
    }

    .header-right {
        gap: 6px;
    }

    .toggle-btn {
        padding: 2px 8px;
        font-size: 11px;
    }

    .step-section {
        padding: 10px;
    }

    .step-title {
        font-size: 13px;
    }

    .drawing-preview {
        min-height: 0;
        overflow: visible;
        height: auto;
    }

    .tab-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    .summary-label {
        min-width: 80px;
    }

    .dialog-box {
        padding: 16px;
        width: 95%;
    }
}
