:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --error-color: #dc2626;
    --radius: 12px;
    --transition: 0.2s ease-in-out;
}

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

body {
    font-family: 'Noto Sans JP', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* Header */
.form-header {
    text-align: center;
    margin-bottom: 32px;
}

.form-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--primary-color);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.notice {
    background-color: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    border-left: 4px solid var(--primary-color);
    text-align: left;
    font-size: 0.9rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.deadline {
    margin-top: 12px;
    color: var(--error-color);
    font-size: 1rem;
    text-align: center;
}

/* Cards */
.question-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.question-card h2 {
    font-size: 1.2rem;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 24px;
    color: var(--text-main);
}

.question-group {
    margin-bottom: 28px;
}

.question-group:last-child {
    margin-bottom: 0;
}

.question-label {
    display: block;
    font-weight: 700;
    margin-bottom: 12px;
    font-size: 1.05rem;
}

.required {
    background-color: var(--error-color);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
}

.instruction {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    margin-top: -16px;
}

/* Form Controls (Optimized for iPad Touch) */
.radio-options, .checkbox-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.radio-options.vertical {
    flex-direction: column;
}

.grid-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
}

.multi-column {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.multi-column .other-input-container {
    grid-column: 1 / -1; /* Make "Other" input span all available columns */
}

.radio-label, .check-label {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    background-color: #fafafa;
    min-height: 48px; /* Apple Human Interface Guidelines: 44pt/px min touch target */
}

.radio-label:hover, .check-label:hover {
    background-color: #f0fdf4;
    border-color: #86efac;
}

/* Hide default inputs */
input[type="radio"], input[type="checkbox"] {
    position: absolute;
    opacity: 0;
}

/* Custom Radio */
.custom-radio {
    width: 24px;
    height: 24px;
    border: 2px solid #cbd5e1;
    border-radius: 50%;
    margin-right: 12px;
    position: relative;
    flex-shrink: 0;
    transition: var(--transition);
}

input[type="radio"]:checked + .custom-radio {
    border-color: var(--primary-color);
}

input[type="radio"]:checked + .custom-radio::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background-color: var(--primary-color);
    border-radius: 50%;
}

input[type="radio"]:checked ~ span:last-child {
    font-weight: 700;
    color: var(--primary-color);
}

.radio-label:has(input[type="radio"]:checked) {
    background-color: #eff6ff;
    border-color: #bfdbfe;
}


/* Custom Checkbox */
.custom-check {
    width: 24px;
    height: 24px;
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    margin-right: 12px;
    position: relative;
    flex-shrink: 0;
    transition: var(--transition);
}

input[type="checkbox"]:checked + .custom-check {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked + .custom-check::after {
    content: '';
    position: absolute;
    left: 7px;
    top: 3px;
    width: 6px;
    height: 12px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.check-label:has(input[type="checkbox"]:checked) {
    background-color: #eff6ff;
    border-color: #bfdbfe;
    font-weight: 700;
    color: var(--primary-color);
}

/* Tool options with dynamic frequency select */
.tool-option {
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: 100%;
}

.tool-option .check-label {
    height: 100%;
}

.tool-freq-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: #f0fdf4; /* 選択時は少し色を変える */
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-main);
    transition: var(--transition);
}

.tool-freq-select:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Likert Scale (5-point Horizontal) */
.likert-scale {
    display: flex;
    justify-content: space-between;
    background-color: #f8fafc;
    border-radius: var(--radius);
    padding: 16px 8px;
    gap: 8px;
}

.likert-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    font-size: 0.9rem;
    position: relative;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
    border: 1px solid transparent; /* 印刷用に透明なボーダーを確保 */
}

.likert-item:hover {
    background-color: #f1f5f9;
}

.likert-item input[type="radio"] {
    position: absolute;
    opacity: 0;
}

.likert-radio {
    width: 28px;
    height: 28px;
    border: 2px solid #cbd5e1;
    border-radius: 50%;
    margin-bottom: 12px;
    background-color: white;
    transition: var(--transition);
    position: relative;
    flex-shrink: 0;
}

.likert-item input[type="radio"]:checked + .likert-radio {
    border-color: var(--primary-color);
}

.likert-item input[type="radio"]:checked + .likert-radio::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background-color: var(--primary-color);
    border-radius: 50%;
}

.likert-item:has(input[type="radio"]:checked) {
    color: var(--primary-color);
    font-weight: 700;
}

@media (max-width: 600px) {
    .likert-scale {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }
    .likert-item {
        flex-direction: row;
        text-align: left;
        padding: 12px 16px;
        background-color: #ffffff;
        border: 1px solid var(--border-color);
    }
    .likert-radio {
        margin-bottom: 0;
        margin-right: 12px;
    }
    .likert-item span br {
        display: none; /* スマホ縦では改行を消す */
    }
}

