/* ==========================================================================
   予実管理システム — 画面スタイル
   方針：Excelの予実表に慣れた人が迷わない「帳票の延長」。
   数字は等幅・右揃え、マイナスは △、差異は良/悪の2色、変更セルは黄色。
   ========================================================================== */

:root {
  --ink: #1f2933;
  --ink-soft: #3e4c59;
  --muted: #6b7783;
  --paper: #f3f5f4;
  --panel: #ffffff;
  --rule: #d9dfdc;
  --rule-strong: #b9c3bf;
  --head: #e9eeec;

  --primary: #24427a;        /* 操作・実績 */
  --primary-ink: #ffffff;
  --primary-soft: #e6ebf4;
  --budget: #8a94a6;         /* 予算 */
  --good: #13795b;
  --good-soft: #e3f2ec;
  --bad: #b42318;
  --bad-soft: #fbe9e7;
  --changed: #fff2b8;        /* 変更セル（Excel運用の黄色ハイライトを踏襲） */
  --locked: #eceeed;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --focus: #2f6fdf;

  --font: 'BIZ UDPGothic', 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', sans-serif;
  --font-num: 'BIZ UDPGothic', 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', sans-serif;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 6px;
  --sidebar: 232px;
}

* { box-sizing: border-box; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  font-feature-settings: 'palt' 0;
}
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
h1, h2, h3 { line-height: 1.35; margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: .02em; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0 0 var(--s3); }
.num, td.num, th.num { font-family: var(--font-num); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.is-good { color: var(--good); }
.is-bad { color: var(--bad); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 骨格 ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s5);
  height: 52px;
  background: var(--primary); color: var(--primary-ink);
}
.brand { display: flex; align-items: baseline; gap: var(--s3); color: inherit; text-decoration: none; }
.brand-name { font-weight: 700; font-size: 1.08rem; letter-spacing: .06em; }
.brand-co { font-size: .86rem; opacity: .8; }
.topbar .spacer { flex: 1; }
.who { font-size: .9rem; text-align: right; line-height: 1.3; }
.who .role { display: block; font-size: .78rem; opacity: .8; }
.topbar form { margin: 0; }
.btn-ghost-light {
  border: 1px solid rgba(255,255,255,.5); background: transparent; color: #fff;
  padding: 5px 12px; border-radius: var(--radius); font: inherit; font-size: .86rem; cursor: pointer;
}
.btn-ghost-light:hover { background: rgba(255,255,255,.12); }

.sidebar { background: var(--panel); border-right: 1px solid var(--rule); padding: var(--s4) 0; overflow-y: auto; }
.nav-group { margin-bottom: var(--s4); }
.nav-title { font-size: .8rem; color: var(--muted); padding: 0 var(--s4); margin: 0 0 var(--s1); }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 6px var(--s4); color: var(--ink); text-decoration: none; border-left: 3px solid transparent; }
.nav a:hover { background: var(--paper); }
.nav a.is-active { border-left-color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.nav .dept { padding: 4px var(--s4) 4px var(--s4); }
.nav .dept-name { display: block; font-size: .95rem; }
.nav .dept-links { display: flex; gap: var(--s3); font-size: .84rem; }
.nav .dept-links a { display: inline; padding: 0; border: 0; color: var(--primary); }
.nav .dept-links a.is-active { background: none; text-decoration: underline; text-decoration-thickness: 2px; }
.nav .disabled { color: var(--muted); padding: 6px var(--s4); display: block; font-size: .92rem; }

.main { padding: var(--s5) var(--s6) var(--s7); min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s4); }
.page-head .sub { color: var(--muted); margin-top: var(--s1); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }

