/* ============================================
   住み替え費用シミュレーター - スタイルシート
   カラー: ネイビー・白・淡いグレー
   ============================================ */

/* --- CSS Variables --- */
:root {
    --navy: #1a2744;
    --navy-light: #2c3e6b;
    --navy-lighter: #3d5289;
    --accent: #2563eb;
    --accent-light: #dbeafe;
    --white: #ffffff;
    --gray-50: #f8f9fb;
    --gray-100: #f1f3f7;
    --gray-200: #e2e6ed;
    --gray-300: #c9cfd9;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --text-primary: #1a2744;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --shadow-sm: 0 1px 2px rgba(26, 39, 68, 0.06);
    --shadow: 0 2px 8px rgba(26, 39, 68, 0.08);
    --shadow-md: 0 4px 16px rgba(26, 39, 68, 0.1);
    --shadow-lg: 0 8px 32px rgba(26, 39, 68, 0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
    background: var(--gray-50);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
}

/* --- Header --- */
#app-header {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
    color: var(--white);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.header-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    opacity: 0.9;
}

.header-brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.3;
}

.header-sub {
    font-size: 0.75rem;
    opacity: 0.75;
    font-weight: 400;
    letter-spacing: 0.04em;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-outline {
    background: transparent;
    color: var(--white);
    border: 1.5px solid rgba(255,255,255,0.4);
}

.btn-outline:hover {
    background: rgba(255,255,255,0.12);
    border-color: rgba(255,255,255,0.7);
}

.btn-outline-danger {
    background: transparent;
    color: #fca5a5;
    border: 1.5px solid rgba(252,165,165,0.4);
}

.btn-outline-danger:hover {
    background: rgba(220,38,38,0.15);
    border-color: #fca5a5;
}

.btn-secondary {
    background: rgba(255,255,255,0.15);
    color: var(--white);
    border: 1.5px solid rgba(255,255,255,0.25);
}

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

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    padding: 6px 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.btn-link:hover {
    color: var(--navy);
    text-decoration: underline;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.78rem;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 1rem;
    transition: color var(--transition);
}

.btn-remove:hover {
    color: var(--danger);
}

/* --- Main Layout --- */
#app-main {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* --- Card --- */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.card-header:hover {
    background: var(--gray-100);
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--navy);
}

.card-header h2 i {
    font-size: 1.05rem;
    color: var(--navy-lighter);
}

.toggle-icon {
    font-size: 0.85rem;
    color: var(--gray-400);
    transition: transform 0.3s ease;
}

.toggle-icon.collapsed {
    transform: rotate(180deg);
}

.card-body {
    padding: 20px;
}

.card-body.collapsed {
    display: none;
}

/* Result card header */
.result-header {
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
    border-bottom: none;
}

.result-header h2 {
    color: var(--white);
}

.result-header h2 i {
    color: rgba(255,255,255,0.8);
}

.result-header .toggle-icon {
    color: rgba(255,255,255,0.6);
}

/* Comment card header */
.comment-header {
    background: linear-gradient(135deg, #065f46 0%, #059669 100%);
    border-bottom: none;
    cursor: default;
}

.comment-header h2 {
    color: var(--white);
}

.comment-header h2 i {
    color: rgba(255,255,255,0.8);
}

/* --- Form Elements --- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.badge-required {
    display: inline-block;
    background: var(--danger);
    color: var(--white);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.02em;
}

input[type="text"],
input[type="date"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-primary);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

input[readonly] {
    background: var(--gray-100);
    color: var(--gray-600);
    cursor: default;
}

.input-with-unit {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.input-with-unit input {
    text-align: right;
    padding-right: 8px;
}

.unit {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
    min-width: 18px;
}

.fixed-badge {
    display: inline-block;
    background: var(--gray-200);
    color: var(--gray-600);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* --- Info Box --- */
.info-box {
    margin-top: 16px;
    background: var(--accent-light);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
}

.info-box h3 {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.info-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.info-item {
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: var(--white);
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid #bfdbfe;
}

/* --- Sub Section --- */
.sub-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}

.sub-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sub-section h3 i {
    color: var(--navy-lighter);
    font-size: 0.9rem;
}

.calc-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
    padding-left: 4px;
}

