/* リセットとベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f7fa;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ヘッダー */
header {
    background: white;
    padding: 30px;
    margin-bottom: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header h1 {
    color: #2c3e50;
    font-size: 28px;
}

header h1 i {
    color: #c0392b;
    margin-right: 10px;
}

header img {
    height: 50px;
    object-fit: contain;
}

nav {
    display: flex;
    gap: 15px;
}

/* ボタンスタイル */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.btn-primary {
    background: #c0392b;
    color: white;
}

.btn-primary:hover {
    background: #a93226;
}

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

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-success {
    background: #e74c3c;
    color: white;
}

.btn-success:hover {
    background: #c0392b;
}

.btn-preview {
    background: #d35400;
    color: white;
}

.btn-preview:hover {
    background: #ba4a00;
}

.btn-add {
    background: #1abc9c;
    color: white;
    margin-top: 10px;
}

.btn-add:hover {
    background: #16a085;
}

.btn.active {
    box-shadow: 0 4px 12px rgba(192, 57, 43, 0.3);
}

/* フォームセクション */
.form-section, .list-section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.form-section h2, .list-section h2 {
    color: #2c3e50;
    margin-bottom: 30px;
    font-size: 24px;
    border-bottom: 3px solid #c0392b;
    padding-bottom: 10px;
}

.form-group {
    margin-bottom: 30px;
}

.form-group h3 {
    color: #34495e;
    margin-bottom: 15px;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-group h3 i {
    color: #c0392b;
}

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
}

.form-field {
    flex: 1;
}

.form-field.full-width {
    flex: 1 1 100%;
}

.form-field label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
}

.required {
    color: #e74c3c;
}

.form-field input,
.form-field textarea,
.form-field select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
    transition: border-color 0.3s;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
    outline: none;
    border-color: #c0392b;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

textarea {
    resize: vertical;
    font-family: inherit;
}

/* 請求明細テーブル */
.items-container {
    overflow-x: auto;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
}

.items-table th {
    background: #34495e;
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: 500;
}

.items-table td {
    padding: 10px;
    border-bottom: 1px solid #ecf0f1;
}

.items-table input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.items-table input:focus {
    outline: none;
    border-color: #c0392b;
}

.delete-item-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
}

.delete-item-btn:hover {
    background: #c0392b;
}

/* 金額計算セクション */
.calculation-section {
    background: #ecf0f1;
    padding: 20px;
    border-radius: 8px;
    max-width: 400px;
    margin-left: auto;
}

.calc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    font-size: 16px;
}

.calc-row label {
    font-weight: 500;
}

.tax-row {
    border-top: 1px solid #bdc3c7;
    border-bottom: 1px solid #bdc3c7;
}

.tax-input {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tax-input input {
    width: 80px;
    padding: 6px;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
}

.total-row {
    font-size: 20px;
    font-weight: bold;
    color: #c0392b;
}

#subtotalDisplay, #taxAmountDisplay, #totalDisplay {
    font-weight: bold;
}

/* アクションボタン */
.form-actions {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    margin-top: 30px;
}

/* 一覧表示 */
.list-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-box {
    flex: 1;
    position: relative;
    min-width: 250px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #7f8c8d;
}

.search-box input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
}

.filter-box {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-box select {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
}

.invoice-list-container {
    display: grid;
    gap: 15px;
}

.invoice-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #c0392b;
    transition: all 0.3s;
    cursor: pointer;
}

.invoice-card:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.invoice-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.invoice-number {
    font-weight: bold;
    color: #2c3e50;
    font-size: 18px;
}

.invoice-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
}

.status-draft {
    background: #95a5a6;
    color: white;
}

.status-sent {
    background: #f39c12;
    color: white;
}

.status-paid {
    background: #27ae60;
    color: white;
}

.invoice-card-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    color: #555;
}

.invoice-info {
    display: flex;
    flex-direction: column;
}

.invoice-info-label {
    font-size: 12px;
    color: #7f8c8d;
}

.invoice-info-value {
    font-weight: 500;
    color: #2c3e50;
}

.invoice-amount {
    font-size: 24px;
    font-weight: bold;
    color: #c0392b;
}

.invoice-card-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

.invoice-card-actions .btn {
    padding: 8px 16px;
    font-size: 13px;
}

