:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #172033;
  background: #f3f6fa;
  font-size: 14px;
}

html {
  width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  width: 100%;
  min-width: 320px;
  overflow-x: hidden;
  background: #f3f6fa;
}

.topbar {
  min-height: 60px;
  padding: 8px 18px 6px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #d3dce7;
  background: #fff;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: 0;
}

.topbar p {
  margin: 2px 0 0;
  color: #617086;
  font-size: 13px;
}

.topbar p.error { color: #b4232c; }
.topbar p.success { color: #087c68; }

.route {
  max-width: 42%;
  color: #4a5b73;
  font-size: 13px;
  overflow-wrap: anywhere;
  text-align: right;
}

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

.floating-window {
  position: fixed;
  z-index: 50;
  top: 70px;
  right: 14px;
  width: min(350px, calc(100vw - 28px));
  max-height: min(680px, calc(100vh - 84px));
  overflow: hidden;
  border: 1px solid #8795a8;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 14px 38px rgba(17, 24, 39, .24);
}

.window-header {
  min-height: 42px;
  padding: 6px 8px 6px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #cbd5e1;
  background: #f7f9fc;
  color: #172033;
}

.window-header > div:first-child {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.window-actions { display: flex; gap: 5px; }

.window-button {
  width: 31px;
  min-width: 31px;
  height: 29px;
  min-height: 29px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
}

#browserState {
  color: #617086;
  font-size: 12px;
  font-weight: 400;
}

.browser-panel-body {
  max-height: calc(100vh - 126px);
  padding: 9px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: start;
  overflow: auto;
}

.browser-stage {
  position: relative;
  width: 100%;
  max-width: none;
  min-height: 250px;
  overflow: hidden;
  border: 1px solid #8c99aa;
  border-radius: 3px;
  background: #111827;
}

#browserView {
  display: none;
  width: 100%;
  height: auto;
  user-select: none;
  touch-action: none;
  -webkit-user-drag: none;
}

#browserPlaceholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #cbd5e1;
  font-size: 13px;
}

.browser-controls {
  display: grid;
  gap: 8px;
}

.browser-controls button { min-height: 27px; padding: 3px 6px; font-size: 12px; }
.browser-controls input { height: 29px; font-size: 13px; }

.browser-window.is-minimized {
  top: auto;
  right: 12px;
  bottom: 12px;
  width: min(230px, calc(100vw - 24px));
}

.browser-window.is-minimized .window-content { display: none; }
.browser-window.is-minimized .window-header { border-bottom: 0; }

.browser-window.is-expanded {
  inset: 8px;
  width: auto;
  max-height: none;
}

.browser-window.is-expanded .browser-panel-body {
  height: calc(100vh - 58px);
  max-height: none;
  grid-template-columns: minmax(320px, 500px) minmax(220px, 1fr);
}

.browser-restore {
  position: fixed;
  z-index: 45;
  right: 12px;
  bottom: 12px;
  min-width: 96px;
  color: #fff;
  border-color: #1f5fc7;
  background: #2365d8;
  box-shadow: 0 8px 22px rgba(17, 24, 39, .22);
}

.modal-layer {
  position: fixed;
  z-index: 100;
  inset: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, .5);
}

.result-dialog {
  width: min(400px, 100%);
  max-height: min(480px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid #8795a8;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .28);
}

.recognize-dialog {
  width: min(460px, 100%);
  overflow: hidden;
  border: 1px solid #8795a8;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .28);
}

.recognize-body {
  padding: 12px;
  display: grid;
  gap: 10px;
}

#recognizeInput {
  min-height: 180px;
  resize: vertical;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

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

.result-header {
  min-height: 44px;
  padding: 7px 8px 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #cbd5e1;
}

.result-header h2 { margin: 0; }

#resultContent {
  min-height: 64px;
  max-height: min(280px, calc(100vh - 190px));
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #172033;
  background: #fff;
  font: 13px/1.55 Consolas, "Microsoft YaHei", monospace;
}

