:root {
  --bg: #f5f6f7; --card: #ffffff; --text: #1a1f24; --muted: #667085; --line: #e4e7ec; --line-strong: #d0d5dd;
  --accent: #0e7c72; --accent-hover: #0b6359; --accent-soft: #e6f4f2; --accent-text: #0a5a52;
  --danger: #b42318; --danger-soft: #fee4e2; --warn: #b54708; --warn-soft: #fef0c7; --ok: #067647; --ok-soft: #dcfae6; --info: #175cd3; --info-soft: #e0eaff;
  --radius: 14px; --radius-sm: 8px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.04);
  --sidebar: 250px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light only; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 1.5rem 0 .6rem; }
h3 { font-size: .95rem; font-weight: 600; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.small { font-size: .85rem; }
.w-full { width: 100%; }
.flex-1 { flex: 1 1 160px; }
.flex-2 { flex: 2 1 240px; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); flex: 0 0 auto; background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 20px 14px; gap: 14px; }
.sidebar-head { padding: 4px 10px 6px; }
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; text-decoration: none; color: var(--text); }
.brand-sub { color: var(--muted); font-size: .8rem; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; text-decoration: none; color: var(--text); font-weight: 500; font-size: .93rem; }
.nav a svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.nav a.active svg { stroke: var(--accent); }
.nav-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; }
.upload-cta { justify-content: center; }
.mobile-bar { display: none; }
.backdrop { display: none; }
.view { flex: 1; min-width: 0; padding: 28px 40px 64px; max-width: 1800px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 720px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.tight { padding: 12px 16px; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); line-height: 1.1; margin-bottom: 4px; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat:hover { border-color: var(--line-strong); }

.row { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .8rem; font-weight: 500; color: var(--muted); min-width: 0; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 10px; width: 100%; min-width: 0; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 72px; resize: vertical; }
input[type="date"] { min-width: 150px; }
input[type="number"] { min-width: 100px; }
.btn, button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line-strong); background: #fff; border-radius: var(--radius-sm); padding: 8px 14px; cursor: pointer; font-weight: 500; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover, button:hover { background: var(--bg); }
.btn.primary, button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover, button.primary:hover { background: var(--accent-hover); }
.btn.ghost, button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover, button.ghost:hover { background: var(--bg); color: var(--text); }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: none; padding: 8px; color: var(--text); display: inline-flex; }
.actions { white-space: nowrap; }
.actions button { padding: 4px 8px; font-size: .85rem; }

.badge { display: inline-flex; align-items: center; font-size: .74rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.p1 { background: var(--danger-soft); color: var(--danger); }
.badge.p2 { background: var(--warn-soft); color: var(--warn); }
.badge.p3 { background: var(--bg); color: var(--muted); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--info-soft); color: var(--info); }
.tag { display: inline-flex; font-size: .74rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); margin-right: 8px; vertical-align: middle; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; background: #fafbfc; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }
.flag-high, .flag-positive { color: var(--danger); font-weight: 600; }
.flag-low { color: var(--warn); font-weight: 600; }
.flag-norm, .flag-negative { color: var(--ok); }

