/* デザインの基準
   ・文字と背景のコントラストは 4.5:1 以上（JIS X 8341-3／WCAG 2.1 AA）。色だけで意味を伝えない（文字のラベルを必ず添える）
   ・操作できるものは 32px 以上の高さ。キーボードだけで操作でき、フォーカスが見える
   ・間隔は 4 の倍数（4・8・12・16・24・32）。本文 14px・行の高さ 1.6
   ・画面の並びをどこでも同じにする（見出し→説明→操作ボタン→絞り込み→一覧）（ISO 9241-110 の「期待との一致」） */
:root {
  --bg: #F4F7F6; --panel: #FFFFFF; --line: #D5DBE1; --line-soft: #E9EDF1; --head: #F7F9FA;
  --text: #1C2730; --muted: #55626D; --accent: #0D6660; --accent-hover: #0A5550; --accent-soft: #E2F0EE; --accent-ink: #FFFFFF;
  --danger: #B3261E; --danger-soft: #FBEAE9; --warn: #7A4F00; --warn-soft: #FFF2D6; --ok: #1B6535; --ok-soft: #E4F3E8;
  --focus: #1A5FB4;
  --mint: #5CC8A0; --mint-soft: #E5F5EE; --yellow: #F2BC3F; --yellow-soft: #FFF5DA; --blue-soft: #E9EFF9; --blue-ink: #2D5BA3; --r-lg: 12px;
  --r: 8px; --r-sm: 6px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  --shadow: 0 8px 28px rgba(16, 32, 48, .14);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; line-height: 1.35; margin: 0; letter-spacing: .02em; }
