:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --text: #18211c;
  --muted: #637064;
  --border: #e5eae3;
  --accent: #0f7b63;
  --accent-dark: #0a5d4a;
  --accent-soft: #dff1eb;
  --danger: #b3261e;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
  overflow-x: hidden;
  padding: 8px;
}

.topbar,
.selection-panel,
.prompt-panel,
.results-panel,
.settings-panel {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 7px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 16px;
  font-weight: 650;
}

h2 {
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
}

#model-summary {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.small-button,
.secondary-button,
.ghost-button,
.primary-button {
  min-height: 28px;
  border-radius: 6px;
  padding: 4px 9px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.icon-button {
  width: 30px;
  padding: 0;
  background: #eef2ec;
  color: var(--text);
}

.icon-button:hover,
.secondary-button:hover,
.small-button:hover,
.ghost-button:hover {
  background: #e4ebe2;
}

.primary-button {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button,
.small-button {
  border: 1px solid var(--border);
  background: #f7f9f6;
  color: var(--text);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.wide-button {
  width: 100%;
}

.settings-panel,
.selection-panel,
.prompt-panel,
.results-panel {
  padding: 8px;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.field-row label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.compact-row {
  display: grid;
  grid-template-columns: 68px 1fr 30px;
  align-items: center;
  column-gap: 8px;
}

.compact-row label {
  color: var(--muted);
}

.compact-row output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 30px;
  padding: 5px 8px;
}

textarea {
  min-height: 88px;
  max-height: 180px;
  padding: 7px 8px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 123, 99, 0.16);
}

.settings-actions,
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.results-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-ghost-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  width: 28px;
  min-width: 28px;
  border: 1px solid transparent;
  padding: 0;
}

.icon-ghost-button:hover,
.icon-ghost-button:focus-visible,
.icon-ghost-button.active {
  border-color: var(--border);
}

.icon-ghost-button[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 10;
  max-width: 180px;
  border-radius: 6px;
  background: rgba(24, 33, 28, 0.94);
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  padding: 6px 8px;
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  transform: translateY(2px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.icon-ghost-button[data-tooltip]:hover::after,
.icon-ghost-button[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.inline-icon {
  width: 16px;
  height: 16px;
  fill: none;
  pointer-events: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.section-title-group {
  min-width: 0;
}

.selection-summary {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-preview {
  min-height: 0;
  max-height: 96px;
  margin-top: 6px;
  overflow: auto;
  border: 1px solid #eff3ee;
  border-radius: 6px;
  background: #fbfcfa;
  color: var(--muted);
  padding: 7px 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.selection-preview.has-text {
  color: var(--text);
}

.preset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.prompt-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  min-width: 0;
}

.prompt-header-group {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.prompt-panel-body {
  margin-bottom: 6px;
}

.generate-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.generate-row .wide-button {
  width: auto;
  min-width: 0;
  flex: 1 1 180px;
}

.auto-generate-control {
  display: inline-flex;
  align-items: center;
  flex: 0 1 auto;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.auto-generate-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.auto-generate-switch {
  position: relative;
  width: 30px;
  height: 18px;
  border-radius: 999px;
  background: #d7ded8;
  transition: background 120ms ease;
}

.auto-generate-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(24, 33, 28, 0.18);
  transition: transform 120ms ease;
}

.auto-generate-toggle:checked + .auto-generate-switch {
  background: var(--accent);
}

.auto-generate-toggle:checked + .auto-generate-switch::after {
  transform: translateX(12px);
}

.preset-chip {
  border: 1px solid #d8e6df;
  border-radius: 999px;
  background: #f2f7f4;
  color: #174d41;
  padding: 3px 7px;
  font-size: 11px;
  line-height: 1.2;
}

.preset-chip:hover,
.preset-chip.active {
  background: #c8e6dc;
}

.prompt-summary-chip {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-line {
  min-height: 0;
  margin: 2px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.status-line:empty {
  display: none;
}

.status-line.error {
  color: var(--danger);
}

.alternatives-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alternative-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.alternative-text {
  padding: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.alternative-text.is-original-preview {
  color: var(--text);
}

.original-preview-change {
  font-weight: 700;
}

.changed-word {
  border-radius: 3px;
  color: #0b7a32;
  cursor: pointer;
  font-weight: 600;
  transition: background 120ms ease;
}

.changed-word:hover {
  background: #e7f3ea;
}

.alternative-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 8px 6px;
}

.alternative-actions button {
  min-height: 0;
  flex: 0 0 auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 0;
}

.alternative-actions button:hover {
  background: transparent;
  color: var(--text);
}

@media (max-width: 320px) {
  .compact-row {
    grid-template-columns: 1fr;
  }
}
