:root {
  --green: #1fb796;
  --green-dark: #159f82;
  --navy: #163245;
  --navy-deep: #0f2634;
  --bronze: #8d7142;
  --teal: #00848b;
  --warning: #eb5844;
  --black: #151515;
  --white: #ffffff;
  --wash: #eaf4f1;
  --panel: #ffffff;
  --panel-soft: #f8fbfa;
  --ink: #112a39;
  --muted: #637783;
  --line: #d7e2df;
  --shadow: 0 18px 45px rgba(22, 50, 69, 0.13);
  --hero-overlay: rgba(15, 49, 58, 0.78);
}

body.dark {
  --wash: #0f1d25;
  --panel: #152c3a;
  --panel-soft: #102632;
  --ink: #f3fbfa;
  --muted: #adc1c8;
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
  --hero-overlay: rgba(9, 31, 40, 0.86);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--wash);
  font-family: Inter, Arial, Helvetica, sans-serif;
  font-weight: 700;
}

button,
select,
textarea,
input {
  font: inherit;
}

button,
select,
textarea,
input {
  outline-color: rgba(31, 183, 150, 0.5);
}

.app {
  width: min(1140px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.hero {
  position: relative;
  min-height: 330px;
  overflow: hidden;
  border-radius: 23px;
  background:
    linear-gradient(90deg, rgba(13, 39, 49, 0.96), var(--hero-overlay)),
    linear-gradient(135deg, #112f3b 0%, #245763 42%, #7e8f85 100%);
  color: var(--white);
  box-shadow: var(--shadow);
}

.hero-bg {
  position: absolute;
  inset: 0;
  opacity: 0.38;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.55), rgba(0, 132, 139, 0.36)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 86px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.06) 0 18%, transparent 18% 45%, rgba(255, 255, 255, 0.05) 45% 58%, transparent 58% 100%);
}

.hero-top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 48px 48px 0;
}

.hero-logo {
  width: 178px;
  height: auto;
  display: block;
  filter: brightness(0) invert(1);
}

.pill-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 168px;
  min-height: 48px;
  padding: 0 24px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: var(--white);
  font-size: 16px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 0 0 1px rgba(255, 255, 255, 0.08);
  pointer-events: none;
  user-select: none;
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 720px;
  padding: 68px 48px 42px;
}

.hero-kicker {
  margin: 0 0 8px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 20px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  color: var(--white);
  font-size: 68px;
  line-height: 0.98;
}

h2 {
  color: var(--ink);
  font-size: 34px;
  line-height: 1.05;
}

.theme-toggle {
  position: absolute;
  right: 48px;
  bottom: 42px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 6px 18px 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: var(--white);
  cursor: pointer;
  user-select: none;
}

.theme-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.32);
  transition: background 160ms ease;
}

.toggle-thumb {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--white);
  transition: transform 160ms ease;
}

.theme-toggle input:checked + .toggle-track {
  background: var(--green);
}

.theme-toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(24px);
}

.tool-status {
  position: sticky;
  top: 14px;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 340px) minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  margin: 18px auto 0;
  padding: 16px 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(22, 50, 69, 0.96);
  color: var(--white);
  box-shadow: 0 16px 36px rgba(22, 50, 69, 0.18);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.1;
  text-transform: uppercase;
}

.tool-status .eyebrow,
.tool-status strong {
  color: rgba(255, 255, 255, 0.8);
}

.status-selection {
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  width: min(100%, 340px);
  min-height: 42px;
  padding: 0 18px;
  border: 2px solid var(--green);
  border-radius: 15px;
  color: var(--white);
  text-align: center;
  box-shadow: 0 0 0 4px rgba(31, 183, 150, 0.1);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  gap: 10px;
  min-width: 100px;
  min-height: 30px;
  color: var(--white);
  text-align: right;
}

.status::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(31, 183, 150, 0.13);
}

.status.is-error::before {
  background: var(--warning);
  box-shadow: 0 0 0 6px rgba(235, 88, 68, 0.13);
}

