:root {
  --bg: #f7f8fa;
  --paper: #ffffff;
  --paper-2: #e6f4f3;
  --ink: #1c2321;
  --muted: #6b7280;
  --line: #e2e4e9;
  --primary: #00645f;
  --primary-d: #004d49;
  --primary-l: #e6f4f3;
  --primary-2: #0a8175;
  --accent: #cc4055;
  --yellow: #FEDC5B;
  --yellow-d: #D4AE2C;
  --orange: #F97316;
  --green: #2f7d46;
  --warn: #b4232b;
  --note: #4d6470;
  --shadow: 0 1px 2px rgba(26, 42, 38, 0.06);
  --shadow-soft: 0 8px 30px rgba(0, 100, 95, 0.08);
  --r: 10px;
  --r-lg: 16px;
  --r-pill: 9999px;
  --topbar-height: 58px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Zen Maru Gothic", "Yu Gothic UI", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  letter-spacing: 0.03em;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: var(--primary);
}

a.secondary-button,
a.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  text-decoration: none;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--topbar-height);
  padding: 8px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.topbar-icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 0 10px;
  background: var(--orange);
  color: #fff;
  border-radius: var(--r-pill);
  box-shadow: 0 2px 0 #c2570d;
}
.topbar-icon-button:hover {
  background: #ea6c10;
}

.sidebar-toggle-btn .icon-chevron-right { display: none; }
.sidebar-toggle-btn .icon-chevron-left  { display: block; }
.sidebar-toggle-btn[aria-expanded="false"] .icon-chevron-left  { display: none; }
.sidebar-toggle-btn[aria-expanded="false"] .icon-chevron-right { display: block; }

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-button svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.topbar-title {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.topbar-title strong {
  overflow: hidden;
  font-size: 17px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.topbar-catch {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
  font-weight: 400;
  white-space: nowrap;
}

.topbar-section-nav {
  display: flex;
  gap: 2px;
  margin-left: 10px;
}

.topbar-sec-link {
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.8125rem;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.topbar-sec-link:hover {
  background: var(--paper-2);
  color: var(--primary);
}

.topbar-note {
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-height));
  transition: grid-template-columns 200ms ease;
}

.app-shell:has(#input-sidebar.is-open) {
  grid-template-columns: clamp(320px, 50%, 720px) minmax(0, 1fr);
}

/* ── Input sidebar ── */
.input-sidebar {
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
  height: calc(100vh - var(--topbar-height));
  overflow: hidden;
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 52px;
}

.sidebar-overlay {
  display: none;
}

.sidebar-overlay[hidden] {
  display: none !important;
}

.sidebar-content {
  display: none;
  overflow-y: auto;
  padding: 20px 18px;
  min-width: 0;
}

.input-sidebar.is-open .sidebar-content {
  display: block;
}

.input-sidebar.is-open .sidebar-rail {
  display: none;
}

.sidebar-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 12px;
  border-left: 0;
  width: 52px;
}

.input-sidebar.is-open .sidebar-rail {
  display: none;
}

.rail-step {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  cursor: default;
}

/* ── Results main ── */
.results-main {
  padding: 28px;
  min-width: 0;
}

.activity-image span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.activity-image strong {
  color: var(--primary);
  font-size: 22px;
}

.eyebrow,
.section-kicker {
  margin: 20px 0 8px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: 34px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.3;
}

h3 {
  font-size: 19px;
  line-height: 1.4;
}

h4 {
  margin-bottom: 6px;
  font-size: 15px;
}

.lead {
  color: var(--muted);
}

