/* ================================
   グローバルスタイル
================================ */
:root {
    --primary: #81C784;
    --primary-dark: #4CAF50;
    --primary-light: #E8F5E9;
    --secondary: #64748b;
    --success: #16a34a;
    --success-light: #f0fdf4;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #0891b2;
    --info-light: #ecfeff;
    --sidebar-width: 240px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #81C784;
    --header-height: 60px;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body {
    font-family: 'Noto Sans JP', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
}

/* ================================
   サイドバー
================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    min-height: 100vh;
    position: fixed;
    left: 0; top: 0;
    z-index: 100;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.logo i { color: #81C784; font-size: 20px; }

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-nav ul { list-style: none; }

.nav-section {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #475569;
    padding: 16px 16px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0;
    transition: all 0.2s;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    color: #fff;
    background: rgba(255,255,255,0.05);
}

.nav-item.active {
    color: #fff;
    background: rgba(129,199,132,0.18);
    border-left-color: var(--primary);
}

.nav-item i { width: 18px; text-align: center; font-size: 15px; }

/* ================================
   メインコンテンツ
================================ */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.top-header {
    height: var(--header-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text);
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    color: var(--text);
}

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

.page-content {
    flex: 1;
    padding: 24px;
}

/* ================================
   ページ切り替え
================================ */
.page { display: none; }
.page.active { display: block; }

/* ================================
   カード
================================ */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.card-body { padding: 20px; }

/* ================================
   ボタン
================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: none;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.btn:hover { opacity: 0.9; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #0e7490; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; justify-content: center; }

/* ================================
   ダッシュボード統計
================================ */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

/* ================================
   ツールバー
================================ */
.page-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.search-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    width: 220px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.search-input:focus { border-color: var(--primary-dark); }

.filter-select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    background: #fff;
}

.filter-select:focus { border-color: var(--primary-dark); }

/* ================================
   テーブル
================================ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: #f8fafc;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.data-table tr:hover td { background: #f8fafc; }

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

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state i { font-size: 40px; margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 14px; }

/* ================================
   バッジ・ステータス
================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-draft { background: #f1f5f9; color: #64748b; }
.badge-sent { background: #E8F5E9; color: #4CAF50; }
.badge-accepted { background: #f0fdf4; color: #16a34a; }
.badge-rejected { background: #fef2f2; color: #dc2626; }
.badge-converted { background: #faf5ff; color: #7c3aed; }
.badge-paid { background: #f0fdf4; color: #16a34a; }
.badge-overdue { background: #fef2f2; color: #dc2626; }
.badge-cancelled { background: #f1f5f9; color: #94a3b8; }

/* ================================
   フォーム
================================ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

.form-full { grid-column: 1 / -1; }

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.required { color: var(--danger); }

.form-group input,
.form-group select,
.form-group textarea {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(129,199,132,0.2);
}

textarea { resize: vertical; }

.form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

/* ================================
   明細テーブル
================================ */
.items-section {
    margin: 20px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.items-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

.items-header h4 {
    font-size: 14px;
    font-weight: 600;
}

.items-table-wrap { overflow-x: auto; }

.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th {
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

.items-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

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

.items-table input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
    background: #fff;
}

.items-table input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(129,199,132,0.2);
}

.items-table input[type="number"] { text-align: right; }

.items-total {
    padding: 12px 16px;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.total-row {
    display: flex;
    gap: 24px;
    font-size: 13px;
    min-width: 260px;
    justify-content: space-between;
}

.total-final {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-dark);
    padding-top: 8px;
    border-top: 2px solid var(--border);
}

.item-amount { text-align: right; font-weight: 500; }

.remove-item-btn {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.2s;
}

.remove-item-btn:hover { background: var(--danger-light); }

/* ================================
   モーダル
================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--card-bg);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-large { max-width: 800px; }
.modal-xlarge { max-width: 900px; }

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.modal-close:hover { color: var(--danger); }

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ================================
   CSV アップロード
================================ */
.csv-upload-section { display: flex; flex-direction: column; gap: 24px; }

