:root {
  --primary: #2f5d8a;
  --primary-dark: #244a6e;
  --bg: #f4f7fa;
  --card: #ffffff;
  --border: #d5dee8;
  --text: #25313d;
  --muted: #7a8794;
  --danger: #b0413e;
  --ok: #4e7a51;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-size: 15px; line-height: 1.6;
}
a { color: var(--primary-dark); }
header.site {
  background: var(--primary); color: #fff; padding: 10px 20px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
header.site .brand { font-weight: bold; font-size: 17px; color: #fff; text-decoration: none; white-space: nowrap; }
header.site .menu { display: flex; align-items: center; gap: 20px; flex: 1; flex-wrap: wrap; }
header.site nav { display: flex; gap: 14px; flex-wrap: wrap; }
header.site nav a, header.site .account a { color: #f2f7fc; text-decoration: none; font-size: 14px; }
header.site nav a:hover, header.site .account a:hover { text-decoration: underline; }
header.site .spacer { flex: 1; }
header.site .account { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
header.site .user { font-size: 13px; color: #dbe7f3; }
/* ハンバーガーボタン (スマホのみ表示) */
header.site .menu-toggle {
  display: none; margin-left: auto; width: 42px; height: 38px; padding: 6px 9px;
  background: transparent; border: 1px solid rgba(255,255,255,0.55); border-radius: 6px;
  cursor: pointer; flex-direction: column; justify-content: space-between;
}
header.site .menu-toggle span { display: block; height: 2px; background: #fff; border-radius: 2px; }
.badge {
  background: #e0503c; color: #fff; border-radius: 10px;
  font-size: 11px; padding: 1px 7px; margin-left: 3px;
}
main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 18px 22px; margin-bottom: 18px;
}
h1 { font-size: 21px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 20px 0 8px; border-left: 4px solid var(--primary); padding-left: 8px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: 14px; }
table.list th { background: #e9eff5; }
table.list td.nowrap { white-space: nowrap; }
table.list tr:hover td { background: #f0f5fa; }
table.list th a { color: var(--text); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
table.list th a:hover { color: var(--primary-dark); }
table.list th .sort-icon { font-size: 11px; color: #a3b1c0; }
table.list th.sorted a { color: var(--primary-dark); }
table.list th.sorted .sort-icon { color: var(--primary-dark); }
.sort-bar { display: none; }
table.detail { width: 100%; border-collapse: collapse; }
table.detail th, table.detail td { border: 1px solid var(--border); padding: 7px 10px; font-size: 14px; text-align: left; }
table.detail th { background: #e9eff5; width: 180px; font-weight: 600; }
.btn {
  display: inline-block; background: var(--primary); color: #fff; border: none;
  padding: 7px 16px; border-radius: 5px; font-size: 14px; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--primary-dark); border: 1px solid var(--primary); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 3px 10px; font-size: 12px; }
form.inline { display: inline; }
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; font-size: 14px; }
.messages li.success { background: #e6efe4; color: var(--ok); }
.messages li.info { background: #e8ecf3; color: #40597e; }
.messages li.error { background: #f6e2e1; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
.form-grid .full { grid-column: 1 / -1; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.field input[type=text], .field input[type=email], .field input[type=date],
.field input[type=datetime-local], .field input[type=password], .field select, .field textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 14px; font-family: inherit; background: #fff;
}
.field .errorlist { color: var(--danger); font-size: 12px; margin: 2px 0 0; padding-left: 16px; }
.field .helptext { color: var(--muted); font-size: 12px; }
ul.checkbox-list { list-style: none; padding: 0; margin: 0; column-count: 2; }
ul.checkbox-list li { font-size: 14px; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=text] { padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; }
.toolbar select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-family: inherit; font-size: 14px; background: #fff; }
.toolbar .spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.login-box { max-width: 380px; margin: 60px auto; }
.intake-item { background: #f7fafd; }
.intake-files { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.file-row .name { flex: 1; min-width: 200px; }
.activity { font-size: 13px; border-left: 3px solid var(--border); padding-left: 10px; margin-bottom: 10px; }
.activity .meta { color: var(--muted); font-size: 12px; }
pre.summary { white-space: pre-wrap; font-family: inherit; margin: 4px 0 0; font-size: 13px; }
.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }

/* 撮影画像ギャラリー */
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin: 0;
}
.photo-card { margin: 0; position: relative; }
.photo-card img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in;
  display: block; background: #e9eff5;
}
.photo-card figcaption {
  font-size: 12px; color: var(--muted); margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.photo-card .photo-delete {
  position: absolute; top: 6px; right: 6px; line-height: 1;
  padding: 2px 8px; opacity: 0.85;
}

/* 更新情報 (メモ) */
.memo-form { display: flex; gap: 8px; align-items: flex-start; }
.memo-form textarea {
  flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 14px; font-family: inherit; resize: vertical;
}
.memo { border-left: 3px solid var(--primary); padding: 6px 12px; margin: 10px 0; background: #f7fafd; border-radius: 0 6px 6px 0; }
.memo-meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.memo-text { font-size: 14px; margin-top: 3px; white-space: pre-wrap; }

/* ファイル一覧 (サムネイルカード) */
.file-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin: 0;
}
.file-card { margin: 0; }
.file-card a { text-decoration: none; }
.file-card img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 6px; border: 1px solid var(--border); display: block; background: #e9eff5;
}
.file-tile {
  width: 100%; aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; border: 1px solid var(--border); background: #e9eff5;
  color: var(--primary-dark); font-weight: bold; font-size: 20px; letter-spacing: 1px;
}
.file-tile-pdf { background: #f6e2e1; color: #93312e; }
.file-tile-svg { background: #e8ecf3; color: #40597e; }
.file-card figcaption {
  font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-meta { font-size: 11px; color: var(--muted); }
.file-actions { display: flex; gap: 4px; margin-top: 4px; }

/* 写真のドラッグ&ドロップ受付エリア */
.dropzone {
  border: 2px dashed var(--primary);
  border-radius: 8px;
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  background: #f7fafd;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone p { margin: 0 0 10px; color: var(--primary-dark); font-size: 15px; line-height: 1.8; }
.dropzone .browse-btn { pointer-events: none; }  /* クリックはエリア全体で受ける */
.dropzone:hover { background: #eaf1f8; }
.dropzone.dragover { background: #d9e6f3; border-color: var(--primary-dark); }
.dropzone.uploading { opacity: 0.6; pointer-events: none; }

/* 拡大表示 (ライトボックス) */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(30, 24, 20, 0.88);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 24px;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 95vw; max-height: 92vh; text-align: center; }
.lightbox img {
  max-width: 95vw; max-height: 85vh; object-fit: contain;
  border-radius: 4px; box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.lightbox figcaption { color: #dbe7f3; font-size: 13px; margin-top: 10px; }

/* ------------------------------------------------------------------
   レスポンシブ (スマホ・タブレット)
   ------------------------------------------------------------------ */
@media (max-width: 900px) {
  main { margin: 16px auto; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  ul.checkbox-list { column-count: 1; }
}

@media (max-width: 768px) {
  body { font-size: 15px; }
  main { margin: 12px auto; padding: 0 10px; }
  .card { padding: 14px 14px; margin-bottom: 12px; border-radius: 8px; }
  h1 { font-size: 19px; }
  h2 { font-size: 16px; margin: 18px 0 8px; }

  /* ヘッダー: ブランド + ハンバーガー。メニューは縦に展開 */
  header.site { padding: 10px 14px; gap: 10px; }
  header.site .brand { font-size: 16px; }
  header.site .menu-toggle { display: flex; }
  header.site .menu {
    display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 0;
    border-top: 1px solid rgba(255,255,255,0.3); margin-top: 6px; padding-top: 6px;
  }
  header.site.open .menu { display: flex; }
  header.site nav { flex-direction: column; gap: 0; }
  header.site nav a, header.site .account a {
    display: block; padding: 11px 6px; font-size: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
  }
  header.site .spacer { display: none; }
  header.site .account { flex-direction: column; align-items: stretch; gap: 0; }
  header.site .user { padding: 10px 6px 4px; }
  header.site .account form { padding: 10px 6px 4px; }
  header.site .account .btn { width: 100%; padding: 10px; font-size: 15px; }

  /* ボタン・入力欄はタップしやすい大きさに。フォントは16px以上でiOSの自動ズームを防ぐ */
  .btn { padding: 10px 16px; font-size: 15px; }
  .btn.small { padding: 7px 12px; font-size: 13px; }
  .field input[type=text], .field input[type=email], .field input[type=date],
  .field input[type=datetime-local], .field input[type=password], .field select, .field textarea,
  .toolbar input[type=text], .toolbar select, .memo-form textarea, .sort-bar select {
    font-size: 16px; padding: 9px 10px;
  }
  .toolbar { gap: 8px; }
  .toolbar input[type=text] { flex: 1 1 100%; min-width: 0; }
  .toolbar select { flex: 1 1 auto; }
  .toolbar .spacer { display: none; }
  .detail-toolbar h1 { flex-basis: 100%; }
  .detail-toolbar .btn { flex: 1 1 auto; text-align: center; }
  .detail-toolbar form.inline { flex: 1 1 auto; display: flex; }
  .detail-toolbar form.inline .btn { width: 100%; }

  /* 案件一覧の並べ替え: 列見出しの代わりにセレクトで指定 */
  .sort-bar { display: flex; gap: 8px; align-items: center; margin: -4px 0 12px; flex-wrap: wrap; }
  .sort-bar label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex: 1; }
  .sort-bar select {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px;
    font-family: inherit; background: #fff; flex: 1; min-width: 0;
  }

  /* 一覧表 → カード表示 */
  table.list.responsive, table.list.responsive tbody, table.list.responsive tr, table.list.responsive td { display: block; width: 100%; }
  table.list.responsive thead { display: none; }
  table.list.responsive tr {
    border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px;
    padding: 8px 12px; background: #fff;
  }
  table.list.responsive tr:hover td { background: transparent; }
  table.list.responsive td {
    border: none; padding: 4px 0; font-size: 14px;
    display: flex; gap: 10px; align-items: baseline;
  }
  table.list.responsive td[data-label]::before {
    content: attr(data-label); flex: 0 0 7em; color: var(--muted); font-size: 12px;
  }
  table.list.responsive td.primary { font-size: 16px; font-weight: 600; padding-bottom: 6px; }
  table.list.responsive td.primary::before { display: none; }
  table.list.responsive td.actions { padding-top: 8px; justify-content: flex-end; }
  table.list.responsive td.actions::before { display: none; }
  table.list.responsive td[colspan] { display: block; }
  table.list.responsive td pre.summary { flex: 1; min-width: 0; }

  /* 詳細表 → 見出しと値を縦積み */
  table.detail, table.detail tbody, table.detail tr, table.detail th, table.detail td { display: block; width: 100%; }
  table.detail tr { border: 1px solid var(--border); border-bottom: none; }
  table.detail tr:last-child { border-bottom: 1px solid var(--border); }
  table.detail th { border: none; padding: 6px 10px 2px; font-size: 12px; color: var(--muted); background: #e9eff5; }
  table.detail td { border: none; border-bottom: 1px solid var(--border); padding: 5px 10px 8px; min-height: 1.6em; }
  table.detail td:last-child { border-bottom: none; }
  /* お客様情報: カスタマー1/2の見出し行を隠し、各値の前に表示 */
  table.detail.customers tr.head { display: none; }
  table.detail.customers td[data-label]::before {
    content: attr(data-label) " "; color: var(--primary-dark); font-size: 12px; font-weight: 600; margin-right: 6px;
  }

  /* フォーム・メモ・ギャラリー */
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .memo-form { flex-direction: column; }
  .memo-form textarea { width: 100%; }
  table.list.responsive td.nowrap { white-space: normal; }
  .memo-form .btn { align-self: flex-end; }
  .photo-grid, .file-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  .dropzone { padding: 20px 12px; }
  .lightbox { padding: 10px; }
  .lightbox figure { max-width: 100vw; }
  .lightbox img { max-width: 96vw; max-height: 80vh; }
  .login-box { margin: 24px auto; }
  .file-row .name { min-width: 0; }
  .messages li { font-size: 14px; }
  .intake-item .toolbar select { flex: 1 1 100%; }
  .intake-item .toolbar .btn { width: 100%; }
}

@media (max-width: 420px) {
  .photo-grid, .file-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  table.list.responsive td[data-label]::before { flex-basis: 6em; }
}

/* 日報 */
.report { border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 10px 0; background: #f7fafd; }
.report-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.report-head .date { font-weight: 700; font-size: 15px; }
.report-head .tags span { display: inline-block; background: #e9eff5; border-radius: 10px; padding: 1px 9px; font-size: 12px; margin-right: 4px; color: var(--primary-dark); }
.report-head .via { font-size: 11px; color: var(--muted); }
.report-body { font-size: 14px; margin-top: 6px; white-space: pre-wrap; }
.report-sub { font-size: 13px; color: #40597e; margin-top: 4px; }
.report-issue { font-size: 13px; color: var(--danger); margin-top: 4px; }
.report-photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.report-photos img { width: 64px; height: 64px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }
.report-form .form-grid { gap: 0 16px; }
.report-actions { display: flex; gap: 6px; margin-left: auto; }
.status-badge { display: inline-block; border-radius: 10px; padding: 1px 9px; font-size: 12px; background: #e9eff5; color: var(--primary-dark); white-space: nowrap; }
.status-badge.in_progress { background: #e2f1e5; color: #2c6a3b; }
.status-badge.completed, .status-badge.invoiced, .status-badge.paid { background: #eceff2; color: #5b6773; }
.status-badge.estimate { background: #fff3dc; color: #8a5a00; }
.progress-bar { display: inline-block; width: 90px; height: 8px; background: #e9eff5; border-radius: 4px; vertical-align: middle; overflow: hidden; }
.progress-bar i { display: block; height: 100%; background: var(--primary); }
.phase-tag { position: absolute; left: 6px; top: 6px; font-size: 11px; background: rgba(47,93,138,0.85); color: #fff; border-radius: 4px; padding: 1px 6px; }
ul.checkbox-list.inline-checks { column-count: 1; display: flex; flex-wrap: wrap; gap: 4px 18px; }

/* 写真台帳の編集 */
.phase-tag.excluded { left: auto; right: 6px; background: rgba(120,120,120,0.85); }
.album-list { list-style: none; margin: 0; padding: 0; }
.album-item {
  display: grid; grid-template-columns: 28px 120px 1fr auto; gap: 12px; align-items: start;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px; background: #fff;
}
.album-item.dragging { opacity: 0.4; }
.album-item.drag-over { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(47,93,138,0.25); }
.album-item .handle { cursor: grab; font-size: 20px; color: var(--muted); text-align: center; user-select: none; }
.album-item img { width: 120px; height: 120px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.album-item .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.album-item .fields label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.album-item .fields input[type=text], .album-item .fields select { width: 100%; }
.album-item .meta { font-size: 12px; color: var(--muted); grid-column: 1 / -1; }
.album-item .move { display: flex; flex-direction: column; gap: 4px; }
.album-item.excluded { background: #f3f4f6; }
.album-item.excluded img { opacity: 0.5; }
@media (max-width: 767px) {
  .album-item { grid-template-columns: 24px 88px 1fr; }
  .album-item img { width: 88px; height: 88px; }
  .album-item .move { grid-column: 1 / -1; flex-direction: row; }
}