.control-card,
.panel,
.history-wrap {
  border: 1px solid var(--line);
  border-radius: 23px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-card {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  padding: 26px;
}

.field,
.metric {
  display: grid;
  align-content: center;
  min-height: 64px;
}

.field {
  grid-template-columns: 82px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.prompt-field {
  grid-template-columns: 82px minmax(260px, 1fr);
}

.db-suggestion {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  text-transform: none;
}

.db-suggestion span {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
}

.db-suggestion strong {
  color: var(--teal);
}

.prompt-row {
  grid-column: 1 / 10;
  display: grid;
  grid-template-columns: minmax(340px, 390px) 150px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.counter-row {
  grid-column: 10 / 13;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 28px;
}

.prop-id-field {
  grid-column: 1 / 5;
  grid-template-columns: 82px minmax(130px, 1fr);
}

.prop-name-field {
  grid-column: 5 / 13;
  grid-template-columns: 108px minmax(260px, 1fr);
}

.field span,
.metric span {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

.metric strong {
  margin-top: 5px;
  color: var(--ink);
  font-size: 18px;
}

select,
input[type="text"],
textarea,
.output {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--ink);
}

select {
  width: 100%;
  min-width: 230px;
  height: 44px;
  padding: 0 38px 0 14px;
  border-radius: 8px;
}

input[type="text"] {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 8px;
}

input[type="text"]::placeholder {
  color: color-mix(in srgb, var(--muted) 75%, transparent);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 20px;
}

.panel {
  min-height: 580px;
  display: flex;
  overflow: hidden;
  flex-direction: column;
}

.panel-header,
.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 26px 26px 20px;
}

textarea,
.output {
  flex: 1;
  width: calc(100% - 52px);
  min-height: 390px;
  margin: 0 26px 26px;
  padding: 18px;
  border-radius: 12px;
  outline: 0;
  resize: none;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.55;
}

.source-rule {
  width: calc(100% - 52px);
  margin: 0 26px 14px;
  padding: 9px 12px;
  border: 1px solid rgba(0, 132, 139, 0.22);
  border-radius: 10px;
  background: rgba(0, 132, 139, 0.055);
  color: var(--teal);
  font-size: 11px;
  line-height: 1.35;
}

.source-rule[hidden] {
  display: none;
}

.source-rule.is-over-limit {
  border-color: rgba(235, 88, 68, 0.42);
  background: rgba(235, 88, 68, 0.08);
  color: var(--warning);
}

textarea::placeholder {
  color: color-mix(in srgb, var(--muted) 80%, transparent);
}

textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(31, 183, 150, 0.12);
}

.output {
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 26px 26px;
}

button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.primary {
  min-width: 142px;
  padding: 0 22px;
  background: var(--green);
  color: var(--white);
}

.create-button {
  justify-self: start;
  min-width: 150px;
}

.primary:hover:not(:disabled) {
  background: var(--green-dark);
}

.secondary,
.ghost-button {
  min-width: 92px;
  padding: 0 18px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.secondary:hover:not(:disabled),
.ghost-button:hover:not(:disabled),
.text-button:hover {
  border-color: var(--green);
  color: var(--green-dark);
}

.text-button {
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0 16px;
}

.history-wrap {
  margin-top: 20px;
  overflow: hidden;
}

.history {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 0 26px 26px;
}

.history-item {
  min-height: 116px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
  color: var(--ink);
  text-align: left;
}

.history-item:hover {
  border-color: var(--green);
}

.history-item strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 14px;
}

.history-item span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.empty-history {
  grid-column: 1 / -1;
  min-height: 70px;
  margin: 0;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 38, 52, 0.42);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(100%, 520px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.modal p:not(.eyebrow) {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 22px;
}

body.dark .hero-logo {
  filter: brightness(0) invert(1);
}

body.dark .tool-status {
  background: var(--navy-deep);
}

body.dark .pill-label,
body.dark .theme-toggle {
  background: rgba(255, 255, 255, 0.12);
}

@media (max-width: 980px) {
  .hero-top {
    align-items: flex-start;
    flex-direction: column;
    padding: 36px 30px 0;
  }

  .hero-content {
    padding: 50px 30px 120px;
  }

  .theme-toggle {
    right: auto;
    left: 30px;
    bottom: 36px;
  }

  h1 {
    font-size: 50px;
  }

  .tool-status,
  .control-card,
  .workspace,
  .history {
    grid-template-columns: 1fr;
  }

  .control-card {
    grid-template-columns: 1fr;
  }

  .prompt-row,
  .counter-row,
  .prop-id-field,
  .prop-name-field {
    grid-column: 1;
  }

  .prompt-row,
  .counter-row {
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .counter-row {
    gap: 14px;
  }

  .tool-status {
    align-items: stretch;
    top: 10px;
    padding: 14px;
  }
}

@media (max-width: 620px) {
  .app {
    width: min(100% - 20px, 1140px);
    padding-top: 10px;
  }

  .hero {
    min-height: 390px;
    border-radius: 18px;
  }

  .hero-logo {
    width: 148px;
  }

  .pill-label {
    min-width: 0;
    width: 100%;
  }

  h1 {
    font-size: 40px;
  }

  h2 {
    font-size: 28px;
  }

  .control-card,
  .tool-status,
  .panel-header,
  .history-header {
    padding: 20px;
  }

  .tool-status {
    border-radius: 16px;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  textarea,
  .output,
  .source-rule {
    width: calc(100% - 40px);
    margin: 0 20px 20px;
  }

  textarea,
  .output {
    min-height: 360px;
  }

  .actions,
  .history {
    padding: 0 20px 20px;
  }

  .primary,
  .secondary,
  .ghost-button,
  .text-button {
    width: 100%;
  }

  .create-button {
    justify-self: stretch;
  }
}
