/* =============================================
   簡易報告書アプリ - メインスタイル
   ============================================= */

/* ---------- リセット・基本設定 ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary:       #7c9ed9;
  --color-primary-dark:  #5a7fc4;
  --color-primary-light: #eef3fb;
  --color-secondary:     #79c0d0;
  --color-danger:        #e08b8b;
  --color-danger-dark:   #cc6e6e;
  --color-success:       #7ec8a0;
  --color-warning:       #e8c07a;
  --color-text:          #3d4a5c;
  --color-text-muted:    #7d90a6;
  --color-border:        #dde5ef;
  --color-bg:            #f0f4f9;
  --color-surface:       #ffffff;
  --shadow-sm:           0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:           0 4px 16px rgba(0,0,0,.1);
  --shadow-lg:           0 10px 40px rgba(0,0,0,.15);
  --radius:              10px;
  --radius-sm:           6px;
  --transition:          .2s ease;
}

html { scroll-behavior: smooth; }

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

/* ---------- ヘッダー ---------- */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--color-primary);
}

.header-brand i {
  font-size: 22px;
}

/* ---------- メイン ---------- */
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 24px 48px;
}

/* ---------- ツールバー ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 200px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  transition: border-color var(--transition);
}

.search-box:focus-within {
  border-color: var(--color-primary);
  background: #fff;
}

.search-box i { color: var(--color-text-muted); }

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--color-text);
}

.search-box input::placeholder { color: var(--color-text-muted); }

.filter-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-group select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 28px 7px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--color-text);
  background: var(--color-bg);
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color var(--transition);
}

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

.record-count {
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
  margin-left: auto;
}

.record-count span { font-weight: 600; color: var(--color-text); }

/* ---------- テーブルラッパー ---------- */
.table-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 報告書テーブル ---------- */
.report-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
  min-width: 860px;
}

/* ---- ヘッダー行 ---- */
.report-table thead tr {
  background: #b8ccec;
  color: #3d4a5c;
  user-select: none;
}

.report-table thead th {
  padding: 11px 14px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-align: left;
  white-space: nowrap;
  border-right: 1px solid rgba(255,255,255,.5);
  background: #b8ccec;
}

/* ヘッダー角丸 */
.report-table thead th:first-child { border-radius: var(--radius) 0 0 0; }
.report-table thead th:last-child  { border-right: none; border-radius: 0 var(--radius) 0 0; }

/* ---- ボディ行 ---- */
.report-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
  cursor: pointer;
}

/* ゼブラストライプ */
.report-table tbody tr:nth-child(even) {
  background: #f5f8fd;
}

.report-table tbody tr:nth-child(odd) {
  background: var(--color-surface);
}

.report-table tbody tr:hover {
  background: #e8f0fb !important;
}

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

/* ---- セル共通 ---- */
.report-table td {
  padding: 10px 14px;
  vertical-align: middle;
  border-right: 1px solid var(--color-border);
  color: var(--color-text);
}

.report-table td:last-child { border-right: none; }

/* ---- 列幅定義 ---- */
.report-table .col-no       { width: 44px;  text-align: center; color: var(--color-text-muted); font-size: 12px; }
.report-table .col-date     { width: 92px;  white-space: nowrap; }
.report-table .col-title    { min-width: 160px; }
.report-table .col-author   { width: 80px;  white-space: nowrap; }
.report-table .col-dept     { width: 110px; }
.report-table .col-time     { width: 110px; white-space: nowrap; font-size: 12.5px; }
.report-table .col-summary  { min-width: 150px; }
.report-table .col-status   { width: 96px;  text-align: center; }
.report-table .col-actions  { width: 88px;  text-align: center; white-space: nowrap; }

