/* リセットCSS */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 基本スタイル */
body {
    font-family: 'Hiragino Kaku Gothic Pro', 'ヒラギノ角ゴ Pro W3', Meiryo, メイリオ, Osaka, 'MS PGothic', Arial, sans-serif;
    background-color: #f5f7fa;
    line-height: 1.6;
    color: #333;
}

/* コンテナ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ヘッダー */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    margin-bottom: 30px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* ナビゲーション */
.navigation {
    display: flex;
    gap: 8px;
    margin-bottom: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

.nav-btn {
    background: white;
    border: 2px solid #667eea;
    color: #667eea;
    padding: 10px 16px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.nav-btn:hover,
.nav-btn.active {
    background: #667eea;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

/* メインコンテンツ */
.main-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    min-height: 500px;
}

/* ページ */
.page {
    display: none; /* デフォルトで非表示 */
}

.page.active {
    display: block; /* activeクラスがあるページのみ表示 */
}

.page h2 {
    color: #2c3e50;
    margin-bottom: 25px;
    font-size: 1.8rem;
    border-bottom: 3px solid #667eea;
    padding-bottom: 10px;
}

.page-description {
    color: #666;
    margin-bottom: 20px;
    font-size: 14px;
    font-style: italic;
}

/* 統計グリッド */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.stat-card {
    background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
    color: white;
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

/* ダッシュボードの統計カードの色を、残ったカードの順番に合わせて調整 */
.stat-card:nth-child(1) { /* 単独クライアント数 */
    background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
}
.stat-card:nth-child(2) { /* 代理店クライアント数 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.stat-card:nth-child(3) { /* 共通品目数 */
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
.stat-card:nth-child(4) { /* 代理店品目数 */
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #333;
}
.stat-card:nth-child(5) { /* 単独クライアント品目数 */
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
}
.stat-card:nth-child(6) { /* 今月の請求書 */
    background: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%);
    color: #333;
}


.stat-card h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    opacity: 0.9;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* ボタン */
.btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    margin-right: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.btn-success {
    background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
}

.btn-secondary {
    background: #95a5a6;
}

.btn-danger {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
}

.btn-warning {
    background: linear-gradient(135deg, #ffa726 0%, #fb8c00 100%);
}

.btn-small { /* 伝票入力ページの「全て選択」「全て解除」など */
    padding: 8px 15px;
    font-size: 12px;
    margin-right: 8px;
    margin-bottom: 5px;
}

.btn-sm { /* テーブル内の編集・削除ボタンなど、より小さいボタン */
    padding: 6px 10px;
    font-size: 11px;
    margin-right: 5px;
    margin-bottom: 0;
    white-space: nowrap; /* ボタン内のテキストが改行されないように */
}

/* フォームコンテナ */
.form-container {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 10px;
    margin: 20px 0;
    border-left: 4px solid #667eea;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.form-container.hidden {
    display: none;
}

.form-container h3 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.3rem;
}

/* フォームグループ */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
}

.form-input,
.form-select,
textarea.form-input { /* テキストエリアにも適用 */
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
    background: white;
}

.form-input:focus,
.form-select:focus,
textarea.form-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    transform: translateY(-1px);
}

.form-input::placeholder {
    color: #95a5a6;
}

/* フォームアクション */
.form-actions {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #e1e8ed;
}

/* データリスト */
.data-list {
    margin-top: 30px;
}

/* テーブル */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.data-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
}

.data-table td {
    padding: 15px;
    border-bottom: 1px solid #e1e8ed;
    font-size: 14px;
}

.data-table tbody tr:hover {
    background: #f8f9fa;
    transition: background 0.2s ease;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* 空のステート */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #95a5a6;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 20px;
}

/* アクションボタンの配置調整（テーブル内のボタンなど） */
.action-buttons {
    white-space: nowrap; /* ボタンが並んで表示されるように */
    display: flex; /* ボタンを横並びにする */
    gap: 5px; /* ボタン間の隙間 */
    justify-content: flex-start; /* 左寄せ */
    align-items: center;
}

/* --- サブクライアント個別管理用スタイル --- */
#subClientIndividualList {
    margin-top: 15px;
    padding: 15px;
    background: #f0f8ff; /* 薄い青の背景 */
    border: 1px solid #cce5ff;
    border-radius: 8px;
}

#subClientIndividualList .data-table {
    box-shadow: none; /* 親のテーブルの影を無効化 */
}

/* サブクライアント編集時の表示/非表示 */
#subClientIndividualList .hidden {
    display: none !important;
}