/* Text Inputs */
.text-input, .textarea-input, .number-input-lg, .number-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
    background-color: #fafafa;
}

.text-input:focus, .textarea-input:focus, .number-input-lg:focus, .number-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.inline-input {
    display: flex;
    align-items: center;
    max-width: 200px;
}

.number-input-lg {
    text-align: right;
    font-size: 1.2rem;
    font-weight: 700;
}

.unit {
    margin-left: 12px;
    font-weight: 500;
}

/* Qualitative Matrix Table */
.matrix-table-container {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: #fff;
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

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

.matrix-table th {
    background-color: #f8fafc;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 var(--border-color); /* To replace the bottom border as border does not stick well */
}

.th-sub {
    font-size: 0.8rem;
    font-weight: normal;
    color: #94a3b8;
}

.matrix-row-label {
    font-weight: 700;
    width: 15%;
    background-color: #f8fafc;
}

.matrix-select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: #fcfcfc;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text-main);
    cursor: pointer;
    transition: var(--transition);
}

.matrix-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.matrix-select:disabled {
    background-color: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
}

.center-align {
    text-align: center !important;
}

.matrix-checkbox-label {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 8px;
}

.custom-check.no-margin {
    margin-right: 0;
}

/* Dim row when "Not Applicable" is checked (Removed as logic changed) */

/* Other input container */
.other-input-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

/* Submit */
.submit-container {
    text-align: center;
    margin-top: 40px;
    margin-bottom: 40px;
}

.submit-note {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.submit-btn {
    background-color: var(--primary-color);
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 16px 48px;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
    transition: var(--transition);
    width: 100%;
    max-width: 400px;
}

.submit-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 8px -1px rgba(37, 99, 235, 0.3);
}

.submit-btn:active {
    transform: translateY(0);
}

.success-message {
    background: white;
    padding: 40px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.success-message h2 {
    color: #16a34a;
    margin-bottom: 16px;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .other-input-container {
        flex-direction: row;
        align-items: center;
    }
    .other-input-container .text-input {
        flex: 1;
    }
}

/* PRINT STYLES */
@media print {
    body {
        background-color: white;
        color: black;
        font-size: 11pt;
    }

    .container {
        max-width: 100%;
        padding: 0;
        margin: 0;
    }

    .question-card {
        box-shadow: none;
        border: 1px solid #ccc;
        margin-bottom: 15px;
        padding: 15px;
        break-inside: avoid;
    }

    .page-break-before {
        page-break-before: always;
    }

    h1 {
        font-size: 16pt;
    }

    .question-card h2 {
        font-size: 12pt;
        border-bottom: 1px solid #000;
        padding-bottom: 5px;
        margin-bottom: 10px;
    }

    .notice {
        border: 1px solid #000;
        box-shadow: none;
        padding: 10px;
    }

    /* Print friendly form elements */
    .radio-label, .check-label {
        border: none;
        padding: 5px;
        min-height: auto;
        background: none !important;
        font-size: 11pt;
    }
    
    .likert-scale {
        background-color: transparent;
        padding: 0;
        gap: 0;
    }

    .likert-item {
        border: none;
        background: none !important;
        padding: 0;
        font-size: 10pt;
    }

    .likert-radio {
        border-color: #000;
        width: 16px;
        height: 16px;
        margin-bottom: 5px;
    }

    .likert-item input[type="radio"]:checked + .likert-radio::after {
        background-color: #000;
        width: 8px;
        height: 8px;
    }

    .matrix-table-container {
        border: none;
        overflow: visible;
    }
    
    .matrix-select {
        border: 1px solid #000;
        background: transparent;
        appearance: none; /* Hide default dropdown arrow for print */
        -webkit-appearance: none;
        padding: 5px;
    }

    .custom-radio, .custom-check {
        border-color: #000;
        width: 16px;
        height: 16px;
    }

    input[type="radio"]:checked + .custom-radio::after {
        background-color: #000;
    }

    input[type="checkbox"]:checked + .custom-check {
        background-color: transparent;
        border-color: #000;
    }

    input[type="checkbox"]:checked + .custom-check::after {
        border-color: #000;
        left: 3px;
        top: 0px;
        width: 5px;
        height: 10px;
    }

    .text-input, .textarea-input, .number-input-lg, .number-input {
        border: 1px solid #000;
        background: transparent;
        border-radius: 0;
    }

    .number-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 8px;
    }

    .submit-container {
        display: none; /* 印刷時は送信ボタンを隠す */
    }

    .radio-label:has(input[type="radio"]:checked),
    .check-label:has(input[type="checkbox"]:checked),
    .likert-item:has(input[type="radio"]:checked) {
        background-color: transparent;
        border-color: transparent;
        color: #000;
    }
}
