/* ===== CSS Variables ===== */
:root {
  --primary: #3d52a0;
  --primary-dark: #2c3d7a;
  --primary-light: #ebedfa;
  --primary-hover: #4a62bb;
  --bg: #f0f2f8;
  --surface: #ffffff;
  --border: #dde2ee;
  --border-light: #eef0f7;
  --text: #1a1f36;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
  --header-h: 52px;
  --toolbar-h: 44px;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 4px rgba(0,0,0,.09);
  --shadow-md: 0 4px 16px rgba(0,0,0,.13);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Meiryo", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
button { cursor: pointer; font-family: inherit; font-size: 13px; border: none; }
input, select, textarea { font-family: inherit; font-size: 13px; }
table { border-collapse: collapse; width: 100%; }

/* ===== Header ===== */
#app-header {
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.app-title { font-size: 16px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.case-count { font-size: 11px; opacity: .75; white-space: nowrap; }
.header-center { flex: 1; display: flex; justify-content: center; padding: 0 8px; }
.header-right { display: flex; align-items: center; gap: 6px; min-width: 200px; justify-content: flex-end; }

/* Search */
.search-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
}
.search-icon {
  position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: rgba(255,255,255,.6); pointer-events: none;
}
#search-input {
  width: 100%;
  height: 32px;
  padding: 0 30px 0 32px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 16px;
  color: #fff;
  outline: none;
  transition: background .15s, border-color .15s;
}
#search-input::placeholder { color: rgba(255,255,255,.55); }
#search-input:focus { background: rgba(255,255,255,.25); border-color: rgba(255,255,255,.6); }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; color: rgba(255,255,255,.6); font-size: 16px; line-height: 1;
  padding: 0 2px;
}
.search-clear:hover { color: #fff; }

/* ===== Toolbar ===== */
#toolbar {
  height: var(--toolbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  flex-shrink: 0;
}
.filter-group { display: flex; align-items: center; gap: 5px; }
.filter-group label { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.filter-group select {
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  max-width: 140px;
}
.filter-group select:focus { border-color: var(--primary); }
.filter-right { margin-left: auto; color: var(--text-muted); font-size: 12px; }

/* ===== Main Content ===== */
#main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ===== List Panel ===== */
#list-panel {
  width: 56%;
  min-width: 400px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
#list-scroll { flex: 1; overflow-y: auto; overflow-x: auto; }

/* Table */
#case-table { table-layout: fixed; min-width: 600px; }
#case-table thead {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
}
#case-table th {
  padding: 7px 8px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
#case-table th.sortable { cursor: pointer; }
#case-table th.sortable:hover { color: var(--primary); }
#case-table th.sort-asc .sort-icon::after { content: ' ▲'; color: var(--primary); }
#case-table th.sort-desc .sort-icon::after { content: ' ▼'; color: var(--primary); }
.sort-icon { font-size: 10px; color: var(--text-light); }

/* 列幅リサイズハンドル */
th { position: relative; }
.col-rh {
  position: absolute; top: 0; right: 0;
  width: 6px; height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 10;
}
.col-rh:hover, .col-rh.dragging { background: rgba(99,102,241,.35); }

/* 予定表ソートアイコン */
.fc-sort-icon { margin-left: 3px; font-size: 10px; color: #94a3b8; }
.fc-sort-icon.active { color: var(--primary); }

/* Column widths */
.col-pj    { width: 130px; }
.col-name  { width: auto; min-width: 160px; }
.col-client { width: 120px; }
.col-phase { width: 80px; }
.col-assign { width: 80px; }
.col-date  { width: 100px; }
.col-amount { width: 110px; }

#case-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}
#case-table tr { cursor: pointer; transition: background .1s; }
#case-table tr:hover { background: var(--primary-light); }
#case-table tr.selected {
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
}
.td-amount { text-align: right; font-variant-numeric: tabular-nums; }

/* Pagination */
#pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
#page-info { font-size: 12px; color: var(--text-muted); flex: 1; text-align: center; }
#page-size-select {
  height: 26px; padding: 0 4px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 12px;
}

/* ===== Detail Panel ===== */
#detail-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
#detail-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-light); gap: 8px;
}
.empty-icon { font-size: 48px; }
#detail-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Detail header */
#detail-header {
  background: var(--surface);
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.detail-pj { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-right: 6px; }
#detail-project-name { font-size: 15px; font-weight: 700; margin: 3px 0 2px; line-height: 1.3; }
.detail-client { font-size: 12px; color: var(--text-muted); }
.detail-actions { margin-top: 8px; display: flex; gap: 6px; }