/* ---------- 月リボン（年度12か月の状況） ---------- */
.ribbon {
  display: grid; grid-template-columns: auto repeat(12, minmax(52px, 1fr));
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  background: var(--panel); margin-bottom: var(--s5); overflow: hidden;
}
.ribbon .fy { display: flex; flex-direction: column; justify-content: center; padding: 6px var(--s3); background: var(--head); border-right: 1px solid var(--rule-strong); font-weight: 700; white-space: nowrap; }
.ribbon .fy small { font-weight: 400; color: var(--muted); font-size: .76rem; }
.ribbon a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 6px 2px 7px; text-decoration: none; color: var(--ink);
  border-right: 1px solid var(--rule);
}
.ribbon a:nth-of-type(3n) { border-right-color: var(--rule-strong); } /* 四半期の区切り */
.ribbon a:last-child { border-right: 0; }
.ribbon .m { font-family: var(--font-num); font-weight: 700; font-size: 1.02rem; line-height: 1.2; }
.ribbon .st { font-size: .72rem; color: var(--muted); line-height: 1.2; }
.ribbon a.is-closed { background: var(--locked); }
.ribbon a.is-closed .st { color: var(--ink-soft); }
.ribbon a.is-open .st { color: var(--warn); font-weight: 700; }
.ribbon a.is-current { background: var(--primary); color: #fff; }
.ribbon a.is-current .st { color: #fff; opacity: .9; }
.ribbon a:hover:not(.is-current) { background: var(--primary-soft); }

/* ---------- パネル・カード ---------- */
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: var(--s5); }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--rule); }
.panel-body { padding: var(--s4); }
.panel-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--rule); }

/* マイページ：当月の合計（1か所だけ大きく見せる） */
.headline { display: grid; grid-template-columns: 1.3fr 1fr 1fr; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel); margin-bottom: var(--s5); }
.headline > div { padding: var(--s4) var(--s5); }
.headline > div + div { border-left: 1px solid var(--rule); }
.headline .label { color: var(--muted); font-size: .9rem; }
.headline .big { font-family: var(--font-num); font-size: 2.2rem; font-weight: 700; line-height: 1.15; letter-spacing: -.01em; }
.headline .big small { font-size: .9rem; font-weight: 400; color: var(--muted); margin-left: 4px; }
.headline .pair { display: flex; gap: var(--s4); margin-top: var(--s2); font-size: .92rem; }
.headline .pair span { white-space: nowrap; }
.bar { display: block; width: 100%; height: 8px; margin-top: var(--s3); }
.bar .track { fill: var(--head); }
.bar .fill { fill: var(--primary); }
.bar.over .fill { fill: var(--good); }
.headline .big.mid { font-size: 1.6rem; }
.progress-note { font-size: .84rem; color: var(--warn); margin: var(--s2) 0 0; }
table.grid.compact { font-size: .86rem; }
table.grid.compact th, table.grid.compact td { padding: 6px 7px; }
.left { text-align: left !important; }
.nowrap { white-space: nowrap; }

