:root {
  --bg: #edf1f5;
  --panel: #ffffff;
  --panel-soft: #f4f7fa;
  --panel-accent: #e8eef5;
  --panel-deep: #eef3f8;
  --ink: #1b2430;
  --muted: #5f6e7d;
  --line: #d2dbe5;
  --line-strong: #bcc9d5;
  --brand: #244767;
  --brand-strong: #1a3550;
  --brand-soft: #dbe6f2;
  --info: #2d6cc8;
  --info-soft: #e1ecfb;
  --warn: #a84f1e;
  --warn-soft: #f8e4d9;
  --gold: #9b7418;
  --gold-soft: #f6ebc8;
  --shadow: 0 2px 8px rgba(19, 36, 54, 0.05);
  --control-height: 32px;
  --control-radius: 4px;
  --control-padding-x: 10px;
  --control-font-size: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Yu Gothic UI", "Segoe UI", "Hiragino Sans", sans-serif;
  background: linear-gradient(180deg, #f1f4f7 0%, #eef2f6 100%);
}

.workspace-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

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

.desk-shell,
.detail-page-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace-nav {
  padding: 12px 10px;
  border-right: 1px solid #aebdcb;
  background: linear-gradient(180deg, #2c4863 0%, #243c54 100%);
}

.brand-block {
  padding: 8px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 12px;
}

.brand-block h2 {
  font-size: 22px;
  color: #fff;
}

.nav-menu {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border-radius: 6px;
  color: #dbe6f0;
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.nav-count {
  min-width: 28px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.nav-item.active .nav-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.topbar,
.detail-topbar,
.toolbar,
.toolbar-row,
.quick-filters,
.saved-views,
.column-toggles,
.staff-filters,
.bulk-actions,
.panel-header,
.form-actions,
.detail-tabs,
.action-strip,
.topbar-stats,
.record-grid,
.detail-summary-band {
  display: flex;
  gap: 12px;
}

.topbar,
.detail-topbar {
  justify-content: space-between;
  align-items: flex-start;
}

.topbar-stats,
.detail-tabs,
.record-grid,
.detail-summary-band {
  flex-wrap: wrap;
}

.hero-copy {
  max-width: 720px;
}

.detail-meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.detail-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #edf4fb;
  border: 1px solid #c9d9ea;
  color: #33516f;
  font-size: 12px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 8px;
  color: #7ea7d5;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 800;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: -0.02em;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 15px;
}

.subcopy,
.section-note,
.panel-message,
.inline-message,
.loading-detail,
.back-link {
  color: var(--muted);
}

.subcopy {
  margin: 8px 0 0;
  max-width: 60ch;
  line-height: 1.4;
  font-size: 13px;
}

.page-body,
.detail-page-body {
  margin-top: 18px;
  display: grid;
  gap: 16px;
}

.section-stack {
  display: grid;
  gap: 16px;
}

.content-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.section-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #dde5ee;
}

.card,
.metric-card,
.record-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toolbar,
.intake-form,
.table-card,
.summary-strip,
.detail-summary-band,
.detail-content {
  padding: 14px;
}

.section-heading {
  margin-bottom: 12px;
}

.staff-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.staff-summary-card {
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f5f8fb 100%);
  text-align: left;
  cursor: pointer;
}

.staff-summary-card strong,
.staff-summary-card span {
  display: block;
}

.staff-summary-card strong {
  margin-bottom: 8px;
}

.staff-summary-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.staff-summary-card.active {
  border-color: #b7d1fb;
  background: linear-gradient(180deg, #eff6ff 0%, #e6f0ff 100%);
}

.toolbar {
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, #ffffff 0%, #f6f9fc 100%);
}

.quick-filters {
  flex-wrap: wrap;
}

.saved-views {
  flex-wrap: wrap;
}

.column-toggles {
  flex-wrap: wrap;
}

.bulk-actions {
  flex-wrap: wrap;
  align-items: center;
}

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

.staff-filters {
  flex-wrap: wrap;
  padding-top: 2px;
}

.toolbar-row {
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
}

input,
select,
textarea,
.button,
.tab-button {
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #ffffff;
}

input,
select,
textarea {
  min-height: 36px;
  padding: 0 10px;
  color: var(--ink);
  font-size: 13px;
}

input::placeholder,
textarea::placeholder {
  color: #91a0ae;
}

input[type="search"] {
  min-width: 360px;
  background: #fbfdff;
}

textarea {
  width: 100%;
  min-height: 78px;
  padding: 10px;
  resize: vertical;
}

.button,
.tab-button,
.table-link {
  min-height: var(--control-height);
  padding: 6px var(--control-padding-x);
  cursor: pointer;
  text-decoration: none;
  transition: 160ms ease;
  font-size: var(--control-font-size);
}

.button {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
  font-weight: 700;
}

.button:hover,
.table-link:hover {
  background: var(--brand-strong);
}

.button.secondary {
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--ink);
}

.button.secondary:hover,
.tab-button:hover {
  background: var(--panel-soft);
}

.quick-filter,
.saved-view,
.action-shortcut,
.staff-filter,
.template-chip,
.column-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: var(--control-radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.column-toggle input {
  min-height: auto;
}

.quick-filter.active,
.saved-view.active,
.action-shortcut.active,
.staff-filter.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.quick-filter:hover,
.saved-view:hover,
.action-shortcut:hover,
.staff-filter:hover,
.template-chip:hover,
.column-toggle:hover {
  background: var(--panel-soft);
}

.quick-filter.active:hover,
.saved-view.active:hover,
.action-shortcut.active:hover,
.staff-filter.active:hover {
  background: var(--brand-strong);
}

.intake-grid {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease, margin-top 0.2s ease;
  max-height: 540px;
}

.intake-grid.is-collapsed {
  max-height: 0;
  opacity: 0;
}

.intake-form {
  background: linear-gradient(180deg, #ffffff 0%, #f9fbfd 100%);
}

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

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

.form-actions {
  align-items: center;
  margin-top: 12px;
}

.top-gap {
  margin-top: 12px;
}

.embedded-card {
  background: linear-gradient(180deg, #fcfdff 0%, #f5f8fb 100%);
  border: 1px solid var(--line);
}

.form-surface {
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfd 100%);
}

.financial-entry-body {
  width: 100%;
}

.financial-entry-form.is-canceled {
  opacity: 0.65;
}

.row-action-group {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.module-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
}

.module-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.module-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.module-existing {
  background: #e8f7ee;
  color: #216c44;
}

.module-scaffolded,
.module-seeded {
  background: #eef4fb;
  color: #355c83;
}

.metric-card {
  min-width: 132px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f4f7fa 100%);
  border-radius: 6px;
}

.metric-card.emphasis {
  background: linear-gradient(180deg, #edf5ff 0%, #e5f0fb 100%);
  border-color: #b9cde3;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.table-card {
  overflow: hidden;
}

.table-header {
  margin-bottom: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  max-height: calc(100vh - 290px);
}

.assessment-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1820px;
  background: white;
}

.assessment-table th,
.assessment-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  font-size: 12px;
}

.assessment-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fbfd;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 800;
}

