:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --surface-3: #fafafa;
  --ink: #1d1d1f;
  --ink-soft: #424245;
  --muted: #6e6e73;
  --muted-2: #8e8e93;
  --line: #d2d2d7;
  --line-soft: #e5e5ea;
  --primary: #0a84ff;
  --primary-strong: #0066cc;
  --primary-soft: #eef5ff;
  --danger: #d70015;
  --danger-soft: #fff1f2;
  --ok: #248a3d;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.06);
  --shadow-soft: 0 4px 14px rgba(0, 0, 0, 0.04);
  --radius: 8px;
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-system);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

img {
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  min-width: 0;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: rgba(245, 245, 247, 0.9);
  padding: 18px 14px;
  backdrop-filter: blur(20px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 2px 4px 8px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
}

.brand-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-subtitle {
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  padding: 9px 11px;
  text-align: left;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease,
    box-shadow 140ms ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.nav-item.is-active {
  border-color: var(--line-soft);
  background: var(--surface);
  color: var(--primary-strong);
  box-shadow: var(--shadow-soft);
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.sync-pill {
  min-height: 34px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  padding: 9px 10px;
}

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

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

.topbar h1,
.panel h2,
.subsection h3,
.overview-item h3,
.report-experiment h3,
.assistant-answer h3 {
  margin: 0;
  color: var(--ink);
}

.topbar h1 {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
}

.topbar p,
.panel-header p,
.subsection-header p,
.muted-text {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar-actions,
.editor-actions,
.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.danger-button,
.template-button,
.question-chip,
.image-upload,
.icon-button {
  min-height: 36px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease,
    box-shadow 140ms ease, transform 140ms ease;
}

.primary-button,
.secondary-button,
.danger-button,
.template-button,
.question-chip,
.image-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
}

.primary-button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(10, 132, 255, 0.22);
}

.primary-button:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.secondary-button,
.template-button,
.question-chip,
.image-upload {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
}

.secondary-button:hover,
.template-button:hover,
.question-chip:hover,
.image-upload:hover {
  border-color: #b7b7bf;
  background: var(--surface-2);
  color: var(--ink);
}

.danger-button {
  border: 1px solid rgba(215, 0, 21, 0.24);
  background: var(--danger-soft);
  color: var(--danger);
}

.danger-button:hover {
  border-color: rgba(215, 0, 21, 0.42);
  background: #ffe5e8;
}

.icon-button {
  display: grid;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 16px;
  padding: 0;
}

.icon-button:hover {
  border-color: rgba(215, 0, 21, 0.28);
  background: var(--danger-soft);
  color: var(--danger);
}

.file-button,
.image-upload {
  position: relative;
  overflow: hidden;
}

.file-button input,
.image-upload input {
  position: absolute;
  inset: 0;
  cursor: pointer;
  opacity: 0;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

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

.assistant-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-header,
.subsection-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
}

.subsection h3,
.overview-item h3,
.report-experiment h3,
.assistant-answer h3 {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.filter-grid,
.report-controls,
.sync-grid {
  display: grid;
  gap: 10px;
}

.filter-grid {
  grid-template-columns: minmax(0, 1.3fr) minmax(140px, 0.7fr) minmax(160px, 0.8fr);
  margin-bottom: 12px;
}

.report-controls {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin-bottom: 16px;
}

.sync-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.35;
  outline: none;
  padding: 8px 10px;
}

input,
select {
  min-height: 38px;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.16);
}

.experiment-list {
  display: grid;
  max-height: calc(100vh - 210px);
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.experiment-item {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--ink);
  padding: 12px;
  text-align: left;
}

.experiment-item:hover {
  border-color: #c7c7cc;
  background: var(--surface);
}

.experiment-item.is-selected {
  border-color: rgba(10, 132, 255, 0.46);
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.experiment-item-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-line {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.experiment-item .meta-line {
  margin-top: 5px;
}

.tag-line {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.tag {
  border: 1px solid rgba(10, 132, 255, 0.22);
  border-radius: 6px;
  background: rgba(10, 132, 255, 0.08);
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  padding: 3px 6px;
}

.empty-inline,
.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--muted);
}

.empty-inline {
  padding: 18px;
  text-align: center;
}

.empty-state {
  display: grid;
  min-height: 320px;
  place-content: center;
  padding: 28px;
  text-align: center;
}

.empty-state h2 {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.3;
}

.empty-state p {
  max-width: 420px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: 14px;
}

.editor-form {
  display: grid;
  gap: 16px;
}

.form-row {
  display: grid;
  gap: 12px;
}

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

.form-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.quick-template-strip,
.question-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-button,
.question-chip {
  min-height: 34px;
  font-size: 13px;
  padding: 7px 10px;
}

.subsection {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--line-soft);
  padding-top: 16px;
}

.steps-list,
.attachments-list {
  display: grid;
  gap: 10px;
}

.step-item {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr) 78px 34px;
  gap: 8px;
  align-items: start;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-3);
  padding: 10px;
}

.step-item textarea {
  min-height: 54px;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.inline-check input {
  width: 16px;
  min-width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
}

.attachment-item {
  display: grid;
  grid-template-columns: 112px minmax(150px, 0.85fr) minmax(190px, 1fr) minmax(180px, 0.9fr) 102px 34px;
  gap: 8px;
  align-items: start;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-3);
  padding: 10px;
}

