/*
 * SOSEC tool foundation
 *
 * This file supplies the common paper, ink, focus, control and state
 * language for tool pages. It deliberately does not choose a tool's editor
 * height, parent layout, column count, card hierarchy or mobile composition.
 * Those decisions stay beside each tool's HTML.
 */

body[data-surface="tool"] {
  --surface-field: #f6f1e7;
  --surface-output: #f0eadf;
  --tool-paper: #f8f3e9;
  --tool-surface: #fbf8f0;
  --tool-field: var(--surface-field);
  --tool-output: var(--surface-output);
  --tool-ink: #211f1a;
  --tool-muted: #706b61;
  --tool-gold: #b7924b;
  --tool-gold-dark: #826329;
  --tool-line: #918b80;
  --tool-hairline: rgba(54, 49, 39, 0.13);
  --tool-focus: rgba(183, 146, 75, 0.2);
  --radius-control: 2px;
  --radius-panel: 3px;
  --control-height: 40px;
  --font-ui: "Segoe UI", "Microsoft YaHei UI", "Noto Sans SC", sans-serif;
  --font-mono: "Cascadia Code", Consolas, "Liberation Mono", monospace;
  background: var(--tool-paper);
  color: var(--tool-ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
}

body[data-surface="tool"] [hidden] {
  display: none !important;
}

body[data-surface="tool"] main {
  padding-top: 16px;
}

/* Compact product chrome. Keeping the boundary note beside the title on wide
   screens gives the task itself the first viewport; tool workbench geometry
   remains entirely page-owned below this header. */
body[data-surface="tool"] main > .tool-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 0.34fr);
  column-gap: 30px;
  row-gap: 8px;
  align-items: start;
  max-width: none;
  margin: 0;
  border-bottom: 1px solid var(--tool-line);
  padding: 0 0 24px;
}

body[data-surface="tool"] main > .tool-header h1 {
  grid-column: 1;
  margin: 0;
  color: var(--tool-ink);
  font-family: var(--font-ui);
  font-size: 30px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.015em;
}

body[data-surface="tool"] main > .tool-header .lead {
  grid-column: 1;
  max-width: 850px;
  margin: 8px 0 0;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
}

body[data-surface="tool"] main > .tool-header .tool-note {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  max-width: 76ch;
  margin: 0;
  border-left: 1px solid var(--tool-gold);
  padding: 1px 0 1px 12px;
  color: var(--tool-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.55;
}

body[data-surface="tool"] main > .tool-header > .tool-header-help {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-width: 0;
  color: var(--tool-muted);
  font: 14px/1.6 var(--font-ui);
}
body[data-surface="tool"] .tool-header-help > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  align-content: center;
  cursor: pointer;
  font-weight: 500;
}

body[data-surface="tool"] .tool-header-help > summary::after {
  content: "+";
}

body[data-surface="tool"] .tool-header-help[open] > summary::after {
  content: "−";
}
body[data-surface="tool"] main > .tool-header .tool-header-help .tool-note {
  margin-top: 8px;
  border: 0;
  padding: 0;
  font-size: 14px;
}

/* Multiple boundary notes flow instead of occupying the same grid cell. */
body[data-surface="tool"] main > .tool-header:has(> .tool-note ~ .tool-note) {
  grid-template-columns: minmax(0, 1fr);
}

body[data-surface="tool"] main > .tool-header + .tool-panel {
  margin-top: 24px;
}
body[data-surface="tool"] main > .tool-header:has(> .tool-note ~ .tool-note) > .tool-note {
  grid-column: 1;
  grid-row: auto;
  max-width: none;
  border-left: 0;
  padding: 0;
}
body[data-surface="tool"] main label:has(> input[type="checkbox"]),
body[data-surface="tool"] main label:has(> input[type="radio"]) {
  background: transparent;
  border-color: var(--tool-hairline);
  border-radius: var(--radius-control);
}

/* These declarations prevent local overflow without turning the named
   elements into a shared component hierarchy. */
body[data-surface="tool"] :is(
  .tool-panel,
  .tool-form,
  .tool-section,
  .tool-actions,
  .button-row,
  .output-field,
  .output-toolbar-row,
  .output-toolbar,
  .tool-output-grid,
  .output-grid,
  .tool-metric-grid,
  .tool-metric,
  .tool-result-list,
  .tool-result-card,
  .tool-filter-bar,
  .tool-segmented,
  .tool-verdict,
  .tool-status
) {
  min-width: 0;
  max-width: 100%;
}

body[data-surface="tool"] main label {
  color: var(--tool-ink);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
}

body[data-surface="tool"] .tool-panel :is(h2, h3) {
  font-family: var(--font-ui);
  font-size: 18px;
  line-height: 1.5;
  letter-spacing: normal;
}

body[data-surface="tool"] .tool-panel label:has(> input[type="checkbox"]) {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
}

/* Controls share material and interaction feedback. Page-specific classes
   loaded with the template remain free to replace any of these properties. */
