:root {
  color-scheme: light;
  --bg: #eef5f7;
  --surface: #ffffff;
  --surface-soft: #f6fafb;
  --line: #d8e4e8;
  --line-strong: #b7cbd2;
  --text: #1d2b32;
  --muted: #667a84;
  --blue: #0b79bf;
  --blue-dark: #075c92;
  --teal: #16837a;
  --orange: #d97721;
  --red: #c84b4b;
  --amber: #e6a327;
  --slate: #64748b;
  --shadow: 0 12px 30px rgba(22, 44, 56, 0.10);
  --radius: 8px;
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: .55;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
}

.app-header {
  grid-column: 1 / -1;
  grid-row: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  appearance: none;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0;
  color: var(--text);
  text-align: left;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 5px 15px rgba(11, 121, 191, 0.22);
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.offline-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.offline-status[data-state="ready"] {
  color: #14635b;
}

.header-context {
  min-width: 0;
  flex: 1;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-context {
  max-width: 260px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-login-button {
  min-height: 40px;
  padding: 0 12px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  display: grid;
  place-items: center;
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.icon-button:hover {
  color: var(--blue);
  border-color: rgba(11, 121, 191, 0.35);
  background: #f1f8fc;
}

.app-nav {
  grid-column: 1;
  grid-row: 2;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 68px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
}

.nav-item svg {
  width: 24px;
  height: 24px;
}

.nav-item:hover,
.nav-item.is-active {
  background: #e8f4fa;
  color: var(--blue-dark);
}

.app-main {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  overflow: auto;
  padding: 24px;
}

.page-grid,
.auth-layout,
.check-layout,
.history-layout {
  max-width: 1180px;
  margin: 0 auto;
}

.auth-layout {
  min-height: calc(100vh - 124px);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-icon {
  width: 70px;
  height: 70px;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 7px 20px rgba(11, 121, 191, 0.22);
  margin-bottom: 18px;
}

.auth-form,
.stack-form {
  display: grid;
  gap: 12px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head.is-compact {
  align-items: center;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  white-space: nowrap;
}

.button.primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(11, 121, 191, 0.22);
}

.button.primary:hover {
  background: var(--blue-dark);
}

.button.neutral {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.button.neutral:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.button.danger {
  background: #fff5f5;
  color: var(--red);
  border-color: #f1c7c7;
}

.button-plus {
  font-size: 20px;
  line-height: 1;
}

.list-panel,
.tool-panel,
.adjustment-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list-panel {
  min-height: 240px;
  overflow: hidden;
}

.empty-state {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 30px;
}

.empty-state strong {
  display: block;
  color: var(--text);
  font-size: 18px;
  margin-bottom: 6px;
}

.row-card {
  width: 100%;
  appearance: none;
  border: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 16px;
  text-align: left;
  color: var(--text);
}

.row-card:last-child {
  border-bottom: 0;
}

.row-card:hover,
.row-card.is-active {
  background: #f1f8fc;
}

.row-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-weight: 850;
  min-width: 0;
}

.row-title span:first-child {
  overflow-wrap: anywhere;
}

.row-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.blue {
  background: #e8f4fa;
  color: var(--blue-dark);
}

.badge.teal {
  background: #e7f5f3;
  color: #126b64;
}

.badge.orange {
  background: #fff3e4;
  color: #a65513;
}

.check-columns,
.history-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(320px, .95fr);
  gap: 16px;
}

.check-stage {
  display: grid;
  gap: 16px;
}

.step-panel {
  max-width: 720px;
  margin: 0 auto;
  padding: 22px;
}

.step-panel h2,
.handover-panel h2 {
  font-size: 24px;
  line-height: 1.3;
}

.step-kicker {
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.step-note {
  color: var(--muted);
  line-height: 1.7;
  margin: 12px 0 18px;
}

.professional-step {
  border-top: 4px solid var(--blue);
}

.patient-step {
  border-top: 4px solid var(--orange);
}

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

.order-toggle button {
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 900;
}

.order-toggle button.is-active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(11, 121, 191, 0.2);
}

.handover-panel {
  max-width: 560px;
  margin: 0 auto;
  padding: 28px;
  text-align: center;
}

.handover-icon {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: #e8f4fa;
  color: var(--blue-dark);
  font-weight: 900;
  font-size: 24px;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(0, .95fr);
  gap: 16px;
}

.private-note {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  line-height: 1.6;
}

.private-note strong {
  display: block;
  color: var(--text);
  margin-bottom: 3px;
}

.profile-card {
  display: grid;
  gap: 4px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}

.profile-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.profile-card strong {
  font-size: 15px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.settings-panel {
  padding: 18px;
}

.settings-panel .field-row {
  grid-template-columns: minmax(0, 1fr) minmax(150px, .42fr);
}

.staff-list {
  grid-column: 1 / -1;
}

.history-columns {
  grid-template-columns: minmax(300px, .78fr) minmax(340px, 1.22fr);
}

.tool-panel {
  padding: 16px;
  min-width: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.short-input {
  width: 140px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field span,
.field legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.field input,
.field select,
.field textarea,
.short-input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfdfe;
  color: var(--text);
  border-radius: 8px;
  outline: 0;
}

.field input {
  height: 42px;
  padding: 0 12px;
}

.field select {
  height: 42px;
  padding: 0 12px;
  appearance: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
  padding: 10px 12px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.short-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(11, 121, 191, 0.14);
}

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

.field.compact input {
  text-align: right;
}

.rating {
  margin-bottom: 18px;
}

.rating-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  gap: 10px;
}

.rating-title {
  font-size: 14px;
  font-weight: 850;
}

.rating-value {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rating-buttons {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px;
}

.rating-button {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 900;
}

.rating-button:hover {
  border-color: var(--line-strong);
}

.rating-button.is-pro {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.rating-button.is-patient {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}

.rating-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  margin-top: 6px;
}

.cs-map-wrap {
  width: min(100%, 520px);
  margin: 0 auto;
  aspect-ratio: 1;
}

.cs-map-wrap canvas {
  width: 100%;
  height: 100%;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 10px;
  font-size: 14px;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.map-legend span:not(.map-overlap)::before,
.map-overlap i::before,
.map-overlap i::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--blue);
}

.map-legend span:nth-child(2)::before {
  background: var(--orange);
}

.map-overlap i {
  position: relative;
  width: 17px;
  height: 17px;
  isolation: isolate;
}

.map-overlap i::before,
.map-overlap i::after {
  position: absolute;
  box-sizing: border-box;
  mix-blend-mode: multiply;
}

.map-overlap i::before {
  top: 0;
  left: 0;
  border: 1px solid var(--blue);
  background: rgb(11 121 191 / 62%);
}

.map-overlap i::after {
  bottom: 0;
  right: 0;
  border: 1px solid var(--orange);
  background: rgb(217 119 33 / 62%);
}

.map-note {
  margin: 6px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.score-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.score-card strong {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.score-card span {
  font-size: 20px;
  font-weight: 900;
}

.adjustment-panel {
  margin-top: 16px;
  padding: 16px;
}

.is-hidden {
  display: none !important;
}

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

.adjustment-wide {
  grid-column: span 3;
}

fieldset.field {
  border: 0;
  padding: 0;
  margin: 0 0 14px;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.chip input:checked + span {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.history-list {
  max-height: calc(100vh - 160px);
  overflow: auto;
}

.history-card {
  padding: 15px;
  border-bottom: 1px solid var(--line);
}

.history-card:last-child {
  border-bottom: 0;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.history-date {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.history-task {
  margin: 10px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.5;
}

.history-factors {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.app-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(10, 30, 40, 0.28);
}

.app-dialog::backdrop {
  background: rgba(9, 26, 36, 0.38);
}

.dialog-panel {
  padding: 20px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #14242b;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 80;
  font-size: 14px;
  font-weight: 800;
}

.list-filter {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
}
.list-filter select {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: white;
  border-radius: var(--radius);
  color: var(--text);
}
.schedule-item {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: white;
  color: var(--text);
  text-align: left;
}
#reviewSchedule h2 { margin-bottom: 10px; }
.form-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.balance-note, .previous-plan {
  padding: 12px 14px;
  background: var(--surface-soft);
  border-left: 3px solid var(--teal);
  border-radius: 4px;
  overflow-wrap: anywhere;
}
.balance-note { grid-column: 1 / -1; }
.balance-note p, .previous-plan p, .reason-item p { margin: 6px 0; white-space: pre-wrap; }
.previous-plan { margin-bottom: 18px; }
.setup-plan { margin: 12px 0; }
.setup-plan summary { cursor: pointer; font-weight: 700; }
.reason-list { margin-top: 20px; }
.reason-list h3, .record-index h3 { font-size: 15px; margin: 0 0 8px; }
.reason-item { border-top: 1px solid var(--line); padding: 12px 0; overflow-wrap: anywhere; }
.reason-item small { display: block; color: var(--muted); margin-top: 2px; }
.plan-details dt { font-weight: 700; margin-top: 12px; }
.plan-details dd { margin: 4px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.record-index { display: grid; gap: 6px; padding: 14px; }
.record-index button { justify-content: flex-start; }
.record-index button[aria-pressed="true"] { border-color: var(--blue); color: var(--blue-dark); }
.history-slider { margin-top: 16px; }
.history-slider input { accent-color: var(--blue); }
#historyReviewer:not(:empty) { margin-top: 14px; }
.field select { appearance: auto; }
#printRecords { display: none; }
@media print {
  #printRecords { display: block; }
  .history-layout:has(#printRecords) #historyList { display: none; }
  .history-card { break-inside: avoid; }
  .history-list { max-height: none; overflow: visible; }
  .record-index, .history-slider { display: none; }
}

@media (max-width: 1180px) {
  .history-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .result-grid,
  .check-columns,
  .history-columns {
    grid-template-columns: 1fr;
  }

  .history-list {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 68px minmax(0, 1fr) 70px;
  }

  .app-header {
    grid-row: 1;
    padding: 8px 12px;
    gap: 12px;
  }

  .brand {
    min-width: 0;
  }

  .header-context,
  .session-context {
    display: none;
  }

  .header-actions {
    margin-left: auto;
  }

  .brand-icon {
    width: 44px;
    height: 44px;
  }

  .app-nav {
    grid-column: 1;
    grid-row: 3;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, 1fr);
  }

  .nav-item {
    min-height: 54px;
  }

  .nav-item svg {
    width: 21px;
    height: 21px;
  }

  .app-main {
    grid-column: 1;
    grid-row: 2;
    padding: 18px 12px;
  }

  .page-head {
    align-items: center;
  }

  h1 {
    font-size: 23px;
  }

  .row-card {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: flex-start;
  }

  .adjustment-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .order-toggle {
    grid-template-columns: 1fr;
  }

  .adjustment-wide {
    grid-column: auto;
  }
}

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

  .app-shell {
    display: block;
  }

  .app-header,
  .app-nav,
  .header-actions,
  .button,
  .icon-button {
    display: none !important;
  }

  .app-main {
    overflow: visible;
    padding: 0;
  }

  .list-panel,
  .tool-panel,
  .adjustment-panel {
    box-shadow: none;
    break-inside: avoid;
  }
}

acs-task-ai { display: block; }
#taskAiHost acs-task-ai { padding: 16px; border: 1px solid var(--line); border-radius: 8px; }
acs-task-ai h3 { margin: 0 0 8px; font-size: 1rem; }
acs-task-ai p { margin: 6px 0 12px; line-height: 1.6; }
acs-task-ai .ai-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
acs-task-ai .ai-suggestion { padding: 12px; background: var(--surface-soft); white-space: pre-wrap; }
acs-task-ai [hidden] { display: none !important; }
@media print { acs-task-ai { display: none; } }