.csv-format-info {
    background: var(--info-light);
    border: 1px solid #a5f3fc;
    border-radius: var(--radius);
    padding: 16px;
}

.csv-format-info h4 {
    color: var(--info);
    margin-bottom: 8px;
    font-size: 14px;
}

.csv-format-info p { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }

.csv-format-table {
    overflow-x: auto;
    margin-bottom: 12px;
}

.csv-format-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.csv-format-table th {
    background: rgba(8,145,178,0.1);
    padding: 6px 10px;
    border: 1px solid #a5f3fc;
    font-weight: 600;
    color: var(--info);
}

.csv-format-table td {
    padding: 6px 10px;
    border: 1px solid #a5f3fc;
    color: var(--text-muted);
}

.csv-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
}

.csv-upload-area:hover, .csv-upload-area.drag-over {
    border-color: var(--primary-dark);
    background: var(--primary-light);
    color: var(--primary-dark);
}

.csv-upload-area i { font-size: 48px; margin-bottom: 12px; }
.csv-upload-area p { margin-bottom: 8px; }

.csv-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* ================================
   プレビュー（印刷用書類）
================================ */
.preview-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    justify-content: flex-end;
}

#document-preview {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    font-size: 13px;
    min-height: 600px;
}

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.doc-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: 4px;
    margin-bottom: 4px;
}

.doc-number { font-size: 13px; color: var(--text-muted); }

/* 旧 .doc-company-info は .doc-company-info-wrap 内に移動したので上書きのみ */
.doc-company-info { text-align: right; font-size: 12px; line-height: 1.8; }

.doc-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 2px solid var(--primary-dark);
}

.doc-to { }

.doc-to-name {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--text);
    padding-bottom: 4px;
    display: inline-block;
}

.doc-info-table { margin-top: 8px; }

.doc-info-table table {
    margin-left: auto;
    border-collapse: collapse;
    font-size: 12px;
}

.doc-info-table td {
    padding: 3px 8px;
    border: 1px solid var(--border);
}

.doc-info-table td:first-child {
    background: #f8fafc;
    font-weight: 600;
    white-space: nowrap;
}

.doc-subject {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text);
}

.doc-items table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 16px;
}

.doc-items th {
    background: var(--primary-dark);
    color: #fff;
    padding: 8px 10px;
    font-weight: 600;
    text-align: left;
}