body[data-surface="tool"] .tool-panel :where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  textarea,
  select
) {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--tool-line);
  border-radius: var(--radius-control);
  background: var(--tool-field);
  color: var(--tool-ink);
  box-shadow: none;
  font-weight: 400;
  font-size: 14px;
  transition: border-color 130ms ease, background-color 130ms ease, box-shadow 130ms ease;
}

body[data-surface="tool"] .tool-panel :where(
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  button,
  .button
) {
  min-height: var(--control-height);
}

body[data-surface="tool"] .tool-panel textarea {
  color: var(--tool-ink);
  font-family: var(--font-mono);
  line-height: 1.5;
  resize: vertical;
}

body[data-surface="tool"] .tool-panel :where(input, textarea, select)::placeholder {
  color: var(--tool-muted);
  opacity: 1;
}

body[data-surface="tool"] .tool-panel :where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  textarea,
  select
):hover {
  border-color: rgba(130, 99, 41, 0.58);
}

body[data-surface="tool"] .tool-panel :where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  textarea,
  select
):focus-visible {
  border-color: var(--tool-gold-dark);
  background: #f9f5ec;
  box-shadow: 0 0 0 3px var(--tool-focus);
  outline: 0;
}

body[data-surface="tool"] .tool-panel :where(textarea[readonly], input[readonly], pre) {
  background: var(--tool-output);
}

body[data-surface="tool"] .tool-panel input[type="file"] {
  padding: 5px;
  font-family: var(--font-ui);
}

body[data-surface="tool"] .tool-panel input[type="file"]::file-selector-button {
  min-height: 32px;
  margin-right: 9px;
  border: 1px solid var(--tool-line);
  border-radius: var(--radius-control);
  padding: 0 10px;
  background: transparent;
  color: var(--tool-ink);
  font: 700 12px/1 var(--font-ui);
  cursor: pointer;
}

body[data-surface="tool"] .tool-panel :where(button, .button) {
  border: 1px solid var(--tool-line);
  border-radius: var(--radius-control);
  padding: 0 13px;
  background: transparent;
  color: var(--tool-ink);
  box-shadow: none;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  transition: transform 80ms ease, border-color 130ms ease, background-color 130ms ease, color 130ms ease;
}

body[data-surface="tool"] .tool-panel :where(button, .button):hover:not(:disabled) {
  border-color: var(--tool-gold-dark);
  background: rgba(183, 146, 75, 0.1);
  color: var(--tool-gold-dark);
  text-decoration: none;
}

body[data-surface="tool"] .tool-panel :where(button, .button):active:not(:disabled) {
  transform: translateY(1px);
}

body[data-surface="tool"] .tool-panel :where(button.primary, .button.primary) {
  border-color: var(--tool-ink);
  background: var(--tool-ink);
  color: var(--tool-paper);
}

body[data-surface="tool"] .tool-panel :where(button.primary, .button.primary):hover:not(:disabled) {
  border-color: #403b32;
  background: #403b32;
  color: var(--tool-paper);
}

body[data-surface="tool"] .tool-panel :where(
  button[aria-pressed="true"],
  button.is-active,
  [aria-selected="true"]
) {
  border-color: var(--tool-gold-dark);
  background: rgba(183, 146, 75, 0.15);
  color: var(--tool-gold-dark);
  box-shadow: inset 0 -2px 0 var(--tool-gold);
}

body[data-surface="tool"] .tool-panel :where(button, .button):disabled,
body[data-surface="tool"] .tool-panel :where(button, .button)[aria-disabled="true"] {
  border-color: var(--tool-hairline);
  background: rgba(54, 49, 39, 0.035);
  color: var(--tool-muted);
  cursor: not-allowed;
  opacity: 0.55;
}

/* A drop target and state message have semantic material, but their parent
   layout remains wholly tool-owned. */
body[data-surface="tool"] .tool-file-drop {
  border-color: rgba(54, 49, 39, 0.35);
  background: rgba(244, 238, 226, 0.52);
}

body[data-surface="tool"] .tool-file-drop:is(.is-dragging, [data-dragging="true"]) {
  border-color: var(--tool-gold-dark);
  background: rgba(183, 146, 75, 0.13);
}

