:root {
  --ink: #17202f;
  --muted: #667085;
  --line: #e2e7ef;
  --soft: #f5f7fb;
  --paper: #ffffff;
  --accent: #14746f;
  --accent-strong: #0f5d59;
  --accent-soft: #e4f6f3;
  --danger: #b42318;
  --success: #067647;
  --sidebar: #111827;
  --sidebar-soft: #1d2735;
  --shadow: 0 10px 26px rgba(15, 23, 42, 0.07);
  --overlay: rgba(15, 23, 42, 0.56);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
  color: var(--ink);
  background: var(--soft);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

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

button,
select {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(21, 127, 114, 0.24);
  outline-offset: 2px;
}

.sidebar {
  min-height: 100vh;
  padding: 22px 16px;
  background: var(--sidebar);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 6px 4px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #07201d;
  background: #65d6ca;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: inset 0 -10px 18px rgba(15, 98, 89, 0.14);
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel-title h3,
.panel-title p,
.status-message {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.1;
}

.brand p {
  margin-top: 5px;
  color: #b8c2cf;
  font-size: 13px;
}

.saved-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #98a2b3;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow: auto;
  padding-right: 4px;
}

.template-item {
  width: 100%;
  min-height: 58px;
  padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 7px;
  color: #f8fafc;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.template-item:hover {
  border-color: rgba(101, 214, 202, 0.5);
  background: #1b2532;
}

.template-item.active {
  border-color: #65d6ca;
  background: #183235;
}

.template-item strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.25;
}

.template-item span {
  display: block;
  color: #b8c2cf;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.empty-list {
  margin: 0;
  padding: 12px;
  color: #b8c2cf;
  font-size: 13px;
  line-height: 1.45;
}

.workspace {
  min-width: 0;
  padding: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  min-height: 116px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.eyebrow {
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.topbar h2 {
  max-width: 780px;
  margin-top: 5px;
  font-size: 25px;
  line-height: 1.16;
}

.category-tabs {
  display: flex;
  gap: 2px;
  align-items: center;
  min-height: 56px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  overflow-x: auto;
}

.category-tab {
  min-width: 96px;
  min-height: 56px;
  border: 1px solid transparent;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.category-tab:hover {
  color: var(--ink);
  background: #f7f9fc;
}

.category-tab.active {
  color: var(--accent-strong);
  background: transparent;
  border-bottom: 3px solid var(--accent);
}

.version-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  justify-content: flex-end;
}

.template-picker {
  min-width: 250px;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.template-picker select,
.field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--paper);
  padding: 0 12px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.template-picker select:hover,
.field input:hover,
#sqlOutput:hover {
  border-color: #b8c2cf;
}

.field input:invalid:not(:placeholder-shown) {
  border-color: rgba(180, 35, 24, 0.65);
}

.template-picker select:disabled,
.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.editor {
  display: grid;
  grid-template-columns: minmax(330px, 420px) minmax(460px, 1fr);
  gap: 18px;
  align-items: start;
  padding: 24px 32px 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.form-panel,
.result-panel {
  padding: 20px;
}

.result-panel {
  min-height: 100%;
}

.panel-title {
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid #edf0f5;
}

.panel-title h3 {
  font-size: 18px;
  line-height: 1.2;
}

.panel-title p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.fields {
  display: grid;
  gap: 13px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  font-size: 13px;
  font-weight: 800;
}

.field small {
  color: var(--muted);
  line-height: 1.35;
  font-size: 12px;
}

.empty-template-note,
.saved-note {
  border: 1px solid #c9eee8;
  border-radius: 8px;
  color: #0f6259;
  background: var(--accent-soft);
  line-height: 1.45;
  font-size: 13px;
  font-weight: 700;
}

.empty-template-note {
  padding: 12px;
}

.saved-note {
  padding: 12px 14px;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 22px;
}

.primary,
.secondary,
.danger-button {
  min-height: 42px;
  border-radius: 7px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.primary:hover,
.secondary:hover {
  transform: none;
}

.primary {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 16px rgba(20, 116, 111, 0.18);
}

.primary:hover {
  background: var(--accent-strong);
}

.secondary {
  color: var(--ink);
  background: #f7f9fc;
  border-color: #d8dee9;
}

.secondary:hover {
  background: #edf1f7;
  border-color: #c8d0dc;
}

.danger-button {
  color: #b42318;
  background: #fff4f2;
  border-color: #f4b4ae;
}

.danger-button:hover {
  background: #ffe7e3;
  border-color: #ea7d73;
}

.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.compact {
  min-height: 44px;
  padding-inline: 16px;
}

.status-message {
  min-height: 18px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-message[data-type="success"] {
  color: var(--success);
}

.status-message[data-type="error"] {
  color: var(--danger);
}

#sqlOutput {
  width: 100%;
  min-height: 520px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 16px;
  color: #111827;
  background-color: #fbfcfe;
  background-image: url("Logo.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: min(420px, 54%);
  line-height: 1.55;
  font-family: Consolas, "Courier New", monospace;
  font-size: 14px;
  white-space: pre;
}

#sqlOutput:placeholder-shown {
  background-color: rgba(251, 252, 254, 0.9);
  background-blend-mode: lighten;
}

#sqlOutput:not(:placeholder-shown) {
  background-image: linear-gradient(rgba(251, 252, 254, 0.72), rgba(251, 252, 254, 0.72)), url("Logo.png");
}

.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 18px 32px 22px;
  color: var(--muted);
  font-size: 13px;
}

.copyright-mark {
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: var(--accent-strong);
  background: var(--paper);
  font-weight: 700;
  line-height: 1;
}

.admin-fab {
  position: fixed;
  right: 20px;
  bottom: 18px;
  z-index: 20;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: var(--paper);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.admin-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  justify-content: flex-end;
  padding: 0;
  background: rgba(17, 24, 39, 0.42);
}

.admin-modal {
  width: min(760px, 100%);
  height: 100vh;
  max-height: 100vh;
  overflow: auto;
  border: 0;
  border-left: 1px solid rgba(216, 221, 231, 0.9);
  border-radius: 0;
  background: var(--paper);
  box-shadow: -18px 0 46px rgba(15, 23, 42, 0.22);
}

.admin-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.admin-modal-header h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #f7f9fc;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.admin-editor {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.admin-login {
  position: relative;
  min-height: calc(100vh - 90px);
  display: grid;
  place-items: start center;
  padding: 38px 22px;
  overflow: hidden;
}