.manual-block {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.manual-block h2 {
  margin-bottom: 10px;
  font-size: 18px;
}

.manual-block p,
.manual-block li {
  color: var(--muted);
  font-size: 14px;
}

.manual-block ul,
.manual-block ol {
  margin: 0;
  padding-left: 20px;
}

.workspace,
.results-main {
  padding: 28px;
}

.workspace-header,
.results-heading,
.plan-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.workspace-header .section-kicker,
.plan-header .section-kicker,
.results-heading .section-kicker {
  margin-top: 0;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: var(--r);
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s, transform 0.1s, box-shadow 0.1s;
}

.primary-button {
  padding: 0 20px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--r-pill);
  box-shadow: 0 3px 0 var(--primary-d);
}
.primary-button:hover {
  background: var(--primary-2);
  transform: translateY(1px);
  box-shadow: 0 2px 0 var(--primary-d);
}

.secondary-button {
  padding: 0 14px;
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--line);
  border-radius: var(--r-pill);
}
.secondary-button:hover {
  border-color: var(--primary);
  background: var(--primary-l);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(204, 64, 85, 0.35);
  outline-offset: 2px;
}

.safety-output {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.status-note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff8f0;
}

.status-note.high {
  border-color: #fca5a5;
  background: #fff5f5;
}

.status-note.medium {
  border-color: #fed7aa;
  background: #fff8f0;
}

.status-note.note {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.status-note-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  color: #d97706;
}

.status-note.high .status-note-icon { color: var(--warn); }
.status-note.note .status-note-icon { color: var(--green); }

.status-note-body {
  min-width: 0;
}

.status-note strong {
  display: block;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 700;
}

.status-note span {
  color: var(--muted);
  font-size: 0.875rem;
}

.case-form,
.summary-panel,
.results-panel,
.session-plan,
.ai-panel,
.ai-entry-panel {
  display: grid;
  gap: 16px;
  margin-bottom: 22px;
}

.form-panel,
.summary-panel,
.results-panel,
.session-plan,
.ai-panel,
.ai-entry-panel,
.ai-context-panel,
.ai-activity-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--paper);
  box-shadow: var(--shadow-soft);
}

.form-panel,
.summary-panel,
.results-panel,
.session-plan,
.ai-panel,
.ai-entry-panel,
.ai-context-panel,
.ai-activity-panel,
.recommendation-card,
.ai-play-card,
.ai-grid section,
.ai-section,
.ai-note,
.ai-tip,
.status-note,
.timeline li {
  box-shadow: none;
}

.ai-entry-panel {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.ai-entry-panel h2,
.ai-entry-panel p {
  margin-bottom: 0;
}

.premium-badge {
  display: none;
}

#sec-safety,
#sec-results,
#session-plan,
#sec-ai {
  scroll-margin-top: calc(var(--topbar-height) + 8px);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.panel-title span {
  min-width: 38px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--paper-2);
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.sidebar-content .field-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label > span,
.minor-heading {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.minor-heading {
  margin: 18px 0 8px;
}

select,
input[type="text"],
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.wide-field {
  display: block;
  margin-top: 14px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.option-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.option:has(input:checked) {
  border-color: rgba(0, 100, 95, 0.55);
  background: #edf7f4;
}

.option input {
  width: 18px;
  height: 18px;
  margin-top: 3px;
  accent-color: var(--primary);
}

.option span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.summary-list,
.card-details,
.plan-context {
  display: grid;
  gap: 8px;
  margin: 0;
}

.summary-list div,
.card-details div,
.plan-context div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd {
  margin: 0;
}

.result-count,
.plan-duration {
  padding: 7px 11px;
  border-radius: 8px;
  background: var(--paper-2);
  color: var(--primary);
  font-weight: 800;
}

.recommendation-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px dashed var(--primary-2);
  border-radius: 8px;
  background: #f6fbf9;
}

.empty-state span {
  color: var(--muted);
}

.recommendation-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: #fff;
  box-shadow: var(--shadow-soft);
  transition: box-shadow 0.15s, transform 0.15s;
}
.recommendation-card:hover {
  box-shadow: 0 12px 36px rgba(0, 100, 95, 0.12);
  transform: translateY(-2px);
}

.activity-image {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  overflow: hidden;
  height: 150px;
  border-radius: 8px;
  background: #f4f7f6;
  border: 1px solid #d8e3df;
}

.activity-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

/* ── child print view (hidden normally) ── */
#child-print-view {
  display: none;
}