.sort-button {
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.sort-button.active {
  color: var(--brand);
}

.sort-button[data-direction="asc"]::after {
  content: "↑";
  margin-left: 6px;
}

.sort-button[data-direction="desc"]::after {
  content: "↓";
  margin-left: 6px;
}

.assessment-table thead tr:first-child th {
  top: 0;
  background: #dde7f0;
  text-align: center;
}

.assessment-table thead tr:nth-child(2) th {
  top: 30px;
}

.assessment-table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
}

.assessment-table .checkbox-col {
  left: 0;
  width: 42px;
  min-width: 42px;
  max-width: 42px;
  text-align: center;
}

.assessment-table tbody .checkbox-col {
  z-index: 3;
}

.assessment-table thead tr > .sticky-col:nth-child(2),
.assessment-table tbody tr > .sticky-col:nth-child(2) {
  left: 42px;
}

.assessment-table thead .sticky-col {
  z-index: 3;
  background: #f8fbfd;
}

.assessment-table thead tr:first-child .sticky-col {
  background: #edf4fb;
}

.assessment-table tbody tr:hover {
  background: #f7fbff;
}

.assessment-table tbody tr {
  box-shadow: inset 0 -1px 0 var(--line);
}

.assessment-table tbody tr.clickable-row {
  cursor: pointer;
}

.is-hidden-col {
  display: none;
}

.assessment-table tbody td:nth-child(5),
.assessment-table tbody td:nth-child(6),
.assessment-table tbody td:nth-child(9) {
  font-weight: 700;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
}

.next-action-chip,
.doc-chip,
.todo-chip {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 800;
}

.next-action-chip {
  background: var(--info-soft);
  color: var(--info);
}

.doc-chip.is-pending,
.todo-chip.has-open {
  background: var(--warn-soft);
  color: var(--warn);
}

.doc-chip.is-done,
.todo-chip {
  background: var(--brand-soft);
  color: var(--brand);
}

.priority-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 800;
  font-size: 11px;
}

.priority-high {
  background: var(--warn-soft);
  color: var(--warn);
}

.priority-mid {
  background: var(--gold-soft);
  color: var(--gold);
}

.priority-low {
  background: var(--brand-soft);
  color: var(--brand);
}

.table-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  background: var(--brand);
  border-radius: var(--control-radius);
  color: white;
  font-weight: 700;
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--brand);
}