details.card > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.card > summary::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; margin-left: 4px; }
details.card[open] > summary::before { transform: rotate(45deg); }
details.card > summary::-webkit-details-marker { display: none; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.two-col { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; align-items: start; }
.thumb { position: relative; display: block; aspect-ratio: 1; background: #eef0f2; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); text-decoration: none; color: inherit; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, rgba(0,0,0,.65)); color: #fff; font-size: .74rem; padding: 18px 8px 6px; line-height: 1.25; }
.thumb .icon { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 1.1rem; font-weight: 700; color: var(--muted); }

.upload-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.upload-item { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.upload-item img, .upload-item .icon { width: 120px; height: 120px; cursor: zoom-in; object-fit: cover; border-radius: 8px; background: #eef0f2; display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; }
.upload-item .fields { display: grid; gap: 6px; grid-template-columns: repeat(4, 1fr); }
.upload-item .fields .wide { grid-column: 1 / -1; }
.upload-item .status { font-size: .8rem; color: var(--muted); grid-column: 1 / -1; }
.upload-item.done { border-color: var(--ok); background: #f6fdf9; }
.upload-item.fail { border-color: var(--danger); }
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 32px 16px; text-align: center; color: var(--muted); cursor: pointer; background: #fafbfc; display: block; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.dropzone input { display: none; }
.dropzone b { color: var(--text); display: block; margin-bottom: 2px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: none; }
.timeline .date { color: var(--muted); font-size: .85rem; }
.timeline .date b { color: var(--text); display: block; }

.diary-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.diary-item:last-child { border-bottom: none; }
.scale { display: flex; gap: 4px; flex-wrap: wrap; }
.scale button { padding: 6px 0; width: 38px; }
.scale button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- plan / checklist ---------- */
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.plan-section { margin-bottom: 20px; }
.plan-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 8px; }
.plan-section-head h2 { margin: 0; }
.plan-topic { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 16px 4px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.next-group { margin-top: 12px; }
.next-group h4 { margin: 0 0 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.next-group div { padding: 5px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.next-group div:last-child { border-bottom: none; }
.visit { display: grid; grid-template-columns: 130px 1fr; gap: 20px; }
.visit .when { color: var(--muted); font-size: .85rem; }
.visit .when b { display: block; color: var(--text); font-size: 1rem; }
.visit .who { font-weight: 600; font-size: 1.05rem; }
.visit .where { color: var(--muted); font-size: .9rem; }
.visit dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 12px 0 0; font-size: .92rem; }
.visit dt { color: var(--muted); }
.visit dd { margin: 0; white-space: pre-wrap; }
.visit .files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.visit .files .thumb { width: 90px; }
.visit .side { text-align: right; }
select[multiple] { min-height: 120px; }
.plan-item { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: start; }
.plan-item:last-child { border-bottom: none; }
.plan-item.done .title { color: var(--muted); text-decoration: line-through; }
.plan-item.na { opacity: .55; }
.plan-item .check { width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--line-strong); background: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; margin-top: 2px; padding: 0; }
.plan-item .check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.plan-item .title { font-weight: 500; }
.plan-item .why { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.plan-item .meta { margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: .82rem; }
.plan-item .result { margin-top: 6px; font-size: .88rem; background: var(--ok-soft); color: #054f31; padding: 6px 10px; border-radius: 8px; }
.plan-item select { width: auto; padding: 4px 26px 4px 8px; font-size: .82rem; }
.plan-filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { border: 1px solid var(--line-strong); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: .85rem; cursor: pointer; text-decoration: none; color: var(--text); }
.chip.on { background: var(--text); color: #fff; border-color: var(--text); }

.doc { max-width: 820px; line-height: 1.6; }
.doc table { font-size: .88rem; }
.doc h1 { margin: .4rem 0 1rem; font-size: 1.5rem; }
.doc h2 { margin-top: 1.8rem; }
.doc code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.doc-list a { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; font-weight: 500; }
.doc-list a:last-child { border-bottom: none; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 40; max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.6); z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal img { max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 8px; background: #fff; }
.modal .panel { background: var(--card); border-radius: var(--radius); padding: 20px; max-width: 680px; width: 100%; max-height: 90vh; overflow: auto; }
.modal-bar { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; }
.modal-bar a, .modal-bar button { background: rgba(255,255,255,.92); color: var(--text); border: none; padding: 8px 12px; border-radius: 8px; text-decoration: none; font-weight: 500; }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }

@media (max-width: 900px) {
  .shell { display: block; }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 35; transform: translateX(-100%); transition: transform .2s ease; height: 100vh; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .sidebar.open { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 34; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .backdrop.open { opacity: 1; pointer-events: auto; }
  .view { padding: 16px 16px 48px; }
  .timeline li { grid-template-columns: 1fr; gap: 4px; }
  .upload-item .fields { grid-template-columns: 1fr 1fr; }
  .plan-item { grid-template-columns: 28px 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .visit { grid-template-columns: 1fr; gap: 8px; }
  .visit dl { grid-template-columns: 1fr; gap: 2px; }
  .visit dd { margin-bottom: 6px; }
  .plan-item .side { grid-column: 2; }
  .stat b { font-size: 1.4rem; }
}
