/* ============================================================
   keika-compli デザインシステム "現場の計器盤"
   対象: 軽貨物ドライバー(年配含む)。高コントラスト・大操作面・
   紙の点検簿の温かみ。ライト/ダーク両対応。オフライン前提で
   日本語はシステムフォント(Hiragino/游/BIZ UD)を精緻に運用。
   ============================================================ */
:root {
  --paper:      #f3f1ea;   /* 温かいオフホワイト(点検簿の紙) */
  --paper-2:    #ece9df;
  --card:       #ffffff;
  --ink:        #17241e;   /* 深い緑黒 */
  --ink-soft:   #4b5a52;
  --ink-faint:  #8a978f;
  --line:       #e2ddd0;   /* ヘアライン */
  --brand:      #0d5a40;   /* 深緑=信頼 */
  --brand-ink:  #0a3f2d;
  --brand-tint: #e6f0ea;
  --accent:     #0f6d4c;
  --ok:         #0d7a55;
  --amber:      #b26a00;
  --amber-bg:   #fbf0dc;
  --amber-line: #efd6a8;
  --red:        #b3261e;
  --red-bg:     #fbeceb;
  --red-line:   #f0c0bc;

  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --sh-1: 0 1px 2px rgba(20,32,26,.06), 0 1px 1px rgba(20,32,26,.04);
  --sh-2: 0 2px 6px rgba(20,32,26,.08), 0 10px 24px rgba(20,32,26,.06);
  --sh-brand: 0 6px 16px rgba(13,90,64,.28);

  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic",
          "Yu Gothic", "Noto Sans JP", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 17px;
  color-scheme: light dark;
}
:root { --accent: #0f6d4c; }

/* ダーク配色トークン。共通の変数セットを、
   ①OS設定がダーク かつ 手動でライト固定していない場合(prefers-color-scheme)
   ②手動でダーク固定(data-theme="dark")
   の両方に適用する。手動ライト固定(data-theme="light")は①を除外して常にライト。 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11150f; --paper-2: #171c15; --card: #1c221a;
    --ink: #edf1ea; --ink-soft: #b3bfb6; --ink-faint: #7c8a80;
    --line: #2b332a; --brand: #3fa580; --brand-ink: #8fd7bb;
    --brand-tint: #17281f; --accent: #37a377; --ok: #45b98d;
    --amber: #e0a44e; --amber-bg: #2b2312; --amber-line: #4a3a17;
    --red: #f08a82; --red-bg: #2c1715; --red-line: #4d211d;
    --sh-1: 0 1px 2px rgba(0,0,0,.4);
    --sh-2: 0 2px 8px rgba(0,0,0,.5), 0 12px 28px rgba(0,0,0,.4);
    --sh-brand: 0 6px 18px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --paper: #11150f; --paper-2: #171c15; --card: #1c221a;
  --ink: #edf1ea; --ink-soft: #b3bfb6; --ink-faint: #7c8a80;
  --line: #2b332a; --brand: #3fa580; --brand-ink: #8fd7bb;
  --brand-tint: #17281f; --accent: #37a377; --ok: #45b98d;
  --amber: #e0a44e; --amber-bg: #2b2312; --amber-line: #4a3a17;
  --red: #f08a82; --red-bg: #2c1715; --red-line: #4d211d;
  --sh-1: 0 1px 2px rgba(0,0,0,.4);
  --sh-2: 0 2px 8px rgba(0,0,0,.5), 0 12px 28px rgba(0,0,0,.4);
  --sh-brand: 0 6px 18px rgba(0,0,0,.5);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
.ic { width: 22px; height: 22px; flex: none; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); background: var(--paper); color: var(--ink);
  font-feature-settings: "palt" 1; line-height: 1.5;
  background-image: radial-gradient(rgba(20,32,26,.025) 1px, transparent 1px);
  background-size: 22px 22px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body { background-image: radial-gradient(rgba(255,255,255,.02) 1px, transparent 1px); }
}
:root[data-theme="dark"] body { background-image: radial-gradient(rgba(255,255,255,.02) 1px, transparent 1px); }

/* ---------- ヘッダ ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: var(--brand); color: #fff;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 0 rgba(0,0,0,.08), 0 6px 20px rgba(13,90,64,.16);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 800;
  letter-spacing: .02em; cursor: pointer; }
.brand .logo { width: 30px; height: 30px; flex: none; filter: drop-shadow(0 1px 1px rgba(0,0,0,.2)); }
.brand .wm { display: flex; flex-direction: column; line-height: 1.05; }
.brand .wm b { font-size: 1.02rem; font-weight: 800; }
.brand .wm span { font-size: .58rem; font-weight: 600; opacity: .8; letter-spacing: .12em; }
.sync-status {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .72rem; font-weight: 700; padding: 5px 11px; border-radius: var(--r-pill);
  background: rgba(255,255,255,.16); color: #fff;
}
.sync-status .dot { width: 7px; height: 7px; border-radius: 50%; background: #7ff0c0; }
.sync-status[data-state="pending"] { background: rgba(255,196,120,.24); }
.sync-status[data-state="pending"] .dot { background: #ffc044; }
.sync-status[data-state="error"] { background: rgba(255,140,130,.26); }
.sync-status[data-state="error"] .dot { background: #ff6b5e; }
.top-right { display: inline-flex; align-items: center; gap: 9px; }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: none; padding: 0; border: 0; cursor: pointer;
  border-radius: var(--r-pill); background: rgba(255,255,255,.16); color: #fff;
}
.theme-toggle:hover { background: rgba(255,255,255,.26); }
.theme-toggle:active { transform: scale(.94); }
.theme-toggle .ic { width: 20px; height: 20px; }

main { padding: 18px 16px 80px; max-width: 500px; margin: 0 auto; }
h2 { margin: 4px 0 4px; font-size: 1.32rem; font-weight: 800; letter-spacing: .01em; }
h2 small { font-size: .72rem; color: var(--ink-faint); font-weight: 600; margin-left: 6px; }
h3 { margin: 24px 0 10px; font-size: .82rem; font-weight: 800; letter-spacing: .08em;
  color: var(--ink-soft); text-transform: none; display: flex; align-items: center; gap: 7px; }
h3::before { content: ""; width: 4px; height: 15px; border-radius: 2px; background: var(--brand); flex: none; }

/* ---------- ホーム 大ボタン ---------- */
.big-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.big-btn {
  position: relative; display: flex; flex-direction: column; gap: 10px;
  width: 100%; padding: 18px 15px 15px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--card); text-align: left; cursor: pointer; color: var(--ink);
  box-shadow: var(--sh-1); transition: transform .12s ease, box-shadow .12s ease, border-color .12s;
  overflow: hidden; font-family: inherit;
  animation: rise .4s cubic-bezier(.2,.7,.3,1) backwards;
}
.big-btn:active { transform: translateY(1px) scale(.995); box-shadow: var(--sh-1); }
.big-btn::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--line); transition: background .15s; }
.big-btn.is-done::before { background: var(--ok); }
.big-btn.is-todo::before { background: var(--amber); }
.big-btn .ic { width: 26px; height: 26px; color: var(--brand); }
.big-btn .t { font-size: 1.06rem; font-weight: 800; }
.big-btn .st { font-size: .8rem; font-weight: 700; display: inline-flex; align-items: center; gap: 5px; }
.big-btn .st.done { color: var(--ok); }
.big-btn .st.todo { color: var(--amber); }
.big-btn:disabled { opacity: .55; cursor: default; }
.big-btn:disabled .ic { color: var(--ink-faint); }
.big-btns .big-btn:nth-child(1){animation-delay:.02s} .big-btns .big-btn:nth-child(2){animation-delay:.07s}
.big-btns .big-btn:nth-child(3){animation-delay:.12s} .big-btns .big-btn:nth-child(4){animation-delay:.17s}

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .big-btn { animation: none; } }