.back-link {
  text-decoration: none;
  font-weight: 700;
}

.detail-summary-band {
  background: linear-gradient(180deg, #ffffff 0%, #f4f7fa 100%);
  border: 1px solid #d8e1eb;
}

.action-strip {
  padding: 10px 12px;
  background: linear-gradient(180deg, #ffffff 0%, #edf3f8 100%);
  align-items: center;
  flex-wrap: wrap;
  border-radius: 6px;
  border: 1px solid #dbe5ee;
}

.tab-button {
  background: #ffffff;
  color: var(--muted);
  font-weight: 700;
  min-height: 30px;
  border-radius: var(--control-radius);
}

.tab-button.active {
  background: var(--info);
  color: white;
  border-color: var(--info);
}

.detail-content {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  border-radius: 10px;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
  align-items: start;
}

.detail-side-panel {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 24px;
}

.side-card {
  padding: 12px;
  border-radius: 6px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
}

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

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

.side-action-button {
  width: 100%;
  justify-content: center;
}

.side-card h3 {
  margin: 0 0 12px;
}

.compact-kv {
  grid-template-columns: 84px 1fr;
  gap: 8px 10px;
}

.detail-content h2,
.record-block h3 {
  margin: 0 0 14px;
  letter-spacing: -0.02em;
}

.detail-content > h2 {
  font-size: 24px;
  margin-bottom: 4px;
}

.document-hero {
  margin-bottom: 12px;
}

.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 12px;
  margin: 0;
  font-size: 13px;
}

.kv dt {
  color: var(--muted);
  font-weight: 700;
}

.kv dd {
  margin: 0;
  white-space: pre-wrap;
  color: var(--ink);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.photo-card {
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: white;
  display: grid;
  grid-template-rows: auto auto;
}

.photo-card img {
  width: 100%;
  height: 220px;
  display: block;
  object-fit: contain;
  background: linear-gradient(180deg, #f6f9fc 0%, #edf3f8 100%);
}

.photo-preview-button {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.photo-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
}

.photo-card-meta strong {
  font-size: 13px;
}

.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(10, 18, 28, 0.82);
  padding: 28px;
}

.photo-lightbox.is-hidden {
  display: none;
}

.photo-lightbox-stage {
  width: min(1200px, calc(100vw - 80px));
  height: min(88vh, 900px);
  padding: 24px;
  border-radius: 14px;
  background: linear-gradient(180deg, #f8fbfd 0%, #edf3f8 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.photo-lightbox-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.photo-lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.record-block {
  flex: 1 1 360px;
  padding: 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.task-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.task-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 6px;
  background: linear-gradient(180deg, #f8fbfe 0%, #f2f7fb 100%);
  border: 1px solid var(--line);
}

.task-row.done {
  opacity: 0.7;
}

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

.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 4px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.check-item input {
  width: 18px;
  height: 18px;
  min-height: 18px;
}

.timeline-card {
  flex: 1 1 360px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid #d7e1eb;
  background: linear-gradient(180deg, #f9fbfd 0%, #f2f6fa 100%);
}

.call-template-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.bulk-actions select,
.toolbar-row select,
.toolbar-row input,
.bulk-actions .button,
.toolbar-row .button {
  min-height: var(--control-height);
}

.timeline-card h3 {
  margin: 0 0 14px;
}

.timeline-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 8px 0;
}

.timeline-item + .timeline-item {
  margin-top: 14px;
}

.timeline-item.muted {
  opacity: 0.78;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--line-strong);
  flex: 0 0 auto;
}

.timeline-dot.active {
  background: var(--info);
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.12);
}

.timeline-item > div:last-child {
  min-width: 0;
  flex: 1;
}

.timeline-item strong {
  display: block;
  line-height: 1.35;
}

.raw-text {
  margin: 0;
  padding: 10px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #fbfdff;
  white-space: pre-wrap;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  line-height: 1.5;
  max-height: 300px;
  overflow: auto;
}

.record-block.qr {
  background: linear-gradient(180deg, #eff7ff 0%, #e8f2ff 100%);
}

.record-block.ocr {
  background: linear-gradient(180deg, #fff4ec 0%, #ffefe2 100%);
}

.record-block.verified {
  background: linear-gradient(180deg, #eff4ff 0%, #e8f0ff 100%);
}

@media (max-width: 960px) {
  .workspace-shell {
    grid-template-columns: 1fr;
  }

  .workspace-nav {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .desk-shell,
  .detail-page-shell {
    padding: 16px;
  }

  .topbar,
  .detail-topbar,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-stats,
  .detail-summary-band {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-side-panel {
    position: static;
  }

  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }

  input[type="search"] {
    min-width: 0;
    width: 100%;
  }

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

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