/* Tool-scoped styles keep shared site changes from altering the editor layout. */
/* Page foundation and design tokens */
body.json-format-page {
  color-scheme: light;
  --json-page: #f3f6f9;
  --json-panel: #ffffff;
  --json-control: #f7f9fb;
  --json-text: #172033;
  --json-muted: #5d6b7d;
  --json-border: #cbd5e1;
  --json-border-strong: #aebaca;
  --json-primary: #086bd8;
  --json-primary-hover: #075bb6;
  --json-focus: #1473e6;
  --json-success: #087a45;
  --json-warning: #9a5a00;
  --json-error: #b42318;
  --json-info-bg: #e8f4ff;
  --json-message-bg: #f5f7fa;
  --json-on-primary: #ffffff;
  --json-disabled-text: #8994a3;
  --json-disabled-background: #e9edf2;
  --json-toolbar-background: #fbfcfd;
  --json-info-text: #07579e;
  --json-info-border: #9dd5ff;
  --json-error-border: #fecaca;
  --json-error-background: #fff5f5;
  --json-error-detail: #7f1d1d;
  --json-content-width: 1500px;
  --json-control-height: 36px;
  --json-radius-large: 10px;
  --json-radius-small: 6px;
  box-sizing: border-box;
  margin: 0;
  color: var(--json-text);
  background: var(--json-page);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

.json-format-page * {
  box-sizing: border-box;
}

/* Page frame and heading */
.json-format-main {
  width: min(var(--json-content-width), calc(100% - 32px));
  margin: 0 auto;
  padding-block: 26px 48px;
}

.json-format-page-header {
  margin-block-end: 16px;
}

.json-format-page-header h1 {
  margin: 8px 0 2px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.25;
}

.json-format-page-header p,
.json-format-panel-heading p {
  margin: 4px 0 0;
  color: var(--json-muted);
}

.json-format-page .breadcrumb {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.json-format-page .breadcrumb a {
  color: var(--json-primary);
}

.json-format-page .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Shared panel surfaces */
.json-format-notice,
.json-format-panel {
  border: 1px solid var(--json-border);
  border-radius: var(--json-radius-large);
  background: var(--json-panel);
}

.json-format-notice {
  margin-block-end: 14px;
  padding: 12px 14px;
  color: var(--json-info-text);
  background: var(--json-info-bg);
}

.json-format-panel {
  margin-block-end: 14px;
  overflow: hidden;
}

.json-format-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-block-end: 1px solid var(--json-border);
}

.json-format-panel-heading h2,
.json-format-editor-heading h3,
.json-error h3,
.json-format-about h2,
.json-format-about h3 {
  margin: 0;
}

.json-format-panel-heading h2 {
  font-size: 18px;
}

/* Actions, controls, and toolbars */
.json-format-actions,
.json-format-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.json-format-actions--push {
  margin-inline-start: auto;
}

.json-format-control {
  min-height: var(--json-control-height);
  border: 1px solid var(--json-border-strong);
  border-radius: var(--json-radius-small);
  color: var(--json-text);
  background: var(--json-control);
  font: inherit;
}

.json-format-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  font-weight: 600;
  cursor: pointer;
}

.json-format-button--primary {
  border-color: var(--json-primary);
  color: var(--json-on-primary);
  background: var(--json-primary);
}

/* Control interaction states */
.json-format-button:hover:not(:disabled) {
  border-color: var(--json-primary);
}

.json-format-button--primary:hover:not(:disabled) {
  background: var(--json-primary-hover);
}

.json-format-control:disabled {
  color: var(--json-disabled-text);
  background: var(--json-disabled-background);
  cursor: not-allowed;
}

.json-format-control:focus-visible,
.json-format-textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--json-focus) 35%, transparent);
  outline-offset: 1px;
}

.json-format-toolbar {
  min-height: 56px;
  padding: 10px 14px;
  border-block-end: 1px solid var(--json-border);
}

.json-format-toolbar--display {
  background: var(--json-toolbar-background);
}

.json-format-setting,
.json-format-range-setting,
.json-format-check,
.json-format-file-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--json-muted);
  white-space: nowrap;
}