/* --- Additional Cost Rows --- */
.additional-cost-row,
.other-annual-cost-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.additional-cost-row input[type="text"],
.other-annual-cost-row input[type="text"] {
    flex: 1;
}

.other-annual-cost-row .input-with-unit {
    flex: 1;
}

.other-annual-name {
    flex: 1;
    min-width: 0;
}

.other-annual-amount {
    max-width: 160px;
}

/* --- Result Area --- */
.result-property-summary {
    text-align: center;
    padding: 12px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.result-property-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--navy);
}

.result-property-detail {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.result-total-box {
    text-align: center;
    padding: 24px 16px;
    background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.result-total-label {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.8);
    font-weight: 500;
    margin-bottom: 4px;
}

.result-total-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--white);
    letter-spacing: 0.02em;
}

/* --- Breakdown Table --- */
.breakdown-toggle {
    text-align: center;
    margin-bottom: 8px;
}

.breakdown-table {
    overflow-x: auto;
}

.breakdown-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.breakdown-table th,
.breakdown-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-200);
    text-align: left;
}

.breakdown-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    white-space: nowrap;
}

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

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

.total-row td {
    font-weight: 700;
    color: var(--navy);
    background: var(--gray-50);
    border-top: 2px solid var(--navy);
    font-size: 1rem;
}

.breakdown-table td:nth-child(3) {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* --- Toggle Switch Row --- */
.toggle-switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
}

.toggle-switch-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray-300);
    border-radius: 24px;
    transition: background-color 0.25s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: var(--white);
    border-radius: 50%;
    transition: transform 0.25s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle-status {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 48px;
}

.toggle-status.active {
    color: var(--accent);
}

/* --- Comparison Cards --- */
.comparison-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.comparison-card {
    background: var(--gray-50);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    border: 2px solid var(--gray-200);
    transition: border-color var(--transition);
}

.comparison-card.current {
    border-color: var(--gray-300);
}

.comparison-card.new-home {
    border-color: var(--accent);
    background: var(--accent-light);
}

.comparison-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.comparison-card.new-home h3 {
    color: var(--accent);
}

.comparison-total {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--navy);
}

.comparison-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.comparison-breakdown {
    margin-top: 12px;
    text-align: left;
}

.comparison-breakdown ul {
    list-style: none;
    padding: 0;
}

.comparison-breakdown li {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-bottom: 1px dashed var(--gray-200);
}

.comparison-breakdown li:last-child {
    border-bottom: none;
}

.comparison-breakdown li span:last-child {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* --- Diff Box --- */
.diff-box {
    text-align: center;
    padding: 20px 16px;
    border-radius: var(--radius);
    background: var(--gray-50);
    border: 2px dashed var(--gray-300);
    transition: all 0.4s ease;
}

.diff-box.positive {
    background: var(--danger-bg);
    border-color: #fca5a5;
}

.diff-box.negative {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 2px solid #34d399;
    box-shadow: 0 4px 20px rgba(5, 150, 105, 0.12);
    padding: 24px 16px;
}

.diff-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.diff-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--navy);
}

.diff-box.positive .diff-value {
    color: var(--danger);
}

.diff-box.negative .diff-value {
    color: var(--success);
    font-size: 1.8rem;
}

.diff-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* --- Savings Badge (お得バッジ) --- */
.savings-badge {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
}

.diff-box.negative .savings-badge {
    display: flex;
}