/* Tabs */
#detail-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 10px;
  flex-shrink: 0;
  gap: 2px;
}
.tab-btn {
  padding: 8px 12px;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.badge {
  display: inline-block;
  background: var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 0 5px;
  font-size: 11px;
  min-width: 18px;
  text-align: center;
}
.tab-btn.active .badge { background: var(--primary-light); color: var(--primary); }

/* Tab panes */
.tab-pane { flex: 1; overflow-y: auto; padding: 12px 14px; }

/* ===== Basic Info Grid ===== */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.info-grid dt {
  font-size: 11px;
  color: var(--text-muted);
  padding: 7px 10px 3px;
  border-bottom: 1px solid var(--border-light);
}
.info-grid dd {
  padding: 7px 10px 3px;
  border-bottom: 1px solid var(--border-light);
  word-break: break-all;
}
.info-grid .full-row { grid-column: span 2; }

/* ===== Finance Tab ===== */
.finance-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.finance-heading {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.finance-table { width: 100%; font-size: 13px; }
.finance-table tr:hover { background: var(--border-light); }
.finance-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-light);
}
.finance-table td:first-child { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.finance-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.finance-table tr.total-row td { font-weight: 700; border-top: 2px solid var(--border); }
.profit-good { color: var(--success); }
.profit-warn { color: var(--warning); }
.profit-bad  { color: var(--danger); }

/* ===== Sub-tables (入金/外注費) ===== */
.subtable-toolbar {
  margin-bottom: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.subtable-scroll { overflow-x: auto; }
.subtable {
  font-size: 12px;
  min-width: 700px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.subtable thead th {
  background: var(--bg);
  padding: 6px 8px;
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.subtable td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtable tr:hover td { background: var(--primary-light); }
.subtable tfoot td {
  padding: 6px 8px;
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: var(--bg);
}
.td-right { text-align: right; font-variant-numeric: tabular-nums; }
.td-check { text-align: center; cursor: pointer; font-size: 14px; }
.check-empty { color: var(--text-light); }
.check-maru { color: var(--warning); }
.check-done  { color: var(--success); }

/* ===== Phase badges ===== */
.phase-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}
/* 新ステータス */
.phase-mitsumori { background: #dbeafe; color: #1d4ed8; }   /* 見積：青 */
.phase-juchu     { background: #d1fae5; color: #065f46; }   /* 受注：緑 */
.phase-gyomu     { background: #fef3c7; color: #b45309; }   /* 業務中：オレンジ */
.phase-seikyuu-s { background: #ede9fe; color: #6d28d9; }   /* 請求：紫 */
.phase-kanryo    { background: #e5e7eb; color: #374151; }   /* 完了：グレー */
.phase-horyuu    { background: #fef9c3; color: #854d0e; }   /* 保留：黄 */
.phase-chyudan   { background: #fee2e2; color: #991b1b; }   /* ロスト：赤 */
/* 旧フェーズ互換 */
.phase-keikaku  { background: #dbeafe; color: #1d4ed8; }
.phase-sekkei   { background: #ede9fe; color: #6d28d9; }
.phase-jissi    { background: #fef3c7; color: #b45309; }
.phase-other    { background: var(--border); color: var(--text-muted); }

/* Outsource status badge */
.status-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}
.status-mihattyu { background: #fef3c7; color: #92400e; }
.status-hattyu   { background: #dbeafe; color: #1e40af; }
.status-seikyuu  { background: #ede9fe; color: #5b21b6; }
.status-kanryo   { background: #d1fae5; color: #065f46; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 32px; padding: 0 14px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: rgba(255,255,255,.2); color: #fff; border: 1px solid rgba(255,255,255,.3); }
.btn-secondary:hover { background: rgba(255,255,255,.3); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-csv { background: #16a34a; color: #fff; border: 1px solid #15803d; }
.btn-csv:hover { background: #15803d; }
.btn-csv-import { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-csv-import:hover { background: #f1f5f9; }

/* ===== 支払CSVインポート プレビュー ===== */
.pip-row-nochange td { color: #94a3b8; }
.pip-row-notfound td, .pip-row-nomatch td { color: #dc2626; background: #fef2f2; }
.pip-badge { display:inline-block; padding:1px 7px; border-radius:10px; font-size:11px; font-weight:600; }
.pip-update   { background:#dcfce7; color:#15803d; }
.pip-nochange { background:#f1f5f9; color:#64748b; }
.pip-new      { background:#dbeafe; color:#1d4ed8; }
.pip-error     { background:#fee2e2; color:#dc2626; }
.pip-duplicate { background:#fef3c7; color:#92400e; }
.pip-row-nomatch   td { color: #1e40af; }
.pip-row-duplicate td { background:#fffbeb; }
.pip-row-duplicate td:first-child { border-left: 3px solid #f59e0b; }
#pip-ac-drop .pip-ac-item:hover { background: #eff6ff; }
#pip-ac-drop .pip-ac-item:active { background: #dbeafe; }
.btn-icon { background: none; color: var(--text-muted); padding: 2px 5px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-icon:hover { background: var(--border); }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  min-width: 180px; z-index: 200; overflow: hidden;
}
.dropdown-menu button {
  display: block; width: 100%; padding: 8px 14px;
  text-align: left; background: none; color: var(--text);
}
.dropdown-menu button:hover { background: var(--primary-light); color: var(--primary); }

/* ===== Modals ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.modal-dialog {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
  width: min(560px, 95vw);
  max-height: 90vh;
}
.modal-lg { width: min(800px, 95vw); }
.modal-sm { width: min(420px, 95vw); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }
.modal-close {
  background: none; color: var(--text-muted); font-size: 20px;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--border); }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Form */
.modal-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  margin-bottom: 12px;
}
.modal-section legend {
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 0 6px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.form-group { display: flex; flex-direction: column; gap: 3px; }
.form-group label { font-size: 11px; color: var(--text-muted); }
.form-group input,
.form-group select,
.form-group textarea {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s;
  background: var(--surface);
  color: var(--text);
}
.form-group textarea { height: auto; padding: 6px 8px; resize: vertical; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group input.error { border-color: var(--danger); }
.readonly-calc { background: var(--bg) !important; color: var(--text-muted); }
.col-span-2 { grid-column: span 2; }
.input-with-btn { display: flex; gap: 6px; align-items: center; }
.input-with-btn input { flex: 1; }
.req { color: var(--danger); }
.form-error { color: var(--danger); font-size: 12px; flex: 1; }

/* ===== Toast ===== */
#toast-container {
  position: fixed; top: 60px; right: 12px;
  z-index: 999; display: flex; flex-direction: column; gap: 6px;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideIn .2s ease;
  max-width: 320px;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(20px); } }

/* ===== Report Panel ===== */
/* レポート系オーバーレイは通常モーダル(500)より低くして、外注費編集等が手前に出るようにする */
.report-overlay { align-items: flex-start; padding: 0; z-index: 400; }
.report-dialog {
  width: 100%; height: 100vh; align-self: stretch;
  background: var(--bg);
  display: flex; flex-direction: column;
  overflow: hidden;
  border-radius: 0;
}
.report-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.report-header h2 { font-size: 16px; font-weight: 700; margin-right: 4px; }
.report-header .modal-close { color: rgba(255,255,255,.8); font-size: 22px; margin-left: auto; }
.report-header .modal-close:hover { color: #fff; background: rgba(255,255,255,.2); }
.report-filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.report-filters .filter-group label { color: rgba(255,255,255,.8); }
.report-filters .filter-group select {
  background: rgba(255,255,255,.15); color: #fff;
  border-color: rgba(255,255,255,.3);
}
.report-filters .filter-group select option { background: var(--primary-dark); color: #fff; }
.report-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.report-section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  flex-shrink: 0;
}
.report-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px 0 0; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.report-section-header .report-section-title {
  border-bottom: none; flex: 1;
}
.report-section-title {
  font-size: 13px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.btn-sm { font-size: 12px; padding: 4px 10px; }
/* KPI cards */
.report-kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.kpi-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 16px; display: flex; flex-direction: column; gap: 4px;
}
.kpi-label { font-size: 11px; color: var(--text-muted); }
.kpi-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); }
/* Tables */
.report-table-scroll { overflow-x: auto; max-height: 320px; overflow-y: auto; }
/* ダッシュボード案件一覧：画面いっぱいに伸ばす */
#modal-report .report-body { overflow-y: hidden; }
#report-case-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
#report-case-scroll  { flex: 1; max-height: none; overflow-x: auto; overflow-y: auto; min-height: 0; }
#report-case-table thead th { position: sticky; top: 0; z-index: 3; background: #f1f5f9; }
#report-case-table tfoot td { position: sticky; bottom: 0; z-index: 3; background: #f1f5f9; font-weight: 600; }
/* 支払予定表・入金予定表：テーブル部分を画面高さいっぱいに、見出し・合計固定 */
#modal-payment-report .report-table-scroll,
#modal-income-report  .report-table-scroll {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}
#pr-table thead th,
#ir-table thead th {
  position: sticky; top: 0; z-index: 3;
  background: var(--bg);
}
#pr-table tfoot td,
#ir-table tfoot td {
  position: sticky; bottom: 0; z-index: 3;
  background: #f1f5f9; font-weight: 700;
  border-top: 2px solid var(--border);
}

/* 予定表スクロール：独立モーダルで縦横スクロール有効 */
#fc-scroll-wrap { height: calc(100vh - 185px); overflow-x: auto; overflow-y: auto; }
.report-table { width: 100%; font-size: 12px; min-width: 600px; }
.report-table thead th {
  padding: 6px 10px; text-align: left;
  background: var(--bg); color: var(--text-muted);
  font-weight: 600; border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: default;
}
.report-table thead th[data-rsort] { cursor: pointer; }
.report-table thead th[data-rsort]:hover { color: var(--primary); }
.report-table thead th.rsort-asc::after  { content: ' ▲'; color: var(--primary); }
.report-table thead th.rsort-desc::after { content: ' ▼'; color: var(--primary); }
.report-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--border-light);
  white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis;
}
.report-table tr:hover td { background: var(--primary-light); }
.report-table tfoot td {
  padding: 6px 10px; font-weight: 700;
  border-top: 2px solid var(--border); background: var(--bg);
}
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.report-table .pos { color: var(--success); }
.report-table .neg { color: var(--danger); }

/* ===== Misc ===== */
.no-data { text-align: center; padding: 32px; color: var(--text-light); font-size: 13px; }

/* Scrollbar */
::-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-light); }

/* ===== 取引先管理 ===== */
.input-with-btn { display: flex; gap: 6px; align-items: center; }
.input-with-btn input { flex: 1; }
.td-actions { white-space: nowrap; text-align: center; }
.btn-danger-icon { color: var(--danger) !important; }

/* ===== 種別バッジ ===== */
.type-badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.type-shishu  { background: #dbeafe; color: #1d4ed8; }
.type-gaichuu { background: #dcfce7; color: #15803d; }

/* ===== フリガナオートコンプリート ===== */
.ac-wrap { position: relative; flex: 1; }
.ac-dropdown { position: absolute; top: 100%; left: 0; right: 0; z-index: 9999; background: #fff; border: 1px solid #d1d5db; border-radius: 4px; list-style: none; margin: 2px 0 0; padding: 0; max-height: 220px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.ac-dropdown li { padding: 7px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f3f4f6; }
.ac-dropdown li:last-child { border-bottom: none; }
.ac-dropdown li:hover, .ac-dropdown li.ac-active { background: #f0f4ff; }
.ac-furi { font-size: 11px; color: #888; margin-left: 8px; }

/* ===== 売上・粗利予定表 ===== */
.forecast-table { border-collapse: collapse; white-space: nowrap; font-size: 12px; }
.forecast-table .fc-sticky { position: sticky; background: #fff; z-index: 2; }
/* thead sticky（縦スクロール時に固定） */
.forecast-table thead th { position: sticky; top: 0; z-index: 4; background: #e8edf5; }
.forecast-table thead .fc-sticky { z-index: 6; background: #f1f5f9; }
/* tfoot sticky（縦スクロール時に画面下部に固定） */
.forecast-table tfoot td { position: sticky; bottom: 0; z-index: 4; background: #f1f5f9; }
.forecast-table tfoot .fc-sticky { z-index: 6; background: #f1f5f9; }
.forecast-table .fc-col-no      { left: 0;     min-width: 120px; max-width: 120px; border-right: 1px solid #e2e8f0; }
.forecast-table .fc-col-name    { left: 120px; min-width: 220px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid #e2e8f0; }
.forecast-table .fc-col-effdate { left: 340px; min-width: 100px; max-width: 100px; text-align: center; font-size: 11px; color: #475569; border-right: 2px solid #cbd5e1; }
.forecast-table .fc-col-label   { left: 440px; min-width: 34px;  width: 34px;      text-align: center; background: #f8fafc; font-size: 11px; }
.forecast-table thead .fc-col-label { background: #f1f5f9; }
.forecast-table tfoot .fc-col-label { background: #f1f5f9; }
.forecast-table .fc-col-total   { left: 474px; min-width: 100px; border-right: 2px solid #cbd5e1; border-left: 1px solid #e2e8f0; }
.forecast-table .fc-period-header { background: #e8edf5; text-align: center; font-size: 11px; color: #475569; border-left: 2px solid #cbd5e1; padding: 3px 6px; }
.forecast-table .fc-month-header  { text-align: center; min-width: 70px; font-size: 11px; border-left: 1px solid #e2e8f0; padding: 3px 4px; }
.forecast-table td, .forecast-table th { padding: 4px 6px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.forecast-table tr.fc-row-uriage td { border-bottom: none; padding-bottom: 2px; }
.forecast-table tr.fc-row-rieki  td { border-bottom: 1px solid #e2e8f0; padding-top: 2px; }
.forecast-table .fc-label-uriage { color: #1d4ed8; font-weight: 700; }
.forecast-table .fc-label-rieki  { color: #15803d; font-weight: 700; }
.forecast-table .fc-uriage { color: #1d4ed8; }
.forecast-table .fc-rieki  { color: #15803d; }
.forecast-table tr.fc-completed td { background: #f0fdf4 !important; }
.forecast-table thead tr:first-child th { background: #e8edf5; }
.forecast-table tfoot tr { background: #f1f5f9; font-weight: 600; }
.forecast-filters { display: inline-flex; align-items: center; gap: 6px; }
.forecast-filters label { font-size: 12px; color: #475569; }
.forecast-filters input[type=month] { padding: 3px 6px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 12px; }

/* ===== 入出金スケジュール ===== */
/* スクロール領域の高さ固定（thead/tfoot sticky を有効化）*/
#cf-scroll-wrap { height: calc(100vh - 185px); }

/* 完了日列 (left: 340px = No120 + Name220) */
.cashflow-table .cf-col-effdate { left: 340px; min-width: 90px; max-width: 90px; text-align: center; font-size: 11px; color: #475569; border-right: 2px solid #cbd5e1; }
/* ラベル・合計列の left を完了日列分ずらす */
.cashflow-table .fc-col-label { left: 430px; }
.cashflow-table .fc-col-total { left: 464px; }

/* thead sticky（縦スクロール時に固定） */
.cashflow-table thead th { position: sticky; top: 0; z-index: 4; background: #e8edf5; }
.cashflow-table thead .fc-sticky,
.cashflow-table thead .cf-col-effdate { z-index: 6; background: #f1f5f9; }

/* tfoot sticky（縦スクロール時に画面下部に固定） */
.cashflow-table tfoot td { position: sticky; bottom: 0; z-index: 4; background: #f1f5f9; }
.cashflow-table tfoot .fc-sticky,
.cashflow-table tfoot .cf-col-effdate { z-index: 6; background: #f1f5f9; }

.cashflow-table .cf-label-income  { color: #1d4ed8; font-weight: 700; }
.cashflow-table .cf-income        { color: #1d4ed8; }
.cashflow-table .cf-label-payment { color: #0891b2; font-weight: 700; }
.cashflow-table .cf-payment       { color: #0891b2; }
.cashflow-table .cf-payment-lead  { background-color: #ecfeff !important; }
.cashflow-table .cf-label-diff    { color: #475569; font-weight: 700; font-size: 10px; }
.cashflow-table .cf-diff          { color: #475569; }
.cashflow-table .cf-diff-neg      { color: #dc2626; font-weight: 600; }
.cashflow-table .cf-diff-pos      { color: #15803d; }
.cashflow-table tr.cf-row-income  td { border-bottom: none; padding-bottom: 2px; }
.cashflow-table tr.cf-row-payment td { border-bottom: none; padding-top: 2px; padding-bottom: 1px; }
.cashflow-table tr.cf-row-diff    td { border-bottom: 1px solid #e2e8f0; padding-top: 1px; font-size: 11px; background-color: #f8fafc; }
.cashflow-table tr.cf-foot-income  td { border-bottom: none; padding-bottom: 2px; }
.cashflow-table tr.cf-foot-payment td { border-bottom: none; padding-top: 2px; padding-bottom: 1px; }
.cashflow-table tr.cf-foot-diff    td { border-bottom: 1px solid #cbd5e1; padding-top: 1px; font-size: 11px; background-color: #f1f5f9; }

/* ===== 取引先管理 種別フィルター ===== */
.cm-toolbar { display: flex; align-items: center; gap: 8px; margin-right: 8px; }
.type-filter-btns { display: flex; gap: 3px; }
.type-filter-btn {
  padding: 3px 10px; font-size: 12px; border-radius: 12px; border: 1px solid #d1d5db;
  background: #fff; color: #374151; cursor: pointer; transition: background .15s, color .15s;
}
.type-filter-btn:hover { background: #f1f5f9; }
.type-filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 類似取引先候補ウォーニング ===== */
.similar-clients-warn {
  margin-top: 6px; padding: 7px 10px; background: #fffbeb;
  border: 1px solid #fcd34d; border-radius: 6px;
  font-size: 12px; color: #92400e; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.similar-icon { font-size: 14px; flex-shrink: 0; }
.similar-item {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; border: 1px solid #fcd34d; border-radius: 4px;
  padding: 1px 7px; font-weight: 600; color: #374151;
}

/* ===== ログイン画面 ===== */
#login-screen {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e8eaf6 0%, #f0f2f8 50%, #e3e8f5 100%);
}
#login-screen.hidden { display: none; }

.login-card {
  background: #fff; border-radius: 16px;
  box-shadow: 0 8px 32px rgba(61,82,160,.13), 0 2px 8px rgba(61,82,160,.08);
  padding: 48px 40px 40px; width: 100%; max-width: 400px;
  display: flex; flex-direction: column; align-items: center; gap: 0;
}

.login-logo { font-size: 40px; margin-bottom: 12px; }

.login-title {
  font-size: 22px; font-weight: 700; color: var(--primary);
  margin: 0 0 32px; letter-spacing: .02em;
}

#login-form { width: 100%; display: flex; flex-direction: column; gap: 16px; }

.login-field { display: flex; flex-direction: column; gap: 6px; }

.login-field label {
  font-size: 13px; font-weight: 600; color: #374151;
}

.login-field input {
  padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 15px; color: #1e293b !important; -webkit-text-fill-color: #1e293b !important;
  outline: none; transition: border-color .15s, box-shadow .15s;
  width: 100%; box-sizing: border-box;
}
.login-field input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(61,82,160,.12);
}
.login-field input:-webkit-autofill,
.login-field input:-webkit-autofill:hover,
.login-field input:-webkit-autofill:focus {
  -webkit-text-fill-color: #1e293b !important;
  box-shadow: 0 0 0px 1000px #fff inset, 0 0 0 3px rgba(61,82,160,.12);
  transition: background-color 9999s ease-in-out 0s;
}

.login-error {
  font-size: 13px; color: #dc2626;
  background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 7px; padding: 9px 12px;
}

.login-submit-btn {
  margin-top: 6px; padding: 13px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; font-weight: 700;
  cursor: pointer; transition: background .15s, transform .1s;
  width: 100%;
}
.login-submit-btn:hover { background: var(--primary-dark); }
.login-submit-btn:active { transform: scale(.98); }
.login-submit-btn:disabled { background: #94a3b8; cursor: not-allowed; transform: none; }

.login-reset-link {
  margin-top: 20px; background: none; border: none;
  color: #64748b; font-size: 13px; cursor: pointer;
  text-decoration: underline; padding: 0;
}
.login-reset-link:hover { color: var(--primary); }

.login-reset-msg {
  margin-top: 12px; width: 100%; font-size: 13px;
  background: #f0fdf4; border: 1px solid #bbf7d0;
  border-radius: 7px; padding: 9px 12px; color: #166534; text-align: center;
}

/* ===== ヘッダー：ログインユーザー情報 ===== */
.auth-user {
  display: flex; align-items: center; gap: 10px;
  padding-left: 12px; border-left: 1px solid var(--border);
}
.auth-email {
  font-size: 12px; color: rgba(255,255,255,.8); max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