/* --- 代理店品目セレクターのスタイル --- */
.agency-item-selector,
.direct-client-item-selector { /* direct-client-item-selector を追加 */
    background: #f0f4ff; /* 薄い水色の背景 */
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 25px;
    border: 1px solid #e1e8ed; /* 修正 */
}

.agency-item-selector .form-group,
.direct-client-item-selector .form-group { /* direct-client-item-selector を追加 */
    margin-bottom: 15px;
}

.agency-item-selector .form-group:last-child,
.direct-client-item-selector .form-group:last-child { /* direct-client-item-selector を追加 */
    margin-bottom: 0;
}

/* --- 請求書作成ページのプレビューコンテナ --- */
#invoicePreviewContainer {
    margin-top: 30px;
    border: 1px solid #e1e8ed;
    padding: 20px;
    border-radius: 10px;
    background-color: #ffffff;
}

#invoicePreviewContainer.hidden {
    display: none;
}

#invoicePreview {
    font-family: 'serif';
    line-height: 1.8;
}

/* 請求書プレビューテーブルのスタイル */
#invoicePreview table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

#invoicePreview th,
#invoicePreview td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

#invoicePreview th {
    background-color: #f2f2f2;
}

#invoicePreview tfoot tr {
    background-color: #f2f2f2;
}


/* --- 伝票入力ページの品目リストと単価編集UI --- */
.slip-item-checkbox {
    transform: scale(1.2); /* チェックボックスを少し大きく */
    margin-right: 5px;
}

.quantity-input {
    width: 80px; /* 数量入力の幅を調整 */
    text-align: right;
    padding: 5px 8px;
}

.unit-price-input {
    width: 100px; /* 単価入力の幅を調整 */
    text-align: right;
    padding: 5px 8px;
}

/* 伝票入力時の単価編集UIの表示/非表示 */
.unit-price-input.hidden,
.save-price-btn.hidden,
.cancel-price-btn.hidden {
    display: none !important;
}

/* 編集中の行のハイライト */
#availableItemsList tbody tr.editing-row {
    background-color: #fffacd; /* 薄い黄色 */
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header {
        padding: 20px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .navigation {
        flex-direction: column;
        align-items: center;
    }
    
    .nav-btn {
        width: 160px;
        margin-bottom: 8px;
        font-size: 11px;
        padding: 8px 12px;
    }
    
    .main-content {
        padding: 20px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    /* ボタンの幅を調整 */
    .btn {
        width: 100%;
        margin-right: 0;
        margin-bottom: 10px;
    }
    .btn-small, .btn-sm { /* 小さいボタンもレスポンシブで調整 */
        width: auto; /* 必要に応じて調整 */
        margin-right: 5px;
        margin-bottom: 5px;
    }
    
    .form-actions {
        display: flex;
        flex-direction: column;
    }
    
    .data-table {
        font-size: 12px;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 8px;
    }
    
    /* 請求書フォームのレイアウト調整 */
    #page6 .form-container .form-group {
        grid-column: span 2; /* 2カラム表示を解除 */
    }
    #invoicePreviewContainer button {
        width: 100%;
    }
    
    .agency-item-selector {
        padding: 15px;
    }

    /* 伝票入力のテーブル内の調整 */
    #availableItemsList .data-table th,
    #availableItemsList .data-table td {
        white-space: normal; /* 折り返しを許可 */
    }
    #availableItemsList .quantity-input,
    #availableItemsList .unit-price-input {
        width: 100%; /* フル幅に */
    }
    .action-buttons {
        flex-wrap: wrap; /* ボタンを折り返す */
        gap: 2px; /* 隙間を小さく */
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }
    
    .header p {
        font-size: 0.9rem;
    }
    
    .stat-number {
        font-size: 2rem;
    }
    
    .page h2 {
        font-size: 1.4rem;
    }
    
    .nav-btn {
        width: 140px;
        font-size: 10px;
        padding: 6px 10px;
    }
}

/* --- 内訳書 HTML プレビューのスタイル (statementHtmlPreviewContainer / statementHtmlPreview 用) --- */

#statementHtmlPreviewContainer {
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid #e1e8ed;
    padding: 20px;
    border-radius: 10px;
    background-color: #ffffff;
}

#statementHtmlPreview {
    font-family: 'serif';
    line-height: 1.8;
}

/* 内訳書テーブルの基本スタイル */
.statement-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.85em;
    border: 1px solid #000;
    table-layout: auto;
}