.json-format-select,
.json-format-input {
  min-width: 130px;
  padding: 6px 10px;
}

.json-format-range-setting input[type="range"] {
  width: 105px;
}

.json-format-range-setting output {
  min-width: 48px;
  color: var(--json-text);
  font-variant-numeric: tabular-nums;
}

.json-format-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--json-primary);
}

/* Editor layout and user-controlled sizing */
.json-format-workspace,
.json-format-editor-pane,
.json-format-code-stage {
  min-width: 0;
}

.json-format-workspace {
  /* Values updated by the display controls. */
  --json-font-size: 14px;
  --json-editor-height: 620px;
  --json-input-ratio: 50%;
  --json-output-ratio: 50%;
  display: grid;
  grid-template-columns: var(--json-input-ratio) var(--json-output-ratio);
  color: var(--editor-text);
  background: var(--editor-background);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: var(--json-font-size);
  line-height: 1.65;
}

.json-format-workspace[data-font="consolas"] {
  font-family: Consolas, "Courier New", monospace;
}

.json-format-workspace[data-font="monospace"] {
  font-family: monospace;
}

/* Editor themes and syntax colors */
.json-format-editor-panel[data-theme="light"] {
  /* Editor surfaces */
  --editor-background: #ffffff;
  --editor-heading: #f7f9fb;
  --editor-gutter: #eef2f6;
  --editor-text: #1f2328;
  --editor-muted: #657080;
  --editor-border: #cbd5e1;
  --editor-selection: rgba(38, 139, 210, 0.24);

  /* JSON syntax */
  --token-key: #0451a5;
  --token-string: #a31515;
  --token-number: #098658;
  --token-boolean: #0000ff;
  --token-null: #0000ff;
  --token-punctuation: #1f2328;
}

.json-format-editor-panel[data-theme="dark"] {
  color-scheme: dark;

  /* Editor surfaces */
  --editor-background: #1e1e1e;
  --editor-heading: #181c22;
  --editor-gutter: #181818;
  --editor-text: #d4d4d4;
  --editor-muted: #9aa6b4;
  --editor-border: #3b414b;
  --editor-selection: rgba(38, 139, 210, 0.38);

  /* JSON syntax */
  --token-key: #9cdcfe;
  --token-string: #ce9178;
  --token-number: #b5cea8;
  --token-boolean: #569cd6;
  --token-null: #569cd6;
  --token-punctuation: #d4d4d4;
}

.json-format-editor-pane {
  color: var(--editor-text);
  background: var(--editor-background);
}

.json-format-editor-pane + .json-format-editor-pane {
  border-inline-start: 1px solid var(--editor-border);
}

/* Editor interaction states */
.json-format-editor-pane.is-dragging {
  box-shadow: inset 0 0 0 3px var(--json-primary);
}

.json-format-editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 9px 14px;
  border-block-end: 1px solid var(--editor-border);
  background: var(--editor-heading);
}

.json-format-editor-heading div {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.json-format-editor-heading h3 {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  white-space: nowrap;
}

.json-format-editor-heading span {
  overflow: hidden;
  color: var(--editor-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.json-format-editor-body {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  height: var(--json-editor-height);
  min-height: 0;
  overflow: hidden;
}

.json-format-line-numbers,
.json-format-highlight,
.json-format-textarea {
  margin: 0;
  border: 0;
  font: inherit;
  line-height: inherit;
  tab-size: 4;
  white-space: pre;
}

.json-format-line-numbers {
  min-height: 100%;
  padding: 14px 10px;
  overflow: hidden;
  color: var(--editor-muted);
  background: var(--editor-gutter);
  text-align: end;
  user-select: none;
}

.json-format-code-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--editor-background);
}

.json-format-highlight,
.json-format-textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 14px;
}

.json-format-highlight {
  width: max-content;
  min-width: 100%;
  min-height: 100%;
  overflow: visible;
  color: var(--editor-text);
  pointer-events: none;
}