.savings-badge-inner {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: linear-gradient(135deg, #059669 0%, #10b981 100%);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 14px;
    border-radius: 20px;
    letter-spacing: 0.04em;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
    animation: badgePop 0.4s ease-out;
}

@keyframes badgePop {
    0% { transform: scale(0.7); opacity: 0; }
    60% { transform: scale(1.08); }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Savings Highlight (お得額ハイライト) --- */
.savings-highlight {
    display: none;
    margin-top: 10px;
    padding: 10px 16px;
    background: rgba(255,255,255,0.7);
    border-radius: 8px;
    border: 1px solid #a7f3d0;
}

.diff-box.negative .savings-highlight {
    display: block;
}

.savings-highlight-text {
    font-size: 0.85rem;
    color: #065f46;
    font-weight: 500;
    line-height: 1.6;
}

.savings-highlight-text strong {
    color: #059669;
    font-size: 1.05rem;
}

/* --- Annual Diff Row (お得強調) --- */
.annual-table .diff-row.is-saving td {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    color: #059669;
    font-weight: 700;
    border-left: 3px solid #34d399;
}

.annual-table .diff-row.is-saving td:first-child::before {
    content: '✨ ';
}

/* --- Bar Chart (お得時の色分け) --- */
.bar-new.is-saving {
    background: linear-gradient(90deg, #10b981, #059669);
}

.bar-saving-label {
    display: none;
    font-size: 0.72rem;
    font-weight: 600;
    color: #059669;
    background: #d1fae5;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    white-space: nowrap;
}

.bar-saving-label.visible {
    display: inline-block;
    animation: badgePop 0.4s ease-out;
}

/* --- Comparison Card (お得時の強調) --- */
.comparison-card.new-home.is-saving {
    border-color: #10b981;
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    box-shadow: 0 4px 16px rgba(5, 150, 105, 0.1);
}

.comparison-card.new-home.is-saving h3 {
    color: #059669;
}

.comparison-card.new-home.is-saving .comparison-total {
    color: #059669;
}

/* --- Annual Savings Summary --- */
.annual-savings-summary {
    margin-top: 16px;
    animation: badgePop 0.4s ease-out;
}

.annual-savings-inner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    border: 2px solid #34d399;
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(5, 150, 105, 0.12);
}

.annual-savings-inner > i {
    font-size: 1.8rem;
    color: #059669;
    flex-shrink: 0;
}

.annual-savings-inner p {
    font-size: 0.92rem;
    color: #065f46;
    font-weight: 500;
    line-height: 1.6;
}

.annual-savings-inner p strong {
    color: #059669;
    font-size: 1.15rem;
}

/* --- Annual Comparison Table --- */
.annual-table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
}

.annual-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.annual-table th,
.annual-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-200);
}

.annual-table th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    white-space: nowrap;
}

.annual-table .col-current {
    background: rgba(156,163,175,0.06);
}

.annual-table .col-new {
    background: rgba(37,99,235,0.04);
}

.annual-table .total-row td {
    font-weight: 700;
    color: var(--navy);
    background: var(--gray-100);
    border-top: 2px solid var(--navy);
    font-size: 0.95rem;
}

.annual-table .diff-row td {
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-light);
}

/* --- Visual Bar Chart --- */
.visual-bar-section {
    padding-top: 8px;
}

.visual-bar-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.bar-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    width: 36px;
    flex-shrink: 0;
    text-align: right;
}

.bar-track {
    flex: 1;
    height: 28px;
    background: var(--gray-100);
    border-radius: 6px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.6s ease;
    min-width: 4px;
}

.bar-current {
    background: linear-gradient(90deg, var(--gray-400), var(--gray-500));
}

.bar-new {
    background: linear-gradient(90deg, var(--accent), var(--navy-lighter));
}

.bar-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 90px;
    text-align: left;
    font-variant-numeric: tabular-nums;
}

/* --- Sales Comment --- */
#sales-comments-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.placeholder-text {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 16px;
}

.sales-comment-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--success);
}

.sales-comment-item.warn {
    border-left-color: var(--warning);
}

.sales-comment-item.info {
    border-left-color: var(--accent);
}

.sales-comment-item i {
    font-size: 1.1rem;
    margin-top: 2px;
    flex-shrink: 0;
}

.sales-comment-item i.fa-check-circle {
    color: var(--success);
}

.sales-comment-item i.fa-exclamation-triangle {
    color: var(--warning);
}

.sales-comment-item i.fa-lightbulb {
    color: var(--accent);
}