/* プレビューセクション */
.preview-section {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.preview-actions {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
}

.invoice-preview-content {
    background: white;
    max-width: 210mm;
    margin: 0 auto;
    padding: 40px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

/* 印刷用請求書スタイル */
.invoice-document {
    font-size: 14px;
    line-height: 1.8;
}

.invoice-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 2px solid #2c3e50;
}

.invoice-title {
    font-size: 32px;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 10px;
}

.invoice-metadata {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
}

.issuer-info, .client-info-box {
    flex: 1;
}

.section-title {
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 16px;
    border-bottom: 2px solid #c0392b;
    padding-bottom: 5px;
}

.info-line {
    margin: 5px 0;
}

.invoice-items-table {
    width: 100%;
    border-collapse: collapse;
    margin: 30px 0;
}

.invoice-items-table th {
    background: #34495e;
    color: white;
    padding: 12px;
    text-align: left;
    font-weight: 500;
}

.invoice-items-table td {
    padding: 12px;
    border-bottom: 1px solid #ecf0f1;
}

.invoice-items-table .text-right {
    text-align: right;
}

.invoice-summary {
    max-width: 400px;
    margin-left: auto;
    margin-top: 20px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #ecf0f1;
}

.summary-row.total {
    background: #ecf0f1;
    font-size: 18px;
    font-weight: bold;
    border: 2px solid #2c3e50;
}

.invoice-notes {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.invoice-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 2px solid #ecf0f1;
}

.bank-info {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

/* 印刷用スタイル */
@media print {
    @page {
        size: A4;
        margin: 10mm;
    }
    
    body {
        background: white;
        margin: 0;
        padding: 0;
    }
    
    .container {
        max-width: 100%;
        padding: 0;
        margin: 0;
    }
    
    header, .preview-actions {
        display: none !important;
    }
    
    .invoice-preview-content {
        box-shadow: none;
        padding: 0;
        max-width: 100%;
        margin: 0;
    }
    
    .invoice-document {
        padding: 15px !important;
        font-size: 12px !important;
    }
    
    .invoice-title {
        font-size: 24px !important;
        margin-bottom: 15px !important;
    }
    
    .invoice-header {
        margin-bottom: 15px !important;
    }
    
    .invoice-header p {
        margin: 3px 0 !important;
        font-size: 11px !important;
    }
    
    .invoice-metadata {
        margin-bottom: 15px !important;
        gap: 10px !important;
    }
    
    .client-info-box,
    .issuer-info {
        padding: 10px !important;
        font-size: 11px !important;
    }
    
    .section-title {
        font-size: 13px !important;
        margin: 10px 0 5px 0 !important;
        padding: 5px 0 !important;
    }
    
    .info-line {
        margin: 3px 0 !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
    }
    
    .invoice-items-table {
        font-size: 11px !important;
        margin-bottom: 10px !important;
    }
    
    .invoice-items-table th,
    .invoice-items-table td {
        padding: 5px !important;
    }
    
    .invoice-summary {
        font-size: 11px !important;
        margin: 10px 0 !important;
        padding: 10px !important;
    }
    
    .summary-row {
        padding: 3px 0 !important;
    }
    
    .summary-row.total {
        font-size: 14px !important;
        padding: 5px 0 !important;
        margin-top: 5px !important;
    }
    
    .invoice-footer {
        margin-top: 10px !important;
        font-size: 11px !important;
    }
    
    .bank-info {
        padding: 8px !important;
        margin: 5px 0 !important;
    }
    
    .invoice-notes {
        font-size: 10px !important;
        padding: 8px !important;
        margin-top: 10px !important;
    }
    
    /* 改ページ防止 */
    .invoice-document,
    .invoice-items-table,
    .invoice-summary,
    .invoice-footer {
        page-break-inside: avoid;
    }
    
    /* 強制的に1ページに収める */
    html, body {
        height: auto !important;
        overflow: visible !important;
    }
}

/* レスポンシブ */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header {
        padding: 20px;
    }
    
    nav {
        flex-direction: column;
    }
    
    .form-row {
        flex-direction: column;
        gap: 15px;
    }
    
    .calculation-section {
        max-width: 100%;
    }
    
    .list-controls {
        flex-direction: column;
    }
    
    .invoice-metadata {
        flex-direction: column;
        gap: 20px;
    }
    
    .items-table {
        font-size: 12px;
    }
    
    .items-table th,
    .items-table td {
        padding: 8px 4px;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
}

/* 空のリスト表示 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 10px;
    color: #95a5a6;
}

/* ローディング表示 */
.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.loading i {
    font-size: 48px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* モーダル */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 10px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 2px solid #ecf0f1;
}

.modal-header h3 {
    margin: 0;
    color: #2c3e50;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #7f8c8d;
    cursor: pointer;
    transition: color 0.3s;
}

.modal-close:hover {
    color: #e74c3c;
}

.modal-body {
    padding: 30px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    padding: 20px 30px;
    border-top: 2px solid #ecf0f1;
}

/* 発行元カード */
.issuer-card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #c0392b;
    margin-bottom: 15px;
}

.issuer-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.issuer-card-header h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 18px;
}

.issuer-badge {
    background: #c0392b;
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
}

.issuer-card-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.issuer-card-actions {
    display: flex;
    gap: 10px;
}

.issuer-card-actions .btn {
    padding: 8px 16px;
    font-size: 13px;
}

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

.invoice-table thead {
    background: #34495e;
    color: white;
}

.invoice-table th {
    padding: 15px;
    text-align: left;
    font-weight: 500;
    font-size: 14px;
}

.invoice-table td {
    padding: 15px;
    border-bottom: 1px solid #ecf0f1;
}

.invoice-table tbody tr {
    transition: background 0.3s;
}

.invoice-table tbody tr:hover {
    background: #f8f9fa;
}

.invoice-table .text-right {
    text-align: right;
}

.invoice-table .text-center {
    text-align: center;
}

.invoice-table-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.invoice-table-actions .btn {
    padding: 6px 12px;
    font-size: 12px;
}

/* ステータス選択 */
.status-select {
    padding: 6px 10px;
    border: 2px solid #ddd;
    border-radius: 20px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.status-select:hover {
    border-color: #c0392b;
}

.status-select.status-draft {
    background: #95a5a6;
    color: white;
    border-color: #95a5a6;
}

.status-select.status-sent {
    background: #f39c12;
    color: white;
    border-color: #f39c12;
}

.status-select.status-paid {
    background: #27ae60;
    color: white;
    border-color: #27ae60;
}