.result-dialog.is-error .result-header { color: #b4232c; }

.result-close {
  width: calc(100% - 24px);
  margin: 0 12px 12px;
}

.login-page {
  min-height: 100vh;
  padding: 20px;
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(340px, 100%);
  padding: 22px;
  border: 1px solid #bcc8d6;
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 14px 38px rgba(17, 24, 39, .16);
}

.login-panel h1 { font-size: 20px; }
.login-panel p { margin: 6px 0 14px; color: #617086; }
.login-panel form { display: grid; gap: 9px; }
.login-panel input { height: 40px; font-size: 18px; text-align: center; }
.login-panel button { min-height: 38px; }
#loginError { min-height: 21px; margin-top: 8px; color: #b4232c; font-size: 13px; }

.browser-actions,
.browser-text-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.workspace {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 8px 18px 12px;
  display: block;
}

.left-column,
.right-column {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.section {
  min-width: 0;
  padding: 7px 11px 8px;
  border: 1px solid #bcc8d6;
  border-radius: 4px;
  background: #fff;
}

h2 {
  margin: 0 0 5px;
  font-size: 14px;
  line-height: 1.25;
  letter-spacing: 0;
}

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

.section-heading h2 { margin: 0; }
.section-heading button { min-height: 27px; padding: 3px 9px; }

.session-heading > div {
  min-width: 0;
  display: grid;
  gap: 1px;
}

#sessionSummary {
  color: #617086;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.context-details {
  margin-bottom: 5px;
  padding-top: 3px;
  border-top: 1px solid #e2e8f0;
}

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

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

label,
.field {
  min-width: 0;
  display: grid;
  gap: 2px;
  color: #33445d;
  font-size: 12px;
}

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

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #aebaca;
  border-radius: 3px;
  color: #111827;
  background: #fff;
}

input,
select {
  height: 29px;
  padding: 4px 8px;
}

input[readonly],
textarea[readonly] { background: #f7f9fc; }

textarea {
  padding: 7px 8px;
  resize: vertical;
  line-height: 1.4;
  font-family: Consolas, "Microsoft YaHei", monospace;
}

label + label,
.grid + label,
label + .actions { margin-top: 5px; }

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid #2365d8;
  outline-offset: 1px;
}

.actions {
  display: grid;
  gap: 7px;
}

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

button {
  min-height: 29px;
  padding: 5px 10px;
  border: 1px solid #aebaca;
  border-radius: 3px;
  color: #223047;
  background: #edf2f7;
  cursor: pointer;
}

button:hover:not(:disabled) { filter: brightness(.96); }
button:disabled { opacity: .55; cursor: wait; }

button.primary { color: #fff; border-color: #1f5fc7; background: #2365d8; }
button.dark { color: #fff; border-color: #1d2635; background: #1d2635; }
button.success { color: #fff; border-color: #087c68; background: #0b8a73; }

.split-control {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.submit-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 1fr);
  gap: 12px;
  align-items: center;
}

.consent {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.consent input { width: 18px; height: 18px; flex: 0 0 auto; }
.submit-button { width: 100%; }

@media (max-width: 720px) {
  input,
  select,
  textarea { font-size: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .route { max-width: none; text-align: left; }
  .workspace { padding: 8px; }
  .floating-window { top: 54px; right: 10px; width: min(320px, calc(100vw - 20px)); max-height: calc(100vh - 72px); }
  .browser-panel-body { max-height: calc(100vh - 122px); padding: 7px; }
  .browser-window.is-expanded { inset: 0; border-radius: 0; }
  .browser-window.is-expanded .browser-panel-body { height: calc(100vh - 42px); grid-template-columns: 1fr; }
  .section-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .section-heading button { max-width: 132px; white-space: normal; }
  .session-actions { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
  .grid.two,
  .grid.three,
  .actions.three,
  .submit-section { grid-template-columns: 1fr; }
  .modal-layer { padding: 18px; }
}

@media (max-width: 480px) {
  .section-heading { grid-template-columns: minmax(0, 1fr) 96px; }
  .section-heading button { width: 96px; max-width: 96px; padding-inline: 5px; font-size: 12px; }
  .session-actions button { padding-inline: 3px; font-size: 12px; }
}