/* ---- タイトルセル ---- */
.td-title {
  font-weight: 600;
  color: var(--color-text);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- 概要セル ---- */
.td-summary {
  color: var(--color-text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

/* ---- カテゴリ左端カラーライン ---- */
.cat-line {
  display: inline-block;
  width: 4px;
  height: 14px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 5px;
}

/* ---- アクションボタン ---- */
.action-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--color-text-muted);
  font-family: inherit;
}

.action-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

.action-btn.delete:hover {
  border-color: var(--color-danger);
  color: var(--color-danger);
  background: #fef2f2;
}

/* ---------- バッジ ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

/* カテゴリバッジ */
.badge-category-業務報告 { background: #d6e4f7; color: #4a6fa5; }
.badge-category-進捗報告 { background: #d2ede0; color: #3a7a5a; }
.badge-category-障害報告 { background: #f7d9d9; color: #a04040; }
.badge-category-提案     { background: #faecd0; color: #8a6020; }
.badge-category-その他   { background: #e8edf4; color: #5a6a7e; }

/* ステータスバッジ */
.badge-status-下書き   { background: #e8edf4; color: #5a6a7e; }
.badge-status-提出済み { background: #d6e4f7; color: #4a6fa5; }
.badge-status-承認済み { background: #d2ede0; color: #3a7a5a; }
.badge-status-差し戻し { background: #f7d9d9; color: #a04040; }

/* ---------- 空・ローディング状態 ---------- */
.empty-state, .loading-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--color-text-muted);
}

.empty-state i, .loading-state i {
  font-size: 56px;
  display: block;
  margin-bottom: 16px;
  opacity: .4;
}

.empty-state p, .loading-state p {
  font-size: 16px;
  margin-bottom: 20px;
}

/* ---------- ページネーション ---------- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 28px;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13.5px;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.page-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

.page-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

.page-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

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

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary {
  background: var(--color-secondary);
  color: #fff;
}
.btn-secondary:hover { background: #0284c7; }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover { background: var(--color-danger-dark); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

/* ---------- モーダル ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
  animation: fadeIn .18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .22s ease;
}

.modal-lg { max-width: 780px; }
.modal-sm { max-width: 420px; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text);
}

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

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---------- フォーム ---------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 140px;
}

.form-group.flex-2 { flex: 2; }

.form-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.form-group + .form-group { /* sibling spacing handled by form-row */ }

.form-group:not(.form-row .form-group) {
  margin-bottom: 14px;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

.required {
  color: var(--color-danger);
  margin-right: 2px;
}

input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

input[type="text"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

textarea { resize: vertical; min-height: 80px; }

/* ---------- フォームセクションラベル ---------- */
.form-section-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-primary-light);
  border-left: 3px solid var(--color-primary);
  padding: 6px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 7px;
}

/* ---------- 時間セパレータ ---------- */
.form-time-sep {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text-muted);
  padding-top: 24px;
  flex-shrink: 0;
}

/* ---------- 施術件数グリッド ---------- */
.form-count-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px 16px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 4px;
}

.form-count-item label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-text-muted);
  display: block;
  margin-bottom: 4px;
}

.count-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.count-input-wrap input[type="number"] {
  width: 70px;
  text-align: center;
  padding: 6px 8px;
  font-weight: 600;
  font-size: 14px;
}

.count-unit {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 500;
}

/* ---------- テーブル行：担当者+訪問場所 ---------- */
.td-sub {
  font-size: 12px;
  color: var(--color-text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

/* ---------- 交通バッジ ---------- */
.badge-transport {
  background: #e8f4f8;
  color: #2a7a9a;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  display: inline-block;
}

.transport-fee {
  font-size: 11.5px;
  color: var(--color-text-muted);
  display: block;
  margin-top: 2px;
}

/* ---------- 施術件数サマリー（テーブル行） ---------- */
.td-cnt-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary);
  display: block;
  line-height: 1.2;
}
.td-cnt-total .cnt-unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-left: 1px;
}
.td-summary-detail {
  font-size: 11.5px;
  color: var(--color-text-muted);
  display: block;
  margin-top: 2px;
}

/* ---------- 詳細モーダル：課題グリッド（2列） ---------- */
.detail-issue-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 4px;
}

/* ---------- 詳細モーダル：施術件数グリッド ---------- */
.detail-cnt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 4px;
}

.detail-cnt-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
  opacity: .55;
}

.detail-cnt-item.active {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  opacity: 1;
}

.cnt-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.detail-cnt-item.active .cnt-label {
  color: var(--color-primary);
}

.cnt-val {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

.detail-cnt-item.active .cnt-val {
  color: var(--color-primary);
}

.cnt-val small {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-left: 2px;
}

/* ---------- 詳細モーダルコンテンツ ---------- */
.detail-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 20px;
}

.detail-meta-item label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.detail-meta-item p {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--color-text);
  margin-top: 2px;
}

.detail-section {
  margin-bottom: 18px;
}

.detail-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-section-title i {
  color: var(--color-primary);
}

.detail-section-body {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--color-text);
  white-space: pre-wrap;
  min-height: 56px;
}

.detail-section-body.empty {
  color: var(--color-text-muted);
  font-style: italic;
}

/* ---------- トースト通知 ---------- */
.toast {
  position: fixed;
  bottom: 32px;
  right: 32px;
  z-index: 9999;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn .25s ease;
  max-width: 360px;
}

.toast.toast-success { background: #16a34a; }
.toast.toast-error   { background: #dc2626; }
.toast.toast-warning { background: #d97706; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- レスポンシブ ---------- */
@media (max-width: 768px) {
  .app-main { padding: 16px 16px 48px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .filter-group { justify-content: stretch; }
  .filter-group select { flex: 1; }
  .table-wrapper { border-radius: var(--radius-sm); }
  .report-table { font-size: 12.5px; }
  .report-table td, .report-table th { padding: 8px 10px; }
  .modal { max-width: 100%; margin: 0; border-radius: var(--radius) var(--radius) 0 0; align-self: flex-end; max-height: 95vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .form-row { flex-direction: column; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; justify-content: center; }
  .toast { right: 16px; bottom: 16px; left: 16px; max-width: unset; }
}

/* ---------- 写真アップロードエリア ---------- */
.photo-upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  background: #f8fafc;
  margin-bottom: 8px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.photo-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 4/3;
  background: #e8edf4;
  box-shadow: var(--shadow-sm);
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: opacity var(--transition);
}
.photo-item img:hover { opacity: .85; }

.photo-del-btn {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(220,50,50,.85);
  border: none; color: #fff;
  font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
  transition: background var(--transition);
}
.photo-del-btn:hover { background: rgba(180,30,30,1); }

.photo-add-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--color-primary-light);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  color: var(--color-primary-dark);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.photo-add-btn:hover { background: var(--color-primary); color: #fff; }
.photo-add-btn:disabled { opacity: .45; cursor: not-allowed; }

.photo-hint {
  font-size: 11.5px;
  color: var(--color-text-muted);
  margin-top: 7px;
}

/* 写真ライトボックス */
.lightbox-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
}
.lightbox-overlay img {
  max-width: 92vw; max-height: 88vh;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}

/* 詳細モーダル内の写真グリッド */
.detail-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.detail-photo-grid img {
  width: 100%; aspect-ratio: 4/3;
  object-fit: cover; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm); cursor: zoom-in;
  transition: opacity var(--transition);
}
.detail-photo-grid img:hover { opacity: .85; }
