:root {
  --malu-sidebar-width: 292px;
  --malu-header-height: 56px;
  --malu-border: #dde3ec;
  --malu-ink: #172033;
  --malu-muted: #657188;
  --malu-bg: #f5f7fb;
  --malu-panel: #ffffff;
  --malu-primary: #233882;
  --malu-primary-soft: #e8ecfb;
}

body {
  height: 100vh;
  overflow: hidden;
  color: var(--malu-ink);
  background: var(--malu-bg);
  font-size: 0.9rem;
}

::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

::-webkit-scrollbar-track {
  background: #eef1f6;
}

::-webkit-scrollbar-thumb {
  background: #aab3c2;
  border: 2px solid #eef1f6;
  border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
  background: #7d8798;
}

* {
  scrollbar-width: auto;
  scrollbar-color: #aab3c2 #eef1f6;
}

a {
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--malu-sidebar-width) minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
}

.app-sidebar {
  min-width: 0;
  min-height: 0;
  background: #111827;
  color: #d7deea;
  border-right: 1px solid #0b1220;
  display: flex;
  flex-direction: column;
}

.brand-block {
  height: var(--malu-header-height);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2f855a;
  color: #fff;
  font-weight: 700;
}

.brand-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: #93a2b8;
}

.sidebar-scroll {
  min-height: 0;
  overflow: auto;
  padding: 0.75rem;
}

.sidebar-section {
  margin: 0.75rem 0 0.35rem;
  padding: 0 0.35rem;
  font-size: 0.68rem;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #7f8ca3;
}

.sidebar-link,
.schema-row,
.relation-link {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  color: #cfd8e7;
  border-radius: 6px;
  padding: 0.38rem 0.5rem;
}

.sidebar-link:hover,
.schema-row:hover,
.relation-link:hover,
.sidebar-link.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.relation-link {
  padding-left: 1.55rem;
  font-size: 0.82rem;
}

.relation-kind {
  width: 1.25rem;
  flex: 0 0 auto;
  color: #8fb0ff;
}

.relation-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-header {
  flex: 0 0 var(--malu-header-height);
  height: var(--malu-header-height);
  background: #fff;
  border-bottom: 1px solid var(--malu-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
}

.header-title {
  min-width: 0;
}

.header-title h1 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

.header-title small {
  color: var(--malu-muted);
}

.content-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1rem;
}

.workspace {
  max-width: 100%;
}

.panel {
  background: var(--malu-panel);
  border: 1px solid var(--malu-border);
  border-radius: 8px;
}

.panel-header {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--malu-border);
}

.panel-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

.panel-body {
  padding: 1rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.metric-card {
  background: #fff;
  border: 1px solid var(--malu-border);
  border-radius: 8px;
  padding: 0.9rem;
}

.metric-label {
  color: var(--malu-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-value {
  margin-top: 0.35rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.table-outer {
  border: 1px solid var(--malu-border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.table-responsive {
  max-width: 100%;
  overflow: auto;
}

.table {
  margin-bottom: 0;
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #4b5870;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.table td,
.table th {
  vertical-align: middle;
}

.cell-value {
  display: block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-block,
.sql-editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.sql-editor {
  min-height: 180px;
  resize: vertical;
}

.nav-tabs .nav-link {
  color: var(--malu-muted);
}

.nav-tabs .nav-link.active {
  color: var(--malu-primary);
  font-weight: 700;
}

.badge-soft {
  color: var(--malu-primary);
  background: var(--malu-primary-soft);
}

.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--malu-muted);
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}

.row-actions {
  width: 1%;
  white-space: nowrap;
}

.row-editor {
  margin-bottom: 1rem;
}

.row-edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
}

.row-edit-field {
  min-width: 0;
}

.field-options {
  min-height: 26px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.saved-query-panel {
  max-height: calc(100vh - var(--malu-header-height) - 2rem);
  display: flex;
  flex-direction: column;
}

.saved-query-panel .tab-content {
  min-height: 0;
  overflow: auto;
}

.saved-query-list {
  display: grid;
  gap: 0.5rem;
  padding: 0.75rem;
}

.saved-query-item {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--malu-border);
}

.saved-query-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.saved-query-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--malu-ink);
}

@media (max-width: 980px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .app-sidebar {
    min-height: auto;
  }

  .sidebar-scroll {
    max-height: 320px;
  }
}
