 
:root {
  --bg0: #f7efe3;
  --bg1: #f0dec5;
  --bg2: #ecd3b0;
  --ink: #241a10;
  --muted: #6c5842;
  --paper: #fff9f0;
  --line: #e4d4bf;
  --brand: #0f766e;
  --brand2: #0b5d57;
  --danger: #b91c1c;
  --shadow: 0 14px 44px rgba(36, 26, 16, 0.12);
  --shadow-soft: 0 8px 24px rgba(36, 26, 16, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  line-height: 1.35;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.45), transparent 34%),
    radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.3), transparent 28%),
    linear-gradient(145deg, var(--bg0), var(--bg1) 45%, var(--bg2));
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image: radial-gradient(circle at 2px 2px, rgba(36, 26, 16, 0.12) 1px, transparent 0);
  background-size: 18px 18px;
}

.app-shell {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  padding: 18px;
  max-width: 1500px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.brand-wrap {
  background: rgba(255, 249, 240, 0.7);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-soft);
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand span {
  color: var(--brand);
}

.brand-wrap small {
  color: var(--muted);
}

.session-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  align-items: end;
  gap: 10px;
  background: rgba(255, 249, 240, 0.82);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  box-shadow: var(--shadow-soft);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.card {
  background: rgba(255, 249, 240, 0.88);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.tables-panel {
  padding: 12px;
  position: sticky;
  top: 10px;
  max-height: calc(100vh - 20px);
  overflow: auto;
}

.panel-title {
  font-weight: 700;
  margin: 4px 0 10px;
}

.table-link {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  text-align: left;
  margin-bottom: 8px;
  padding: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.94rem;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.table-link:hover {
  transform: translateY(-1px);
}

.table-link.active {
  border-color: var(--brand);
  background: rgba(15, 118, 110, 0.1);
}

.table-link small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  font-size: 11px;
}

.data-panel {
  min-width: 0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.toolbar h2 {
  margin: 0;
  font-size: 1.2rem;
}

.toolbar small {
  color: var(--muted);
}

.toolbar-right {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.input {
  width: 100%;
  min-width: 0;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  outline: none;
  font-family: inherit;
}

.input.small {
  min-width: 80px;
  width: 80px;
}

.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  color: #fff;
  background: linear-gradient(140deg, var(--brand), var(--brand2));
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  min-height: 42px;
  transition: transform 120ms ease, filter 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.btn.secondary {
  background: #374151;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn.danger {
  background: var(--danger);
}

.btn i {
  margin-right: 6px;
}

.table-wrap {
  padding: 0;
  overflow: auto;
  position: relative;
}

.table-wrap::after {
  content: '';
  position: sticky;
  right: 0;
  width: 18px;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(to right, rgba(255, 249, 240, 0), rgba(255, 249, 240, 0.8));
  float: right;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.table th,
.table td {
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
}

.table td:last-child {
  white-space: nowrap;
}

.row-check {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
  cursor: pointer;
}

.selection-info {
  margin: 0 0 10px;
  padding: 0 4px;
  font-size: 13px;
}

.table th {
  position: sticky;
  top: 0;
  background: #f7efe3;
  color: #4b3c2a;
}

.muted {
  color: var(--muted);
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  background: rgba(15, 118, 110, 0.12);
  color: #0d6760;
}

.editor-wrap {
  margin-top: 10px;
  padding: 12px;
}

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

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

.editor-grid .full {
  grid-column: 1 / -1;
}

.editor-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

textarea.input {
  min-height: 90px;
  resize: vertical;
}

.alert,
.success {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.alert {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.foot {
  margin-top: 12px;
  text-align: center;
  color: var(--muted);
  padding: 8px;
}

@media (max-width: 1240px) {
  .session-controls {
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
  }

  .session-controls .btn {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .tables-panel {
    max-height: none;
    position: static;
    display: flex;
    flex-direction: column;
  }

  #tables {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .table-link {
    margin-bottom: 0;
    min-height: 68px;
  }

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

  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar-right {
    width: 100%;
  }

  .toolbar-right label {
    flex: 1;
    min-width: 110px;
  }

  .toolbar-right .btn {
    flex: 1;
    min-width: 120px;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    gap: 10px;
  }

  .brand-wrap,
  .session-controls,
  .card {
    border-radius: 12px;
  }

  .session-controls {
    grid-template-columns: 1fr;
    width: 100%;
  }

  #tables {
    grid-template-columns: 1fr;
  }

  .toolbar {
    padding: 10px;
  }

  .toolbar h2 {
    font-size: 1.05rem;
  }

  .toolbar small {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .table {
    min-width: 640px;
  }

  .editor-actions {
    flex-direction: column;
  }

  .editor-actions .btn {
    width: 100%;
  }

  .btn i {
    margin-right: 4px;
  }
}