.doc-items td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.doc-items tr:nth-child(even) td { background: #f8fafc; }

.doc-totals {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 24px;
}

.doc-totals table {
    border-collapse: collapse;
    font-size: 13px;
    min-width: 280px;
}

.doc-totals td {
    padding: 6px 12px;
    border: 1px solid var(--border);
}

.doc-totals td:first-child {
    background: #f8fafc;
    font-weight: 600;
    width: 120px;
}

.doc-total-final td {
    background: var(--primary-dark) !important;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}

.doc-notes {
    font-size: 12px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 16px;
    white-space: pre-wrap;
}

.doc-bank-info {
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    white-space: pre-wrap;
    background: #f8fafc;
}

.doc-bank-info h4 {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

/* ================================
   メール
================================ */
.email-note {
    background: var(--warning-light);
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 12px;
    font-size: 12px;
    color: var(--warning);
    margin-top: 12px;
    line-height: 1.8;
}

/* ================================
   クイック作成メニュー
================================ */
.quick-menu {
    position: fixed;
    bottom: 80px;
    right: 24px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    z-index: 200;
}

.quick-menu-item {
    padding: 12px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    transition: background 0.2s;
}

.quick-menu-item:hover { background: var(--bg); }
.quick-menu-item i { color: var(--primary-dark); width: 18px; }

/* ================================
   トースト通知
================================ */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: #1e293b;
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    min-width: 240px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ================================
   アクションボタン群
================================ */
.action-btns {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
}

/* ================================
   印刷スタイル
================================ */
@media print {
    .sidebar, .top-header, .preview-actions, .modal-header, .modal-footer { display: none !important; }
    /* PDF確認ダイアログは印刷しない */
    #pdfConfirmModal { display: none !important; }
    /* previewModal だけ印刷対象 */
    .modal-overlay { position: static !important; background: none !important; padding: 0 !important; }
    .modal { box-shadow: none !important; max-width: 100% !important; max-height: none !important; }
    .modal-body { overflow: visible !important; padding: 0 !important; }
    #document-preview { border: none !important; padding: 0 !important; }
    body { display: block !important; }
}

/* ================================
   レスポンシブ
================================ */
@media (max-width: 1024px) {
    :root { --sidebar-width: 200px; }
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-btn { display: block; }

    .page-content { padding: 16px; }

    .form-grid { grid-template-columns: 1fr; }
    .form-full { grid-column: 1; }

    .dashboard-stats { grid-template-columns: 1fr 1fr; }

    .page-toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-left, .toolbar-right { justify-content: space-between; }
    .search-input { width: 100%; }

    .doc-meta { grid-template-columns: 1fr; }
    .doc-header { flex-direction: column; gap: 16px; }
    .doc-company-info { text-align: left; }
    .doc-company-info-wrap { flex-direction: row-reverse; justify-content: flex-end; }

    .modal { margin: 0; border-radius: 0; max-height: 100vh; }
    .modal-overlay { padding: 0; }
}

@media (max-width: 480px) {
    .dashboard-stats { grid-template-columns: 1fr; }
}

/* ================================
   ユーザー管理
================================ */
.user-notice {
    background: var(--warning-light);
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 12px;
    color: var(--warning);
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    line-height: 1.7;
}
.user-notice i { margin-top: 2px; flex-shrink: 0; }

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

/* ================================
   設定のデフォルト備考枠
================================ */
.setting-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
    margin: 20px 0 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--primary-light);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ================================
   ローディング
================================ */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    gap: 12px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ================================
   スクロールバー
================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ================================
   請求書一覧 新UI
================================ */

/* フィルターバー */
.inv-filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 12px;
    gap: 12px;
    flex-wrap: wrap;
}
.inv-filter-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}
.inv-filter-right { display: flex; gap: 8px; }
.inv-filter-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}
.inv-active-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.inv-filter-chip {
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid #A5D6A7;
    border-radius: 12px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
}

/* フィルターパネル */
.inv-filter-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.inv-filter-panel-inner {
    padding: 16px 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    align-items: end;
}
.inv-filter-row {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.inv-filter-row label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}
.inv-filter-row input,
.inv-filter-row select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #fff;
}
.inv-filter-row input:focus,
.inv-filter-row select:focus { border-color: var(--primary); }
.inv-filter-actions {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* タブバー */
.inv-tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    border-bottom: 2px solid var(--border);
}
.inv-tab {
    background: none;
    border: none;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
    font-family: inherit;
}
.inv-tab:hover { color: var(--primary-dark); }
.inv-tab.active {
    color: var(--primary-dark);
    border-bottom-color: var(--primary-dark);
    font-weight: 600;
}

/* テーブルヘッダー */
.inv-table-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
    min-height: 48px;
}
.inv-selected-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
}
.inv-table-meta {
    font-size: 12px;
    color: var(--text-muted);
    flex: 1;
}
.inv-page-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}
.inv-page-controls select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
    font-family: inherit;
    background: #fff;
}