.sales-comment-text {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.6;
}

.sales-comment-text strong {
    color: var(--navy);
}

/* --- Footer --- */
#app-footer {
    text-align: center;
    padding: 20px 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--gray-200);
    background: var(--white);
}

/* --- Print Footer (hidden on screen) --- */
.print-footer {
    display: none;
}

/* --- Validation Error --- */
.input-error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(220,38,38,0.12) !important;
}

.error-message {
    font-size: 0.75rem;
    color: var(--danger);
    margin-top: 2px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .header-inner {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 16px;
    }

    .header-brand {
        justify-content: center;
    }

    .header-actions {
        justify-content: center;
        flex-wrap: wrap;
    }

    .header-actions .btn {
        flex: 1;
        justify-content: center;
        min-width: 0;
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    #app-main {
        padding: 12px 10px 30px;
        gap: 14px;
    }

    .card-body {
        padding: 16px 14px;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .comparison-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .comparison-total {
        font-size: 1.35rem;
    }

    .result-total-value {
        font-size: 1.75rem;
    }

    .annual-table th,
    .annual-table td {
        padding: 8px 8px;
        font-size: 0.82rem;
    }

    .bar-row {
        flex-wrap: wrap;
    }

    .bar-value {
        width: 100%;
        text-align: center;
        min-width: 0;
    }

    .other-annual-cost-row {
        flex-wrap: wrap;
    }

    .other-annual-name {
        flex: 1 1 100%;
    }

    .info-items {
        flex-direction: column;
        gap: 6px;
    }
}

@media (max-width: 480px) {
    .header-brand h1 {
        font-size: 1rem;
    }

    .diff-value {
        font-size: 1.25rem;
    }

    .comparison-card {
        padding: 14px 12px;
    }
}

/* --- Print Styles --- */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    html {
        font-size: 12px;
    }

    body {
        background: white;
    }

    .no-print,
    .no-print-toggle {
        display: none !important;
    }

    .always-print {
        display: block !important;
    }

    #app-header {
        position: static;
        box-shadow: none;
    }

    .header-inner {
        padding: 10px 16px;
    }

    #app-main {
        padding: 10px 16px;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ccc;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .card-body,
    .card-body.collapsed {
        display: block !important;
    }

    .toggle-icon {
        display: none;
    }

    .card-header {
        cursor: default;
    }

    .print-footer {
        display: block;
        text-align: center;
        padding: 16px;
        font-size: 0.8rem;
        color: #666;
        border-top: 1px solid #ccc;
        margin-top: 20px;
    }

    .result-total-box {
        background: var(--navy) !important;
    }

    .result-header {
        background: var(--navy) !important;
    }

    .comment-header {
        background: #059669 !important;
    }

    .bar-fill {
        transition: none;
    }
}

/* --- Utility --- */
.font-tabular {
    font-variant-numeric: tabular-nums;
}

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }

/* =============================================
   お得演出アニメーション
   ============================================= */

/* --- コイン装飾（差額ボックス内） --- */
.coin-decorations {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    border-radius: inherit;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.diff-box {
    position: relative;
    overflow: hidden;
}

.diff-box.negative .coin-decorations {
    opacity: 1;
}

.coin {
    position: absolute;
    font-size: 1.4rem;
    line-height: 1;
    opacity: 0;
    transform: translateY(20px) scale(0.5);
}

.coin .coin-img {
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 2px 6px rgba(250, 204, 21, 0.5));
}