.cpv-header {
  text-align: center;
  margin-bottom: 24px;
}

.cpv-sub {
  font-size: 1.1rem;
  color: var(--muted);
  margin: 0;
}

.cpv-grid {
  display: block;
}

.cpv-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 32px;
  box-sizing: border-box;
  text-align: center;
  break-before: page;
  page-break-before: always;
}

.cpv-card:first-child {
  break-before: avoid;
  page-break-before: avoid;
}

.cpv-img {
  width: min(70vw, 70vh);
  height: min(70vw, 70vh);
  overflow: hidden;
  background: var(--paper-2);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cpv-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cpv-img svg {
  width: 60%;
  height: 60%;
}

.cpv-title {
  font-size: 2rem;
  font-weight: 700;
  margin: 24px 0 0;
  line-height: 1.4;
}

/* ── lightbox ── */
#img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#img-lightbox[hidden] {
  display: none;
}

.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.80);
  cursor: zoom-out;
}

.lb-img {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.activity-image .image-fallback {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  height: 100%;
}

.activity-image:not(.is-missing) .image-fallback {
  display: none;
}

.card-topline {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.rank,
.fit {
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.rank {
  background: var(--ink);
  color: #fff;
}

.fit {
  background: #e4f3ef;
  color: var(--primary);
}

.recommendation-card h3 {
  margin-bottom: 0;
}

.recommendation-card p,
.card-details dd,
.detail-grid p,
.detail-grid li,
.timeline p {
  color: var(--muted);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-row span {
  padding: 4px 7px;
  border-radius: 8px;
  background: #f0f3f2;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.card-details {
  font-size: 14px;
}

.card-details div {
  grid-template-columns: 76px 1fr;
}

.card-caution {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #fff2f3;
  color: var(--warn);
  font-size: 14px;
}

details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 800;
}

/* カード詳細アコーディオン — 開いた時にカードとdetail-gridを全幅展開 */
.recommendation-list .recommendation-card:has(details[open]) {
  grid-column: 1 / -1;
}

.recommendation-card details summary {
  cursor: pointer;
  font-size: 0.875rem;
  color: #4b5563;
  padding: 6px 0;
  list-style: none;
  user-select: none;
}

.recommendation-card details summary::before {
  content: "▶ ";
  font-size: 0.7em;
}

.recommendation-card details[open] summary::before {
  content: "▼ ";
}

.recommendation-card details[open] .detail-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.detail-grid section {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: #f7f9f8;
}

.detail-grid ol,
.detail-grid ul,
.plan-safety ul {
  margin: 0;
  padding-left: 20px;
}

.plan-context {
  margin-bottom: 14px;
}

.plan-safety {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #e1c9ce;
  border-radius: 8px;
  background: #fff7f8;
}

.plan-safety strong {
  color: var(--warn);
}

.timeline {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: plan;
}

.timeline li {
  display: grid;
  grid-template-columns: 95px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.time {
  color: var(--primary);
  font-weight: 800;
}

.timeline h3 {
  margin-bottom: 4px;
}

.timeline-content {
  min-width: 0;
}

/* ── plan activity mini-card ── */
.plan-activity-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fafafa;
}

.pac-icon {
  flex-shrink: 0;
}

.pac-icon svg,
.pac-icon img {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
}

.pac-icon img.zoomable {
  cursor: pointer;
}

.pac-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pac-summary {
  margin: 0;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--ink);
}

.pac-body-text {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.pac-rationale {
  margin: 0;
  font-size: 0.75rem;
  color: #9ca3af;
  line-height: 1.5;
}

.ai-workbench {
  display: grid;
  grid-template-columns: minmax(220px, 30%) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.ai-workspace-page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.ai-premium-hero {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ai-premium-hero h1 {
  max-width: 760px;
  margin-bottom: 6px;
  font-size: 22px;
}

.ai-premium-hero p {
  max-width: 780px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.premium-note {
  display: none;
}

.project-name-field {
  display: grid;
  gap: 5px;
  max-width: 420px;
  margin-top: 14px;
}

.project-name-field span,
.history-search-field span,
.history-title-field span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.project-name-field input,
.history-search-field input,
.history-title-field input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.privacy-note {
  display: block;
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid rgba(178, 83, 58, 0.22);
  border-radius: 8px;
  background: #fff7ed;
  color: #8a3a1f;
  font-size: 0.82rem;
  line-height: 1.6;
}

.ai-instruction-field .privacy-note {
  margin: -2px 0 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #8a3a1f;
}

.ai-workspace-grid {
  display: grid;
  grid-template-columns: minmax(260px, 30%) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.ai-workspace-chat {
  min-height: calc(100vh - var(--topbar-height) - 48px);
}

.ai-workspace-preview {
  display: grid;
  gap: 16px;
  min-width: 0;
}

/* ── AI shell (ai.html) ── */
.ai-shell:has(#chat-sidebar.is-open) {
  grid-template-columns: clamp(320px, 50%, 720px) minmax(0, 1fr);
}

.ai-results-main {
  display: grid;
  gap: 16px;
  align-content: start;
}

.ai-chat-pane {
  position: sticky;
  top: calc(var(--topbar-height) + 16px);
}

.workspace-status {
  display: grid;
  gap: 8px;
}

.ai-side-actions {
  display: grid;
  gap: 8px;
}

.workspace-export-menu summary {
  display: block;
  text-align: center;
}

.ai-chat-pane {
  position: sticky;
  top: calc(var(--topbar-height) + 16px);
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
}

.ai-chat-history {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

.ai-chat-message {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ai-chat-message.user {
  border-color: rgba(0, 100, 95, 0.35);
  background: #eaf6f3;
}

.ai-chat-message.system {
  background: #f0f3f2;
}

.ai-chat-message strong {
  color: var(--primary);
  font-size: 13px;
}

.ai-chat-message p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.ai-instruction-field textarea {
  min-height: 136px;
}

.ai-preview-pane {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.ai-activity-stack {
  display: grid;
  gap: 14px;
}

.ai-play-card {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ai-play-card details {
  grid-column: 1 / -1;
}

.ai-play-card details .detail-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.ai-play-card details section {
  background: #fff;
  border: 1px solid var(--line);
}

.ai-play-card .activity-image {
  grid-row: span 1;
  width: 64px;
  height: 64px;
  min-height: unset;
  border-radius: 8px;
  align-self: start;
}

.ai-play-card h3,
.ai-play-card p {
  margin-bottom: 0;
}

.ai-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-card-actions button {
  min-height: 36px;
  padding: 0 10px;
  font-size: 14px;
}

.ai-placeholder {
  margin-bottom: 0;
  color: var(--muted);
}

.ai-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ai-grid section,
.ai-section,
.ai-note {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
}

.ai-grid h3,
.ai-section h3,
.ai-tip h4 {
  margin-bottom: 8px;
}

.ai-grid p,
.ai-grid li,
.ai-section p,
.ai-section li,
.ai-note p,
.ai-note span {
  color: var(--muted);
}

.ai-grid ul,
.ai-tip ul {
  margin: 0;
  padding-left: 20px;
}

.ai-timeline {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.ai-timeline li {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: #fff;
}

.ai-timeline span {
  color: var(--primary);
  font-weight: 800;
}

.ai-timeline p,
.ai-note p {
  margin-bottom: 0;
}

.ai-tip-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ai-tip {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ai-tip dl,
.ai-tip div {
  display: grid;
  gap: 8px;
}

.ai-tip dl {
  margin: 10px 0 0;
}

.ai-tip div {
  grid-template-columns: 96px 1fr;
}

.ai-tip dd {
  min-width: 0;
}

.ai-note {
  border-left: 6px solid var(--primary);
}

.ai-revision {
  padding: 12px;
  border: 1px solid rgba(0, 100, 95, 0.24);
  border-radius: 8px;
  background: #edf7f4;
}

.ai-revision strong {
  color: var(--primary);
}

.ai-revision ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.ai-revision li {
  color: var(--muted);
}

.clipboard-fallback {
  width: 100%;
  min-height: 180px;
  margin-bottom: 30px;
}

@media (max-width: 1100px) {
  .field-grid,
  .option-grid,
  .option-grid.compact,
  .recommendation-list,
  .ai-grid,
  .ai-tip-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar-note {
    display: none;
  }

  .app-shell,
  .app-shell:has(#input-sidebar.is-open) {
    grid-template-columns: 1fr;
  }

  .input-sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    z-index: 25;
    width: min(360px, 92vw);
    grid-template-columns: 1fr;
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  .input-sidebar.is-open {
    transform: translateX(0);
  }

  .input-sidebar .sidebar-rail {
    display: none;
  }

  .input-sidebar.is-open .sidebar-content {
    display: block;
  }

  .workspace,
  .results-main {
    padding: 18px;
  }

  .workspace-header,
  .results-heading,
  .plan-header {
    display: grid;
  }

  .ai-entry-panel,
  .ai-premium-hero,
  .ai-workspace-grid,
  .ai-play-card {
    grid-template-columns: 1fr;
  }

  .ai-shell,
  .ai-shell:has(#chat-sidebar.is-open) {
    grid-template-columns: 1fr;
  }

  .ai-results-main {
    padding: 18px;
  }

  .ai-workspace-page {
    padding: 18px;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    flex: 1 1 180px;
  }

  .field-grid,
  .option-grid,
  .option-grid.compact,
  .recommendation-list,
  .detail-grid,
  .ai-play-card details .detail-grid,
  .ai-workbench,
  .ai-grid,
  .ai-tip-list {
    grid-template-columns: 1fr;
  }

  .ai-chat-pane {
    position: static;
  }

  .ai-play-card .activity-image {
    grid-row: auto;
    height: 180px;
  }

  .history-item,
  .history-item-actions,
  .wpv-two-col,
  .wpv-dl,
  .wpv-program-card {
    grid-template-columns: 1fr;
  }

  .history-item {
    display: grid;
    align-items: stretch;
  }

  .history-item-actions {
    display: grid;
  }

  .status-note,
  .summary-list div,
  .card-details div,
  .plan-context div,
  .timeline li,
  .ai-timeline li,
  .ai-tip div {
    grid-template-columns: 1fr;
  }
}

/* ── auth widget ── */
.auth-widget {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.auth-logged-in {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-avatar {
  border-radius: 50%;
  width: 28px;
  height: 28px;
}

.auth-name {
  font-size: 0.8125rem;
  color: #374151;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-login-btn {
  font-size: 0.8125rem;
}

/* ── history tab ── */
.history-toolbar {
  margin-bottom: 12px;
}

.history-search-field,
.history-title-field {
  display: grid;
  gap: 4px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
}

.history-meta {
  font-size: 0.75rem;
  color: #9ca3af;
}

.history-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

.history-delete-btn {
  background: none;
  border: 1px solid #fca5a5;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
  color: #dc2626;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-delete-btn:hover {
  background: #fef2f2;
}

/* ── AI workspace tabs ── */
.ai-tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid #e5e7eb;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.ai-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 8px 16px;
  font-size: 0.875rem;
  cursor: pointer;
  color: #6b7280;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}

.ai-tab:hover {
  color: #1f2937;
}

.ai-tab-active {
  color: #1f2937;
  border-bottom-color: #1f2937;
  font-weight: 700;
}

.ai-tab-panel {
  min-height: 200px;
}

.record-empty {
  color: #9ca3af;
  font-size: 0.875rem;
  padding: 24px 0;
}

.record-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.record-handoff {
  font-size: 1rem;
  line-height: 1.7;
  padding: 12px;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  margin-bottom: 12px;
}

.record-template {
  font-size: 0.8125rem;
  white-space: pre-wrap;
  background: #f3f4f6;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  line-height: 1.6;
}

.record-detail-block summary {
  cursor: pointer;
  font-size: 0.875rem;
  color: #4b5563;
  padding: 6px 0;
}

/* ── workspace print view ── */
#workspace-print-view {
  display: none;
}

.wpv-document {
  color: #111827;
  font-family: "Yu Gothic", "Meiryo", sans-serif;
}

.wpv-header {
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 2px solid #1f2937;
  margin-bottom: 18px;
}

.wpv-header span {
  color: #4b5563;
  font-size: 0.82rem;
  font-weight: 700;
}

.wpv-header h1 {
  margin: 0;
  font-size: 1.65rem;
}

.wpv-header p {
  margin: 0;
  color: #4b5563;
}

.wpv-section {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 14px;
}

.wpv-section h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  border-left: 4px solid #00645f;
  padding-left: 8px;
}

.wpv-section p,
.wpv-section li,
.wpv-dl dd,
.wpv-timeline span {
  color: #374151;
  line-height: 1.65;
}

.wpv-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.wpv-dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  margin: 0;
}

.wpv-dl.compact {
  grid-template-columns: 1fr;
  gap: 4px;
}

.wpv-dl div {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px;
}

.wpv-dl dt {
  color: #00645f;
  font-weight: 700;
}

.wpv-dl dd {
  margin: 0;
}

.wpv-timeline {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.wpv-timeline li,
.wpv-activity-row,
.wpv-program-card {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.wpv-timeline li {
  display: grid;
  gap: 4px;
}

.wpv-activity-row h3,
.wpv-program-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.wpv-program-card {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  margin-bottom: 10px;
}

.wpv-program-card img {
  width: 120px;
  height: 90px;
  border-radius: 8px;
  object-fit: cover;
}

.wpv-caution {
  font-size: 0.82rem;
}

.wpv-child-card {
  display: grid;
  place-items: center;
  min-height: 100vh;
  break-after: page;
  page-break-after: always;
  text-align: center;
}

.wpv-child-card img {
  width: min(72vw, 72vh);
  height: min(72vw, 72vh);
  object-fit: contain;
}

.wpv-child-card h1 {
  margin: 18px 0 0;
  font-size: 2rem;
}

.caregiver-intro {
  font-size: 0.875rem;
  color: #6b7280;
  margin-bottom: 16px;
}

.caregiver-block {
  padding: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 10px;
  background: #fff;
}

.caregiver-block h4 {
  font-size: 0.9375rem;
  margin-bottom: 6px;
}

.caregiver-tweak {
  font-size: 0.8125rem;
  color: #4b5563;
  margin-top: 4px;
}

.caregiver-caution,
.caregiver-note {
  font-size: 0.75rem;
  color: #9ca3af;
  margin-top: 8px;
}

/* ── stepper ── */
.stepper-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 0 16px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 0;
  align-items: center;
}

.step-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--r-pill);
  padding: 5px 14px;
  font-size: 0.8125rem;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.step-chip:hover {
  background: var(--primary-l);
  border-color: var(--primary);
  color: var(--primary);
}

.step-num {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
}

.step-chip-active {
  background: var(--yellow);
  border-color: var(--yellow-d);
  color: var(--primary);
  box-shadow: 0 2px 0 var(--yellow-d);
}

.step-chip-active .step-num {
  color: var(--primary);
  opacity: 0.7;
}

.step-chip-done {
  background: var(--primary-l);
  border-color: var(--primary);
  color: var(--primary);
}

.step-chip-done .step-num {
  color: var(--primary);
  opacity: 0.6;
}

.step-nav-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #f3f4f6;
}

.step-done-note {
  font-size: 0.875rem;
  color: #6b7280;
}

/* ── filter bar ── */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0 16px;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 16px;
}

.filter-search {
  width: 100%;
  max-width: 360px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.875rem;
  outline: none;
}

.filter-search:focus {
  border-color: #6b7280;
  box-shadow: 0 0 0 2px rgba(107, 114, 128, 0.15);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.chips-label {
  font-size: 0.75rem;
  color: #6b7280;
  font-weight: 600;
  padding: 0 4px;
}

.chip {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
  color: #374151;
  transition: background 0.15s, border-color 0.15s;
}

.chip:hover {
  background: #e5e7eb;
}

.chip-active {
  background: #1f2937;
  border-color: #1f2937;
  color: #fff;
}

.chip-clear {
  background: none;
  border: 1px solid #d1d5db;
  color: #6b7280;
  font-size: 0.75rem;
}

.chip-clear:hover {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #dc2626;
}

/* ── help button & popup ── */
.option-wrap {
  position: relative;
  display: contents;
}

.option-wrap:has(.help-btn) {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 0;
}

.option-wrap .option {
  border-radius: 8px 0 0 8px;
  border-right: none;
}

.help-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 0 8px 8px 0;
  background: #fff;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}

.help-btn svg {
  width: 14px;
  height: 14px;
}

.help-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.option-wrap:has(input:checked) .help-btn {
  border-color: rgba(0, 100, 95, 0.55);
  background: #edf7f4;
}

.help-popup {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 200;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 10px 14px;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--ink);
  min-width: 220px;
  max-width: 300px;
  grid-column: 1 / -1;
}

.help-popup.is-open {
  display: block;
}

/* ── recommendation mode toggle ── */
.reco-mode-toggle {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ── match rate badge ── */
.match-rate {
  display: inline-block;
  background: #d1fae5;
  color: #065f46;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* ── session plan slot actions ── */
.plan-slot-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.slot-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.slot-btn svg {
  width: 13px;
  height: 13px;
}

.slot-btn:hover {
  background: var(--paper-2);
  border-color: var(--primary);
  color: var(--primary);
}

.slot-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.slot-btn-delete:hover {
  background: #fef2f2;
  border-color: var(--accent);
  color: var(--accent);
}

/* ── swap picker ── */
.slot-swap-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.slot-swap-picker[hidden] {
  display: none;
}

.swap-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 2px;
}

.swap-search {
  flex: 1 1 180px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 0.82rem;
  background: var(--paper);
  color: var(--ink);
}

.swap-search:focus {
  outline: 2px solid rgba(32, 122, 91, 0.18);
  border-color: var(--primary);
}

.swap-hint {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.74rem;
}

.swap-results {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.swap-chip {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--ink);
  transition: background 0.12s, border-color 0.12s;
}

.swap-chip:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.swap-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ── export menu ── */
.export-menu {
  position: relative;
}

.export-menu summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.export-menu summary::-webkit-details-marker {
  display: none;
}

.export-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  min-width: 180px;
  z-index: 100;
  overflow: hidden;
}

.export-dropdown button {
  background: none;
  border: none;
  text-align: left;
  padding: 10px 16px;
  font-size: 0.875rem;
  cursor: pointer;
  color: #1f2937;
}

.export-dropdown button:hover {
  background: #f3f4f6;
}

@media (max-width: 820px) {
  .topbar-section-nav {
    display: none;
  }

  .input-sidebar {
    width: min(340px, 88vw);
  }

  .sidebar-overlay {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: block;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(17, 24, 39, 0.34);
    cursor: pointer;
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-height: 56px;
  }

  .top-bar {
    gap: 8px;
    padding: 8px 12px;
  }

  .topbar-icon-button {
    min-width: 40px;
    padding: 0 9px;
  }

  .topbar-title strong {
    font-size: 15px;
  }

  .topbar-catch {
    display: none;
  }

  .topbar-link {
    min-height: 38px;
    padding: 0 10px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .auth-widget {
    min-width: 0;
  }

  .auth-name {
    display: none;
  }

  .workspace,
  .results-main,
  .ai-results-main,
  .ai-workspace-page {
    padding: 12px;
  }

  .workspace-header,
  .results-heading,
  .plan-header {
    gap: 8px;
  }

  .form-panel,
  .summary-panel,
  .results-panel,
  .session-plan,
  .ai-panel,
  .ai-entry-panel,
  .ai-context-panel,
  .ai-activity-panel,
  .recommendation-card,
  .ai-play-card {
    padding: 14px;
  }

  .recommendation-list {
    gap: 10px;
  }

  .activity-image {
    height: 120px;
  }

  .stepper-nav {
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 10px 0 12px;
    scrollbar-width: thin;
  }

  .step-chip,
  #stepper-expand-toggle {
    flex: 0 0 auto;
  }

  #stepper-expand-toggle {
    margin-left: 0 !important;
  }

  .step-nav-row,
  .ai-side-actions {
    grid-template-columns: 1fr;
  }

  .step-nav-row {
    flex-direction: column;
    align-items: stretch;
  }

  .step-nav-row button,
  .ai-entry-panel .primary-button,
  .ai-side-actions button,
  .workspace-export-menu summary {
    width: 100%;
  }

  .ai-entry-panel {
    gap: 12px;
  }

  .ai-tab-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: thin;
  }

  .ai-tab {
    flex: 0 0 auto;
    padding: 8px 12px;
    white-space: nowrap;
  }

  .project-name-field,
  .project-name-field input,
  .ai-instruction-field textarea,
  textarea,
  input,
  select {
    max-width: 100%;
  }
}

@media print {
  body.workspace-print-mode .top-bar,
  body.workspace-print-mode .ai-workspace-page > :not(#workspace-print-view),
  body.workspace-print-mode #clipboard-fallback {
    display: none !important;
  }

  body.workspace-print-mode #workspace-print-view {
    display: block !important;
  }

  body.workspace-print-mode .ai-workspace-page {
    display: block;
    padding: 0;
  }

  body.workspace-print-mode {
    background: #fff;
  }

  body.workspace-print-mode .wpv-child-card:last-child {
    break-after: avoid;
    page-break-after: avoid;
  }
}

@media print {
  body.child-print-mode .top-bar,
  body.child-print-mode .app-shell {
    display: none !important;
  }

  body.child-print-mode #child-print-view {
    display: block !important;
  }

  body.child-print-mode .cpv-card {
    height: 100vh;
    break-before: page;
    page-break-before: always;
  }

  body.child-print-mode .cpv-card:first-child {
    break-before: avoid;
    page-break-before: avoid;
  }
}

@media print {
  body {
    background: #fff;
  }

  .input-sidebar,
  .top-bar,
  .case-form,
  .header-actions,
  .export-menu,
  .summary-panel,
  .results-panel,
  .filter-bar,
  .stepper-nav,
  .stepper-wrapper > .stepper-nav,
  .ai-entry-panel,
  #safety-output,
  .plan-slot-actions,
  .slot-swap-picker,
  .reco-mode-toggle {
    display: none !important;
  }

  .app-shell,
  .ai-shell,
  .workspace,
  .results-main,
  .ai-results-main {
    display: block;
    padding: 0;
  }

  .session-plan {
    box-shadow: none;
    border: 0;
    page-break-inside: avoid;
  }

  .workspace-header {
    display: none;
  }

  @page {
    margin: 16mm 12mm;
  }
}