/* ---------- 表 ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .93rem; }
table.grid th, table.grid td { padding: 6px 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
table.grid thead th { background: var(--head); font-weight: 700; text-align: center; white-space: nowrap; border-bottom: 1px solid var(--rule-strong); position: sticky; top: 0; z-index: 2; }
table.grid thead tr:nth-child(2) th { top: 33px; }
table.grid tbody tr:hover td { background: #fafbfb; }
table.grid tfoot td, table.grid tr.total td, table.grid tr.total th { font-weight: 700; background: var(--primary-soft); border-top: 2px solid var(--primary); }
table.grid .sep-l { border-left: 1px solid var(--rule-strong); }
table.grid th.row-head { text-align: left; font-weight: 700; white-space: nowrap; background: var(--panel); }
table.grid .kind-b { color: var(--ink-soft); }
table.grid tr.sub td, table.grid tr.sub th { color: var(--muted); font-size: .86rem; }
table.grid tr.block-start td, table.grid tr.block-start th { border-top: 1px solid var(--rule-strong); }
table.grid td.is-future { color: var(--muted); }
table.grid .col-current { background: var(--primary-soft) !important; }

.tag { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: .78rem; line-height: 1.7; border: 1px solid var(--rule-strong); color: var(--ink-soft); background: var(--panel); white-space: nowrap; }
.tag.new { border-color: #7aa7e0; color: #1f4f91; background: #eef4fc; }
.tag.g { border-color: #b8a6d9; color: #50348a; background: #f4f0fa; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: .88rem; white-space: nowrap; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--budget); }
.status.ok::before { background: var(--good); }
.status.todo::before { background: var(--warn); }
.status.lock::before { background: var(--ink-soft); border-radius: 1px; }

/* ---------- 入力グリッド ---------- */
.input-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s5); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--rule); background: var(--panel); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s4); font-size: .84rem; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--rule-strong); border-radius: 2px; }
.legend .l-changed { background: var(--changed); }
.legend .l-locked { background: var(--locked); }
.legend .l-reason { background: var(--warn-soft); border-color: #e2b46b; }

.sheet-wrap { overflow: auto; max-height: calc(100vh - 290px); min-height: 360px; border-top: 0; }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: .9rem; }
table.sheet th, table.sheet td { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 0; height: 32px; background: var(--panel); }
table.sheet thead th { position: sticky; z-index: 3; background: var(--head); font-weight: 700; white-space: nowrap; padding: 4px 8px; text-align: center; }
table.sheet thead tr:nth-child(1) th { top: 0; height: 30px; }
table.sheet thead tr:nth-child(2) th { top: 30px; height: 30px; font-size: .82rem; }
table.sheet thead th.grp-budget { background: #e7e9ee; }
table.sheet thead th.grp-actual { background: #dfe6f3; }
table.sheet thead th.grp-diff { background: #e3ebe7; }
table.sheet .sticky-1, table.sheet .sticky-2 { position: sticky; z-index: 2; }
table.sheet .sticky-1 { left: 0; width: 64px; min-width: 64px; }
table.sheet .sticky-2 { left: 64px; width: 260px; min-width: 260px; border-right: 2px solid var(--rule-strong); }
table.sheet thead .sticky-1, table.sheet thead .sticky-2 { z-index: 4; }
table.sheet td.code { padding: 0 8px; font-family: var(--font-num); color: var(--muted); font-size: .84rem; }
table.sheet td.pname { padding: 3px 8px; line-height: 1.3; }
table.sheet td.pname .n { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 244px; }
table.sheet td.pname .c { display: block; font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 244px; }
table.sheet td.calc { padding: 0 8px; font-family: var(--font-num); text-align: right; white-space: nowrap; background: #fafbfb; min-width: 92px; }
table.sheet td.calc.gp { font-weight: 700; }
table.sheet td.grp-start, table.sheet th.grp-start { border-left: 2px solid var(--rule-strong); }
table.sheet input.cell {
  width: 100%; min-width: 96px; height: 31px; border: 0; margin: 0; padding: 0 8px;
  font-family: var(--font-num); font-size: .92rem; text-align: right; background: transparent; color: var(--ink);
}
table.sheet input.cell:focus { outline: 2px solid var(--focus); outline-offset: -2px; background: #fff; }
table.sheet input.cell[readonly] { color: var(--ink-soft); cursor: default; }
table.sheet td.ro { background: var(--locked); }
table.sheet td.is-changed, table.sheet td.is-changed input { background: var(--changed); }
table.sheet td.note { min-width: 260px; }
table.sheet td.note input.cell { text-align: left; font-family: var(--font); min-width: 260px; }
table.sheet td.need-reason, table.sheet td.need-reason input { background: var(--warn-soft); }
table.sheet tr.total td { background: var(--primary-soft); font-weight: 700; position: sticky; top: 60px; z-index: 2; border-bottom: 2px solid var(--primary); }
table.sheet tr.total td.sticky-1, table.sheet tr.total td.sticky-2 { z-index: 3; }
table.sheet tr.is-focus td { box-shadow: inset 0 2px 0 var(--focus), inset 0 -2px 0 var(--focus); }
table.sheet input.cell.is-invalid { color: var(--bad); font-weight: 700; }

.savebar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s4); background: var(--panel); border-top: 1px solid var(--rule-strong);
}
.savebar .count { font-weight: 700; }
.savebar .count.zero { font-weight: 400; color: var(--muted); }

/* ---------- フォーム・ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 16px; border-radius: var(--radius);
  font: inherit; font-weight: 700; font-size: .95rem; text-decoration: none; cursor: pointer;
  border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink);
}
.btn:hover { filter: brightness(1.08); }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--panel); color: var(--primary); }
.btn.secondary:hover { background: var(--primary-soft); filter: none; }
.btn.danger { background: var(--panel); color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 30px; padding: 0 10px; font-size: .86rem; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.seg a { padding: 5px 12px; text-decoration: none; color: var(--ink); font-size: .88rem; }
.seg a + a { border-left: 1px solid var(--rule-strong); }
.seg a.is-on { background: var(--ink-soft); color: #fff; font-weight: 700; }

label { font-weight: 700; display: block; margin-bottom: var(--s1); }
input[type=text], input[type=email], input[type=password], input[type=number], select {
  width: 100%; height: 40px; padding: 0 var(--s3); font: inherit; color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: var(--radius); background: #fff;
}
input:focus, select:focus { outline: 3px solid rgba(47,111,223,.35); border-color: var(--focus); }
.field { margin-bottom: var(--s4); }
.field .hint { font-size: .84rem; color: var(--muted); margin-top: var(--s1); }
.field-error { color: var(--bad); font-size: .88rem; margin-top: var(--s1); }
.form-row { display: grid; grid-template-columns: 2fr 1.4fr 1fr .8fr auto; gap: var(--s3); align-items: end; }
.form-row .field { margin: 0; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; cursor: pointer; }

.flash { padding: var(--s3) var(--s4); border-radius: var(--radius); margin-bottom: var(--s4); border: 1px solid; }
.flash.ok { background: var(--good-soft); border-color: #9cd3bd; color: #0b5a43; }
.flash.err { background: var(--bad-soft); border-color: #f0b4ad; color: #8a1a12; }
.flash.lock { background: var(--locked); border-color: var(--rule-strong); color: var(--ink-soft); }
.flash ul { margin: var(--s1) 0 0; padding-left: 1.2em; }

details.add-project > summary { cursor: pointer; font-weight: 700; color: var(--primary); list-style: none; }
details.add-project > summary::-webkit-details-marker { display: none; }
details.add-project > summary::before { content: '＋ '; }
details.add-project[open] > summary::before { content: '－ '; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--s5); align-items: start; }
.two-col > * { min-width: 0; }
.panel-note { margin: 0; padding: var(--s2) var(--s4); font-size: .86rem; color: var(--warn); background: var(--warn-soft); border-bottom: 1px solid var(--rule); }
.chart-box { position: relative; height: 260px; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { padding: var(--s2) 0; border-bottom: 1px solid var(--rule); font-size: .9rem; }
.activity li:last-child { border-bottom: 0; }
.activity time { color: var(--muted); font-family: var(--font-num); font-size: .84rem; margin-right: var(--s2); }
.empty { padding: var(--s6) var(--s4); text-align: center; color: var(--muted); }

/* ---------- ログイン ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-side {
  background: var(--primary); color: #fff; padding: var(--s7);
  display: flex; flex-direction: column; justify-content: space-between;
}
.login-side .sys { font-size: 2.4rem; font-weight: 700; letter-spacing: .08em; line-height: 1.3; }
.login-side .grp { opacity: .85; margin-top: var(--s3); }
.login-side .mini-ribbon { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; max-width: 520px; }
.login-side .mini-ribbon span { height: 46px; border-radius: 3px; background: rgba(255,255,255,.14); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; font-family: var(--font-num); font-size: .78rem; }
.login-side .mini-ribbon span.on { background: rgba(255,255,255,.34); }
.login-side .note { font-size: .84rem; opacity: .75; }
.login-main { display: flex; align-items: center; justify-content: center; padding: var(--s6); background: var(--panel); }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin-bottom: var(--s2); }
.login-card .lead { color: var(--muted); margin-bottom: var(--s5); }
.login-card .btn { width: 100%; min-height: 44px; margin-top: var(--s2); }
.demo-accounts { margin-top: var(--s5); font-size: .84rem; color: var(--muted); border-top: 1px solid var(--rule); padding-top: var(--s3); }
.demo-accounts table { width: 100%; border-collapse: collapse; }
.demo-accounts td { padding: 2px 0; }

/* ---------- レスポンシブ ---------- */
@media (max-width: 1100px) {
  .two-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--rule); padding: var(--s2) 0; max-height: 220px; }
  .main { padding: var(--s4); }
  .headline { grid-template-columns: 1fr; }
  .headline > div + div { border-left: 0; border-top: 1px solid var(--rule); }
  .ribbon { grid-template-columns: repeat(6, 1fr); }
  .ribbon .fy { grid-column: 1 / -1; border-right: 0; border-bottom: 1px solid var(--rule-strong); flex-direction: row; gap: var(--s2); }
  .login-page { grid-template-columns: 1fr; }
  .login-side { padding: var(--s5); }
  .login-side .mini-ribbon, .login-side .note { display: none; }
  .who .role { display: none; }
  .brand-co { display: none; }
  .topbar { padding: 0 var(--s4); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print {
  .sidebar, .topbar, .savebar, .page-actions, .ribbon { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .sheet-wrap { max-height: none; overflow: visible; }
}
.error-page { min-height: 100vh; }
.reason { min-width: 200px; }
