/* 圃場管理 — スマホ優先。ボタンは高さ48px以上（仕様書 5章） */
:root {
  --green-900: #1f3d14;
  --green-700: #2f5d1e;
  --green-600: #3c7a27;
  --green-100: #e3efdc;
  --green-50: #f2f7ee;
  --gray-900: #1f2420;
  --gray-700: #4a514b;
  --gray-500: #7c847d;
  --gray-300: #cfd4cf;
  --gray-200: #e4e7e3;
  --gray-100: #f1f2f0;
  --bg: #f7f7f4;
  --white: #fff;
  --red-700: #b42318;
  --red-50: #fdecea;
  --amber-700: #92400e;
  --amber-50: #fef6e7;
  --radius: 12px;
  --tap: 48px;
  --nav-h: 64px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  color: var(--gray-900);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 16px; line-height: 1.55; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--green-700); }
[hidden] { display: none !important; }

/* ---------- レイアウト ---------- */
.app { min-height: 100vh; }
.shell { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--green-700); color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; letter-spacing: .02em; }
.topbar .who { font-size: 13px; opacity: .85; }
.page { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h2 { margin: 0; font-size: 20px; flex: 1; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--white); border-top: 1px solid var(--gray-200);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--gray-500); font-size: 12px; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--green-700); }

@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-left: 200px; }
  .nav {
    top: 0; right: auto; width: 200px; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--gray-200); padding-top: 64px;
  }
  .nav a { flex: 0; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 20px; font-size: 15px; min-height: 52px; }
  .nav a.active { background: var(--green-50); }
  .topbar { margin-left: -200px; padding-left: 216px; }
  .page { padding: 24px; }
}

/* ---------- 部品 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 10px; border: 1px solid var(--gray-300);
  background: var(--white); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--gray-900);
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.btn.primary:hover { background: var(--green-900); }
.btn.danger { color: var(--red-700); border-color: #f1b8b2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--gray-200); border-color: var(--gray-200); color: var(--gray-500); cursor: not-allowed; transform: none;
}
.btn svg { width: 20px; height: 20px; }

.card { background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.muted { color: var(--gray-500); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

label.field { display: block; }
label.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; color: var(--gray-700); }
label.field > span .req { color: var(--red-700); margin-left: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--gray-300); background: var(--white);
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus, .btn:focus-visible, .check-row:focus-within { outline: 3px solid #9cc68a; outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* ステータスバッジ */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.badge.cultivating { background: var(--green-600); color: #fff; }
.badge.empty { background: var(--gray-200); color: var(--gray-700); }
.badge.planned { background: var(--amber-50); color: var(--amber-700); }
.badge.in_progress { background: var(--green-100); color: var(--green-900); }
.badge.completed { background: var(--gray-100); color: var(--gray-500); }
.badge.inactive { background: var(--red-50); color: var(--red-700); }

/* 圃場カード */
.field-list { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .field-list { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .field-list { grid-template-columns: 1fr 1fr 1fr; } }
.field-card { display: flex; gap: 12px; align-items: stretch; padding: 14px; }
.field-card.cultivating { border-left: 6px solid var(--green-600); }
.field-card.empty { border-left: 6px solid var(--gray-300); }
.field-card.selected { background: var(--green-50); border-color: var(--green-600); }
.field-card .num { font-size: 20px; font-weight: 800; letter-spacing: .02em; }
.field-card .name { font-size: 14px; color: var(--gray-700); }
.field-card .meta { font-size: 13px; color: var(--gray-500); margin-top: 6px; }
.field-card .progress { font-size: 13px; margin-top: 6px; color: var(--gray-700); }
.field-card .actions { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.select-box {
  width: 28px; height: 28px; flex: none; accent-color: var(--green-700); margin-top: 2px; cursor: pointer;
}
.bar {
  height: 6px; border-radius: 3px; background: var(--gray-200); margin-top: 4px; overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--green-600); }

.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--gray-300);
  background: var(--white); font-weight: 600; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--green-700); border-color: var(--green-700); color: #fff; }

.sticky-action {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 25;
  padding: 12px 16px; background: rgba(255,255,255,.96); border-top: 1px solid var(--gray-200);
  display: flex; gap: 12px; align-items: center;
}
@media (min-width: 900px) { .sticky-action { left: 200px; bottom: 0; } }

