:root {
  --navy: #13213c;
  --navy-2: #1c2e50;
  --surface: #f5f3ef;
  --panel: #ffffff;
  --line: #e2ddd5;
  --text: #1d232b;
  --muted: #5f6772;
  --teal: #0b766f;
  --teal-dark: #085c56;
  --warn-bg: #fff4dc; --warn: #7a4b00;
  --danger-bg: #fde7e7; --danger: #9b1c1c;
  --ok-bg: #e3f4ec; --ok: #145c3a;
  --info-bg: #e6eef9; --info: #1f4b85;
  --accent-bg: #efe8fb; --accent: #5a3a91;
  --sample-bg: #f1e9d8; --sample: #6b4e12;
  --radius: 6px;
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface); line-height: 1.55; }
a { color: var(--teal-dark); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid #5bb8b0; outline-offset: 1px;
}
.skip { position: absolute; left: -999px; top: 0; background: #fff; padding: 8px; z-index: 10; }
.skip:focus { left: 8px; }
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #d8deea; padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; }
.logo-chip { background: #fff; border-radius: 4px; padding: 3px 6px; display: inline-flex; }
.logo-chip img { display: block; width: 92px; height: auto; }
.brand-name { color: #fff; font-weight: 700; letter-spacing: .12em; font-size: 13px; }
.nav { list-style: none; margin: 0; padding: 0; }
.nav a { display: block; color: #d8deea; text-decoration: none; padding: 9px 12px; border-radius: var(--radius); margin-bottom: 2px; }
.nav-group { margin: 16px 12px 6px; font-size: 11.5px; letter-spacing: .08em; color: #9aa6bd; font-weight: 600; }
#nav > .nav-group:first-child { margin-top: 4px; }
.nav-close, .nav-scrim { display: none; }
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a[aria-current="page"] { background: var(--teal); color: #fff; font-weight: 600; }
.side-note { font-size: 12px; color: #9aa6bd; margin: 20px 8px 0; }
.workspace { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topmeta { flex: 0 0 auto; white-space: nowrap; display: flex; gap: 8px; align-items: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.menu-btn { display: none; flex: 0 0 auto; }
.pill { border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.pill-local { background: var(--ok-bg); color: var(--ok); }
.main { padding: 20px 24px 48px; max-width: 1360px; width: 100%; }
.main:focus { outline: none; }
.flash { margin: 0 24px; }
.flash:empty { display: none; }
.flash-ok, .flash-warn, .flash-error { margin-top: 12px; padding: 10px 14px; border-radius: var(--radius); }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.panel h2 { font-size: 16px; margin: 0; }
.panel h3 { font-size: 14px; margin: 14px 0 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .panel { margin-bottom: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.empty { color: var(--muted); padding: 8px 0; margin: 0; }
.loading { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 12px; color: var(--muted); font-weight: 600; background: #faf9f6; white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total th, tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.neg { color: var(--danger); }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 4px; white-space: nowrap; font-weight: 600; }
.badge-neutral { background: #eceae5; color: #3d434b; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-accent { background: var(--accent-bg); color: var(--accent); }
.badge-muted { background: #e9e9ea; color: #4a4f57; }
.badge-sample { background: var(--sample-bg); color: var(--sample); }
.flow { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0; }
.flow li { flex: 1 1 110px; background: #faf9f6; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; display: flex; flex-direction: column; font-size: 12.5px; }
.flow-n { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.flow-done { background: var(--ok-bg) !important; }
.cycle { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; padding: 0; margin: 0; list-style: none; counter-reset: c; }
.cycle li { border-left: 3px solid var(--teal); background: #faf9f6; padding: 6px 10px; display: flex; flex-direction: column; font-size: 12.5px; }
.compact { margin: 4px 0; padding-left: 18px; }
.compact li { margin: 3px 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 16px; margin: 0 0 12px; }
.facts div { border-bottom: 1px dashed var(--line); padding-bottom: 4px; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 14px; }
.fields .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: #39404a; font-weight: 600; }
.req { font-size: 11px; color: var(--danger); font-weight: 600; margin-left: 6px; }
label .req { display: inline; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--text); border: 1px solid #c9c3b8; border-radius: 4px; padding: 6px 8px; background: #fff; min-width: 0; }
textarea { resize: vertical; }
[aria-invalid="true"] { border-color: var(--danger); background: #fff8f8; }
.inline { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; }
.inline.tight { gap: 4px; }
.inline.tight select { padding: 3px 4px; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font: inherit; font-weight: 600; border: 1px solid #b9b2a6; background: #fff; color: var(--text); padding: 7px 14px; border-radius: 4px; cursor: pointer; }
.btn:hover:not(:disabled) { background: #f3f1ec; }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--teal-dark); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.form-errors:empty { display: none; }
.form-errors { background: var(--danger-bg); color: var(--danger); border-radius: 4px; padding: 6px 12px; margin: 6px 0; width: 100%; }
.form-errors p, .form-errors ul { margin: 2px 0; }
.bulk textarea { width: 100%; }
.bulk label { margin-bottom: 4px; }
.preview { background: var(--info-bg); border-radius: var(--radius); padding: 8px 14px; margin: 10px 0; }
.preview-sample { background: var(--sample-bg); }
.preview ul { margin: 4px 0; }
.deal-form { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.calc { font-variant-numeric: tabular-nums; color: var(--muted); margin: 10px 0 0; }
.task { border: 1px solid var(--line); border-radius: var(--radius); margin: 6px 0; background: #fff; }
.task summary { cursor: pointer; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.task[open] summary { border-bottom: 1px solid var(--line); background: #faf9f6; }
.task form, .task .inquiry-body { padding: 10px 12px; }
.task-title { font-weight: 600; }
.inquiry-body pre { white-space: pre-wrap; word-break: break-word; font: inherit; background: #faf9f6; padding: 8px; border-radius: 4px; margin: 0; max-height: 240px; overflow: auto; }
.sub-form { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 10px; }
.warn-text { color: var(--warn); background: var(--warn-bg); padding: 6px 10px; border-radius: 4px; }
.warn-list { color: var(--warn); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 10px; }
.kpis > div { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; }
.k-label { font-size: 12px; color: var(--muted); }
.k-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.media .grid-2 { margin-top: 12px; }
.notfound { max-width: 480px; margin: 80px auto; background: #fff; padding: 24px; border-radius: var(--radius); border: 1px solid var(--line); }
code { font-size: 12px; background: #f1efea; padding: 1px 4px; border-radius: 3px; }

/* 折畳み・広告設定・候補・帳票明細 */
details.more { margin: 8px 0; }
details.more > summary { cursor: pointer; padding: 6px 0; color: var(--teal-dark); font-weight: 600; }
details.more > summary.btn { display: inline-block; color: var(--text); }
.intake { margin: 0 0 12px; }
.intake > summary { display: inline-block; list-style: none; }
.intake > summary::-webkit-details-marker { display: none; }
.intake[open] > summary { margin-bottom: 10px; }
.intake-body { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: #fcfbf9; margin-bottom: 12px; }
.filter { margin: 4px 0 10px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; margin: 0 0 12px; min-width: 0; }
legend { font-weight: 700; padding: 0 4px; }
.group-status { max-width: 260px; margin-bottom: 8px; }
.readiness { background: var(--warn-bg); border-radius: var(--radius); padding: 8px 14px; margin-bottom: 10px; }
.readiness p { margin: 2px 0; }
.ok-text { color: var(--ok); background: var(--ok-bg); padding: 6px 10px; border-radius: 4px; }
.counter { font-weight: 400; font-size: 12px; color: var(--muted); }
.counter.over { color: var(--danger); font-weight: 600; }
.candidate { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; }
.candidate header { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 6px; }
.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.lines-edit input, .lines-edit select { width: 100%; }
.lines-edit td { padding: 4px; }
td, dd { overflow-wrap: anywhere; }
.client-pick { display: flex; flex-direction: column; gap: 3px; }
.client-pick input[type="search"] { margin-bottom: 4px; }
.client-pick .hint { font-weight: 400; }
.file-pick { flex-direction: row; align-items: center; gap: 8px; }
.csv-map th select { margin-top: 4px; width: 100%; min-width: 120px; font-weight: 400; }
.csv-map td { white-space: pre-wrap; }

/* R5: 直感的な操作のための部品 */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.quick { padding: 14px 18px; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.head-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.back { margin: 0 0 6px; font-size: 13px; }
.empty-state { padding: 12px 0; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.empty-state p { margin: 0; color: var(--muted); }
.error-panel { border-color: #e7b9b9; background: #fffafa; }
.error-panel p { margin: 0 0 4px; color: var(--danger); font-weight: 600; }
.deal-new { border-color: var(--teal); }
fieldset.group { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 12px 0 4px; margin: 0 0 8px; }
fieldset.group > legend { font-size: 14px; padding: 0 8px 0 0; color: var(--text); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 18px; max-width: 760px; }
.form-grid .wide { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.opt { font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.form-submit { align-items: center; border-top: 1px solid var(--line); padding-top: 12px; }
.form-submit .hint { margin: 0; }
.steps { list-style: none; display: flex; gap: 0; padding: 0; margin: 4px 0 14px; counter-reset: none; }
.steps li { flex: 1 1 0; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 3px solid var(--line); color: var(--muted); font-size: 13px; }
.steps li.current { border-bottom-color: var(--teal); color: var(--text); font-weight: 700; }
.steps li.done { border-bottom-color: #9cc9c4; color: var(--text); }
.step-n { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; align-items: center; justify-content: center; background: #eceae5; font-weight: 700; font-size: 12px; flex: 0 0 auto; }
.steps li.current .step-n { background: var(--teal); color: #fff; }
.steps li.done .step-n { background: #cfe7e4; color: var(--teal-dark); }
.step-body { padding: 2px 0; }
.file-pick { font-weight: 600; }

.login-box { max-width: 380px; margin: 10vh auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-box h1 { font-size: 20px; margin: 8px 0 16px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 700; letter-spacing: .12em; }
.login-form { display: flex; flex-direction: column; gap: 6px; }
.login-form input { font-size: 16px; padding: 10px; }
.login-form .btn { margin-top: 12px; }
.nav-logout { display: block; margin: 12px 8px 0; font: inherit; font-weight: 600; color: #d8deea; background: transparent; border: 1px solid #4a5b7c; border-radius: 4px; min-height: 40px; padding: 0 14px; cursor: pointer; }
.nav-logout:hover { background: var(--navy-2); color: #fff; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 240px; transform: translateX(-100%); transition: transform .15s; z-index: 20; }
  .nav-open .sidebar { transform: none; }
  .nav-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); border: 0; z-index: 15; }
  .nav-open .nav-scrim { display: block; }
  .nav-close { display: block; margin: 0 0 8px auto; font: inherit; font-weight: 600; color: #fff; background: transparent; border: 1px solid #4a5b7c; border-radius: 4px; min-height: 44px; padding: 0 14px; }
  .nav a { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .quick-actions .btn { flex: 1 1 100%; }
  .steps li { flex-direction: column; text-align: center; gap: 4px; font-size: 12px; padding: 6px 4px; }
  .menu-btn { display: inline-block; font: inherit; border: 1px solid #b9b2a6; background: #fff; border-radius: 4px; padding: 5px 10px; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 16px; }
  .topmeta .pill-local { display: none; }
  html, body { overflow-x: hidden; }
  input, select, textarea { font-size: 16px; }
  .btn, .menu-btn, details.more > summary, .nav a { min-height: 44px; }
  .btn { padding: 10px 16px; }
  details.more > summary { display: flex; align-items: center; }
  .inline > label, .inline > select, .inline > input { flex: 1 1 100%; }
  .inline.tight > * { flex: 1 1 auto; }
  .group-status { max-width: none; }
  .sticky-actions { position: sticky; bottom: 0; background: #fff; padding: 8px 0; margin: 0; border-top: 1px solid var(--line); }
  .main { padding: 14px 12px 40px; }
  .flash { margin: 0 12px; }
  .grid-2, .kpis { grid-template-columns: 1fr; }
  .panel { padding: 12px; }
  /* 表はカード状に積む */
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap tr, .table-wrap th, .table-wrap td { display: block; }
  .table-wrap thead { position: absolute; left: -9999px; }
  .table-wrap tr { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; padding: 4px 0; }
  .table-wrap td, .table-wrap tbody th { border: none; display: flex; justify-content: space-between; gap: 12px; padding: 4px 10px; text-align: right; }
  .table-wrap td::before, .table-wrap tbody th::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; font-weight: 600; }
  .table-wrap td > form { flex-wrap: wrap; justify-content: flex-end; }
}
@media (max-width: 480px) {
  .topmeta { display: none; }
  .topbar { gap: 8px; }
}
