/* ==================================================================
   GENBA CHECK 共通スタイル（トークン・リセット・共有部品・図面ビューア）
   端末別の見た目は phone.css / tablet.css / desktop.css で上書きする。
   ================================================================== */
:root {
  --c-bg: #f3f4f6;
  --c-surface: #ffffff;
  --c-ink: #1f2937;
  --c-ink-sub: #6b7280;
  --c-line: #d1d5db;
  --c-primary: #2563eb;
  --c-primary-ink: #ffffff;
  --c-danger: #dc2626;
  --c-accent-inspection: #2563eb;
  --c-accent-instruction: #7c3aed;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --tap: 48px;               /* 手袋でも押せる最小サイズ */
  --font: "Meiryo", メイリオ, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--c-ink);
  background: var(--c-bg);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}
.app-root { height: 100%; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
img { user-select: none; -webkit-user-drag: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: #eef2ff; padding: 1px 5px; border-radius: 4px; }

/* ---- ボタン ---- */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  background: var(--c-surface);
  color: var(--c-ink);
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-primary-ink); }
.btn-danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn-plain { background: var(--c-surface); }
.btn.full { width: 100%; }
button.mini {
  min-height: 32px; padding: 0 10px; border: 1px solid var(--c-line);
  border-radius: var(--r-sm); background: var(--c-surface); color: var(--c-ink); font-size: 13px; font-weight: 600;
}
button.mini.danger { color: var(--c-danger); border-color: #f3c2c2; }
button.mini:disabled { opacity: .35; }

/* ---- フォーム ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--c-ink-sub); }
.field-input {
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  font-size: 16px;
  background: #fff;
  width: 100%;
}
.field-input.inline, .field-input.inline { min-height: 36px; width: auto; }

/* ---- バッジ / セグメント ---- */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap;
  background: var(--c-ink-sub);
}
.badge.inspection { background: var(--c-accent-inspection); }
.badge.instruction { background: var(--c-accent-instruction); }
.segmented { display: inline-flex; border: 1px solid var(--c-line); border-radius: var(--r-md); overflow: hidden; background: #fff; }
.segmented .seg { border: 0; background: #fff; padding: 0 16px; min-height: 40px; font-weight: 600; color: var(--c-ink-sub); }
.segmented .seg.active { background: var(--c-primary); color: #fff; }

/* ---- カード行 ---- */
.card-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 14px; margin-bottom: 8px;
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-md);
  text-align: left; color: var(--c-ink);
}
.card-row.active { border-color: var(--c-primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.card-row:disabled { opacity: .5; }
.card-row-main { flex: 1; min-width: 0; }
.card-row-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-row-sub { font-size: 12px; color: var(--c-ink-sub); }
.chev { color: var(--c-ink-sub); font-size: 20px; }

.empty-note { color: var(--c-ink-sub); font-size: 14px; padding: 16px; text-align: center; }
.phase-note { color: var(--c-ink-sub); font-size: 13px; background: #f8fafc; border: 1px dashed var(--c-line); border-radius: var(--r-sm); padding: 10px; }
.pane-h { margin: 0 0 8px; font-size: 15px; }
.pane-h.sm { font-size: 13px; color: var(--c-ink-sub); }
.marker-status { font-weight: 700; font-size: 14px; margin: 6px 0; }
.kv { display: flex; gap: 8px; font-size: 13px; color: var(--c-ink-sub); margin: 4px 0; }
.grow, .dt-project-head .grow { flex: 1; }

/* ---- トースト（日本語メッセージ） ---- */
.toast-host {
  position: fixed; left: 0; right: 0; bottom: calc(12px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 9999; pointer-events: none;
}
.toast {
  max-width: min(92vw, 480px); padding: 12px 16px; border-radius: var(--r-md);
  background: #111827; color: #fff; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; transform: translateY(12px); transition: .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--c-danger); }

/* ---- シート / ダイアログ ---- */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 9000;
  opacity: 0; transition: opacity .2s;
}
.sheet-overlay.show { opacity: 1; }
.sheet-box {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  background: var(--c-surface); border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 16px 16px calc(16px + var(--safe-b));
  transform: translateY(16px); transition: transform .2s;
}
.sheet-overlay.show .sheet-box { transform: none; }
.sheet-box.dialog { align-self: center; border-radius: var(--r-lg); margin: 16px; }
.sheet-box.full { align-self: center; border-radius: var(--r-lg); margin: 12px; }
.sheet-overlay:has(.dialog), .sheet-overlay:has(.full) { align-items: center; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-title { margin: 0; font-size: 17px; }
.sheet-x { border: 0; background: transparent; font-size: 20px; color: var(--c-ink-sub); min-width: var(--tap); min-height: var(--tap); }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
.dialog-msg { white-space: pre-wrap; }

/* ==================================================================
   図面ビューア（共通コア）
   ================================================================== */
.pv-root { position: relative; width: 100%; height: 100%; background: #e5e7eb; overflow: hidden; }
.pv-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.pv-stage:active { cursor: grabbing; }
.pv-canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.pv-img { display: block; width: 100%; height: 100%; background: #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.pv-markers { position: absolute; inset: 0; }
.pv-empty {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  color: var(--c-ink-sub); font-size: 14px;
}

.pv-marker {
  position: absolute; width: 0; height: 0;
}
.pv-marker-label {
  position: absolute; left: 0; top: 0;
  transform: translate(-50%, -50%) scale(var(--pv-inv-scale, 1));
  transform-origin: center;
  min-width: 34px; height: 34px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  background: var(--pv-marker-color, #d9534f); color: #fff;
  border: 2px solid #fff; border-radius: 999px;
  font-weight: 800; font-size: 17px; line-height: 1;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.pv-marker.current .pv-marker-label { outline: 3px solid #1d4ed8; outline-offset: 1px; }
.pv-marker.dragging .pv-marker-label { opacity: .85; }

/* ---- 端末切り替え（動作確認用） ---- */
.devsw {
  position: fixed; right: 8px; bottom: calc(8px + var(--safe-b)); z-index: 8000;
  display: flex; gap: 4px; align-items: center;
  background: rgba(17,24,39,.82); color: #fff; padding: 5px 8px; border-radius: 999px; font-size: 11px;
}
.devsw-label { opacity: .7; }
.devsw-btn { border: 0; background: transparent; color: #fff; padding: 4px 8px; border-radius: 999px; font-size: 11px; }
.devsw-btn.active { background: var(--c-primary); }

.hidden-file { display: none; }

/* ==================================================================
   Phase 2: 自動保存インジケータ / 音声入力 / 番号詳細 / 写真 / 拡大表示
   ================================================================== */

/* ---- 自動保存インジケータ ---- */
.savebar {
  position: fixed; top: calc(8px + var(--safe-t)); right: 8px; z-index: 9500;
  display: flex; align-items: center; gap: 6px;
  background: #111827; color: #fff; padding: 6px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 700; opacity: 0; transform: translateY(-6px);
  transition: opacity .2s, transform .2s; pointer-events: none;
}
.savebar.show { opacity: .95; transform: none; }
.savebar-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.savebar[data-state="saving"] .savebar-dot { background: #f0ad4e; }
.savebar[data-state="saved"] .savebar-dot { background: #5cb85c; }
.savebar[data-state="error"] { background: var(--c-danger); }
.savebar[data-state="error"] .savebar-dot { background: #fff; }

/* ---- 音声入力シート ---- */
.voice-body { display: flex; flex-direction: column; gap: 10px; }
.voice-hint { font-size: 13px; color: var(--c-ink-sub); }
.voice-hint:empty { display: none; }
.voice-controls { display: flex; gap: 8px; }
.voice-controls .btn { flex: 1; min-height: 52px; font-size: 16px; }
.voice-status { font-size: 14px; font-weight: 700; min-height: 20px; }
.voice-status.rec { color: var(--c-danger); }
.voice-status.warn { color: #b45309; }
.voice-kb-note { font-size: 13px; color: var(--c-ink-sub); }
.voice-textarea, .mdetail-textarea {
  width: 100%; border: 1px solid var(--c-line); border-radius: var(--r-md);
  padding: 10px 12px; font: inherit; font-size: 16px; resize: vertical; min-height: 72px; background: #fff;
}

/* ---- 番号詳細（3端末共通） ---- */
.mdetail { display: flex; flex-direction: column; gap: 14px; }
.mdetail-head { display: flex; align-items: center; gap: 8px; }
.mdetail-num {
  width: 34px; height: 34px; border-radius: 999px; color: #fff; font-weight: 800;
  display: flex; align-items: center; justify-content: center; font-size: 16px; flex: none;
}
.mdetail-title { font-weight: 800; flex: 1; }
.mdetail-statusrow { display: flex; align-items: center; gap: 10px; }
.mdetail-status { min-height: 40px; border: 2px solid var(--c-line); border-radius: var(--r-md); padding: 4px 10px; font: inherit; font-size: 15px; font-weight: 700; background: #fff; }
.mdetail-field { display: flex; flex-direction: column; gap: 6px; }
.mdetail-field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.mdetail-field-head .field-label { white-space: nowrap; }
.mdetail-mic { min-height: 42px; padding: 0 12px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.mdetail-photos { display: flex; flex-direction: column; gap: 6px; }
.photo-add-btns { display: flex; gap: 6px; flex: none; }
.mini-btn { min-height: 40px; padding: 0 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.photo-busy { font-size: 13px; font-weight: 700; color: var(--c-primary); }
.photo-busy:empty { display: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo-empty { font-size: 13px; color: var(--c-ink-sub); padding: 8px 0; }
.photo-cell { border: 1px solid var(--c-line); border-radius: var(--r-sm); overflow: hidden; background: #fff; }
.photo-thumb { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #f1f5f9; cursor: pointer; }
.photo-cell-ops { display: flex; }
.photo-cell-ops .pc-op { flex: 1; border: 0; border-top: 1px solid var(--c-line); background: #fff; min-height: 34px; font-size: 13px; color: var(--c-ink); }
.photo-cell-ops .pc-op + .pc-op { border-left: 1px solid var(--c-line); }
.photo-cell-ops .pc-op.del { color: var(--c-danger); }
.photo-cell-ops .pc-op:disabled { opacity: .3; }
.photo-cell-idx { font-size: 11px; color: var(--c-ink-sub); text-align: center; padding: 2px 0; }

/* ---- 写真拡大 ---- */
.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 9800;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; transition: opacity .18s;
}
.lightbox-overlay.show { opacity: 1; }
.lightbox { position: relative; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.lightbox-img { max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 6px; }
.lightbox-close {
  position: absolute; top: -6px; right: -6px; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: #fff; font-size: 18px; font-weight: 800;
}
.lightbox-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.sheet-lead { font-size: 15px; margin: 0 0 4px; }

/* ---- 写真注記エディタ ---- */
.sheet-box.full { max-width: 900px; width: 96vw; height: 92vh; max-height: 92vh; display: flex; flex-direction: column; }
.sheet-box.full .sheet-body { flex: 1; min-height: 0; overflow: hidden; }
.anno-body { display: flex; flex-direction: column; gap: 8px; height: 100%; }
.anno-tools, .anno-colors, .anno-edit { display: flex; gap: 6px; flex-wrap: wrap; }
.anno-tool { min-height: 42px; padding: 0 12px; border: 1px solid var(--c-line); border-radius: var(--r-sm); background: #fff; font-weight: 700; font-size: 14px; }
.anno-tool.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.anno-color { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #cbd5e1; }
.anno-color.active { border-color: #111827; box-shadow: 0 0 0 2px #111827; }
.anno-stage { flex: 1; min-height: 0; background: #1f2937; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: var(--r-sm); }
.anno-canvas { max-width: 100%; max-height: 100%; touch-action: none; cursor: crosshair; background: #fff; }
.anno-edit .btn { min-height: 42px; padding: 0 12px; font-size: 13px; }
.anno-hint { font-size: 12px; color: var(--c-ink-sub); text-align: center; margin: 4px 0 0; }

.field-error { color: var(--c-danger); font-size: 12px; font-weight: 700; margin-top: 4px; }
.field-error[hidden] { display: none; }

.photo-thumb-wrap { position: relative; }
.photo-anno-badge { position: absolute; left: 4px; top: 4px; background: rgba(17,24,39,.8); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 4px; }

/* ---- 番号詳細: 担当業者 / 期限 ---- */
.mdetail-meta { display: flex; gap: 10px; flex-wrap: wrap; }
.mdetail-metafield { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }

/* ---- 帳票の作成ダイアログ ---- */
.export-bar { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.export-open { min-height: 40px; padding: 0 14px; font-size: 13px; }
.export-send { min-height: 40px; padding: 0 12px; font-size: 13px; background: #fff; border: 1px solid var(--c-line); }
.send-sheet { display: flex; flex-direction: column; gap: 10px; }
.send-sheet .fmt-row .btn { flex: 1; }
.exp-dialog { display: flex; flex-direction: column; gap: 14px; }
.exp-section { display: flex; flex-direction: column; gap: 8px; }
.exp-check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.exp-check input, .exp-inline input[type="checkbox"] { width: 20px; height: 20px; }
.exp-inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.field-input.sm { width: 80px; min-height: 38px; }
.exp-settings { background: #f8fafc; border: 1px solid var(--c-line); border-radius: var(--r-md); padding: 10px; }
.exp-preview {
  border: 1px solid var(--c-line); background: #e9edf2; border-radius: var(--r-sm);
  max-height: 46vh; overflow: auto; padding: 10px;
}
.exp-preview-hint { color: var(--c-ink-sub); font-size: 13px; padding: 16px; text-align: center; }
.exp-preview .report-paper { zoom: 0.5; }
.exp-actions-wrap { gap: 10px; }
.exp-action-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.exp-action-label { font-weight: 800; width: 52px; flex: none; }
.exp-action-row .btn { min-height: 44px; padding: 0 16px; flex: 1; min-width: 72px; }
.exp-action-row .btn:disabled { opacity: .5; }

/* 帳票: 作成 → ダウンロード/共有 の2段 */
.fmt-block { border: 1px solid var(--c-line); border-radius: var(--r-md); padding: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.fmt-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fmt-row .btn { min-height: 44px; padding: 0 16px; flex: 1; min-width: 120px; }
.fmt-row .btn[hidden] { display: none; }
.fmt-status { font-size: 12px; color: var(--c-ink-sub); font-weight: 700; word-break: break-all; }

/* ---- データ管理シート ---- */
.dm-body { display: flex; flex-direction: column; gap: 18px; }
.dm-section { display: flex; flex-direction: column; gap: 8px; }
.dm-section .pane-h { margin: 0; border-left: 4px solid var(--c-primary); padding-left: 8px; }
.dm-note { font-size: 12px; color: var(--c-ink-sub); margin: 0; }
.dm-usage-line { font-size: 13px; font-weight: 700; }
.dm-bar { height: 10px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.dm-bar-fill { height: 100%; background: var(--c-primary); }
.dm-persist { font-size: 12px; font-weight: 700; margin-top: 6px; padding: 4px 8px; border-radius: var(--r-sm); background: #f1f5f9; color: var(--c-ink-sub); }
.dm-persist.ok { background: #dcfce7; color: #166534; }
.dm-persist.warn { background: #fef3c7; color: #92400e; }
.dm-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dm-count { background: #f8fafc; border: 1px solid var(--c-line); border-radius: var(--r-sm); padding: 8px; text-align: center; }
.dm-count b { display: block; font-size: 18px; }
.dm-count span { font-size: 11px; color: var(--c-ink-sub); }
.lib-inuse-list { margin: 6px 0; padding-left: 20px; font-size: 13px; }
.lib-inuse-list li { margin: 2px 0; }
.dm-vendors { display: flex; flex-direction: column; gap: 4px; }
.dm-vendor-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--c-line); border-radius: var(--r-sm); background: #fff; }
.dm-vendor-name { flex: 1; font-weight: 600; }

/* ---- 期限アラート ---- */
.due-badge { display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 999px; color: #fff; font-size: 10px; font-weight: 800; }
.due-badge[hidden] { display: none; }
.due-chip { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px; color: #fff; font-size: 10px; font-weight: 800; white-space: nowrap; }
.overdue-badge { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 999px; background: #dc2626; color: #fff; font-size: 10px; font-weight: 800; white-space: nowrap; flex: none; }

/* ---- 定型文 ---- */
.mdetail-field-btns { display: flex; gap: 8px; }
.mdetail-field-btns > button { flex: 1; min-height: 42px; }
.tpl-list { display: flex; flex-direction: column; gap: 6px; }
.tpl-item { text-align: left; border: 1px solid var(--c-line); border-radius: var(--r-sm); background: #fff; padding: 12px 14px; font-size: 15px; line-height: 1.4; color: var(--c-ink); min-height: 44px; }
.tpl-item:active { background: #eff6ff; }
.dm-tpl { display: flex; flex-direction: column; gap: 6px; }
.np-carry { border: 1px solid var(--c-line); border-radius: var(--r-sm); padding: 10px; background: #f8fafc; display: flex; flex-direction: column; gap: 6px; }

.dt-topbar-btn { border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff; border-radius: var(--r-sm); padding: 5px 12px; font-size: 12px; font-weight: 700; }
.ui-phone .ph-gear { min-height: 40px; padding: 0 12px; font-size: 18px; }
