:root {
  --bg: #f6f8ff;
  --surface: #ffffff;
  --surface-soft: #f4f7ff;
  --ink: #172033;
  --muted: #667085;
  --line: #dfe6f3;
  --accent: #635bff;
  --accent-dark: #4437d7;
  --accent-soft: #eeedff;
  --teal: #00b8a9;
  --warn: #b76e00;
  --danger: #c24135;
  --shadow: 0 10px 28px rgba(33, 41, 63, 0.07);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f8faff 0%, #ffffff 260px),
    #ffffff;
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.entry-screen,
.app-shell {
  display: none;
}

.entry-screen.active {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 12%, rgba(99, 91, 255, 0.12), transparent 30%),
    radial-gradient(circle at 82% 18%, rgba(0, 184, 169, 0.12), transparent 26%),
    var(--bg);
}

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

.entry-brand {
  padding: 0 0 18px;
  border-bottom-color: var(--line);
  color: var(--ink);
}

.entry-brand span {
  color: var(--muted);
}

.entry-card h1 {
  margin: 24px 0 10px;
  font-size: 30px;
  line-height: 1.2;
}

.entry-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.entry-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 26px;
}

.entry-option {
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 18px;
  text-align: left;
  display: grid;
  align-content: center;
  gap: 8px;
}

.entry-option:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.entry-option strong {
  font-size: 19px;
}

.entry-option span {
  color: var(--muted);
  line-height: 1.55;
}

.primary-entry {
  background: linear-gradient(135deg, #635bff, #00b8a9);
  border-color: transparent;
  color: #ffffff;
}

.primary-entry span {
  color: rgba(255, 255, 255, 0.82);
}

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

.sidebar {
  background: #f7f9ff;
  color: var(--ink);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 16px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #635bff, #00b8a9);
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: 14px;
}

.nav-item:hover,
.nav-item.active {
  background: #eeedff;
  color: var(--accent-dark);
}

.nav-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #edf2ff;
  font-size: 14px;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.sidebar-note strong,
.sidebar-note span {
  display: block;
}

.sidebar-note strong {
  color: var(--ink);
  font-weight: 600;
  word-break: break-all;
}

.workspace {
  padding: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
}

.topbar-actions,
.form-actions,
.export-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.small-button,
.danger-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

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

.ghost-button,
.small-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  background: #fff5f4;
  color: var(--danger);
  border-color: #f1c9c5;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.portal-mode .nav-item[data-view="dashboard"] {
  display: none;
}

.admin-mode [data-portal-only] {
  display: none !important;
}

.portal-mode .sidebar-note {
  margin-top: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.metric {
  padding: 16px;
  min-height: 118px;
}

.metric span,
.metric small {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin: 12px 0 10px;
  font-size: 30px;
  line-height: 1;
}

.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.archive-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 18px;
}

.admin-org-panel {
  grid-column: 1 / -1;
}

.org-create-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 0.6fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.org-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.org-filter-bar .active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.organization-list {
  display: grid;
  gap: 8px;
}

.organization-row {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(260px, 1.2fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.organization-row.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #f7f6ff, #ffffff);
}

.organization-main {
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  color: var(--ink);
}

.organization-main strong,
.organization-main span {
  display: block;
}

.organization-main span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.organization-row input {
  font-size: 12px;
  color: var(--muted);
}

.empty-row {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
}

.review-section.embedded {
  box-shadow: none;
  margin-bottom: 14px;
}

.panel {
  padding: 16px;
}

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

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
}

.timeline-item,
.review-card,
.doctor-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.status {
  border-radius: 999px;
  padding: 5px 9px;
  color: #475467;
  background: #f2f4f7;
  font-size: 12px;
  white-space: nowrap;
}

.status.pending {
  color: var(--warn);
  background: #fff4df;
}

.status.approved {
  color: #04756f;
  background: #dffcf8;
}

.status.rejected {
  color: var(--danger);
  background: #fff1f0;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  padding: 12px;
}

.timeline-item strong {
  display: block;
  margin-bottom: 4px;
}

.timeline-item span {
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: 18px;
}

.form-panel,
.doctor-editor {
  display: grid;
  gap: 14px;
  align-content: start;
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fbfcff;
  outline: none;
  font-weight: 500;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.11);
  background: #ffffff;
}

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

.upload-box {
  border: 1px dashed #aeb8ff;
  border-radius: 8px;
  background: #fbfcff;
  padding: 16px;
  gap: 6px;
  min-height: 98px;
  justify-content: center;
}