h2 { font-size: 16px; line-height: 1.4; margin: 0 0 12px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: 8px; top: -80px; background: var(--panel); padding: 8px 16px; border-radius: var(--r-sm); z-index: 100; box-shadow: var(--shadow); }
.skip:focus { top: 8px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* レイアウト：上の帯（左上＝システム名とロゴ、右上＝ログイン中の会社と利用者）＋左のメニュー＋右の作業領域 */
:root { --appbar-h: 60px; }
.appbar { position: sticky; top: 0; z-index: 30; height: var(--appbar-h); display: flex; align-items: center; gap: 16px; padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.appbar-brand { display: flex; align-items: center; border-radius: var(--r-sm); }
.appbar-brand img { display: block; height: 34px; width: auto; }
.appbar .search { position: relative; flex: 0 1 420px; margin-left: 40px; }
.appbar .search input { width: 100%; height: 38px; padding: 0 12px 0 38px; border-radius: 19px; background: var(--bg); border-color: transparent; }
.appbar .search input:hover { border-color: var(--line); }
.appbar .search input:focus { background: var(--panel); border-color: var(--accent); }
.search-ico { position: absolute; left: 12px; top: 10px; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.appbar-user { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.who { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.35; margin-right: 8px; min-width: 0; }
.who-company { font-weight: 700; font-size: 14px; }
.who-name { color: var(--muted); font-size: 12px; }
.who span { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layout { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: calc(100vh - var(--appbar-h)); }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 8px 12px 24px; position: sticky; top: var(--appbar-h); height: calc(100vh - var(--appbar-h)); overflow-y: auto; display: flex; flex-direction: column; }
.side .nav { flex: 1 0 auto; }
.credit { margin: 24px 8px 0; font-size: 12px; color: var(--muted); }
.auth .credit { text-align: center; margin-top: 16px; }
.credit-links { display: block; margin-top: 4px; }
.credit-links a { margin-right: 12px; color: var(--muted); }
.auth .credit-links a { margin: 0 6px; }
.nav-group { margin: 20px 0 6px; padding: 0 12px; font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .04em; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 6px 12px; border-radius: 10px; color: var(--text); text-decoration: none; }
.nav a .nav-label { flex: 1; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a .ico { color: var(--muted); }
.nav a.active .ico { color: var(--accent); }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 7px; line-height: 18px; min-width: 20px; text-align: center; }
.main { padding: 28px 36px 64px; min-width: 0; }
#view { max-width: 1440px; }
#view:focus { outline: none; }
.search-results { position: absolute; top: 42px; left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); z-index: 20; max-height: 380px; overflow: auto; }
.search-results a { display: block; padding: 8px 12px; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--line-soft); }
.search-results a:hover, .search-results a:focus { background: var(--bg); }

.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .lead { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 16px; }
/* はじめに（新しく使い始めた会社の管理者向け） */
.setup { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px 8px; margin-bottom: 20px; }
.setup-head { display: flex; align-items: center; gap: 12px; }
.setup-head h2 { margin: 0; font-size: 16px; flex: 1; }
.setup-bar { height: 6px; border-radius: 3px; background: var(--line-soft); margin: 12px 0 4px; overflow: hidden; }
.setup-bar span { display: block; height: 100%; background: var(--mint); border-radius: 3px; }
.setup-steps { list-style: none; margin: 0; padding: 0; }
.setup-steps li { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.setup-steps li:first-child { border-top: 0; }
.setup-no { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--accent); color: var(--accent); font-weight: 700; font-size: 14px; }
.setup-steps li.done .setup-no { background: var(--mint-soft); border-color: var(--mint); color: #17795A; }
.setup-text { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.setup-text small { flex-basis: 100%; color: var(--muted); font-size: 13px; }
.setup-steps li.done b { color: var(--muted); }

/* お知らせ（運営から） */
.news { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--mint); border-radius: var(--r-lg); padding: 12px 16px; margin-bottom: 20px; color: var(--text); text-decoration: none; }
.news.important { border-left-color: var(--yellow); background: var(--yellow-soft); }
.news:hover { border-color: var(--accent); }
.news-tag { font-size: 12px; font-weight: 700; color: var(--accent); }
.news.important .news-tag { color: #7A4F00; }
.news .news-title { flex: 1; font-weight: 700; min-width: 12em; }
.news-more { font-size: 13px; color: var(--accent); font-weight: 700; }
.news-list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; max-width: 900px; }
.news-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 20px; border: 0; background: none; text-align: left; cursor: pointer; }
.news-item + .news-item { border-top: 1px solid var(--line-soft); }
.news-item:hover { background: var(--bg); }
.news-item .news-title { flex: 1; }
.news-item.unread .news-title { font-weight: 700; }
.news-date { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; min-width: 6.5em; }
.news-body { line-height: 1.9; white-space: normal; }
.notice-btn .badge { margin-left: 2px; }

/* ホーム：あいさつ → 今月の数字（金額） → 業務ごとの欄（2列）。要対応の行は黄色の印と「要対応」の文字 */
.hello { margin-bottom: 20px; }
.hello h1 { font-size: 24px; }
.hello .lead { color: var(--muted); margin: 6px 0 0; }
.hello .lead strong { color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 20px; color: var(--text); text-decoration: none; }
.kpi:hover { border-color: var(--accent); }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 700; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: 12px; color: var(--muted); }
.hareas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.harea { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.harea h2 { display: flex; align-items: center; gap: 10px; margin: 0; padding: 14px 20px; font-size: 16px; border-bottom: 1px solid var(--line-soft); }
.harea-ico { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; }
.harea-sales .harea-ico { background: var(--accent-soft); color: var(--accent); }
.harea-stock .harea-ico { background: var(--mint-soft); color: #17795A; }
.harea-billing .harea-ico { background: var(--yellow-soft); color: #8A5C00; }
.harea-expense .harea-ico { background: var(--blue-soft); color: var(--blue-ink); }
.hrow { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 16px 8px 20px; color: var(--text); text-decoration: none; }
.hrow + .hrow { border-top: 1px solid var(--line-soft); }
.hrow:hover { background: var(--bg); }
.hrow-label { flex: 1; display: flex; flex-direction: column; }
.hrow-label small { color: var(--muted); font-size: 12px; }
.hrow-num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hrow-num small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.hrow-go { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hrow.attention .hrow-label { font-weight: 700; }
.hrow.attention .hrow-label::after { content: '要対応'; align-self: flex-start; margin-top: 2px; font-size: 11px; font-weight: 700; color: #7A4F00; background: var(--yellow-soft); border: 1px solid var(--yellow); border-radius: 10px; padding: 0 8px; line-height: 18px; order: 2; }
.hrow.attention::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--yellow); flex: none; margin-left: -12px; }

/* ボタン */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: var(--r-sm); padding: 6px 16px; cursor: pointer; min-height: 36px; text-decoration: none; color: var(--text); white-space: nowrap; font-weight: 500; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.small { min-height: 32px; padding: 3px 12px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* 表 */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; max-height: 70vh; }
table.list { width: 100%; border-collapse: separate; border-spacing: 0; }
table.list th, table.list td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
table.list th { background: var(--head); font-weight: 700; font-size: 12px; color: var(--muted); white-space: nowrap; position: sticky; top: 0; z-index: 1; border-bottom-color: var(--line); }
table.list th.num, table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td, table.list tr.clickable:focus td { background: #F2F8F7; }
table.list tr.clickable:focus { outline: none; }
table.list tr.clickable:focus td:first-child { box-shadow: inset 3px 0 0 var(--focus); }
table.list tr:last-child td { border-bottom: 0; }
.table-hint { font-size: 12px; color: var(--muted); margin: 6px 2px 0; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input[type=date], .filters input[type=search], .filters select { width: auto; }
.filters label.inline { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 700; }
.filters label.inline input { width: 280px; }

.chip { display: inline-block; border-radius: 10px; padding: 0 10px; font-size: 12px; font-weight: 600; line-height: 22px; background: var(--line-soft); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* フォーム */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form .full { grid-column: 1 / -1; }
.field > label { display: block; }
.label-text { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.req { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700; color: var(--danger); background: var(--danger-soft); border-radius: 4px; padding: 0 5px; line-height: 18px; vertical-align: 1px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=email], input[type=search], select, textarea {
  width: 100%; border: 1px solid #B9C2CA; border-radius: var(--r-sm); padding: 7px 10px; background: #fff; min-height: 38px; }
input:hover, select:hover, textarea:hover { border-color: #8E9AA5; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
textarea { min-height: 76px; resize: vertical; }
.lines { width: 100%; border-collapse: collapse; margin-top: 4px; }
.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 4px; font-weight: 700; }
.lines td { padding: 3px 4px; }
.lines input, .lines select { min-height: 34px; padding: 4px 8px; }
.totals { margin-left: auto; width: 340px; margin-top: 12px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; padding: 2px 0; }
.totals .grand { font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }

/* 右から出る画面 */
.drawer-back { position: fixed; inset: 0; background: rgba(16, 28, 40, .32); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(880px, 100%); background: var(--panel); z-index: 31; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.drawer header { padding: 16px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.drawer header h2 { margin: 0; font-size: 18px; }
.drawer .body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.drawer .body h2 { margin-top: 8px; }
.drawer footer { padding: 12px 24px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: var(--head); }
.kv { display: grid; grid-template-columns: 128px 1fr; gap: 8px 16px; margin: 0 0 16px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }

.error { background: var(--danger-soft); color: var(--danger); border-left: 4px solid var(--danger); border-radius: var(--r-sm); padding: 10px 14px; margin-bottom: 16px; font-weight: 600; }
.error ul { margin: 6px 0 0; padding-left: 20px; font-weight: 400; }
.notice { background: var(--warn-soft); color: var(--warn); border-left: 4px solid #C98A00; border-radius: var(--r-sm); padding: 10px 14px; margin-bottom: 16px; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1C2730; color: #fff; padding: 10px 20px; border-radius: var(--r-sm); opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; box-shadow: var(--shadow); }
#toast.show { opacity: 1; }

/* ログイン */
.auth { min-height: 100vh; display: grid; place-content: center; justify-items: center; padding: 24px; }
.auth .card { width: min(440px, 100%); padding: 32px; }
.auth-logo { display: block; width: 180px; height: auto; margin-bottom: 24px; }
.auth h1 { margin-bottom: 4px; }
.auth .field { margin-top: 16px; }
.auth .btn { width: 100%; margin-top: 24px; min-height: 42px; }

/* グラフ（月別） */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 72px 1fr 220px; gap: 12px; align-items: center; font-size: 13px; }
.bar { height: 14px; border-radius: 3px; background: var(--accent); min-width: 2px; }
.bar.sub { background: #7FA9A5; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* 帳票の印刷用 */
.print-page { background: #fff; width: 210mm; min-height: 297mm; margin: 0 auto 24px; padding: 16mm 15mm; color: #000; font-size: 12px; box-shadow: var(--shadow); }
.print-toolbar { display: flex; gap: 12px; justify-content: center; align-items: center; padding: 16px; }
.pp-title { text-align: center; font-size: 24px; letter-spacing: .3em; margin: 0 0 16px; }
.pp-head { display: flex; justify-content: space-between; gap: 20px; }
.pp-to { font-size: 16px; border-bottom: 1px solid #000; padding-bottom: 4px; min-width: 60%; }
.pp-from { text-align: right; font-size: 12px; }
.pp-total { margin: 16px 0; font-size: 16px; border: 1px solid #000; display: inline-block; padding: 6px 16px; }
.pp-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.pp-table th, .pp-table td { border: 1px solid #000; padding: 4px 6px; }
.pp-table th { background: #EEE; }
.pp-sum { width: 300px; margin-left: auto; margin-top: 8px; border-collapse: collapse; }
.pp-sum td { border: 1px solid #000; padding: 3px 6px; }
@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-page { width: auto; min-height: auto; margin: 0; padding: 0; box-shadow: none; }
  @page { size: A4; margin: 14mm; }
}

.menu-toggle { display: none; }
.nav-pw { display: none !important; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; align-content: start; }
  .appbar { position: static; height: auto; min-height: var(--appbar-h); flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .appbar-brand img { height: 28px; }
  .appbar-user { display: contents; }
  .appbar-brand { margin-right: auto; }
  .pw-btn, .guide-btn { display: none !important; }
  .side.open .nav-pw { display: flex !important; }
  .appbar .search { order: 4; flex: 1 1 100%; margin: 4px 0 0; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 20px; }
  .hareas { grid-template-columns: 1fr; }
  .who { order: 3; flex-basis: 100%; flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 8px; margin: 0; }
  .who span { max-width: 100%; }
  .side { position: static; height: auto; padding-bottom: 12px; display: block; }
  .side .credit { display: none; }
  .menu-toggle { display: inline-flex; margin-bottom: 4px; }
  .side .nav { display: none; }
  .side.open .nav { display: block; }
  .main { padding: 16px; }
  .form { grid-template-columns: 1fr; }
  .totals { width: 100%; }
  .kv { grid-template-columns: 96px 1fr; }
  table.list td, table.list th { white-space: nowrap; }
  .filters label.inline input { width: 100%; }
  .bar-row { grid-template-columns: 60px 1fr; }
  .bar-row > :last-child { grid-column: 1 / -1; text-align: left; }
}

/* 狭い画面：表や日付の欄が引き出しの外にはみ出さない（表は横にスクロール） */
.form > *, .field { min-width: 0; }
input[type=date], select { max-width: 100%; min-width: 0; }
.filters select { max-width: 100%; }
