:root {
  --green: #1f6b4d;
  --green-deep: #174f39;
  --green-tint: #e9f2ed;
  --ink: #23302a;
  --muted: #6f7a73;
  --bg: #f6f3ec;
  --card: #ffffff;
  --line: #e6dfd1;
  --line-soft: #efeadf;
  --late: #a8641a;
  --late-tint: #fbf1e1;
  --err: #a63a2e;
  --err-tint: #f9e9e6;
  --manual: #55606b;
  --manual-tint: #eceff1;
  --shadow: 0 1px 2px rgba(60, 50, 30, .05), 0 4px 14px rgba(60, 50, 30, .04);
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
a { color: var(--green); text-underline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.brand-en { font-size: 10.5px; letter-spacing: .22em; color: var(--muted); font-weight: 600; }

/* ---- ボタン ---- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 600; padding: 9px 16px; border-radius: 8px; cursor: pointer;
  min-height: 40px;
}
.btn:hover { border-color: #cfc6b3; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-deep); border-color: var(--green-deep); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-block { width: 100%; }
.btn-sm { font-size: 12.5px; padding: 5px 10px; min-height: 32px; font-weight: 500; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---- ログイン ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-box {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px 28px;
}
.login-box h1 { font-size: 24px; margin: 4px 0 8px; letter-spacing: .04em; }
.login-lead { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-box label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: #fff;
  border: 1px solid #d8d0bf; border-radius: 8px; padding: 9px 11px;
}
textarea { resize: vertical; }
.form-error { color: var(--err); font-size: 13px; min-height: 1.6em; margin: 6px 0; }

/* ---- 骨格 ---- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--green-deep); color: #e7f0eb; padding: 26px 16px 18px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side .brand-en { color: #9dbfae; }
.brand { font-size: 20px; font-weight: 700; letter-spacing: .06em; margin-top: 2px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  color: #dbe9e1; text-decoration: none; font-size: 13.5px; padding: 8px 10px; border-radius: 7px;
}
.side-nav a:hover { background: rgba(255, 255, 255, .08); }
.side-nav .n { font-size: 12px; color: #9dbfae; font-variant-numeric: tabular-nums; white-space: nowrap; }
.side-nav .n b { color: #f3c98b; font-weight: 600; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid rgba(255, 255, 255, .12); padding-top: 12px; }
.side-link { appearance: none; background: none; border: 0; color: #dbe9e1; font: inherit; font-size: 13.5px; text-align: left; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.side-link:hover { background: rgba(255, 255, 255, .08); }

.main { padding: 30px 34px 60px; min-width: 0; max-width: 1280px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; letter-spacing: .04em; }

/* ---- 件数帯 ---- */
.summary {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.sum-cell {
  appearance: none; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
  padding: 16px 20px 14px; border-left: 1px solid var(--line-soft); min-width: 0;
}
.sum-cell:first-child { border-left: 0; }
.sum-cell:hover { background: #fbf9f4; }
.sum-cell[aria-pressed="true"] { background: var(--green-tint); }
.sum-label { display: flex; margin-bottom: 2px; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--green); } .dot.late { background: var(--late); } .dot.error { background: var(--err); } .dot.manual { background: var(--manual); }
.sum-num { display: block; font-size: 34px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.sum-num small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.sum-sub { display: block; font-size: 12px; color: var(--muted); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 2px 6px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--green); flex: none; }

/* ---- グループ表 ---- */
.group { margin-top: 22px; scroll-margin-top: 16px; }
.group-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 0 2px 8px; }
.group-head h2 { font-size: 16px; letter-spacing: .03em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

.rows-head, .row {
  display: grid;
  grid-template-columns: 74px minmax(130px, 1.1fr) 132px minmax(0, 2fr) 58px 58px 74px;
  gap: 12px; align-items: center; padding: 10px 16px;
}
.rows-head { font-size: 11.5px; color: var(--muted); font-weight: 600; background: #fbf9f4; border-bottom: 1px solid var(--line-soft); letter-spacing: .04em; }
.row { border-top: 1px solid var(--line-soft); font-size: 14px; }
.row:first-of-type { border-top: 0; }
.row.is-disabled { opacity: .5; }
.row > * { min-width: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.badge.ok { color: var(--green-deep); background: var(--green-tint); border-color: #cfe3d8; }
.badge.late { color: var(--late); background: var(--late-tint); border-color: #f0dcbb; }
.badge.error { color: var(--err); background: var(--err-tint); border-color: #efcfca; }
.badge.unknown, .badge.manual { color: var(--manual); background: var(--manual-tint); border-color: #dde2e6; }
.badges { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }

.c-name a { color: var(--ink); font-weight: 600; text-decoration: none; }
.c-name a:hover { text-decoration: underline; }
.c-name .sub { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.c-date .d { font-variant-numeric: tabular-nums; }
.c-date .ago { display: block; font-size: 12px; color: var(--muted); }
.c-date .ago.late { color: var(--late); font-weight: 600; }
.c-title { font-size: 13.5px; }
.c-title a { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.c-title .note { color: var(--muted); font-size: 12.5px; }
.c-title .errtext { color: var(--err); font-size: 12.5px; }
.c-act { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.lbl { display: none; }

/* ---- ダイアログ ---- */
.dlg { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(30, 40, 30, .25); color: var(--ink); }
.dlg-narrow { width: min(420px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(25, 40, 32, .45); }
.dlg form { padding: 24px; }
.dlg h2 { font-size: 18px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-grid label.check { flex-direction: row; font-weight: 500; }
.f-wide { grid-column: 1 / -1; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 13.5px; padding: 10px 18px; border-radius: 8px; max-width: calc(100vw - 32px); z-index: 50; }
.foot-note { margin-top: 28px; font-size: 12px; color: var(--muted); }
.empty { padding: 22px 16px; color: var(--muted); font-size: 13.5px; }

/* ---- タブレット以下：サイドバー→上部バー ---- */
@media (max-width: 900px) {
  .shell { display: block; }
  .side { position: static; height: auto; padding: 14px 16px 10px; gap: 10px; overflow: visible; }
  .side-head { display: flex; align-items: baseline; gap: 10px; flex-direction: row-reverse; justify-content: flex-end; }
  .brand { font-size: 17px; margin: 0; }
  .side-nav { flex-direction: row; overflow-x: auto; gap: 4px; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav a { flex: none; background: rgba(255, 255, 255, .08); padding: 6px 11px; font-size: 12.5px; }
  .side-foot { flex-direction: row; margin-top: 0; padding-top: 6px; }
  .side-link { font-size: 12.5px; padding: 6px 8px; }
  .main { padding: 20px 14px 48px; }
}

/* ---- スマホ：表を縦積みの行に ---- */
@media (max-width: 760px) {
  .page-head h1 { font-size: 21px; }
  .page-head .btn { width: 100%; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sum-cell { padding: 12px 14px; }
  .sum-cell:nth-child(odd) { border-left: 0; }
  .sum-cell:nth-child(n+3) { border-top: 1px solid var(--line-soft); }
  .sum-num { font-size: 28px; }
  .rows-head { display: none; }
  .row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name st" "date date" "title title" "meta act";
    gap: 6px 10px; padding: 13px 14px; align-items: start;
  }
  .c-st { grid-area: st; } .c-name { grid-area: name; } .c-date { grid-area: date; } .c-title { grid-area: title; }
  .c-meta { grid-area: meta; display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-self: center; }
  .c-act { grid-area: act; flex-direction: row; }
  .badges { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
  .c-date .ago { display: inline; margin-left: 8px; }
  .num { text-align: left; }
  .lbl { display: inline; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .dlg form { padding: 18px; }
}
@media (min-width: 761px) {
  .c-meta { display: contents; }
}

/* ==== 第2段：下書き ==== */
.side-drafts { display: flex; justify-content: space-between; align-items: baseline; width: 100%; margin-top: 10px; border-top: 1px solid rgba(255, 255, 255, .12); border-radius: 0 0 7px 7px; padding-top: 14px; }
.side-drafts .n { font-size: 12px; color: #f3c98b; font-weight: 600; font-variant-numeric: tabular-nums; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.notice { background: #fbf6ea; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 18px; font-size: 14px; line-height: 1.7; }
.notice-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.hint { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 5px; line-height: 1.6; }
.dlg-left { margin-right: auto; }
.dlg-wide { width: min(860px, calc(100vw - 24px)); }
.dlg-actions { flex-wrap: wrap; }

.drows-head, .drow {
  display: grid; grid-template-columns: 84px minmax(120px, 1fr) minmax(0, 2.4fr) 70px 96px 84px;
  gap: 12px; align-items: center; padding: 10px 16px;
}
.drows-head { font-size: 11.5px; color: var(--muted); font-weight: 600; background: #fbf9f4; border-bottom: 1px solid var(--line-soft); letter-spacing: .04em; }
.drow { border-top: 1px solid var(--line-soft); font-size: 14px; }
.drow > * { min-width: 0; }
.drow .errtext { display: block; font-size: 12px; margin-top: 3px; }

.tabs { display: flex; gap: 4px; margin: 14px 0 0; border-bottom: 1px solid var(--line); }
.tab { appearance: none; background: none; border: 0; font: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted); padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--green); border-bottom-color: var(--green); }
.preview { border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; padding: 18px 20px; max-height: 46vh; overflow: auto; background: #fff; line-height: 1.95; font-size: 15px; overflow-wrap: anywhere; }
.preview h2 { font-size: 18px; margin: 22px 0 10px; padding-left: 10px; border-left: 3px solid var(--green); }
.preview h2:first-child { margin-top: 0; }
.preview h3 { font-size: 15.5px; margin: 16px 0 8px; }
.preview p { margin: 0 0 12px; }
.preview ul, .preview ol { margin: 0 0 12px 1.3em; }
.body-edit { width: 100%; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; padding: 14px; font: 13px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 46vh; resize: vertical; }

@media (max-width: 760px) {
  .head-actions { width: 100%; }
  .drows-head { display: none; }
  .drow { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; padding: 13px 14px; }
  .drow > :nth-child(3) { grid-column: 1 / -1; }
  .dlg-actions .btn { flex: 1 1 auto; }
  .dlg-left { margin-right: 0; }
  .preview { padding: 14px; }
}
@media (max-width: 900px) {
  .side-drafts { width: auto; margin-top: 0; border-top: 0; padding-top: 6px; gap: 6px; }
}
/* 下書き行：更新状況の行用の grid-area 指定（.c-name 等）を打ち消す */
.drow > * { grid-area: auto; }
@media (max-width: 760px) {
  .drow { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "dname dst" "dtitle dtitle" "dmeta dact"; }
  .drow > :nth-child(1) { grid-area: dst; justify-self: end; }
  .drow > :nth-child(2) { grid-area: dname; }
  .drow > :nth-child(3) { grid-area: dtitle; }
  .drow > :nth-child(4) { display: none; }
  .drow > :nth-child(5) { grid-area: dmeta; align-self: center; font-size: 12px; }
  .drow > :nth-child(6) { grid-area: dact; }
}
.edit-hint { margin: 8px 0 0; }
.preview.is-editable { cursor: text; }
.preview.is-editable:focus { outline: 2px solid var(--green); outline-offset: -2px; }
.tabs + .edit-hint + .preview { border-top: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.tabs + .edit-hint + .preview + .body-edit { border-top: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.regen-label { display: block; font-size: 13px; font-weight: 600; }
.regen-label textarea { display: block; width: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: inherit; font-weight: 400; line-height: 1.7; background: #fff; }
#regenBox .check { margin-top: 10px; font-size: 13px; }
/* 自動更新・検品 */
.auto-panel { padding: 14px 16px; margin: 0 0 18px; font-size: 13.5px; }
.auto-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.auto-list { list-style: none; margin: 10px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line-soft); display: grid; gap: 6px; }
.auto-list li { overflow-wrap: anywhere; }
.review-box { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-top: 12px; font-size: 13.5px; line-height: 1.7; background: #fff; }
.review-box.is-ng { background: #fdf3f1; border-color: #ecc9c3; }
.review-box.is-ok { background: #f1f8f4; border-color: #cfe3d8; }
.review-box ul { margin: 6px 0 0 1.2em; }
.review-box li { margin-bottom: 4px; overflow-wrap: anywhere; }
.review-box details { margin-top: 6px; color: var(--muted); }
.review-head { margin: 0; }