.diff-box.negative.in-view .coin {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.coin-1 { top: 8px; left: 10px; animation-delay: 0s; }
.coin-2 { top: 6px; right: 12px; animation-delay: 0.15s; }
.coin-3 { bottom: 10px; left: 16px; animation-delay: 0.3s; }
.coin-4 { bottom: 8px; right: 10px; animation-delay: 0.45s; }

.diff-box.negative.in-view .coin-1 { animation: coinBounce 0.6s 0s ease-out forwards, coinFloat 2.5s 0.6s ease-in-out infinite; }
.diff-box.negative.in-view .coin-2 { animation: coinBounce 0.6s 0.15s ease-out forwards, coinFloat 3s 0.75s ease-in-out infinite; }
.diff-box.negative.in-view .coin-3 { animation: coinBounce 0.6s 0.3s ease-out forwards, coinFloat 2.8s 0.9s ease-in-out infinite; }
.diff-box.negative.in-view .coin-4 { animation: coinBounce 0.6s 0.45s ease-out forwards, coinFloat 3.2s 1.05s ease-in-out infinite; }

@keyframes coinBounce {
    0%   { opacity: 0; transform: translateY(30px) scale(0.3) rotate(-30deg); }
    50%  { opacity: 1; transform: translateY(-8px) scale(1.15) rotate(10deg); }
    70%  { transform: translateY(4px) scale(0.95) rotate(-5deg); }
    100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}

@keyframes coinFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-5px) rotate(5deg); }
    75% { transform: translateY(3px) rotate(-3deg); }
}

/* --- キラキラ（スパークル） --- */
.sparkle {
    position: absolute;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    color: #fbbf24;
}

.sparkle-1 { top: 14px; left: 36px; }
.sparkle-2 { top: 20px; right: 34px; }
.sparkle-3 { bottom: 18px; left: 50%; }

.diff-box.negative.in-view .sparkle-1 { animation: sparkleGlow 1.6s 0.5s ease-in-out infinite; }
.diff-box.negative.in-view .sparkle-2 { animation: sparkleGlow 1.6s 0.9s ease-in-out infinite; }
.diff-box.negative.in-view .sparkle-3 { animation: sparkleGlow 1.6s 1.3s ease-in-out infinite; }

@keyframes sparkleGlow {
    0%, 100% { opacity: 0; transform: scale(0.5) rotate(0deg); }
    50%  { opacity: 1; transform: scale(1.3) rotate(180deg); }
}

/* --- お得バッジ 絵文字ぴょん --- */
.diff-box.negative.in-view .savings-badge-inner {
    animation: iconJump 0.5s 0.2s ease-out, iconWiggle 2s 1s ease-in-out infinite;
}

@keyframes iconJump {
    0%   { transform: translateY(0) scale(1); }
    40%  { transform: translateY(-6px) scale(1.25); }
    70%  { transform: translateY(2px) scale(0.9); }
    100% { transform: translateY(0) scale(1); }
}

@keyframes iconWiggle {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(-12deg); }
    40% { transform: rotate(12deg); }
    60% { transform: rotate(-6deg); }
    80% { transform: rotate(6deg); }
}

/* --- 新居カード お得コインバッジ --- */
.card-coin-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 12px rgba(245, 158, 11, 0.4);
    opacity: 0;
    transform: scale(0);
    z-index: 2;
}

.card-coin-badge .coin-img {
    width: 24px;
    height: 24px;
    filter: drop-shadow(0 1px 2px rgba(200, 150, 0, 0.3));
}

/* --- コイン画像共通 --- */
.coin-img {
    display: inline-block;
    width: 1em;
    height: 1em;
    object-fit: contain;
    vertical-align: middle;
    filter: drop-shadow(0 1px 3px rgba(200, 150, 0, 0.35));
}

.coin-img-sm {
    width: 1.1em;
    height: 1.1em;
}

.coin-img-md {
    width: 1.3em;
    height: 1.3em;
}

.coin-img-lg {
    width: 2.2rem;
    height: 2.2rem;
}

.coin-img-rain {
    width: 1em;
    height: 1em;
}

.comparison-card.new-home {
    position: relative;
}

.comparison-card.new-home.is-saving.in-view .card-coin-badge {
    opacity: 1;
    animation: coinBadgePop 0.5s 0.3s ease-out forwards, coinBadgePulse 2s 1s ease-in-out infinite;
}