.attachment-item textarea {
  min-height: 38px;
}

.attachment-preview {
  grid-column: 2 / 5;
  width: 180px;
  height: 112px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
}

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

.overview-item {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-3);
  padding: 16px;
}

.overview-number {
  color: var(--primary);
  font-size: 28px;
  font-weight: 750;
  line-height: 1;
}

.overview-item h3 {
  margin-top: 10px;
}

.overview-item p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.data-table {
  display: grid;
  gap: 8px;
}

.data-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1.3fr) minmax(0, 1fr) 112px;
  gap: 12px;
  align-items: center;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-3);
  padding: 11px 12px;
}

.data-row strong {
  color: var(--primary-strong);
  font-size: 13px;
}

.data-row div,
.data-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.report-panel {
  overflow: hidden;
}

.report-preview {
  display: grid;
  gap: 12px;
  min-width: 0;
  border-top: 1px solid var(--line-soft);
  padding-top: 16px;
}

.report-preview h2 {
  font-size: 19px;
}

.report-preview p {
  margin: 6px 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.report-experiment {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-3);
  padding: 14px;
  overflow-wrap: anywhere;
}

.report-experiment ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.report-image {
  width: 220px;
  max-height: 150px;
  margin: 8px 8px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: cover;
}

.assistant-box {
  display: grid;
  gap: 10px;
}

.assistant-box .primary-button {
  justify-self: start;
}

.assistant-answer {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
  overflow-wrap: anywhere;
}

.assistant-answer ol {
  margin: 0;
  padding-left: 20px;
}

.assistant-answer li {
  margin: 6px 0;
}

.sync-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.muted-text {
  overflow-wrap: anywhere;
}

.security-card {
  margin-top: 18px;
  border-top: 1px solid var(--line-soft);
  padding-top: 18px;
}

.toggle-field {
  display: grid;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(10px);
}

.gate-dialog {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
}

.gate-badge {
  width: fit-content;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(10, 132, 255, 0.1);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.gate-dialog h2 {
  margin: 0;
  font-size: 24px;
}

.gate-dialog p {
  margin: 0;
}

.gate-field {
  display: grid;
  gap: 8px;
}

.gate-field span {
  font-size: 14px;
  color: var(--muted);
}

.gate-error {
  color: #b42318;
  font-size: 14px;
}

body.is-locked {
  overflow: hidden;
}

body.is-auth-locked {
  overflow: hidden;
}

:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.22);
  outline-offset: 2px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .split-layout,
  .assistant-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .experiment-list {
    max-height: 360px;
  }
}

@media (max-width: 900px) {
  .topbar {
    display: grid;
  }

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

  .filter-grid,
  .report-controls,
  .sync-grid,
  .form-row.two,
  .form-row.three {
    grid-template-columns: minmax(0, 1fr);
  }

  .attachment-item {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .attachment-item > :not(.remove-attachment) {
    grid-column: 1 / 2;
  }

  .attachment-preview {
    grid-column: 1 / 2;
  }

  .remove-attachment {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
  }

  .data-row {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 5px;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    display: block;
    height: auto;
    min-height: calc(70px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    border-right: 0;
    background: rgba(250, 250, 250, 0.9);
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 24px rgba(0, 0, 0, 0.07);
  }

  .brand,
  .sidebar-footer {
    display: none;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
  }

  .nav-item {
    display: flex;
    min-height: 56px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    font-size: 11px;
    font-weight: 650;
    line-height: 1.18;
    padding: 7px 4px;
    text-align: center;
    white-space: normal;
    word-break: keep-all;
  }

  .nav-item.is-active {
    border-color: rgba(10, 132, 255, 0.18);
    background: var(--primary-soft);
    box-shadow: none;
  }

  .workspace {
    padding: 16px 14px 96px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 14px;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .topbar p {
    font-size: 13px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    width: 100%;
  }

  .topbar-actions .primary-button,
  .topbar-actions .secondary-button {
    width: 100%;
    min-height: 38px;
    padding: 8px 6px;
    font-size: 12px;
  }

  .panel {
    padding: 14px;
  }

  .panel-header,
  .subsection-header {
    display: grid;
    gap: 10px;
  }

  .panel h2 {
    font-size: 16px;
  }

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

  .experiment-item-title {
    white-space: normal;
  }

  .step-item {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .step-item .step-time,
  .step-item .step-text,
  .step-item .inline-check {
    grid-column: 1 / 2;
  }

  .step-item .remove-step {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
  }

  .editor-actions,
  .sync-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .editor-actions .primary-button,
  .editor-actions .secondary-button,
  .editor-actions .danger-button,
  .sync-actions .secondary-button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding-inline: 10px;
  }

  .nav-item {
    font-size: 10px;
    padding-inline: 2px;
  }
}

@media (max-width: 340px) {
  .topbar-actions {
    grid-template-columns: minmax(0, 1fr);
  }
}

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

  .sidebar,
  .topbar-actions,
  .report-controls,
  .panel-header .primary-button {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .workspace {
    padding: 0;
  }

  .panel {
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .view {
    display: none !important;
  }

  #view-reports {
    display: block !important;
  }
}
