:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --line: #d7dee6;
  --line-strong: #b7c2ce;
  --text: #17202b;
  --muted: #667485;
  --brand: #1d5d75;
  --brand-strong: #174a5d;
  --accent: #2f7d67;
  --slate: #52606f;
  --focus: #8cc7ff;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

h1,
h2,
p {
  margin: 0;
}

.topbar {
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  color: #fff;
  background: var(--brand);
  border-bottom: 1px solid var(--brand-strong);
}

h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 4px;
  color: #d7e4e8;
  font-size: 12px;
}

.mobile-summary,
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  white-space: nowrap;
}

.mobile-summary span {
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  color: #e8f2f5;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #55c887;
}

.workspace {
  min-height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: minmax(330px, 34vw) minmax(500px, 1fr) minmax(260px, 300px);
  gap: 12px;
  padding: 12px;
}

.left-pane,
.form-pane,
.log-pane {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.panel-title {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line);
}

h2 {
  flex: 0 0 auto;
  font-size: 15px;
}

.segmented {
  max-width: 100%;
  display: inline-flex;
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  scrollbar-width: thin;
}

button {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--brand);
  border-radius: 7px;
  color: #fff;
  background: var(--brand);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

button:hover {
  background: var(--brand-strong);
}

button:focus-visible,
input:focus,
select:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.segmented button {
  flex: 0 0 auto;
  min-height: 34px;
  border: 0;
  border-radius: 0;
  color: var(--text);
  background: #fff;
}

.segmented button.active {
  color: #fff;
  background: var(--accent);
}

.secondary {
  border-color: var(--slate);
  background: var(--slate);
}

.secondary:hover {
  background: #465260;
}

.icon-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-color: var(--line-strong);
  color: var(--text);
  background: #fff;
  font-size: 18px;
}

.document-preview {
  height: calc(100vh - 210px);
  min-height: 410px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: #e6ebef;
}

.document-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.sample-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.sample-actions .secondary {
  grid-column: 1 / -1;
}

.primary-action {
  background: var(--accent);
  border-color: var(--accent);
}

.primary-action:hover {
  background: #286b59;
}

form {
  padding: 12px;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(3, minmax(145px, 1fr));
  gap: 11px 12px;
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

legend {
  padding: 0 6px;
  color: var(--brand);
  font-weight: 700;
}

label {
  min-width: 0;
  display: grid;
  gap: 5px;
  color: #3a4654;
  font-size: 12px;
}

input,
select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
}

.wide {
  grid-column: span 2;
}

.form-id {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 2px;
}

.log-pane {
  display: flex;
  flex-direction: column;
}

#event_log {
  flex: 1;
  min-height: 220px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  color: #18212f;
  background: #fbfcfe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 1240px) {
  .workspace {
    grid-template-columns: minmax(330px, 40vw) minmax(480px, 1fr);
  }

  .log-pane {
    grid-column: 1 / -1;
  }

  #event_log {
    max-height: 260px;
  }
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: minmax(220px, 1fr) auto;
  }

  .mobile-summary {
    display: none;
  }

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

  .document-preview {
    height: auto;
    min-height: 0;
    max-height: 440px;
    aspect-ratio: 16 / 9;
  }

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

  .sample-actions .secondary {
    grid-column: auto;
  }

  fieldset {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
}

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

  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px;
  }

  h1 {
    font-size: 19px;
  }

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

  .mobile-summary {
    display: flex;
    flex-wrap: wrap;
  }

  .status {
    justify-self: start;
  }

  .workspace {
    gap: 10px;
    padding: 10px;
  }

  .left-pane,
  .form-pane,
  .log-pane {
    border-radius: 8px;
  }

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1 0 auto;
    min-width: max-content;
    padding: 0 12px;
  }

  .document-preview {
    max-height: none;
    aspect-ratio: 4 / 3;
    padding: 10px;
  }

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

  .sample-actions button,
  .toolbar button {
    min-height: 42px;
    padding: 0 10px;
  }

  form {
    padding: 10px;
  }

  fieldset {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 10px;
  }

  .wide {
    grid-column: span 1;
  }

  label {
    font-size: 13px;
  }

  input,
  select {
    height: 42px;
    font-size: 16px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  #event_log {
    max-height: 240px;
  }
}

@media (max-width: 420px) {
  .sample-actions {
    grid-template-columns: 1fr;
  }

  .form-id {
    white-space: normal;
  }
}