.admin-login::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("Logo.png");
  background-position: center 58%;
  background-repeat: no-repeat;
  background-size: min(520px, 78%);
  opacity: 0.06;
  pointer-events: none;
}

.admin-login-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.admin-login-card h3,
.admin-login-card p {
  margin: 0;
}

.admin-login-card h3 {
  font-size: 18px;
  line-height: 1.2;
}

.admin-login-card p {
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.admin-login-error {
  padding: 10px 12px;
  border: 1px solid #f4b4ae;
  border-radius: 7px;
  color: var(--danger) !important;
  background: #fff4f2;
  font-weight: 800;
}

.admin-workbench {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 82px);
}

.admin-list {
  padding: 16px;
  border-right: 1px solid var(--line);
  background: #f8fafc;
}

.admin-list-header {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

#adminTemplateList {
  display: grid;
  gap: 8px;
}

.admin-template-item {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  text-align: left;
  cursor: pointer;
}

.admin-template-item.active {
  border-color: #65d6ca;
  background: var(--accent-soft);
}

.admin-template-item strong,
.admin-template-item span {
  display: block;
}

.admin-template-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 140px 90px;
  gap: 12px;
  align-items: end;
}

.admin-check {
  grid-column: 1 / -1;
}

.admin-login label,
.admin-editor label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.admin-login input,
.admin-editor input,
.admin-editor select,
.admin-editor textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  padding: 0 12px;
}

.admin-editor textarea {
  min-height: 220px;
  padding: 13px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.45;
}

.admin-editor .admin-short-textarea {
  min-height: 84px;
  font-family: inherit;
}

.admin-preview {
  min-height: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #111827;
  background: #fbfcfe;
  padding: 13px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.45;
}

.admin-check {
  min-height: 42px;
  grid-template-columns: auto 1fr;
  align-items: center;
  align-content: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.admin-check input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.admin-field-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
}

.admin-field-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #c9eee8;
  border-radius: 8px;
  color: #0f6259;
  background: var(--accent-soft);
  font-size: 13px;
  line-height: 1.35;
}

.admin-field-preview strong,
.admin-field-preview code {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.admin-field-preview code {
  padding: 3px 6px;
  border: 1px solid #9ce2d8;
  border-radius: 6px;
  color: #0f6259;
  background: #ffffff;
  font-family: Consolas, "Courier New", monospace;
}

.admin-field-preview small {
  color: var(--muted);
  font-weight: 800;
}

.admin-fields {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.admin-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.admin-field-row select,
.admin-field-row button,
.admin-field-row input:nth-of-type(n + 3) {
  grid-column: span 1;
}

.admin-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
}

@media (max-width: 1040px) {
  body {
    grid-template-columns: 270px minmax(0, 1fr);
  }

  .editor {
    grid-template-columns: 1fr;
  }

  .admin-workbench,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .admin-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-modal {
    width: min(680px, 100%);
  }

  #sqlOutput {
    min-height: 380px;
  }
}

@media (max-width: 760px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding: 18px;
  }

  .workspace {
    padding: 20px;
  }

  .topbar {
    display: grid;
    align-items: stretch;
  }

  .topbar h2 {
    font-size: 26px;
  }

  .version-tools {
    align-items: stretch;
  }

  .category-tabs {
    margin-top: 0;
  }

  .template-picker {
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .version-tools,
  .actions,
  .admin-field-tools,
  .admin-field-row,
  .admin-actions {
    grid-template-columns: 1fr;
    display: grid;
  }

  .admin-field-row input:nth-of-type(n + 3) {
    grid-column: auto;
  }

  .admin-modal {
    width: 100%;
  }
}

.omega-return { display: block; color: #8ce7e0; margin: 0 0 24px; padding: 10px 0; font-size: .9rem; }
