:root {
  --canvas: #f5f7fa;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-selected: #eef3ff;
  --ink-strong: #101828;
  --ink: #243044;
  --muted: #5f6c7b;
  --line: #dfe5ec;
  --line-strong: #c9d2dd;
  --primary: #315bea;
  --primary-hover: #2549c9;
  --primary-soft: #eaf0ff;
  --success: #087a55;
  --success-soft: #e8f7f1;
  --warning: #9a5a00;
  --warning-soft: #fff5df;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --focus: #93b4ff;
  --shadow-popover: 0 8px 28px rgba(16, 24, 40, .16);
  --shadow-drawer: -10px 0 30px rgba(16, 24, 40, .14);
  --ease-out: cubic-bezier(.23, 1, .32, 1);
}

html { color-scheme: light; }
body {
  min-width: 320px;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { touch-action: manipulation; }
.skip-link {
  position: fixed;
  inset: 8px auto auto 8px;
  z-index: 100;
  transform: translateY(-150%);
  padding: 9px 13px;
  border-radius: 7px;
  background: var(--ink-strong);
  color: #fff;
}
.skip-link:focus { transform: translateY(0); }

header.appbar {
  display: grid;
  grid-template-columns: auto minmax(150px, 220px) auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 24px;
  background: rgba(255, 255, 255, .97);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: block;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
}
header.appbar h1 { margin: 0; color: var(--ink-strong); font-size: 15px; line-height: 1.15; letter-spacing: -.01em; }
header.appbar h1 span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 500; }
select, input[type=text], input[type=date], input[type=number], input[type=search], input[type=file] {
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
select:hover, input:hover { border-color: #aeb9c6; }
select:focus-visible, input:focus-visible, button:focus-visible, summary:focus-visible, .task-row:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-color: var(--primary);
}
.project-select { width: 100%; min-width: 0; max-width: none; font-weight: 600; }
.workspace-tabs {
  display: inline-flex;
  align-items: center;
  width: max-content;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-subtle);
}
.workspace-tab {
  min-height: 32px;
  padding: 5px 13px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
}
.workspace-tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink-strong);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}
.workspace-tab:disabled { cursor: not-allowed; opacity: .42; }
.header-context { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; margin-left: 0; }
.badge {
  display: block;
  min-width: 0;
  max-width: 330px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge::before { content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 7px 1px 0; border-radius: 50%; background: #98a2b3; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  transition: transform 140ms var(--ease-out), border-color 140ms ease, background-color 140ms ease, color 140ms ease;
}
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.btn:hover { border-color: #9cacbe; color: var(--ink-strong); background: var(--surface-subtle); }
.btn:active { transform: scale(.97); }
.btn:disabled { cursor: not-allowed; opacity: .45; }
.btn.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.btn.primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); color: #fff; opacity: 1; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: #f0b3ad; background: var(--danger-soft); color: var(--danger); }

main#mainContent { max-width: 1440px; margin: 0 auto; padding: 22px 24px 64px; }
.view-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 0 0 16px; }
.view-heading h2 { margin: 0; color: var(--ink-strong); font-size: 21px; line-height: 1.2; letter-spacing: -.025em; text-wrap: balance; }
.view-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.view-meta { color: var(--muted); font: 500 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.card {
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: none;
}
.card h3 { margin: 0 0 12px; color: var(--ink-strong); font-size: 14px; letter-spacing: -.01em; }
.card h3 small { color: var(--muted); font-weight: 450; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: start; gap: 14px; margin-bottom: 18px; }
.metric-group { position: relative; min-width: 0; }
.metric-group-head { min-height: 61px; padding: 0 2px 9px; }
.metric-group-head h3 { margin: 0; color: var(--ink-strong); font-size: 14px; line-height: 1.3; letter-spacing: -.01em; }
.metric-group-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.35; text-wrap: pretty; }
.metric-stack { overflow: visible; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.kpi {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  min-height: 67px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.kpi:last-child { border-bottom: 0; }
.kpi:first-child { border-radius: 11px 11px 0 0; }
.kpi:last-child { border-radius: 0 0 11px 11px; }
.kpi.primary { min-height: 84px; background: var(--surface-subtle); }
.kpi .lbl { min-width: 0; color: var(--muted); font-size: 11px; letter-spacing: 0; }
.kpi-title { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.kpi .lbl b { color: var(--ink); font-size: 12px; line-height: 1.3; }
.kpi-code { position: relative; padding: 1px 5px; border-radius: 4px; background: var(--primary-soft); color: #2949b8; cursor: help; font: 650 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.kpi-code::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 30;
  bottom: calc(100% + 8px);
  left: 0;
  width: max-content;
  max-width: min(270px, calc(100vw - 32px));
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--ink-strong);
  color: #fff;
  box-shadow: 0 4px 10px rgba(16, 24, 40, .18);
  font: 500 12px/1.5 Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  white-space: normal;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms var(--ease-out);
}
.metric-group:last-child .kpi-code::after { right: 0; left: auto; }
.kpi-code:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.kpi-code:focus::after { opacity: 1; transform: translateY(0); }
@media (hover: hover) and (pointer: fine) {
  .kpi-code:hover::after { opacity: 1; transform: translateY(0); }
}
.kpi-sub { display: block; margin-top: 3px; font-size: 12px; line-height: 1.35; }
.kpi-reading { flex: 0 0 auto; min-width: 64px; text-align: right; }
.kpi .val { margin: 0; color: var(--ink-strong); font: 650 17px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: -.035em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi.primary .val { font-size: 22px; }
.kpi .val small { color: var(--muted); font: 500 11px/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: 0; }
.kpi-state { display: inline-block; margin-top: 5px; padding: 2px 6px; border-radius: 5px; background: var(--surface); color: var(--muted); font-size: 10.5px; font-weight: 650; white-space: nowrap; }
.kpi.good .val { color: var(--success); }
.kpi.warn .val { color: var(--warning); }
.kpi.bad .val { color: var(--danger); }
.kpi.good .kpi-state { background: var(--success-soft); color: var(--success); }
.kpi.warn .kpi-state { background: var(--warning-soft); color: #7a4700; }
.kpi.bad .kpi-state { background: var(--danger-soft); color: var(--danger); }

.charts { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(320px, .9fr); gap: 14px; margin-bottom: 14px; }
.chartbox { position: relative; height: 320px; }
.note { color: var(--muted); font-size: 12px; line-height: 1.45; }
.quality-wrap { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.quality-label { flex: 0 0 auto; padding-top: 5px; color: var(--muted); font-size: 12px; font-weight: 650; }
.quality { display: flex; flex-wrap: wrap; gap: 7px; margin: 0; }
.chip { padding: 4px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--muted); font-size: 11.5px; }
.chip b { color: var(--ink); }
.chip.warn { border-color: #efd6a3; background: var(--warning-soft); color: #7a4700; }
.chip.warn b { color: #7a4700; }

.tasks-card { padding: 0; overflow: hidden; }
.tablebar { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; padding: 14px 16px; margin: 0; border-bottom: 1px solid var(--line); }
.tablebar h3 { margin: 0 auto 0 0; }
.tablebar label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.tablebar input[type=search] { min-width: 220px; }
.viewtoggle { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-subtle); overflow: visible; }
.viewtoggle button { min-height: 30px; padding: 4px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 600; }
.viewtoggle button.active { background: var(--surface); color: var(--ink-strong); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
.tablewrap { max-height: 560px; overflow: auto; border: 0; border-radius: 0; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: 12px; }
th, td { padding: 8px 10px; border-bottom: 1px solid #e9edf2; text-align: left; }
td.num, th.num { text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
thead th { top: 0; z-index: 2; background: var(--surface-subtle); color: var(--muted); font-size: 10.5px; font-weight: 650; letter-spacing: .02em; }
tbody tr { transition: background-color 120ms ease; }
tbody tr:hover { background: #f6f8fc; }
tbody tr:has(.task-link:focus-visible) { background: var(--surface-selected); }
tr.excluded { opacity: .52; }
td.title { max-width: 330px; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
td.overdue { color: var(--danger); font-weight: 650; }
.task-link { padding: 0; border: 0; background: transparent; color: var(--primary); cursor: pointer; font: 650 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.task-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.pill { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 5px; background: var(--primary-soft); color: #2949b8; font-size: 10.5px; font-weight: 650; }
#ganttWrap { max-height: 560px; border: 0; border-radius: 0; }

.snapshot-layout { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 14px; }
.snapshots-workspace.no-project .snapshot-layout { max-width: 600px; }
.workspace-intro { max-width: 600px; margin: 54px auto 20px; }
.workspace-intro h2 { color: var(--ink-strong); font-size: 22px; letter-spacing: -.025em; }
.workspace-intro p { max-width: 62ch; margin-inline: auto; }
.snapshot-layout form, .frm { gap: 11px; }
.snapshot-layout form > label, .frm label { color: var(--ink); font-size: 12px; font-weight: 600; }
.snapshot-layout form > label input, .frm label input { font-weight: 400; }
.snap-list li { min-height: 44px; padding: 8px 2px; }
.snap-list li b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.del { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px; }
.del:hover { background: var(--danger-soft); }

.settings-popover {
  inset: 70px 20px auto auto;
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 86px);
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-popover);
}
.popover-head { padding: 15px 17px 12px; }
.popover-head h2 { color: var(--ink-strong); font-size: 15px; }
.popover-close, .drawer-close { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.popover-close:hover, .drawer-close:hover { background: var(--surface-subtle); color: var(--ink-strong); }
.popover-close svg, .drawer-close svg { width: 18px; height: 18px; }
.settings-popover .frm { padding: 14px 17px 17px; }
.settings-table { white-space: normal; }
.settings-table input[type=number] { min-height: 34px; }
details { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
details:last-of-type { border-bottom: 0; }
details summary { color: var(--ink-strong); }

.task-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(620px, 100vw);
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-drawer);
}
.task-drawer::backdrop { background: rgba(16, 24, 40, .38); }
.task-drawer[open] { display: flex; flex-direction: column; }
.drawer-header { display: flex; align-items: flex-start; gap: 14px; padding: 18px 20px 16px; border-bottom: 1px solid var(--line); }
.drawer-heading { min-width: 0; flex: 1; }
.drawer-key { margin: 0 0 4px; color: var(--primary); font: 650 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.drawer-heading h2 { margin: 0; color: var(--ink-strong); font-size: 20px; line-height: 1.3; letter-spacing: -.02em; overflow-wrap: anywhere; }
.drawer-subline { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 9px; color: var(--muted); font-size: 12px; }
.drawer-body { flex: 1; overflow: auto; padding: 18px 20px 36px; }
.detail-progress { margin-bottom: 18px; padding: 13px 14px; border-radius: 9px; background: var(--surface-subtle); }
.detail-progress-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.detail-progress-head strong { color: var(--ink-strong); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.progress-track { height: 7px; overflow: hidden; border-radius: 99px; background: #e3e8ef; }
.progress-bar { height: 100%; border-radius: inherit; background: var(--primary); }
.detail-section { padding: 16px 0; border-bottom: 1px solid var(--line); }
.detail-section:first-child { padding-top: 0; }
.detail-section:last-child { border-bottom: 0; }
.detail-section h3 { margin: 0 0 10px; color: var(--ink-strong); font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 18px; }
.detail-field { min-width: 0; }
.detail-field dt { margin: 0 0 2px; color: var(--muted); font-size: 10.5px; font-weight: 650; }
.detail-field dd { margin: 0; color: var(--ink); font-size: 13px; overflow-wrap: anywhere; }
.detail-copy { margin: 0; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; }
.detail-empty { color: var(--muted); font-style: italic; }
.detail-warning { padding: 10px 12px; border-radius: 8px; background: var(--warning-soft); color: #744300; font-size: 12px; }
.detail-loading { display: grid; gap: 10px; }
.skeleton { height: 14px; border-radius: 5px; background: #e9edf2; }
.skeleton:nth-child(2) { width: 78%; }
.skeleton:nth-child(3) { width: 58%; }
.detail-error { padding: 14px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); }

#toast { z-index: 60; max-width: min(520px, calc(100vw - 24px)); border-radius: 8px; background: var(--ink-strong); box-shadow: 0 4px 12px rgba(16,24,40,.18); }
#toast.ok { background: var(--success); }

@media (max-width: 1160px) {
  header.appbar { grid-template-columns: auto minmax(140px, 1fr) auto auto; }
  .badge { grid-column: 2 / -1; grid-row: 2; max-width: none; }
  .header-context { grid-column: 4; grid-row: 1; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .charts { grid-template-columns: 1fr; }
  .chartbox { height: 300px; }
  .snapshot-layout { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  header.appbar { grid-template-columns: minmax(0, 1fr) auto; gap: 9px; padding: 10px 12px; }
  .brand-lockup { grid-column: 1; grid-row: 1; }
  .brand-mark { width: 30px; height: 30px; flex-basis: 30px; }
  .workspace-tabs { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .workspace-tab { flex: 1; min-height: 38px; }
  .project-select { grid-column: 1; grid-row: 3; min-height: 44px; }
  .header-context { grid-column: 2; grid-row: 3; }
  #milestoneSel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .badge { grid-column: 1 / -1; grid-row: 4; font-size: 11.5px; }
  main#mainContent { padding: 16px 12px 48px; }
  .view-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .kpis { grid-template-columns: 1fr; gap: 16px; }
  .metric-group-head { min-height: 0; }
  .kpi { min-height: 64px; }
  .kpi.primary { min-height: 78px; }
  .kpi-code::after,
  .metric-group:last-child .kpi-code::after {
    position: fixed;
    inset: auto 16px 16px;
    width: auto;
    max-width: none;
    transform: translateY(4px);
  }
  .quality-wrap { flex-direction: column; gap: 6px; }
  .tablebar input[type=search] { order: 5; width: 100%; min-width: 0; min-height: 44px; }
  .tablebar select { min-height: 44px; }
  .settings-popover { inset: 64px 10px auto 10px; width: auto; max-height: calc(100dvh - 74px); }
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  header.appbar h1 span { display: none; }
  header.appbar .badge { display: none; }
  .header-context .btn { min-width: 44px; padding: 7px 10px; }
  .kpi .val { font-size: 17px; }
  .chartbox { height: 270px; }
  .card { padding: 15px 14px; }
  .tasks-card { padding: 0; }
  .task-drawer { width: 100vw; }
  .drawer-header, .drawer-body { padding-inline: 16px; }
}
@media (max-width: 360px) {
  .header-context .btn .btn-label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