.upload-box:hover {
  border-color: var(--accent);
  background: #f8f7ff;
}

.upload-box input {
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 12px;
}

.upload-box strong {
  font-size: 14px;
}

.upload-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.upload-box.compact {
  min-height: 112px;
}

.split-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
}

.doctor-list-panel {
  align-self: start;
}

.doctor-list {
  display: grid;
  gap: 10px;
}

.doctor-card {
  width: 100%;
  padding: 12px;
  text-align: left;
  border-color: var(--line);
  display: grid;
  gap: 6px;
}

.doctor-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

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

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

.review-board {
  display: grid;
  gap: 16px;
}

.review-detail-header,
.review-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
}

.missing-panel {
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #ffcbc7;
  border-radius: 8px;
  background: #fff6f5;
  color: #6f2f28;
}

.missing-panel strong {
  display: block;
  margin-bottom: 8px;
}

.missing-panel ul {
  margin: 0;
  padding-left: 20px;
  line-height: 1.7;
}

.missing-panel p {
  margin: 8px 0 0;
  color: var(--muted);
}

.review-detail-header {
  padding: 18px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.review-detail-header h2,
.review-section-heading h2 {
  margin: 0;
  font-size: 18px;
}

.review-detail-header p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.review-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.review-summary span {
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.review-queue {
  display: grid;
  gap: 10px;
}

.review-queue-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.review-queue-row.needs-review {
  border-color: #f0b84b;
  background: linear-gradient(180deg, #fffbf3, #ffffff);
}

.review-queue-stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.review-section {
  padding: 16px;
}

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

.review-fields {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 14px;
}

.review-field {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  min-height: 42px;
  border-bottom: 1px solid var(--line);
}

.review-field:last-child {
  border-bottom: 0;
}

.review-field span,
.review-field strong {
  padding: 11px 12px;
  line-height: 1.55;
}

.review-field span {
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 700;
}

.review-field strong {
  font-weight: 600;
  white-space: pre-wrap;
  word-break: break-word;
}

.review-field a {
  color: var(--accent-dark);
  text-decoration-color: rgba(99, 91, 255, 0.35);
}

.empty-value {
  color: var(--muted);
  font-weight: 500;
}

.review-card {
  display: grid;
  gap: 10px;
}

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

.review-actions button.is-active {
  box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.16);
  transform: none;
}

.review-actions button:disabled {
  cursor: default;
  opacity: 1;
}

.review-feedback {
  margin: 0;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.review-feedback.saving {
  color: var(--accent-dark);
  background: #eef2ff;
}

.review-feedback.success {
  color: #04756f;
  background: #dffcf8;
}

.review-feedback.error {
  color: var(--danger);
  background: #fff1f0;
}

.review-card textarea {
  min-height: 76px;
}

.archive-tree {
  margin: 0;
  padding: 16px;
  border-radius: 8px;
  background: #17251f;
  color: #e8f5ee;
  overflow: auto;
  line-height: 1.55;
}

.muted {
  color: var(--muted);
  line-height: 1.65;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17251f;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .app-shell.active {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 14px;
    gap: 14px;
  }

  .brand {
    padding-bottom: 10px;
  }

  .nav {
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  }

  .nav-item {
    justify-content: center;
    min-height: 40px;
    font-size: 12px;
  }

  .nav-icon,
  .sidebar-note {
    display: none;
  }

  .metric-grid,
  .dashboard-layout,
  .form-grid,
  .split-layout,
  .archive-layout,
  .review-board {
    grid-template-columns: 1fr;
  }

  .org-create-form,
  .organization-row,
  .review-queue-row {
    grid-template-columns: 1fr;
  }

  .review-detail-header {
    display: grid;
  }

  .review-summary {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .entry-card {
    padding: 20px;
  }

  .entry-actions {
    grid-template-columns: 1fr;
  }

  .entry-card h1 {
    font-size: 26px;
  }

  .workspace {
    padding: 18px;
  }

  .topbar,
  .field-row,
  .upload-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar-actions,
  .form-actions,
  .export-actions {
    width: 100%;
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    width: 100%;
  }

  .nav {
    display: flex;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .nav-item {
    flex: 0 0 104px;
  }

  .nav-item[hidden] {
    display: none;
  }

  .sidebar,
  .workspace {
    overflow-x: hidden;
  }
}