/* ---------- リスト ---------- */
.todo-list { margin: 12px 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.todo-list li {
  padding: 13px 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-sm); box-shadow: var(--sh-1); display: flex; align-items: center; gap: 10px;
}
.todo-list li::before { content: ""; width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--ink-faint); }
.todo-list li.todo::before { background: var(--amber); }
.todo-list li.done::before { background: var(--ok); }
.todo-list li small { color: var(--ink-faint); }

/* ---------- フォーム ---------- */
form label { display: block; margin: 16px 0 6px; font-weight: 700; font-size: .92rem; }
input, select, textarea {
  width: 100%; padding: 13px 14px; font-size: 1.05rem; font-family: inherit;
  border: 1.5px solid var(--line); border-radius: var(--r-sm); background: var(--card); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint);
}
input[type="file"] { padding: 10px; background: var(--paper-2); border-style: dashed; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--brand); }

.actions { margin-top: 26px; display: grid; gap: 10px; }
.primary {
  padding: 16px; font-size: 1.12rem; font-weight: 800; border: 0; border-radius: var(--r-md);
  background: linear-gradient(180deg, #12735170 0%, transparent 100%), var(--brand);
  color: #fff; cursor: pointer; box-shadow: var(--sh-brand); font-family: inherit;
  transition: transform .1s, filter .1s; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.primary:active { transform: translateY(2px) scale(.97); filter: brightness(.8); }
.primary:disabled { opacity: .6; cursor: default; }
.primary .ic { width: 20px; height: 20px; }
.secondary {
  padding: 14px; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--r-md);
  color: var(--ink); font-size: 1rem; font-weight: 700; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background .12s, border-color .12s;
}
.secondary:active { background: var(--brand-tint); border-color: var(--brand); transform: translateY(1px) scale(.97); }
.secondary .ic { width: 19px; height: 19px; color: var(--brand); flex: none; }
.notice { margin-top: 14px; font-size: .85rem; color: var(--ink-soft); line-height: 1.6; }
.notice a { color: var(--brand); }
.legal-links { margin-top: 6px; font-size: .8rem; color: var(--ink-soft); line-height: 1.8; }
.legal-links a { color: var(--ink-soft); text-decoration: underline; }

/* ---------- トースト(操作フィードバック) ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 200; max-width: min(92vw, 460px); width: max-content;
  background: var(--ink); color: var(--paper);
  font-weight: 800; font-size: .95rem; line-height: 1.4;
  padding: 13px 18px; border-radius: var(--r-md); box-shadow: var(--sh-2);
  animation: toast-in .25s cubic-bezier(.2,.7,.3,1);
  pointer-events: none; text-align: center;
}
.toast.toast-error { background: var(--red); color: var(--card); }
.toast.out { opacity: 0; transform: translateX(-50%) translateY(8px); transition: opacity .35s, transform .35s; }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(12px); } to { opacity: 1; transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- 警告バナー ---------- */
.alert-banner {
  border-radius: var(--r-md); padding: 13px 15px; margin-bottom: 12px; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; gap: 10px; box-shadow: var(--sh-1);
  animation: rise .35s cubic-bezier(.2,.7,.3,1) backwards;
}
.alert-banner .ic { width: 22px; height: 22px; flex: none; }
.alert-banner small { display: block; font-weight: 600; opacity: .85; margin-top: 2px; }
.alert-overdue { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-line); }
.alert-soon { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-line); }

