:root {
  --bg: #f4f6f4; --panel: #ffffff; --text: #1b2420; --muted: #5d6b64; --line: #d7ddd9;
  --brand: #1f6f43; --brand-ink: #ffffff; --accent: #e8a317; --ok: #1f7a3a; --warn: #a86400; --bad: #b3261e;
  --warn-bg: #fff4dc; --bad-bg: #fde8e6; --ok-bg: #e5f4ea; --info-bg: #e7f0fb;
  --radius: 12px; --tap: 48px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614; --panel: #1b211e; --text: #e6ece8; --muted: #9fb0a7; --line: #2f3833;
    --brand: #3fa56d; --brand-ink: #08130d; --warn-bg: #3a2c10; --bad-bg: #3d1714; --ok-bg: #12301d; --info-bg: #142636;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif; font-size: 16px; line-height: 1.6; }
body { padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.loading { padding: 2rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.w100 { width: 100%; }
.mt05 { margin-top: .5rem; }
.mt1 { margin-top: 1rem; }
.mt2 { margin-top: 2rem; }
.pre { white-space: pre-wrap; font-size: .85rem; max-height: 40vh; overflow: auto; }
.narrow { max-width: 120px; }
.hidden { display: none !important; }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 上部バー */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .5rem; padding: .5rem 1rem; background: var(--brand); color: var(--brand-ink); }
.top .title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.5); min-height: 40px; }
.top .back { font-size: 1.1rem; }
.sync { font-size: .8rem; padding: .1rem .5rem; border-radius: 99px; background: var(--accent); color: #2a1b00; }
.sync.offline { background: var(--bad); color: #fff; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1rem; }

/* ボタン・入力 */
button, .btn { font: inherit; min-height: var(--tap); padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 700; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.ok { color: var(--ok); border-color: var(--ok); }
button.sm { min-height: 36px; padding: .25rem .7rem; font-size: .9rem; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; width: 100%; min-height: var(--tap); padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); }
textarea { min-height: 90px; }
input[type="checkbox"] { width: 24px; height: 24px; min-height: 24px; vertical-align: middle; }
label { display: block; font-size: .9rem; color: var(--muted); margin: .6rem 0 .2rem; }
label.req::after { content: " 必須"; color: var(--bad); font-size: .75rem; }
label.chk { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 .8rem; }

/* パネル・カード */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .8rem; }
.tile { display: flex; flex-direction: column; gap: .3rem; min-height: 120px; padding: 1rem; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); text-decoration: none; color: var(--text); text-align: left; }
.tile .no { font-size: 1.6rem; font-weight: 800; color: var(--brand); line-height: 1; }
.tile .t { font-weight: 700; }
.tile .d { font-size: .85rem; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin: .5rem 0 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
.card .k { font-size: .8rem; color: var(--muted); }
.card .v { font-size: 1.2rem; font-weight: 700; }

.notice { border-radius: 10px; padding: .7rem .9rem; margin: .5rem 0; background: var(--info-bg); }
.notice.warn { background: var(--warn-bg); }
.notice.bad { background: var(--bad-bg); }
.notice.ok { background: var(--ok-bg); }
.pill { display: inline-block; padding: 0 .55rem; border-radius: 99px; font-size: .8rem; background: var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.draft-mark { display: inline-block; padding: .1rem .6rem; border: 2px solid var(--warn); color: var(--warn); border-radius: 6px; font-weight: 700; }
.final-mark { display: inline-block; padding: .1rem .6rem; border: 2px solid var(--ok); color: var(--ok); border-radius: 6px; font-weight: 700; }

/* タブ */
.tabs { display: flex; gap: .3rem; overflow-x: auto; padding-bottom: .3rem; margin-bottom: .8rem; -webkit-overflow-scrolling: touch; }
.tabs a { flex: 0 0 auto; padding: .5rem .8rem; border-radius: 99px; border: 1px solid var(--line); text-decoration: none; color: var(--text); background: var(--panel); font-size: .92rem; }
.tabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* 表 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { border-bottom: 1px solid var(--line); padding: .45rem .5rem; text-align: left; vertical-align: top; font-size: .92rem; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }
td input, td select { min-height: 38px; padding: .25rem .4rem; }

/* 一覧 */
.list-item { display: block; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin-bottom: .5rem; text-decoration: none; color: var(--text); }
.list-item .t { font-weight: 700; }

/* 割付 */
.spanbar { display: flex; height: 34px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin: .3rem 0; }
.spanbar span { display: flex; align-items: center; justify-content: center; font-size: .72rem; border-right: 1px solid var(--line); background: var(--ok-bg); overflow: hidden; }
.spanbar span.adj { background: var(--warn-bg); }
.cand { border: 2px solid var(--line); border-radius: 10px; padding: .6rem .8rem; margin: .4rem 0; cursor: pointer; background: var(--panel); }
.cand.on { border-color: var(--brand); }

/* 写真 */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.photo { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #000; }
.photo img { width: 100%; height: 130px; object-fit: cover; display: block; }
.photo .cap { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.6); color: #fff; font-size: .75rem; padding: .1rem .4rem; }
.anno-wrap { position: relative; display: inline-block; max-width: 100%; }
.anno-wrap img { max-width: 100%; max-height: 60vh; display: block; }
.anno { position: absolute; transform: translate(-50%, -50%); background: rgba(179,38,30,.9); color: #fff; font-size: .8rem; font-weight: 700; padding: .1rem .35rem; border-radius: 4px; white-space: nowrap; pointer-events: none; }

/* 図面 */
.drawing { background: #fff; color: #000; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; overflow-x: auto; }
.drawing svg { display: block; max-width: 100%; height: auto; }

/* モーダル */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--panel); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 1rem 1rem 1.5rem; }
@media (min-width: 760px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
.modal h2 { margin-top: 0; }
.modal-foot { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

.toast { position: fixed; left: 50%; bottom: calc(1.2rem + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #23302a; color: #fff; padding: .7rem 1.1rem; border-radius: 10px; z-index: 99; max-width: 92vw; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); }

.auth { max-width: 460px; margin: 2rem auto; }
.steps { counter-reset: s; padding-left: 0; list-style: none; }
.steps li { counter-increment: s; position: relative; padding-left: 2.2rem; margin: .5rem 0; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--brand); color: var(--brand-ink); text-align: center; font-weight: 700; line-height: 1.6rem; }
.steps li.done::before { content: "✓"; background: var(--ok); }
.steps li.todo { font-weight: 700; }

/* 印刷 */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .top, .tabs, .no-print, .modal-bg, .toast, button { display: none !important; }
  .print-only { display: block; }
  .wrap { max-width: none; padding: 0; }
  .panel { border: none; padding: 0; }
  .drawing { border: none; }
  .print-a3 { page: a3; }
  .page-break { break-before: page; }
}
@page a3 { size: A3 landscape; margin: 10mm; }
.doc { background: #fff; color: #000; padding: 1.2rem; border: 1px solid var(--line); }
.doc h1 { text-align: center; letter-spacing: .5em; font-size: 1.5rem; }
.doc table th, .doc table td { border: 1px solid #999; font-size: .85rem; color: #000; background: #fff; }
.doc .total { font-size: 1.3rem; font-weight: 800; border-bottom: 3px double #000; display: inline-block; padding: 0 .5rem; }
@media print {
  body.print-modal #app { display: none !important; }
  body.print-modal .modal-bg { display: block !important; position: static; background: none; }
  body.print-modal .modal { max-height: none; overflow: visible; padding: 0; }
  body.print-modal .modal > h2 { display: none; }
}
.doc .notice { background: #fff4dc; color: #000; }
.doc .notice.bad { background: #fde8e6; }

/* v0.2 追加: 案件の流れ・会計・共有・レビュー */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .3rem 0 1rem; }
.chip { display: inline-block; padding: .45rem .8rem; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: inherit; text-decoration: none; font-size: .9rem; }
.chip:hover { border-color: var(--brand); }
.chip.off { opacity: .55; cursor: not-allowed; }
.star { font-size: 1.3rem; color: var(--line); background: none; border: none; }
.star.on { color: #d49b00; }
.stamp-box { display: inline-block; width: 3.2rem; height: 3.2rem; border: 1px solid #999; border-radius: 4px; text-align: center; line-height: 3.2rem; color: #999; margin-top: .3rem; }
.pre-line { white-space: pre-line; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.anno.warn { background: rgba(196,120,0,.92); }
tr.overdue td { background: var(--warn-bg); }
pre.big { font-size: 1.25rem; letter-spacing: .08em; text-align: center; padding: .8rem; }
.doc.a4 { max-width: 210mm; margin: 0 auto; }
h4 { margin: 1rem 0 .3rem; }
@media print { .doc.a4 { border: none; padding: 0; max-width: none; } }
.hidden-file { display: none; }
.plan-card.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand) inset; }
