:root {
  --fg: #222;
  --muted: #777;
  --border: #ddd;
  --bg: #fafafa;
  --accent: #2b6cb0;
  --danger: #c53030;
  --chip-unpaid: #e0a800;
  --chip-exhibit: #2b6cb0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--fg);
  background: var(--bg);
}

header.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

header.topnav h1 {
  font-size: 16px;
  margin: 0 16px 0 0;
  white-space: nowrap;
}

header.topnav nav a {
  padding: 6px 10px;
  text-decoration: none;
  color: var(--fg);
  border-radius: 4px;
  font-size: 14px;
}
header.topnav nav a.active,
header.topnav nav a:hover {
  background: #eef3fb;
  color: var(--accent);
}

.save-bar {
  margin-left: auto;
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  align-items: center;
}
.save-bar #save-changes-btn { font-weight: bold; }
.save-bar .saved-ok { color: #1a7a3c; font-weight: bold; }
.save-bar .save-hint { max-width: 280px; }

main#app {
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}
main#app.wide { max-width: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}

.toolbar select, .toolbar input[type=text] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
button:hover { background: #f0f0f0; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { opacity: 0.9; }
button.danger { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: 0.6; cursor: default; }

.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chip {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eee;
  color: var(--fg);
}
.chip.unpaid { background: var(--chip-unpaid); color: #fff; }
.chip.exhibit { background: var(--chip-exhibit); color: #fff; }
.chip.sold { background: #6b7280; color: #fff; }
.chip.hidden-chip { background: #6b7280; color: #fff; }

.list-table-wrap {
  overflow: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
}
table.work-table {
  font-size: 12px;
  white-space: nowrap;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
table.work-table th, table.work-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}
table.work-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f5f5f5;
}
table.work-table tr.work-row { cursor: pointer; }
table.work-table tr.work-row:hover { background: #f5f9ff; }
table.work-table tr.hidden-row { background: #f2f2f2; color: var(--muted); }
table.work-table tr.hidden-row:hover { background: #ececec; }
table.work-table td.col-thumb { text-align: center; }
table.work-table td.col-thumb img { max-width: 76px; max-height: 76px; width: auto; height: auto; display: block; margin: 0 auto; border-radius: 3px; }
table.work-table td.col-thumb .no-thumb { font-size: 10px; color: var(--muted); }
table.work-table td.col-title { font-weight: bold; }
table.work-table td.col-exhibition { white-space: normal; line-height: 1.4; }
table.work-table td.col-exhibition .ex-more { color: var(--muted); font-size: 11px; }

/* 所在・ステータス・展示遍歴セル: クリック/フォーカスでその場編集・コピペできる（design.md §4-1） */
table.work-table td.col-location,
table.work-table td.col-status {
  cursor: pointer;
}
table.work-table td.col-location:hover,
table.work-table td.col-status:hover {
  background: #f5f9ff;
}
table.work-table td.col-location input.cell-edit-input {
  width: 100%;
  border: 1px solid var(--accent);
  background: #fff;
  font: inherit;
  color: inherit;
  padding: 2px 4px;
  border-radius: 3px;
  box-sizing: border-box;
}
table.work-table td.col-status select.cell-edit-select {
  width: 100%;
  font: inherit;
}
table.work-table td.col-exhibition:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #eef4ff;
}
table.work-table td.col-exhibition.ex-copied {
  background: #dff5df;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 2;
}
.col-resizer:hover, .col-resizer.active { background: var(--accent); opacity: 0.5; }

form.detail-form {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.field-row label { color: var(--muted); font-size: 13px; }
.field-row input[type=text],
.field-row input[type=number],
.field-row select,
.field-row textarea {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 100%;
}

section.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
}
section.panel h2 { font-size: 15px; margin: 0 0 10px; }
section.panel h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); }

/* ラベル+入力欄を横並びに並べる（規格の固定引き・0号の固定価格・原価率/消費税率など、短い数値入力用） */
.field-row-inline-list { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 10px; }
.field-row-inline-list .field-row-inline { display: flex; align-items: center; gap: 6px; }
.field-row-inline-list .field-row-inline label { color: var(--muted); font-size: 13px; white-space: nowrap; }
.field-row-inline-list .field-row-inline input {
  width: 90px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data-table th, table.data-table td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}
table.data-table th { background: #f5f5f5; }
table.data-table.price-table {
  table-layout: fixed;
  min-width: 900px;
  border: 2px solid var(--border);
}
table.data-table.price-table td, table.data-table.price-table th { text-align: right; }
table.data-table.price-table td:first-child, table.data-table.price-table th:first-child { text-align: left; }
/* ヘッダとデータの境目の横罫線を太く */
table.data-table.price-table thead tr:last-child th { border-bottom: 2px solid var(--border); }
/* 号数列の右側（号数とS規格の間）の縦罫線を太く */
table.data-table.price-table th:first-child,
table.data-table.price-table td:first-child { border-right: 2px solid var(--border); }
/* 規格（S/F/P/M）を分けている縦罫線を太く */
table.data-table.price-table thead tr:first-child th:not(:first-child):not(:last-child) { border-right: 2px solid var(--border); }
table.data-table.price-table thead tr:last-child th:nth-child(3),
table.data-table.price-table thead tr:last-child th:nth-child(6),
table.data-table.price-table thead tr:last-child th:nth-child(9) { border-right: 2px solid var(--border); }
table.data-table.price-table tbody td:nth-child(4),
table.data-table.price-table tbody td:nth-child(7),
table.data-table.price-table tbody td:nth-child(10) { border-right: 2px solid var(--border); }
table.data-table.price-table td input[type=number] {
  width: 100%;
  box-sizing: border-box;
  padding: 3px 4px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 3px;
}

.table-scroll { overflow-x: auto; }

.image-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.image-list .image-item { border: 1px solid var(--border); border-radius: 4px; padding: 4px; text-align: center; }
/* 一覧のサムネイルと同じく、元画像のアスペクト比のまま表示する（クロップしない）。 */
.image-list .image-item img { max-width: 100px; max-height: 100px; width: auto; height: auto; display: block; margin: 0 auto; }
.image-list .image-item .path { font-size: 10px; color: var(--muted); max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* スマホから撮った写真をその場でアップロードする欄（design.md §4-9） */
.image-upload { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.image-upload input[type="file"] { flex: 1; min-width: 200px; }
.image-upload #upload-image-msg { flex-basis: 100%; }
.image-upload #upload-image-msg .msg { margin-bottom: 0; }
.manual-image-path { margin-top: 10px; }
.manual-image-path summary { font-size: 12px; color: var(--muted); cursor: pointer; }

.wafer-row { display: flex; gap: 8px; margin-bottom: 6px; align-items: center; }

.price-box {
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 10px;
  margin: 10px 0;
  font-size: 13px;
}
.price-box .amount { font-size: 20px; font-weight: bold; }
.price-box .judge { color: var(--muted); }

.msg { padding: 8px 10px; border-radius: 4px; margin-bottom: 10px; font-size: 13px; }
.msg.info { background: #e8f0fe; color: #1a4a8a; }
.msg.warn { background: #fff3cd; color: #7a5600; }
.msg.error { background: #fde2e2; color: #7a1f1f; }

.actions-row { display: flex; gap: 8px; margin-top: 12px; }

table.data-table tr.row-error { background: #fde2e2; }
table.data-table tr.row-error:hover { background: #fbd0d0; }

.checkbox-cell { text-align: center; }

/* スマホで開くためのQRコード（design.md §4-9・ADR-056） */
#phone-qr-btn { margin-left: 8px; font-size: 12px; }
#phone-qr-panel {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  text-align: center;
}
#phone-qr-panel .qr-title { font-size: 13px; margin-bottom: 8px; }
#phone-qr-panel .qr-items { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; }
#phone-qr-panel .qr-item svg { display: block; margin: 0 auto; }
#phone-qr-panel .qr-url { font-size: 12px; color: var(--muted); margin-top: 4px; }
#phone-qr-panel .qr-note { font-size: 11px; color: var(--muted); margin-top: 8px; }
body.read-only #phone-qr-btn { display: none; }

/* ============================================================
   閲覧専用モード（design.md §14・ADR-055）
   Cloudflare Pages へ公開したとき（https）は、保存・編集・アップロードの導線を隠す。
   一覧の検索・絞り込み・並び替えと、詳細の閲覧だけを残す。
   ============================================================ */
body.read-only nav a[data-route="new"],
body.read-only nav a[data-route="masters"],
body.read-only #list-actions,
body.read-only #export-result,
body.read-only .checkbox-cell,
body.read-only .image-upload,
body.read-only .manual-image-path,
body.read-only #price-panel-section .actions-row,
body.read-only #price-panel-section button,
body.read-only .image-list .image-item button,
body.read-only [data-remove-exhibition],
body.read-only #add-exhibition-btn {
  display: none !important;
}
/* 展示遍歴の「追記」入力欄一式（追記ボタンと同じ行）も隠す */
body.read-only #ex-date,
body.read-only #ex-name,
body.read-only #ex-venue,
body.read-only #ex-gallery,
body.read-only #ex-note { display: none; }
/* 所在・ステータスのその場編集（クリックで入力欄化）も無効にする */
body.read-only table.work-table td.col-location,
body.read-only table.work-table td.col-status { cursor: default; pointer-events: none; }
body.read-only table.work-table td.col-location:hover,
body.read-only table.work-table td.col-status:hover { background: transparent; }

/* ============================================================
   スマホ向け表示（design.md §4-10・ADR-054）
   一覧の横長テーブルは画面幅が狭いと読めないため、1作品＝1カードに組み替える。
   列見出しは隠し、各セルの data-label を値の前に小さく出して項目名が分かるようにする。
   ============================================================ */
@media (max-width: 720px) {
  main#app { padding: 10px; }
  header.topnav { padding: 8px 10px; }
  header.topnav h1 { font-size: 15px; margin-right: 8px; }

  /* 絞り込み・並び順は横幅いっぱいの縦積みにして、指で押せる大きさにする。
     検索欄だけは「検索」ボタンと同じ行に収まるようにする。 */
  .toolbar { gap: 6px; }
  .toolbar select { flex: 1 1 100%; min-height: 38px; font-size: 16px; }
  .toolbar input[type=text] { flex: 1 1 180px; min-height: 38px; font-size: 16px; }
  .toolbar button { min-height: 38px; }
  /* iOSは16px未満の入力欄でフォーカス時に自動ズームするため、入力系は16pxにする */
  .field-row input, .field-row select, .field-row textarea,
  .image-upload input[type="file"] { font-size: 16px; }

  /* 詳細・新規登録フォームはラベルと入力を縦に積む */
  .field-row { grid-template-columns: 1fr; gap: 2px; }
  form.detail-form { padding: 12px; }

  /* 一覧: テーブル → カード */
  .list-table-wrap { overflow: visible; background: transparent; border: none; border-radius: 0; }
  table.work-table { display: block; table-layout: auto; white-space: normal; font-size: 13px; }
  table.work-table colgroup,
  table.work-table thead { display: none; }
  table.work-table tbody { display: block; }
  table.work-table tr.work-row {
    display: grid;
    grid-template-columns: 22px 92px minmax(0, 1fr);
    gap: 2px 10px;
    align-items: start;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
  }
  /* カード内では1セル＝1行なので、表としての罫線・詰め物は消す
     （table.data-table の枠線が残ると項目ごとに箱が並んで見えてしまう）。 */
  table.work-table td {
    display: block;
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
    grid-column: 3;
    border: none;
    padding: 1px 0;
  }
  table.work-table td.checkbox-cell { grid-column: 1; grid-row: 1; }
  table.work-table td.checkbox-cell input { width: 18px; height: 18px; }
  table.work-table td.col-thumb { grid-column: 2; grid-row: 1 / span 99; }
  table.work-table td.col-thumb img { max-width: 92px; max-height: 92px; }
  table.work-table td.col-title { font-size: 15px; margin-bottom: 2px; }
  /* 素材はほぼ全作品で同じ文字列なので、カードでは省いて情報量を絞る */
  table.work-table td.col-material { display: none; }
  table.work-table td[data-label]::before {
    content: attr(data-label) " ";
    color: var(--muted);
    font-size: 11px;
  }
  /* 所在・ステータスのその場編集はカードでも生きるが、幅は内容なりにする */
  table.work-table td.col-location,
  table.work-table td.col-status { max-width: none; }

  /* 詳細ビューの展示遍歴など、一覧以外の表は横スクロールに逃がして
     ページ全体が横に広がらないようにする。 */
  section.panel table.data-table:not(.work-table) {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