/* 記録画面 */
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg .chip { min-height: var(--tap); padding: 0 18px; font-size: 15px; }
.steps { display: grid; gap: 8px; }
.step-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 14px;
  border: 1px solid var(--gray-300); border-radius: 10px; background: var(--white); text-align: left; cursor: pointer; font-weight: 600;
}
.step-btn .no {
  width: 30px; height: 30px; border-radius: 50%; background: var(--gray-100); display: grid; place-items: center;
  font-size: 14px; flex: none;
}
.step-btn[aria-pressed="true"] { border-color: var(--green-700); background: var(--green-50); box-shadow: inset 0 0 0 1px var(--green-700); }
.step-btn[aria-pressed="true"] .no { background: var(--green-700); color: #fff; }
.step-btn .tag { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--green-700); }
.check-list { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .check-list { grid-template-columns: 1fr 1fr; } }
.check-row {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 12px;
  border: 1px solid var(--gray-300); border-radius: 10px; background: var(--white); cursor: pointer;
}
.check-row input { width: 26px; height: 26px; accent-color: var(--green-700); flex: none; }
.check-row.checked { border-color: var(--green-700); background: var(--green-50); }
.section-title { font-size: 15px; font-weight: 700; margin: 20px 0 8px; display: flex; align-items: center; gap: 8px; }
.section-title .n {
  width: 24px; height: 24px; border-radius: 50%; background: var(--green-700); color: #fff;
  display: inline-grid; place-items: center; font-size: 13px;
}

/* メッセージ */
.alert { border-radius: 10px; padding: 12px 14px; font-size: 15px; }
.alert.error { background: var(--red-50); color: var(--red-700); border: 1px solid #f4c7c1; }
.alert.info { background: var(--green-50); color: var(--green-900); border: 1px solid var(--green-100); }
.alert.warn { background: var(--amber-50); color: var(--amber-700); border: 1px solid #f6dfb3; }
.alert .btn { margin-top: 8px; }

.offline-banner {
  position: sticky; top: 0; z-index: 50; background: var(--red-700); color: #fff;
  padding: 10px 16px; font-weight: 700; font-size: 15px; text-align: center;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px);
  background: var(--gray-900); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.ok { background: var(--green-700); }
.toast.err { background: var(--red-700); }

/* テーブル（PC）・リスト（スマホ） */
.table-wrap { overflow-x: auto; background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-200); text-align: left; vertical-align: middle; }
.table th { background: var(--gray-100); font-size: 13px; color: var(--gray-700); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--green-50); }
.table input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--green-700); }
.only-pc { display: none; }
@media (min-width: 900px) { .only-pc { display: block; } .only-sp { display: none !important; } }

.log-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; }
.log-item input { width: 24px; height: 24px; accent-color: var(--green-700); margin-top: 2px; }
.log-item .date { font-weight: 700; }
.log-item .task { font-weight: 700; font-size: 16px; }
.list { background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius); }
.list > * + * { border-top: 1px solid var(--gray-200); }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 16px 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--gray-200); margin-bottom: 16px; overflow-x: auto; }
.tabs a {
  padding: 12px 16px; min-height: var(--tap); text-decoration: none; color: var(--gray-500); font-weight: 700;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--green-700); border-color: var(--green-700); }

/* ダイアログ */
.dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 24px);
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.dialog::backdrop { background: rgba(20,30,20,.45); }
.dialog .d-head { padding: 16px 20px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; }
.dialog .d-head h3 { margin: 0; font-size: 18px; flex: 1; }
.dialog .d-body { padding: 16px 20px; }
.dialog .d-foot { padding: 12px 20px 20px; display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.dialog .d-foot .btn { min-width: 120px; }

.history { font-size: 14px; }
.history li { padding: 6px 0; border-bottom: 1px dashed var(--gray-200); }
.step-edit { display: flex; gap: 8px; align-items: center; }
.step-edit .input { min-height: 44px; }
.step-edit .btn { min-height: 44px; padding: 0 10px; }

/* ログイン */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(420px, 100%); padding: 28px 24px; }
.auth h1 { margin: 0 0 4px; font-size: 22px; color: var(--green-700); }

.empty-state { text-align: center; padding: 40px 16px; color: var(--gray-500); }
.spinner { padding: 40px; text-align: center; color: var(--gray-500); }