.json-format-textarea {
  z-index: 1;
  resize: none;
  overflow: auto;
  color: transparent;
  background: transparent;
  caret-color: var(--editor-text);
  -webkit-text-fill-color: transparent;
}

.json-format-textarea::selection {
  color: transparent;
  background: var(--editor-selection);
}

.json-format-textarea::placeholder {
  color: var(--editor-muted);
  -webkit-text-fill-color: var(--editor-muted);
}

.json-format-code-stage.is-plain .json-format-highlight {
  display: none;
}

.json-format-code-stage.is-plain .json-format-textarea {
  color: var(--editor-text);
  -webkit-text-fill-color: var(--editor-text);
}

/* JSON syntax tokens */
.json-token--key {
  color: var(--token-key);
}

.json-token--string {
  color: var(--token-string);
}

.json-token--number {
  color: var(--token-number);
}

.json-token--boolean {
  color: var(--token-boolean);
}

.json-token--null {
  color: var(--token-null);
}

.json-token--punctuation {
  color: var(--token-punctuation);
}

/* Messages, errors, and results */
.json-message {
  min-height: 42px;
  margin: 0;
  padding: 10px 14px;
  border-block-start: 1px solid var(--json-border);
  color: var(--json-muted);
  background: var(--json-message-bg);
}

.json-message--success {
  color: var(--json-success);
}

.json-message--warning {
  color: var(--json-warning);
}

.json-message--error {
  color: var(--json-error);
}

.json-error {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-block-start: 1px solid var(--json-error-border);
  color: var(--json-error);
  background: var(--json-error-background);
}

/* Visibility states override component display declarations. */
.json-error[hidden],
.json-format-result-panel[hidden] {
  display: none;
}

.json-error p {
  margin: 4px 0;
}

.json-error pre {
  max-width: min(900px, 75vw);
  margin: 6px 0 0;
  overflow: auto;
  color: var(--json-error-detail);
}

.json-format-file-name {
  flex-wrap: wrap;
}

.json-format-file-name input {
  width: 260px;
}

.json-format-stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin: 0;
}

.json-format-stats div {
  min-width: 0;
  padding: 14px;
  border-inline-end: 1px solid var(--json-border);
}

.json-format-stats div:last-child {
  border-inline-end: 0;
}

.json-format-stats dt {
  color: var(--json-muted);
  font-size: 12px;
}

.json-format-stats dd {
  margin: 2px 0 0;
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* Tool description */
.json-format-about {
  padding: 22px;
}

.json-format-about-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
}

.json-format-about li + li {
  margin-block-start: 4px;
}

.json-format-privacy {
  padding: 12px;
  border: 1px solid var(--json-info-border);
  border-radius: var(--json-radius-small);
  color: var(--json-info-text);
  background: var(--json-info-bg);
}

/* Responsive layout */
@media (max-width: 900px) {
  /* Narrow desktop and tablet */
  .json-format-main {
    width: calc(100% - 20px);
  }

  .json-format-panel-heading,
  .json-error {
    align-items: stretch;
    flex-direction: column;
  }

  .json-format-actions--push {
    margin-inline-start: 0;
  }

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

  .json-format-editor-pane + .json-format-editor-pane {
    border-block-start: 1px solid var(--editor-border);
    border-inline-start: 0;
  }

  .json-format-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .json-format-stats div:nth-child(3n) {
    border-inline-end: 0;
  }
}

@media (max-width: 580px) {
  /* Smartphone */
  .json-format-toolbar,
  .json-format-actions,
  .json-format-setting,
  .json-format-range-setting,
  .json-format-file-name {
    flex-direction: column;
    align-items: stretch;
  }

  .json-format-button,
  .json-format-select,
  .json-format-input,
  .json-format-file-name input {
    width: 100%;
  }

  .json-format-range-setting input[type="range"] {
    width: 100%;
  }

  .json-format-stats,
  .json-format-about-grid {
    grid-template-columns: 1fr;
  }

  .json-format-stats div,
  .json-format-stats div:nth-child(3n) {
    border-block-end: 1px solid var(--json-border);
    border-inline-end: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .json-format-page * {
    scroll-behavior: auto !important;
  }
}
