/* サンエイ通信 請求・見積管理 - スタイル */

:root {
    --white: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --bg: #f8fafc;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --text-dark: #1e293b;
    --text-gray: #64748b;
    --border: #e2e8f0;
    --bg-gray: #f8fafc;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --sidebar-width: 240px;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #2563eb;
    --sidebar-text: #ffffff;
    --sidebar-text-muted: rgba(255,255,255,0.7);
    --sidebar-text-dim: rgba(255,255,255,0.4);
    --sidebar-border: rgba(255,255,255,0.1);
    --accent: #2563eb;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans JP', sans-serif;
    font-size: 14px;
    color: var(--text-dark);
    background-color: var(--bg-gray);
    line-height: 1.6;
}

/* サイドバー */
.sidebar {
    position: fixed;
    left: 0; top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 100;
    font-size: 17px;
}
.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-header h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--accent);
}
.sidebar-header .subtitle {
    font-size: 11px;
    color: var(--sidebar-text-dim);
    margin-top: 2px;
    letter-spacing: 0.5px;
}
.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}
.nav-section {
    padding: 12px 12px 8px 24px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sidebar-text-dim);
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin: 2px 12px;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
}
.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}
.nav-item.active {
    background: var(--accent);
    color: #fff;
}
.nav-item svg {
    width: 20px; height: 20px; flex-shrink: 0;
}
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--sidebar-border);
}
.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    color: var(--sidebar-text-muted);
}
.user-avatar {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}
.user-name {
    font-size: 14px;
    color: var(--sidebar-text);
}
.logout-btn {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 12px;
    background: var(--sidebar-border);
    border: none;
    border-radius: 6px;
    color: var(--sidebar-text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    text-align: center;
}
.logout-btn:hover {
    background: rgba(255,255,255,0.2);
    color: var(--sidebar-text);
}

/* メインコンテンツ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: #f8f9fc;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 24px 0 24px;
    margin-bottom: 24px;
}
.page-header h2 {
    font-size: 24px; font-weight: 600; color: #1e293b;
}
.header-actions {
    display: flex; gap: 12px;
}
.content {
    padding: 0 24px 24px 24px;
}

/* ボタン */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
    background: white;
    color: var(--text-dark);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: #f8f9fc;
    border-color: var(--primary);
    color: var(--primary);
}
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* フォーム */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: var(--text-gray);
    font-size: 13px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* テーブル */
.table-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 20px; text-align: left; border-bottom: 1px solid #e5e7eb; }
th {
    background: #f8f9fc;
    font-weight: 600;
    color: #6b7280;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
tbody tr { cursor: pointer; }
tbody tr:hover td { background: #f8f9fc; }
tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* カード */
.card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
}

/* アラート */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
}
.alert-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}
.alert-success {
    background: #f0fdf4;
    color: var(--success);
    border: 1px solid #bbf7d0;
}

/* ログインページ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
}
.login-box {
    width: 100%;
    max-width: 400px;
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo h1 {
    font-size: 36px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 3px;
}
.login-box .subtitle {
    text-align: center;
    color: var(--text-gray);
    margin-bottom: 32px;
}
.login-box .btn-primary {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    margin-top: 8px;
}

/* 検索バー */
.search-bar {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    background: #f8f9fc;
    border-bottom: 1px solid #e5e7eb;
    align-items: center;
}
.search-bar input {
    flex: 1;
    max-width: 240px;
    padding: 8px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
}

/* 月タブ */
.toolbar-row {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
}
.month-tabs-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.tab-nav-btn {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-light);
}
.tab-nav-btn:hover { background: var(--bg); color: var(--text); }
.month-tabs {
    display: flex;
    gap: 8px;
    overflow: hidden;
}
.month-tab {
    padding: 6px 16px;
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}
.month-tab:hover { background: var(--bg); }
.month-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

/* エクスポートボタン */
.export-buttons {
    display: flex;
    gap: 8px;
}
.btn-export {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    font-size: 12px;
    color: #1e293b;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-export:hover {
    background: #f8f9fc;
    border-color: var(--primary);
    color: var(--primary);
}

/* 件数バー */
.report-count-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    font-size: 13px;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
}

/* テーブルラッパー */
.table-wrapper { overflow-x: auto; }
.table-wrapper table { width: 100%; border-collapse: collapse; }
.table-wrapper thead th {
    background: var(--bg);
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    white-space: nowrap;
}
.table-wrapper thead th.text-right,
.table-wrapper tbody td.text-right { text-align: right; }
.table-wrapper tbody td {
    padding: 10px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 15px;
}
.table-wrapper tbody tr:last-child td { border-bottom: none; }

