:root {
  --primary: #8a6d5c;
  --primary-dark: #6d5546;
  --bg: #faf7f4;
  --card: #ffffff;
  --border: #e4dcd4;
  --text: #3a322c;
  --muted: #8c8178;
  --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: #fdf6ef; 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: #f0e5da; }
/* ハンバーガーボタン (スマホのみ表示) */
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: #f3ede7; }
table.list td.nowrap { white-space: nowrap; }
table.list tr:hover td { background: #fbf5ef; }
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: #b7aa9e; }
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: #f3ede7; 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: #fdfaf6; }
.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: #f3ede7;
}
.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: #fdfaf6; 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: #f3ede7;
}
.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: #f3ede7;
  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: #fdfaf6;
  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: #f7efe7; }
.dropzone.dragover { background: #f0e2d4; 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: #f0e5da; 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: #f3ede7; }
  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; }
}
