:root {
  --bg: #f3efe7;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #fffdf9;
  --ink: #1f2f3d;
  --muted: #5d6d78;
  --line: #d8d2c5;
  --accent: #045d56;
  --accent-strong: #013d38;
  --accent-soft: #d7f0ea;
  --warm: #b25b2e;
  --warm-soft: #ffe6d8;
  --danger: #a12c2c;
  --danger-soft: #ffe0e0;
  --shadow: 0 18px 42px rgba(39, 47, 56, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Aptos", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 214, 177, 0.55) 0%, transparent 27%),
    radial-gradient(circle at top right, rgba(138, 207, 192, 0.35) 0%, transparent 30%),
    linear-gradient(180deg, #f7f3eb 0%, #efe8db 100%);
}

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

button {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.65rem 1rem;
  background: #edf1f4;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(31, 47, 61, 0.12);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.72rem 0.85rem;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.8rem 0.75rem;
  border-bottom: 1px solid #e7e0d3;
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: #faf7f1;
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 1rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1.1rem 1.2rem;
  border-radius: 24px;
  color: #f9fffc;
  background:
    linear-gradient(140deg, rgba(4, 93, 86, 0.96), rgba(1, 61, 56, 0.98)),
    #013d38;
  box-shadow: var(--shadow);
}

.toolbar-copy h1,
.section-heading h3,
.results-header h2,
.subsection h2,
.dialog-header h2 {
  margin: 0;
}

.toolbar-copy {
  display: grid;
  gap: 0.4rem;
}

.eyebrow {
  margin: 0;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(241, 255, 252, 0.78);
}

.toolbar-status {
  margin: 0;
  color: rgba(241, 255, 252, 0.82);
}

.toolbar-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 0.55rem;
  align-items: center;
}

.hero-button {
  background: linear-gradient(135deg, #ffcf66, #f39c2d);
  color: #422400;
  border-color: rgba(105, 62, 0, 0.15);
}

.return-button {
  background: linear-gradient(135deg, #0d6d9f, #0a4d73);
  color: #f5fbff;
  border-color: rgba(6, 56, 84, 0.2);
}

.nav-button.active {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(161, 44, 44, 0.2);
}

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

.workspace.erd-mode {
  grid-template-columns: minmax(0, 1fr);
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(216, 210, 197, 0.95);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.sidebar-mode {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
}

.sidebar-help {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.sidebar-footer {
  display: flex;
  justify-content: center;
  padding: 0.4rem 1rem 1rem;
}

.content-stack {
  display: grid;
}

.content-panel {
  display: none;
}

.content-panel.active {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 720px;
}

.panel-title {
  padding: 1rem 1.1rem;
  border-bottom: 1px solid #e7e0d3;
  font-weight: 800;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(248, 243, 234, 0.92));
}

.with-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.inline-actions,
.sidebar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.panel-section,
.panel-body {
  padding: 1rem 1.1rem;
}

.panel-body {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.field-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
}

.table-list {
  padding: 0 0.9rem 0.9rem;
  overflow: auto;
  display: grid;
  gap: 0.45rem;
  align-content: start;
  max-height: min(28rem, calc(100vh - 21rem));
}

.table-item {
  width: 100%;
  padding: 0.85rem 0.9rem;
  border-radius: 16px;
  border: 1px solid #e3dccf;
  background: var(--panel-strong);
  text-align: left;
}

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

.table-item span {
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.table-item.active {
  background: linear-gradient(180deg, #f7fffd, #def4ee);
  border-color: rgba(4, 93, 86, 0.35);
}

.saved-query-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.75rem 0.8rem;
  border-radius: 16px;
  border: 1px solid #e3dccf;
  background: var(--panel-strong);
  position: relative;
}

.saved-query-load {
  width: 100%;
  text-align: left;
  background: transparent;
  box-shadow: none;
  padding: 0.15rem 1.8rem 0.15rem 0.2rem;
}

.saved-query-load:hover:not(:disabled) {
  transform: none;
  box-shadow: none;
}

.saved-query-delete {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  min-width: 1.55rem;
  width: 1.55rem;
  height: 1.55rem;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
}

.subsection {
  display: grid;
  gap: 0.65rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid #ece4d6;
  border-radius: 16px;
  background: rgba(255, 253, 249, 0.78);
}

#tableDetailsContent {
  display: grid;
  gap: 1.3rem;
}

.subsection > .field-label {
  margin-bottom: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}

.table-scroll {
  overflow: auto;
  border: 1px solid #e8e0d3;
  border-radius: 18px;
  background: #ffffff;
}

.empty-state {
  padding: 1.2rem;
  border: 1px dashed #d2c8b8;
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 253, 249, 0.7);
}

.hint-text {
  margin: 0;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.table-details-footer {
  margin-top: 0.25rem;
  display: flex;
  gap: 1rem;
  width: 100%;
  justify-content: flex-start;
  justify-self: stretch;
  align-self: start;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.table-meta strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.browse-layout,
.sql-layout,
.erd-layout {
  grid-template-rows: auto auto 1fr;
}

.erd-layout {
  align-content: stretch;
}

.erd-canvas-wrap {
  overflow: hidden;
  border: 1px solid #e8e0d3;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(250, 247, 241, 0.96)),
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(216, 210, 197, 0.22) 39px, rgba(216, 210, 197, 0.22) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(216, 210, 197, 0.22) 39px, rgba(216, 210, 197, 0.22) 40px);
}

#erdCanvas {
  display: block;
}

.editor-card {
  display: grid;
  gap: 0.7rem;
}

.editor-wrap {
  position: relative;
}

#sqlEditor {
  min-height: 240px;
  padding-right: 1rem;
  font-family: "IBM Plex Mono", "Cascadia Code", monospace;
  line-height: 1.5;
}

.autocomplete {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  width: min(360px, calc(100% - 1.6rem));
  max-height: 220px;
  overflow: auto;
  border: 1px solid #d9d0c1;
  border-radius: 16px;
  background: #fffdf9;
  box-shadow: 0 16px 38px rgba(31, 47, 61, 0.15);
  z-index: 4;
}

.autocomplete-item {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 0.75rem 0.85rem;
  background: transparent;
  text-align: left;
  box-shadow: none;
}

.autocomplete-item.active,
.autocomplete-item:hover {
  background: #f5f8fa;
}

.results-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.sql-results {
  min-height: 200px;
}

.sql-messages {
  display: grid;
  gap: 0.6rem;
}

.sql-message {
  padding: 0.85rem 0.95rem;
  border-radius: 14px;
  background: #faf6ee;
  border: 1px solid #e5ddcf;
}

.record-fields,
.column-rows {
  display: grid;
  gap: 0.85rem;
}

.column-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  padding: 0.8rem;
  border-radius: 18px;
  background: #fbf8f2;
  border: 1px solid #e7dfd1;
  position: relative;
}

.column-row-top,
.column-row-bottom,
.column-row-foreign {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.column-row-top {
  align-items: end;
  padding-right: 2.2rem;
  flex-wrap: nowrap;
}

.remove-column-corner-btn {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  min-width: 1.8rem;
  width: 1.8rem;
  height: 1.8rem;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.inline-field-horizontal {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}

.inline-field-horizontal.inline-field-reference {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
}

.field-label-inline {
  display: inline-block;
  margin-bottom: 0;
  min-width: max-content;
}

.inline-field-type {
  flex: 0 0 auto;
}

.column-row-top > .inline-field {
  flex-wrap: nowrap;
}

.inline-field-type .column-type {
  width: auto;
  height: 30px;
  min-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}

.inline-field-horizontal .column-name {
  height: 30px;
  min-height: 30px;
  min-width: min(16rem, 34vw);
}

.inline-field-reference {
  flex: 1 1 18rem;
}

.inline-field-reference input,
.inline-field-reference select {
  min-width: 12rem;
}

.column-row .column-default,
.column-row .column-ref-table,
.column-row .column-ref-column {
  height: 30px;
  min-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}

.inline-field-reference-table,
.inline-field-reference-column {
  flex: 0 1 auto;
}


.column-type {
  width: auto;
  min-width: 0;
  justify-self: start;
}

.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
}

.checkbox-field input {
  width: auto;
}

.checkbox-field.is-disabled,
.inline-field.is-disabled {
  opacity: 0.5;
}

.record-row {
  cursor: pointer;
}

.record-row.selected {
  background: #eef8f6;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 800;
}

.badge-primary {
  color: #0c5b47;
  background: #d9f3eb;
}

.badge-foreign {
  color: #9b4c1f;
  background: #ffe5d3;
}

.app-dialog {
  width: min(980px, calc(100vw - 2rem));
  border: 0;
  border-radius: 24px;
  padding: 0;
  box-shadow: 0 28px 64px rgba(19, 33, 43, 0.28);
}

.app-dialog::backdrop {
  background: rgba(11, 26, 34, 0.45);
}

.dialog-form {
  display: grid;
  max-height: calc(100vh - 3rem);
}

.dialog-header,
.dialog-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.15rem;
}

.dialog-header {
  border-bottom: 1px solid #e7e0d3;
}

.dialog-body {
  padding: 1rem 1.15rem;
  overflow: auto;
}

.dialog-footer {
  border-top: 1px solid #e7e0d3;
}

.dialog-close {
  padding: 0.35rem 0.75rem;
  min-width: 0;
}

.dialog-section {
  margin-top: 1.2rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.inline-field {
  display: grid;
  gap: 0.35rem;
}

.column-row-top .inline-field-horizontal,
.column-row-bottom .inline-field-horizontal,
.column-row-foreign .inline-field-horizontal {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.6rem;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .inline-field-horizontal {
    width: 100%;
  }

  .inline-field-horizontal .column-name,
  .inline-field-reference input {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .toolbar,
  .with-actions,
  .results-header,
  .dialog-header,
  .dialog-footer,
  .section-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions,
  .inline-actions,
  .sidebar-actions {
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .toolbar-actions > button,
  .inline-actions > button,
  .sidebar-actions > button {
    width: 100%;
  }
}