body[data-surface="tool"] :is(.tool-status, .status, [role="status"], [aria-live="polite"]) {
  color: var(--tool-muted);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

body[data-surface="tool"] :is(.tool-status, .status).error,
body[data-surface="tool"] :is(.tool-status, .status)[data-state="error"] {
  color: var(--red);
}

body[data-surface="tool"] :is(.tool-status, .status)[data-state="success"] {
  color: var(--green);
}

body[data-surface="tool"] :is(.tool-status, .status)[data-state="warning"] {
  color: var(--tool-gold-dark);
}

body[data-surface="tool"] .output-label {
  color: var(--tool-ink);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  overflow-wrap: anywhere;
}

body[data-surface="tool"] .output-toolbar button {
  min-width: 44px;
  min-height: 44px;
}

body[data-surface="tool"] .tool-output-more {
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

body[data-surface="tool"] .tool-output-more > summary {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 8px;
  border: 1px solid var(--tool-line);
  border-radius: var(--radius-control);
  list-style: none;
  font-size: 20px;
  line-height: 1;
}

body[data-surface="tool"] .tool-output-more > summary::-webkit-details-marker { display: none; }
body[data-surface="tool"] .tool-output-more > summary:hover { background: var(--surface-output); }
body[data-surface="tool"] .tool-output-menu {
  position: absolute;
  z-index: 5;
  inset: calc(100% + 4px) 0 auto auto;
  display: grid;
  gap: 4px;
  min-width: 132px;
  max-width: 240px;
  padding: 8px;
  border: 1px solid var(--tool-line);
  border-radius: var(--radius-control);
  background: var(--tool-paper);
  box-shadow: 0 6px 16px rgba(33,31,26,.12);
}

body[data-surface="tool"] .tool-output-menu button { width: 100%; text-align: start; }
body[data-surface="tool"] .output-toolbar-compact { flex-wrap: nowrap; flex: 0 0 auto; }
body[data-surface="tool"] .output-toolbar-compact > button { flex: 0 0 auto; }
body[data-surface="tool"] .output-toolbar-row:has(> .output-toolbar-compact) {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

body[data-surface="tool"] .tool-metric,
body[data-surface="tool"] .tool-result-card {
  overflow-wrap: anywhere;
}

body[data-surface="tool"] .tool-metric strong {
  color: var(--tool-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: normal;
  text-transform: none;
}

body[data-surface="tool"] .tool-metric :is(span, output) {
  color: var(--tool-ink);
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

body[data-surface="tool"] .tool-panel :where(fieldset, details) {
  min-width: 0;
  max-width: 100%;
}

body[data-surface="tool"] .tool-panel details summary {
  color: var(--tool-ink);
  cursor: pointer;
  font-family: var(--font-ui);
}

body[data-surface="tool"] .tool-panel details:not(.tool-output-more):not(.tool-result-card) > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
}

body[data-surface="tool"] .tool-panel details:not(.tool-output-more):not(.tool-result-card) > summary::after {
  content: "+";
  position: static;
  flex: 0 0 auto;
  color: var(--tool-muted);
  font: 16px/1 var(--font-ui);
}

body[data-surface="tool"] .tool-panel details[open]:not(.tool-output-more):not(.tool-result-card) > summary::after {
  content: "−";
}

body[data-surface="tool"] .tool-result-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
  align-items: start;
}

body[data-surface="tool"] .tool-result-card summary [class$="-head"] {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  gap: 4px;
}

body[data-surface="tool"] .tool-result-card summary [class$="-head"] > * {
  min-width: 0;
  max-width: 100%;
  text-align: start;
  white-space: normal;
}

body[data-surface="tool"] .tool-result-card > summary {
  position: relative;
  display: block;
  list-style: none;
  padding-inline-end: 28px;
  font-weight: 400;
}

body[data-surface="tool"] .tool-result-card > summary::-webkit-details-marker {
  display: none;
}

body[data-surface="tool"] .tool-result-card > summary::after {
  content: "+";
  position: absolute;
  inset-inline-end: 8px;
  top: 12px;
  color: var(--tool-muted);
  font: 16px/1 var(--font-ui);
}

body[data-surface="tool"] .tool-result-card[open] > summary::after {
  content: "−";
}

body[data-surface="tool"] .tool-result-card > summary strong {
  font-weight: 650;
}

body[data-surface="tool"] .tool-panel :where(table) {
  max-width: 100%;
  color: var(--tool-ink);
}

body[data-surface="tool"] .tool-panel :where(th) {
  color: var(--tool-muted);
  font-family: var(--font-ui);
}

body[data-surface="tool"] .related-tools {
  border-top-color: var(--tool-line);
}

body[data-surface="tool"] .related-tools-list a {
  border-color: var(--tool-hairline);
  background: transparent;
}

body[data-surface="tool"] .related-tools-list a:hover {
  border-color: var(--tool-gold-dark);
  background: rgba(183, 146, 75, 0.07);
  text-decoration: none;
}

/* The retired six-page rail is product chrome, not page geometry. A scoped
   selector is sufficient; no priority override is needed. */
body[data-surface="tool"] main :is(
  .tool-studio-index,
  .url-studio-number,
  .tool-studio-nav,
  .url-rail
) {
  display: none;
}

body[data-surface="tool"] .tool-studio-kicker,
body[data-surface="tool"] .url-studio-kicker {
  color: var(--tool-gold-dark);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.085em;
  text-transform: uppercase;
}

@media (max-width: 700px) {
  body[data-surface="tool"] {
    --control-height: 44px;
  }

  body[data-surface="tool"] .tool-panel summary {
    min-height: 44px;
    align-content: center;
  }

  body[data-surface="tool"] main {
    padding-top: 12px;
  }

  body[data-surface="tool"] main > .tool-header {
    display: block;
    padding-bottom: 20px;
  }

  body[data-surface="tool"] main > .tool-header h1 {
    font-size: 26px;
  }

  body[data-surface="tool"] main > .tool-header .lead {
    font-size: 14px;
    line-height: 1.6;
  }

  body[data-surface="tool"] main > .tool-header .tool-note {
    margin-top: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body[data-surface="tool"] *,
  body[data-surface="tool"] *::before,
  body[data-surface="tool"] *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
