/* 短絡電流計算書作成ツール - スマートフォン縦画面優先 / 白背景・紺アクセント */
:root {
  --accent: #1c3d6e;
  --accent-light: #e8eef7;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #d5dbe5;
  --danger: #b3261e;
  --warn-bg: #fff6e5;
  --warn-fg: #8a5a00;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
.loading { padding: 24px; text-align: center; color: var(--muted); }

/* ヘッダー */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
}
.header-back { color: #fff; text-decoration: none; font-size: 26px; line-height: 1; padding: 4px 10px; }
.header-back-spacer { width: 20px; }
.header-titles { min-width: 0; }
.header-title { font-size: 17px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-sub { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ページ */
.page { padding: 14px 14px 28px; max-width: 720px; margin: 0 auto; }
.page.with-bottom-bar { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.group-title { font-size: 15px; color: var(--accent); border-left: 4px solid var(--accent); padding-left: 8px; margin: 22px 0 10px; }
.muted { color: var(--muted); font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* ボタン（指で押しやすい大きさ） */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 8px 16px; margin: 4px 4px 4px 0;
  font-size: 15px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); cursor: pointer;
}
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn-danger { color: var(--danger); border-color: #e6b2ae; }
.btn-sm { min-height: 36px; padding: 4px 10px; font-size: 13px; }
.btn-big { width: 100%; min-height: 54px; font-size: 16px; justify-content: flex-start; padding-left: 18px; }
.btn-add { width: 100%; border-style: dashed; color: var(--accent); font-weight: 700; }

/* ホーム */
.home-hero { text-align: center; padding: 18px 0 8px; }
.home-logo { font-size: 44px; }
.home-title { margin: 4px 0; font-size: 22px; color: var(--accent); }
.home-desc { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.home-menu { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.home-note { font-size: 12px; color: var(--muted); margin-top: 18px; }
.btn-resume {
  width: 100%; min-height: 64px; display: flex; flex-direction: column; align-items: flex-start;
  background: var(--accent-light); border: 2px solid var(--accent); border-radius: 12px;
  padding: 10px 16px; margin-bottom: 8px; cursor: pointer;
}
.resume-label { font-weight: 700; color: var(--accent); font-size: 15px; }
.resume-name { font-size: 13px; color: var(--muted); }

/* 入力欄 */
.field { display: block; margin: 12px 0; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.req { color: var(--danger); font-style: normal; font-size: 11px; margin-left: 6px; border: 1px solid var(--danger); border-radius: 4px; padding: 0 4px; }
.field-input {
  width: 100%; min-height: 46px; font-size: 16px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text);
}
.field-input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.field-row { display: flex; align-items: center; gap: 8px; }
.field-row .field-input { flex: 1; }
.unit { color: var(--muted); font-size: 14px; white-space: nowrap; }
.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.error-box { margin: 8px 0; }
.error-item { color: var(--danger); background: #fdecec; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 6px 0; }

/* セクション */
.section { background: var(--card); border: 1px solid var(--border); border-radius: 12px; margin: 10px 0; }
.section-title { padding: 13px 14px; font-weight: 700; font-size: 15px; cursor: pointer; list-style: none; }
.section-title::-webkit-details-marker { display: none; }
.section-title::before { content: '▸ '; color: var(--accent); }
details[open] > .section-title::before { content: '▾ '; }
.section-body { padding: 0 14px 14px; }

/* モード切替・短絡点切替 */
.mode-toggle { display: flex; gap: 6px; margin: 8px 0; }
.mode-btn {
  flex: 1; min-height: 44px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; font-size: 14px; cursor: pointer;
}
.mode-btn.selected { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.point-toggle { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.point-btn {
  text-align: left; border: 2px solid var(--border); border-radius: 12px; background: #fff;
  padding: 10px 14px; cursor: pointer;
}
.point-btn.selected { border-color: var(--accent); background: var(--accent-light); }
.point-label { display: block; font-weight: 700; font-size: 15px; color: var(--accent); }
.point-desc { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.diagram { width: 100%; height: auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; }

/* マスター情報 */
.master-info { background: var(--accent-light); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 8px 0; }
.master-line { margin: 2px 0; }
.master-line.warn { color: var(--danger); }
.master-src { color: var(--muted); font-size: 12px; }

/* 電線カード */
.wire-card { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin: 10px 0; background: #fbfcfe; }
.wire-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.wire-title { font-weight: 700; color: var(--accent); }
.wire-ops { display: flex; flex-wrap: wrap; }

/* 結果表示 */
.result-main { text-align: center; padding: 12px 0; }
.result-caption { color: var(--muted); font-size: 13px; }
.result-value { margin: 6px 0; }
.result-num { font-size: 46px; font-weight: 800; color: var(--accent); letter-spacing: 1px; }
.result-unit { font-size: 20px; color: var(--muted); margin-left: 6px; }
.result-pending .result-msg { color: var(--muted); font-size: 14px; margin: 6px 0; }
.badge { display: inline-block; font-size: 12px; padding: 2px 10px; border-radius: 999px; }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid #e8c882; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table th, .detail-table td { border-bottom: 1px solid var(--border); padding: 7px 6px; text-align: left; vertical-align: top; }
.detail-table th { color: var(--muted); font-weight: 500; width: 58%; }
.notice { font-size: 13px; color: var(--muted); background: #f2f4f8; border-radius: 8px; padding: 8px 10px; }
.notice-warn { background: var(--warn-bg); color: var(--warn-fg); }

/* 一覧カード */
.project-card, .circuit-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; margin: 10px 0; overflow: hidden; }
.project-open, .circuit-open { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px; cursor: pointer; font: inherit; color: inherit; }
.project-name, .circuit-name { font-weight: 700; font-size: 15px; }
.project-meta, .circuit-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.project-actions, .circuit-actions { display: flex; border-top: 1px solid var(--border); padding: 4px 8px; flex-wrap: wrap; }
.circuit-is { margin-top: 6px; }
.is-label { color: var(--muted); font-size: 13px; }
.is-value { font-size: 22px; font-weight: 800; color: var(--accent); }
.is-unit { font-size: 13px; color: var(--muted); margin: 0 6px 0 3px; }
.circuit-incomplete { color: var(--danger); font-size: 13px; margin-top: 6px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 6px; }
.sort-select { max-width: 130px; }
.io-row { display: flex; flex-wrap: wrap; margin-top: 14px; }

/* マスター管理 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.master-table { border-collapse: collapse; font-size: 13px; min-width: 640px; background: #fff; }
.master-table th, .master-table td { border: 1px solid var(--border); padding: 5px 7px; white-space: nowrap; }
.master-table th { background: var(--accent-light); }
.disabled-row { opacity: .45; }

/* 下部固定バー */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
.bottom-bar .btn { flex: 1; margin: 0; }
.bar-is { font-weight: 800; color: var(--accent); font-size: 15px; white-space: nowrap; }

/* ダイアログ */
.overlay { position: fixed; inset: 0; background: rgba(20, 28, 42, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog { background: #fff; border-radius: 14px; padding: 18px; max-width: 480px; width: 100%; max-height: 86vh; overflow-y: auto; }
.dialog-title { font-size: 17px; margin: 0 0 8px; color: var(--accent); }
.dialog-actions { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.diff-detail { margin-top: 8px; }
.diff-detail.hidden { display: none; }
.diff-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 6px 0; font-size: 13px; }
.diff-title { font-weight: 700; }
.diff-line { color: var(--muted); }

/* トースト・オフライン表示・更新バー */
.toast {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(8px);
  background: #2a3546; color: #fff; padding: 10px 20px; border-radius: 999px; font-size: 14px;
  opacity: 0; transition: all .25s; z-index: 60; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.offline-badge {
  display: none; position: fixed; top: calc(env(safe-area-inset-top) + 52px); left: 50%; transform: translateX(-50%);
  background: var(--warn-bg); color: var(--warn-fg); border: 1px solid #e8c882;
  font-size: 12px; padding: 3px 12px; border-radius: 999px; z-index: 30;
}
.offline-badge.show { display: block; }

/* ── PWA状態表示（オンライン/オフライン/キャッシュ準備/更新/エラー） ── */
.pwa-badge {
  display: none; position: fixed; top: calc(env(safe-area-inset-top) + 52px); left: 50%; transform: translateX(-50%);
  font-size: 12px; padding: 3px 12px; border-radius: 999px; z-index: 30; white-space: nowrap;
  border: 1px solid transparent;
}
.pwa-badge.show { display: block; }
.pwa-badge.pwa-ok { background: #e8f4ec; color: #1e6b3a; border-color: #a9d6b8; }
.pwa-badge.pwa-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: #e8c882; }
.pwa-badge.pwa-error { background: #fdecec; color: var(--danger); border-color: #e6b2ae; }
.pwa-subline {
  display: none; position: fixed; top: calc(env(safe-area-inset-top) + 80px); left: 12px; right: 12px; z-index: 30;
  background: #fffef4; border: 1px solid #e8c882; color: #5c4a12;
  font-size: 12px; padding: 8px 12px; border-radius: 10px; text-align: center;
}
.pwa-subline.show { display: block; }
.a2hs-steps { font-size: 14px; padding-left: 22px; line-height: 1.9; }
@media print { .pwa-badge, .pwa-subline, .a2hs-overlay { display: none !important; } }

.update-bar {
  position: fixed; bottom: calc(70px + env(safe-area-inset-bottom)); left: 12px; right: 12px; z-index: 40;
  background: var(--accent-light); border: 1px solid var(--accent); border-radius: 12px;
  display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; font-size: 14px;
}
.back-link { color: var(--accent); text-decoration: none; }
.about-list { padding-left: 20px; font-size: 14px; }

/* ── 帳票（画面プレビュー＋印刷） ───────────────────── */
.report-preview .report-page {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 16px; margin: 12px 0; overflow-x: auto;
}
.rep-doc-title { font-size: 18px; font-weight: 800; text-align: center; margin: 4px 0 10px; letter-spacing: 4px; }
.rep-h2 { font-size: 14px; margin: 14px 0 6px; border-left: 4px solid var(--accent); padding-left: 6px; }
.rep-p { font-size: 12.5px; margin: 4px 0; }
.rep-note { font-size: 11.5px; color: var(--muted); margin: 4px 0; }
.rep-warn { color: var(--warn-fg); }
.rep-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 4px 0; }
.rep-table th, .rep-table td { border: 1px solid #666; padding: 4px 6px; text-align: left; }
.rep-table th { background: #eef2f8; font-weight: 600; white-space: nowrap; }
.rep-is { font-weight: 800; }
.rep-result { font-size: 18px; margin: 8px 0; padding: 10px; border: 2px solid var(--accent); border-radius: 8px; text-align: center; }
.rep-result strong { font-size: 26px; color: var(--accent); }
.rep-foot { margin-top: 16px; font-size: 11px; color: var(--muted); border-top: 1px solid #999; padding-top: 6px; }

@media print {
  body { background: #fff; }
  .app-header, .bottom-bar, .no-print, .offline-badge, .update-bar, .toast { display: none !important; }
  .page { padding: 0; max-width: none; }
  .report-preview .report-page {
    border: 0; border-radius: 0; margin: 0; padding: 0;
    page-break-after: always; break-after: page;
  }
  .report-preview .report-page:last-child { page-break-after: auto; }
  @page { size: A4 portrait; margin: 14mm 12mm; }
  .rep-table { page-break-inside: auto; }
  .rep-table tr { page-break-inside: avoid; }
}