@keyframes coinBadgePop {
    0%   { opacity: 0; transform: scale(0) rotate(-90deg); }
    60%  { opacity: 1; transform: scale(1.2) rotate(10deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes coinBadgePulse {
    0%, 100% { transform: scale(1); box-shadow: 0 3px 10px rgba(245, 158, 11, 0.4); }
    50%  { transform: scale(1.1); box-shadow: 0 4px 18px rgba(245, 158, 11, 0.6); }
}

/* --- 年間お得サマリー 豚アイコン + コイン --- */
.savings-icon-group {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.savings-piggy {
    font-size: 2.2rem;
    line-height: 1;
}

.savings-coins-float {
    position: absolute;
    top: -8px;
    right: -12px;
    font-size: 1.1rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(250, 204, 21, 0.5));
    opacity: 0;
}

.annual-savings-summary.in-view .savings-piggy {
    animation: piggyBounce 0.8s ease-out;
}

.annual-savings-summary.in-view .savings-coins-float {
    animation: coinDropIn 0.5s 0.4s ease-out forwards, coinFloat 2.5s 1s ease-in-out infinite;
}

@keyframes piggyBounce {
    0%   { transform: scale(0.6) rotate(-10deg); }
    40%  { transform: scale(1.15) rotate(5deg); }
    60%  { transform: scale(0.9) rotate(-3deg); }
    80%  { transform: scale(1.05) rotate(1deg); }
    100% { transform: scale(1) rotate(0deg); }
}

@keyframes coinDropIn {
    0%   { opacity: 0; transform: translateY(-18px) scale(0.5); }
    60%  { opacity: 1; transform: translateY(3px) scale(1.1); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- コインレイン（紙吹雪的なコインアニメ） --- */
.savings-coin-rain {
    position: relative;
    height: 0;
    overflow: visible;
    pointer-events: none;
}

.rain-coin {
    position: absolute;
    font-size: 1rem;
    line-height: 1;
    filter: drop-shadow(0 1px 3px rgba(250, 204, 21, 0.5));
    opacity: 0;
    animation: rainDrop var(--rain-duration, 1.2s) var(--rain-delay, 0s) ease-in forwards;
    left: var(--rain-x, 0%);
}

@keyframes rainDrop {
    0%   { opacity: 0; transform: translateY(-20px) rotate(0deg) scale(0.7); }
    15%  { opacity: 1; }
    50%  { opacity: 1; transform: translateY(8px) rotate(180deg) scale(1); }
    100% { opacity: 0; transform: translateY(24px) rotate(360deg) scale(0.5); }
}

/* --- スクロール連動 表示アニメーション --- */
.animate-on-scroll {
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.animate-on-scroll:not(.in-view) .coin,
.animate-on-scroll:not(.in-view) .sparkle {
    animation: none !important;
    opacity: 0 !important;
}

/* --- 差額値のカウントアップ風パルス (お得時) --- */
.diff-box.negative.in-view .diff-value {
    animation: valuePulse 0.8s 0.2s ease-out;
}

@keyframes valuePulse {
    0%   { transform: scale(0.8); opacity: 0.5; }
    50%  { transform: scale(1.08); opacity: 1; }
    70%  { transform: scale(0.96); }
    100% { transform: scale(1); opacity: 1; }
}

/* --- バーチャートのお得ラベル アニメ --- */
.bar-saving-label.visible {
    animation: badgePop 0.4s ease-out, labelPulse 2s 1s ease-in-out infinite;
}

@keyframes labelPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* --- 印刷時はアニメーション無効化 --- */
@media print {
    .coin-decorations,
    .card-coin-badge,
    .savings-coin-rain,
    .rain-coin {
        display: none !important;
    }

    .animate-on-scroll {
        opacity: 1 !important;
        transform: none !important;
    }

    * {
        animation: none !important;
    }
}

/* --- レスポンシブ調整 --- */
@media (max-width: 768px) {
    .coin { font-size: 1rem; }
    .sparkle { font-size: 0.75rem; }
    .card-coin-badge { width: 30px; height: 30px; font-size: 0.75rem; top: -6px; right: -6px; }
    .savings-piggy { font-size: 1.6rem; }
}

@media (max-width: 480px) {
    .diff-box.negative .diff-value { font-size: 1.4rem; }
    .coin-1, .coin-3 { display: none; }
}