/* 内訳書ヘッダー情報 */
.statement-header {
    text-align: center;
    margin-bottom: 20px;
    font-family: 'Hiragino Kaku Gothic Pro', 'ヒラギノ角ゴ Pro W3', Meiryo, メイリオ, Osaka, 'MS PGothic', Arial, sans-serif;
}
.statement-header p {
    margin: 0;
    line-height: 1.4;
    font-weight: normal;
}
.statement-header .client-name {
    font-size: 1.5em;
    font-weight: normal;
}
.statement-header .period {
    font-size: 1.2em;
    margin-top: 5px;
    font-weight: normal;
}
.statement-header .period-range {
    font-size: 0.9em;
    color: #555;
    margin-top: 5px;
    font-weight: normal;
}

/* テーブルヘッダーのスタイル */
.statement-table thead th {
    background-color: #e9ecef;
    text-align: center;
    vertical-align: middle;
    padding: 8px 4px;
    border: 1px solid #000;
    font-weight: normal;
    white-space: nowrap;
}

/* サブクライアントグループヘッダー */
.statement-table .sub-client-group-header td {
    background-color: #f2f2f2;
    font-weight: normal;
    padding: 8px;
    border: 1px solid #000;
    text-align: left;
    white-space: nowrap;
}

/* 明細行のスタイル */
.statement-table .item-row td {
    padding: 6px 4px;
    border: 1px solid #000;
    vertical-align: middle;
    white-space: nowrap;
    text-align: right;
}

.statement-table .item-row td:nth-child(1),
.statement-table .item-row td:nth-child(2) {
    text-align: left;
}
.statement-table .item-row.item-unit-price td:first-child {
    text-align: right;
    padding-right: 15px;
    border-bottom: 1px solid #000;
    border-top: none;
}
.statement-table .item-row.item-unit-price td:not(:first-child) {
    border-top: none;
}

/* サブクライアント合計行のスタイル */
.statement-table .sub-client-summary td {
    background-color: #e9ecef;
    font-weight: normal;
    padding: 8px;
    border: 1px solid #000;
    text-align: right;
}
.statement-table .sub-client-summary td:first-child {
    text-align: left;
    border-right: 1px solid #000;
}

/* 全体合計行のスタイル */
.statement-table tfoot .grand-total td {
    background-color: #dee2e6;
    font-weight: normal;
    font-size: 1.1em;
    padding: 10px;
    border: 2px solid #000;
    text-align: right;
}
.statement-table tfoot .grand-total td:first-child {
    text-align: left;
    border-right: 2px solid #000;
}
@media print {
    body {
        font-size: 8pt;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        margin: 0;
        padding: 0;
    }
    .container, .main-content {
        width: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
        min-height: auto;
    }
    .header, .navigation, .page-description, .form-container, .btn, .empty-state, 
    .form-group, .form-actions, #selectedInvoiceDetails, #invoicePreviewContainer,
    .page:not(.active) {
        display: none !important; 
    }
    #statementHtmlPreviewContainer {
        border: none;
        box-shadow: none;
        padding: 0;
        display: block !important;
    }
    #statementHtmlPreview {
        background-color: transparent !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }

    .statement-table {
        width: auto;
        border: 1px solid #000;
        font-size: 6pt;
        margin-bottom: 0;
        table-layout: auto;
    }
    .statement-table thead th,
    .statement-table tbody td,
    .statement-table tfoot td {
        border-color: #000 !important;
        padding: 1px 2px;
        vertical-align: middle;
        white-space: nowrap;
    }
    .statement-table .item-row.item-unit-price td:first-child {
        border-bottom: 1px solid #000 !important;
    }

    page-break-inside: avoid;
    page-break-after: always;

    .sub-client-group-header, .sub-client-summary {
        page-break-inside: avoid;
    }
    .item-row {
        page-break-inside: avoid;
    }
    
    @media all {
        .page-break { display: none; }
    }
    @media print {
        .page-break { display: block; page-break-before: always; }
    }
    
    /* === 修正箇所 === */
    .statement-table .grand-total-amount-row td:not(:first-child) {
        font-weight: normal !important; /* 太字を解除 */
        font-size: 6pt !important; /* 元の8ptから2pt小さくする */
    }
    
    .statement-table thead th,
    .statement-table tbody td,
    .statement-table tfoot td {
        border: 0 !important;
    }
    /* 品目名と単価のセルの右側にのみ罫線を残す */
    .statement-table thead th:nth-child(1),
    .statement-table thead th:nth-child(2),
    .statement-table tbody .item-row td:nth-child(1),
    .statement-table tbody .item-row td:nth-child(2) {
        border-right: 1px solid #000 !important;
    }
    /* 数量の合計行の右側罫線 */
    .statement-table .sub-client-summary-quantity td:last-child,
    .statement-table .grand-total-quantity-row td:last-child {
        border-right: 1px solid #000 !important;
    }
}
.quantity-input::-webkit-outer-spin-button,
.quantity-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.quantity-input[type=number] {
    -moz-appearance: textfield;
}