/* 右クリックメニュー */
.context-menu {
    display: none;
    position: fixed;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 180px;
    padding: 6px 0;
}
.context-menu.show { display: block; }
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    color: #1e293b;
    transition: background 0.15s;
}
.context-menu-item:hover { background: #f8f9fc; }
.context-menu-item.danger { color: #ef4444; }
.context-menu-item.danger:hover { background: #fef2f2; }
.context-menu-divider { height: 1px; background: #e5e7eb; margin: 6px 0; }
tr.context-highlight { background: rgba(37, 99, 235, 0.1) !important; }

/* 編集カード */
.edit-card {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 16px;
    overflow: hidden;
}
.edit-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    font-weight: 600;
    font-size: 14px;
    color: #1e293b;
    background: #f8f9fc;
    border-bottom: 1px solid #e5e7eb;
}
.edit-card-body { padding: 20px; }
.edit-card-body.no-padding { padding: 0; }

/* フォームレイアウト */
.form-row-header { display: flex; gap: 32px; align-items: flex-start; }
.form-section { flex: 1; }
.form-section-title { font-weight: 600; font-size: 14px; color: #1e293b; margin-bottom: 16px; }
.form-section-divider { width: 1px; background: #e5e7eb; align-self: stretch; }
.form-row-inline { display: flex; gap: 16px; align-items: flex-start; }
.form-row-inline .form-group { margin-bottom: 0; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-row-3 .form-group { margin-bottom: 0; }

/* 編集テーブル */
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table thead th {
    background: #f8f9fc;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}
.edit-table tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
}
.edit-table tbody tr:last-child td { border-bottom: none; }
.edit-table input, .edit-table select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 13px;
}
.edit-table input:focus, .edit-table select:focus {
    outline: none;
    border-color: var(--primary);
}
.edit-table input[type="number"] { text-align: right; }

/* 削除ボタン */
.btn-delete {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}
.btn-delete:hover { background: #fef2f2; }

/* 合計ボックス */
.totals-box { max-width: 320px; margin-left: auto; }
.total-line {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
}
.total-line.total-grand {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
    border-bottom: none;
    padding-top: 16px;
}

/* モーダル共通 */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}
.modal-overlay.active, .modal-overlay.show { display: flex; }
.modal-box {
    background: #fff;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
}
.modal-close:hover { color: #1e293b; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
}

/* 取引先リスト */
.customer-list { max-height: 400px; overflow-y: auto; }
.customer-item {
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.customer-item:hover {
    background: #f8f9fc;
    border-color: var(--primary);
}
.customer-item-name { font-weight: 500; margin-bottom: 4px; }
.customer-item-address { font-size: 12px; color: #6b7280; }

/* バッジ */
.badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
    text-align: center;
    display: inline-block;
}
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #16a34a; }
.badge-yellow { background: #fef3c7; color: #d97706; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-gray { background: #f3f4f6; color: #6b7280; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* レポートタブ */
.report-tabs {
    display: flex; gap: 4px; margin-bottom: 20px;
    border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.report-tab {
    padding: 10px 20px; border: none; background: none;
    cursor: pointer; font-size: 14px; color: var(--text-light);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.report-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.report-tab:hover { color: var(--text); }
.report-section { display: none; }
.report-section.active { display: block; }

/* サマリーカード */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.summary-card {
    background: var(--white);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.summary-card-label { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.summary-card-value { font-size: 28px; font-weight: 600; color: var(--text); }
.summary-card-sub { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.summary-card-sub.positive { color: #16a34a; }
.summary-card-sub.negative { color: #dc2626; }

/* レポートカード */
.report-card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}
.report-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.report-card-body { padding: 20px; }
.ranking-list { display: flex; flex-direction: column; }
.ranking-item {
    display: flex; align-items: center;
    padding: 12px 0; border-bottom: 1px solid var(--border);
}
.ranking-item:last-child { border-bottom: none; }
.ranking-rank { width: 30px; font-weight: 600; color: var(--text-light); }
.ranking-name { flex: 1; font-weight: 500; }
.ranking-count { color: var(--text-light); font-size: 13px; margin-right: 16px; }
.ranking-amount { font-weight: 500; min-width: 100px; text-align: right; }

/* 設定カード */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}
.settings-card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}
.settings-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.settings-card-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.settings-card-title { font-size: 16px; font-weight: 600; color: var(--text); }
.settings-card-body { padding: 20px; max-height: 400px; overflow-y: auto; }
.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 8px;
}
.item-row .item-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}
.btn-icon {
    width: 32px; height: 32px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ユーティリティ */
.mb-0 { margin-bottom: 0 !important; }
.mb-16 { margin-bottom: 16px; }
.mt-8 { margin-top: 8px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-gap-8 { display: flex; gap: 8px; align-items: center; }
.justify-center { justify-content: center; }
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.p-20 { padding: 20px; }
.cursor-pointer { cursor: pointer; }
.text-muted { color: var(--text-light); }
.empty-state { padding: 20px; text-align: center; color: var(--text-light); }
.w-80 { width: 80px; }
.w-300 { width: 300px; }
.flex-1 { flex: 1; }

/* 数値入力スピナー非表示 */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

/* flatpickr */
.flatpickr-calendar { font-family: inherit; box-shadow: 0 4px 20px rgba(0,0,0,0.15); border-radius: 8px; }
.flatpickr-day.selected { background: var(--accent); border-color: var(--accent); }
.flatpickr-day:hover { background: #e5e7eb; }

/* レスポンシブ */
@media (max-width: 1200px) {
    .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
    .form-row-header { flex-direction: column; gap: 24px; }
    .form-section-divider { width: 100%; height: 1px; }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; background: none; border: none; font-size: 24px; cursor: pointer; margin-right: 16px; }
    .desktop-only { display: none !important; }
    .form-row-3 { grid-template-columns: 1fr; }
    .form-row-inline { flex-direction: column; }
    .form-row-inline .form-group { width: 100% !important; }
}
@media (min-width: 769px) {
    .mobile-only { display: none !important; }
    .menu-toggle { display: none; }
}
