:root {
  --bg: oklch(1 0 0);
  --surface: oklch(0.97 0.006 165);
  --surface-strong: oklch(0.935 0.01 165);
  --ink: oklch(0.22 0.028 165);
  --muted: oklch(0.46 0.022 165);
  --line: oklch(0.87 0.012 165);
  --brand: oklch(0.34 0.075 165);
  --primary: oklch(0.52 0.17 56.6);
  --primary-hover: oklch(0.46 0.16 56.6);
  --primary-soft: oklch(0.95 0.035 56.6);
  --danger: oklch(0.55 0.19 25);
  --success: oklch(0.48 0.12 150);
  --focus: oklch(0.62 0.16 245);
  --on-fill: oklch(1 0 0);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--surface); }
body { margin: 0; min-height: 100vh; background: var(--surface); }
button, input, select, textarea { font: inherit; color: inherit; }
button, select, input { min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
[hidden] { display: none !important; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: 1.35rem; line-height: 1.25; }
h2 { margin-bottom: 4px; font-size: 1.12rem; line-height: 1.3; }

:focus, :focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.boot-status { padding: 40px 20px; text-align: center; color: var(--muted); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
  width: min(100%, 430px);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
}
.product-mark { margin-bottom: 5px; color: var(--brand); font-weight: 750; }
.login-copy, .subtitle, .panel-heading p { margin-bottom: 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.login-copy { margin-bottom: 24px; }
.sso-login { display: flex; align-items: center; justify-content: center; text-decoration: none; }
.emergency-login { margin-top: 18px; border-top: 1px solid var(--line); }
.emergency-login summary {
  padding: 18px 0 4px;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 650;
  cursor: pointer;
}
.emergency-login form { margin-top: 16px; }

.app-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(16px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.app-header .product-mark { margin-bottom: 1px; }
.user-actions { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: .88rem; }

.workspace {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 3vw, 42px) 48px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: 20px;
  align-items: start;
}
.results-column { min-width: 0; display: grid; gap: 20px; }
.panel {
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
}
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; }
.compact-heading { margin-bottom: 18px; }
.step-label {
  flex: none;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--brand);
  font-size: .875rem;
  font-weight: 700;
}

form { display: grid; gap: 22px; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend, .field > label, .inline-save > label, .preset-row > label { margin-bottom: 8px; font-size: .9rem; font-weight: 700; }
legend { padding: 0; }
.field { min-width: 0; display: grid; align-content: start; }
.field.compact { max-width: 210px; margin-top: 12px; }
.optional { color: var(--muted); font-weight: 500; }

input:not([type="radio"]):not([type="checkbox"]), select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  padding: 10px 12px;
  transition: border-color 180ms, background-color 180ms;
}
textarea { resize: vertical; line-height: 1.55; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }

.style-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.style-card {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 180ms, background-color 180ms;
}
.style-card:hover { border-color: var(--brand); }
.style-card:has(input:checked) { border-color: var(--primary-hover); background: var(--primary-soft); }
.style-card:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.style-card input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.style-name { font-size: .92rem; font-weight: 750; }
.style-description { grid-column: 1 / -1; color: var(--muted); font-size: .875rem; line-height: 1.45; }
.selected-text { display: none; color: var(--brand); font-size: .875rem; font-weight: 750; }
.style-card:has(input:checked) .selected-text { display: inline; }

.segmented-options { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented-options label, .issue-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.segmented-options label:has(input:checked), .issue-grid label:has(input:checked) { border-color: var(--brand); background: var(--surface); font-weight: 650; }
input[type="radio"], input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.description-list { display: grid; gap: 10px; margin-top: 12px; }
.quick-grid, .advanced-grid { display: grid; gap: 12px; }
.quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.advanced-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.help-text, .error-text { margin: 6px 0 0; font-size: .875rem; line-height: 1.4; }
.help-text { color: var(--muted); }
.error-text { min-height: 0; color: var(--danger); font-weight: 600; }
.error-text:empty { display: none; }
.form-error { margin: -8px 0 0; }

.advanced { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.advanced summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.advanced-grid { padding: 4px 0 18px; }

.button {
  min-height: 44px;
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 720;
  transition: background-color 180ms, border-color 180ms, transform 150ms;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.primary { background: var(--primary); color: var(--on-fill); }
.primary:hover:not(:disabled) { background: var(--primary-hover); }
.secondary { border-color: var(--line); background: var(--bg); color: var(--brand); }
.secondary:hover:not(:disabled) { border-color: var(--brand); background: var(--surface); }
.brand-button { background: var(--brand); color: var(--on-fill); }
.brand-button:hover:not(:disabled) { background: var(--ink); }
.danger-button { border-color: var(--line); background: var(--bg); color: var(--danger); }
.danger-button:hover:not(:disabled) { border-color: var(--danger); }
.full { width: 100%; }
.generate-button { width: 100%; min-width: 148px; }
.button[data-loading="true"] { cursor: wait; opacity: .72; }

.result-textarea { min-height: 250px; background: var(--surface); }
.result-help { margin-top: 9px; }
.correction-result { min-height: 160px; margin: 16px 0 10px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.inline-save { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; margin-top: 14px; padding: 14px; background: var(--surface); border-radius: 10px; }
.inline-save label { grid-column: 1 / -1; }
.preset-row { display: grid; grid-template-columns: minmax(130px, 1fr) auto auto auto; gap: 8px; align-items: end; margin-top: 18px; }
.preset-row label { grid-column: 1 / -1; }
.issue-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 11px 14px;
  border-radius: 9px;
  background: var(--brand);
  color: var(--on-fill);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms;
}
.toast:not(:empty) { opacity: 1; }
.error-banner {
  position: fixed;
  z-index: 2;
  top: 92px;
  right: 18px;
  max-width: min(390px, calc(100vw - 36px));
  padding: 11px 14px;
  border: 1px solid var(--danger);
  border-radius: 9px;
  background: var(--bg);
  color: var(--danger);
  font-size: .875rem;
  font-weight: 700;
}
.error-banner:empty { display: none; }

@media (max-width: 839px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .settings-panel { order: 1; }
  .results-column { order: 2; }
  .app-header { align-items: flex-start; flex-wrap: wrap; }
  .app-header > div:first-child { flex: 1 1 210px; }
  .user-actions { align-items: flex-end; flex-direction: column; gap: 6px; }
}

@media (max-width: 580px) {
  .login-shell { padding: 14px; }
  .login-panel, .panel { padding: 18px; }
  .app-header { gap: 10px; padding: 13px 16px; }
  .user-actions { flex: 1 1 120px; }
  .workspace { padding: 14px 12px 32px; gap: 14px; }
  .error-banner { top: 116px; }
  .style-grid, .quick-grid, .advanced-grid { grid-template-columns: minmax(0, 1fr); }
  .preset-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .preset-row select { grid-column: 1 / -1; }
  .preset-row .button { padding-inline: 8px; }
  .inline-save { grid-template-columns: minmax(0, 1fr); }
  .inline-save label { grid-column: auto; }
  .result-actions .button { flex: 1 1 150px; }
}

@media (max-width: 339px) {
  .issue-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