/* 請求書テーブル */
.inv-list-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.inv-list-table th {
    background: #f8fafc;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.inv-list-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.inv-list-table tr:last-child td { border-bottom: none; }
.inv-list-table tr:hover td { background: #f8fafc; }
.inv-row-overdue td { background: #fff8f8; }
.inv-row-overdue:hover td { background: #fef2f2 !important; }
.inv-row-selected td { background: #F1F8E9 !important; }

/* 列幅 */
.inv-col-check { width: 36px; text-align: center; }
.inv-col-name { min-width: 160px; }
.inv-col-number { width: 160px; }
.inv-col-amount { width: 110px; text-align: right; }
.inv-col-date { width: 100px; white-space: nowrap; }
.inv-col-due { width: 100px; white-space: nowrap; }
.inv-col-status { width: 100px; }
.inv-col-person { width: 90px; }
.inv-col-actions { width: 160px; }

/* 宛先名 */
.inv-name-main { font-weight: 600; color: var(--text); font-size: 13px; }
.inv-name-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* 請求書番号リンク */
.inv-number-link {
    color: var(--primary-dark);
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.inv-number-link:hover { opacity: 0.8; }

/* バッジ（請求書専用） */
.inv-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.inv-badge-blue   { background: #EFF6FF; color: #2563EB; }
.inv-badge-green  { background: #F0FDF4; color: #16A34A; }
.inv-badge-orange { background: #FFFBEB; color: #D97706; }
.inv-badge-red    { background: #FEF2F2; color: #DC2626; }
.inv-badge-gray   { background: #F1F5F9; color: #64748B; }

/* ================================
   請求書ステータス インラインセレクト
================================ */
.inv-status-select {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    border-radius: 12px;
    padding: 4px 24px 4px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    white-space: nowrap;
    /* 下矢印アイコンを疑似要素で代用 */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748b'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    background-size: 8px 5px;
    transition: opacity 0.15s, box-shadow 0.15s;
    font-family: inherit;
    width: 100%;
}
.inv-status-select:hover  { opacity: 0.85; box-shadow: 0 0 0 2px rgba(0,0,0,0.08); }
.inv-status-select:focus  { box-shadow: 0 0 0 2px var(--primary); }

/* 各ステータス配色 */
.inv-status-draft     { background-color: #F1F5F9; color: #64748B; }
.inv-status-sent      { background-color: #EFF6FF; color: #2563EB; }
.inv-status-cancelled { background-color: #FEF2F2; color: #DC2626; }

/* ================================
   見積書ステータス インラインセレクト
================================ */
.quo-status-select {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    border-radius: 12px;
    padding: 4px 24px 4px 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    white-space: nowrap;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748b'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 7px center;
    background-size: 8px 5px;
    transition: opacity 0.15s, box-shadow 0.15s;
    font-family: inherit;
    width: 100%;
}
.quo-status-select:hover  { opacity: 0.85; box-shadow: 0 0 0 2px rgba(0,0,0,0.08); }
.quo-status-select:focus  { box-shadow: 0 0 0 2px var(--primary); }

/* 見積書 各ステータス配色 */
.quo-status-draft     { background-color: #F1F5F9; color: #64748B; }
.quo-status-sent      { background-color: #EFF6FF; color: #2563EB; }
.quo-status-accepted  { background-color: #F0FDF4; color: #16A34A; }
.quo-status-rejected  { background-color: #FEF2F2; color: #DC2626; }
.quo-status-converted { background-color: #FDF4FF; color: #9333EA; }

/* ================================
   推奨バッジ
================================ */
.badge-recommend {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    background: #E8F5E9;
    color: #4CAF50;
    border: 1px solid #A5D6A7;
    margin-left: 6px;
    vertical-align: middle;
}

/* ================================
   取引先詳細
================================ */
.client-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.detail-item label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 4px;
}

.detail-item p {
    font-size: 14px;
    color: var(--text);
}

/* ================================
   インライン編集
================================ */
.editable-cell {
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 4px;
    transition: background 0.2s;
}

.editable-cell:hover { background: var(--primary-light); color: var(--primary-dark); }

/* ================================
   ダッシュボードオーバーレイ
================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

.sidebar-overlay.active { display: block; }

/* ================================
   チャート期間タブ
================================ */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.chart-period-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: 6px;
    padding: 3px;
}
.chart-tab {
    background: none;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    font-family: inherit;
}
.chart-tab:hover { color: var(--text); background: rgba(255,255,255,0.6); }
.chart-tab.active {
    background: #fff;
    color: var(--primary-dark);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ================================
   予算執行状況
================================ */
.budget-summary-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.budget-summary-header { margin-bottom: 12px; }
.budget-summary-header h4 { font-size: 15px; font-weight: 600; color: var(--text); }
.budget-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 8px;
}
.budget-summary-item { text-align: center; }
.budget-summary-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.budget-summary-value { font-size: 18px; font-weight: 700; }

.budget-client-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.budget-client-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}
.budget-client-card:hover { box-shadow: var(--shadow-lg); }
.budget-client-card-no-budget { border-style: dashed; opacity: 0.8; }
.budget-client-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    gap: 8px;
}
.budget-client-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
}
.budget-client-actions { display: flex; gap: 4px; flex-shrink: 0; }
.budget-amounts { margin-bottom: 12px; }
.budget-amount-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid var(--bg);
    font-size: 13px;
}
.budget-amount-label { color: var(--text-muted); }
.budget-amount-value { font-weight: 600; }
.budget-progress-wrap { margin-top: 8px; }
.budget-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.budget-progress-bar-bg {
    background: var(--bg);
    border-radius: 99px;
    height: 10px;
    overflow: visible;
    position: relative;
}
.budget-progress-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.5s ease;
    min-width: 2px;
}
.budget-progress-over-indicator {
    position: absolute;
    right: -2px;
    top: -3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid #fff;
}

@media (max-width: 768px) {
    .budget-summary-grid { grid-template-columns: repeat(2, 1fr); }
    .budget-client-grid { grid-template-columns: 1fr; }
}

/* ================================
   メールテンプレート設定
================================ */
.email-tmpl-vars {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 20px;
}
.email-tmpl-vars-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.email-tmpl-vars-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.tmpl-var {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary-dark);
    border: 1px solid #A5D6A7;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-family: monospace;
    font-weight: 600;
    cursor: default;
    user-select: all;
}

/* ================================
   画像アップロードUI（ロゴ・印影）
================================ */
.img-upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.img-upload-block {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.img-upload-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.img-upload-label i { color: var(--primary-dark); }

.img-upload-hint {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 4px;
}

.img-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: #fafbfc;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    position: relative;
    overflow: hidden;
}

.img-upload-area:hover,
.img-upload-area.drag-over {
    border-color: var(--primary-dark);
    background: var(--primary-light);
}

.img-upload-area.has-image {
    border-style: solid;
    border-color: var(--primary);
    background: #fff;
}

.img-upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    padding: 24px;
    text-align: center;
    pointer-events: none;
}

.img-upload-placeholder i {
    font-size: 36px;
    color: var(--primary);
    opacity: 0.6;
}

.img-upload-placeholder p {
    font-size: 13px;
    margin: 0;
}

.img-upload-fmt {
    font-size: 11px !important;
    color: var(--text-muted);
    background: var(--bg);
    border-radius: 4px;
    padding: 2px 8px;
}

.img-upload-preview {
    max-width: 100%;
    max-height: 140px;
    object-fit: contain;
    border-radius: 6px;
    padding: 8px;
    display: block;
}

.img-upload-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    background: var(--primary-light);
    border-radius: 6px;
    border: 1px solid #A5D6A7;
}

.img-filename {
    font-size: 11px;
    color: var(--primary-dark);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.img-upload-info {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}

.img-upload-info i { color: var(--primary); }

/* ================================
   書類内 ロゴ・印影
================================ */

/* doc-headerの左側（タイトル＋ロゴ） */
.doc-header-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* 会社情報ラップ（印影＋テキスト） */
.doc-company-info-wrap {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    text-align: right;
}

.doc-company-info { font-size: 12px; line-height: 1.8; }

/* ロゴ画像（書類左上） */
.doc-logo {
    max-height: 60px;
    max-width: 200px;
    object-fit: contain;
    display: block;
    margin-bottom: 4px;
}

/* 印影画像（書類右上・会社情報の横） */
.doc-seal {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
    opacity: 0.85;
    /* 印鑑らしく薄い赤みを重ねる（PNG透過推奨時はそのまま） */
    mix-blend-mode: multiply;
}

/* 印刷時もそのまま表示 */
@media print {
    .doc-logo { max-height: 55px; }
    .doc-seal { width: 66px; height: 66px; }
}

/* レスポンシブ */
@media (max-width: 768px) {
    .img-upload-grid { grid-template-columns: 1fr; }
    .doc-seal { width: 56px; height: 56px; }
    .doc-logo { max-height: 48px; }
}