/* ---------- ローディング / 空状態 ---------- */
.skeleton { background: linear-gradient(90deg, var(--paper-2) 25%, var(--line) 37%, var(--paper-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-sm); height: 56px; margin-bottom: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-faint); }
.empty .ic { width: 44px; height: 44px; margin: 0 auto 10px; color: var(--ink-faint); opacity: .6; }

/* ---------- ポータルへ戻る ---------- */
.portal-back { position: fixed; left: 14px; bottom: 14px; z-index: 60; display: inline-flex;
  align-items: center; gap: 7px; background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 10px 14px; font: 800 13px/1 var(--font); text-decoration: none;
  box-shadow: var(--sh-2); }

/* ---------- オンボーディング ---------- */
.onboard { position: fixed; inset: 0; z-index: 100; background: var(--brand);
  color: #fff; display: flex; flex-direction: column; justify-content: center; padding: 32px 26px; }
.onboard .logo { width: 74px; height: 74px; margin-bottom: 20px; }
.onboard h1 { font-size: 1.7rem; font-weight: 800; margin-bottom: 6px; }
.onboard p.lead { opacity: .9; margin-bottom: 26px; }
.onboard ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 16px; margin-bottom: 34px; }
.onboard li { display: flex; gap: 13px; align-items: flex-start; }
.onboard li .ic { width: 26px; height: 26px; flex: none; margin-top: 2px; }
.onboard li b { display: block; font-weight: 800; }
.onboard li span { opacity: .85; font-size: .9rem; }
.onboard button { padding: 17px; font-size: 1.12rem; font-weight: 800; border: 0; border-radius: var(--r-md);
  background: #fff; color: var(--brand); cursor: pointer; box-shadow: var(--sh-2); font-family: inherit; }

/* ---------- 印刷様式(据え置き) ---------- */
/* 紙面プレビューはテーマに関係なく常に白紙+濃色文字(ダークテーマで不可視になる事故防止) */
.print-sheet { background: #fff; color: #1a2b24; padding: 14px; border-radius: 8px; }
.print-table { width: 100%; border-collapse: collapse; background: #fff; color: #1a2b24; font-size: .8rem; }
.print-table th, .print-table td { border: 1px solid #999; padding: 6px 8px; text-align: left; }
.print-table th { background: #eef3f1; }
.print-meta { margin: 8px 0 16px; color: #333; }
.print-title { margin: 0 0 8px; }
.print-head { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: .85rem; }
.print-head td { border: 1px solid #999; padding: 6px 10px; }
.print-head .stamp-box { width: 70px; height: 56px; text-align: center; color: #666; vertical-align: top; font-size: .7rem; }
.print-foot { font-size: .7rem; color: #444; margin-top: 8px; }
.matrix-table .item-col { min-width: 200px; text-align: left; }
.matrix-table .mark { text-align: center; width: 26px; padding: 4px 2px; }
.matrix-table .inspector { font-size: .6rem; text-align: center; padding: 2px; }
@media print {
  .topbar, .actions, .notice, .no-print, .portal-back,
  a[aria-label="ポータルへ戻る"] { display: none !important; }
  body { background: #fff !important; background-image: none; }
  main { max-width: none; padding: 0; }
  @page { size: A4 landscape; margin: 12mm; }
  .print-sheet { padding: 0; border-radius: 0; }
  .print-table { font-size: 9pt; }
  .print-table th { background: #eee !important; -webkit-print-color-adjust: exact; }
  .matrix-table { font-size: 8pt; }
  .matrix-table .item-col { min-width: 150px; }
}
