/* Critical: HTML hidden attribute support */
[hidden] {
  display: none !important;
}

:root {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color-scheme: light;
  --bg: #f5f7fb;
  --bg-accent: #edf2f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #eef3fb;
  --text: #10233f;
  --text-muted: #4e637f;
  --border: #d4deeb;
  --link: #1d4ed8;
  --link-hover: #1e40af;
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --ok-fg: #166534;
  --ok-bg: #dcfce7;
  --ok-border: #86efac;
  --warn-fg: #92400e;
  --warn-bg: #ffedd5;
  --warn-border: #fdba74;
  --danger-fg: #991b1b;
  --danger-bg: #fee2e2;
  --danger-border: #fca5a5;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #090f1c;
    --bg-accent: #0a1222;
    --surface: #0d172b;
    --surface-soft: #0f1d35;
    --surface-strong: #0b1529;
    --text: #dbe4f2;
    --text-muted: #8da2c2;
    --border: #22334f;
    --link: #93c5fd;
    --link-hover: #bfdbfe;
    --brand: #3b82f6;
    --brand-strong: #2563eb;
    --ok-fg: #bbf7d0;
    --ok-bg: #12382a;
    --ok-border: #1f6f4f;
    --warn-fg: #fed7aa;
    --warn-bg: #422006;
    --warn-border: #9a4a11;
    --danger-fg: #fecaca;
    --danger-bg: #3b1111;
    --danger-border: #b91c1c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg-accent) 0%, var(--bg) 100%);
  color: var(--text);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  color: var(--link-hover);
}

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

.app-sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
}

.brand-block {
  display: flex;
  gap: 0.7rem;
  align-items: center;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-weight: 700;
  color: #eff6ff;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
}

.brand-title {
  font-weight: 700;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  color: var(--text-muted);
}

.menu-item:hover,
.menu-item.active {
  color: var(--text);
  background: var(--surface-strong);
}

.menu-icon {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
}

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

.identity-pill {
  margin: 0.35rem 0 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-main {
  padding: 1rem 1.25rem;
}

.app-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.app-topbar h1 {
  margin: 0;
  font-size: 1.35rem;
  color: var(--text);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.86rem;
  margin: -0.25rem 0 0.9rem;
  color: var(--text-muted);
}

.breadcrumbs .current {
  color: var(--text);
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 0.8rem;
}

.project-picker {
  display: grid;
  gap: 0.25rem;
}

.project-picker label {
  font-size: 0.76rem;
  color: var(--text-muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font: inherit;
}

input[readonly] {
  color: var(--text-muted);
  background: var(--surface-soft);
}

textarea {
  resize: vertical;
}

.chip {
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
}

.chip.ok {
  color: var(--ok-fg);
  background: var(--ok-bg);
  border-color: var(--ok-border);
}

.chip.warn {
  color: var(--warn-fg);
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.page-content {
  min-width: 0;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.panel h2,
.panel h3 {
  margin: 0 0 0.75rem;
  color: var(--text);
}

.quick-grid,
.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.quick-grid {
  margin-bottom: 1rem;
}

.quick-card {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 0.95rem;
  display: block;
}

.quick-title {
  color: var(--text);
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.quick-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.meta-grid {
  display: grid;
  gap: 0.65rem;
}

.meta-grid > div {
  display: grid;
  gap: 0.25rem;
}

.meta-grid .k {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 0.4rem 0.65rem;
  text-transform: lowercase;
  transition: all 0.18s ease;
}

.tab.active,
.tab:hover {
  color: var(--text);
  background: var(--surface-strong);
  border-color: var(--brand);
}

.split-layout {
  display: grid;
  grid-template-columns: 290px 6px 1fr;
  min-height: 68vh;
}

.split-nav {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem;
  overflow: auto;
}

.split-nav-header {
  margin-bottom: 0.7rem;
}

.split-nav-header h3 {
  margin: 0;
  color: var(--text);
  font-size: 0.98rem;
}

.split-nav-header p {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.split-divider {
  cursor: col-resize;
  user-select: none;
  background: transparent;
  border-radius: 999px;
  margin: 0 0.2rem;
}

.split-divider:hover,
.split-divider.dragging {
  background: #2f63a0;
}

.split-main {
  min-width: 0;
}

.context-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}

.context-tabs {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.context-tab {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.34rem 0.65rem;
  color: var(--text-muted);
  background: var(--surface);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.18s ease;
}

.context-tab:hover,
.context-tab.active {
  color: var(--text);
  background: var(--surface-strong);
  border-color: var(--brand);
}

.workspace-tabs-shell {
  margin-bottom: 0.75rem;
}

.workspace-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.workspace-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem 0.4rem 0.25rem 0.55rem;
  background: var(--surface);
}

.workspace-tab.active {
  border-color: var(--brand);
  background: var(--surface-strong);
}

.workspace-tab a {
  color: var(--text-muted);
  font-size: 0.83rem;
  max-width: 270px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-tab.active a,
.workspace-tab a:hover {
  color: var(--text);
}

.workspace-tab-close,
.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  width: 1.45rem;
  height: 1.45rem;
  display: inline-grid;
  place-items: center;
}

.workspace-tab-close:hover,
.icon-btn:hover {
  color: var(--text);
  background: var(--surface-strong);
}

.warehouse-entity-tabs {
  margin-bottom: 0.7rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.52);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-card {
  width: min(700px, 100%);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 1rem;
  box-shadow: 0 20px 35px rgba(2, 6, 23, 0.35);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}

.modal-head h3 {
  margin: 0;
}

.modal-results {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.4rem;
  max-height: 340px;
  overflow: auto;
}

.modal-result-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  color: var(--text);
  background: var(--surface-soft);
}

.modal-result-item:hover {
  border-color: var(--brand);
  background: var(--surface-strong);
}

body.modal-open {
  overflow: hidden;
}

.tree-branch {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.55rem;
  padding: 0.4rem 0.5rem;
  background: var(--surface);
}

.tree-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.tree-meta {
  display: inline-flex;
  gap: 0.3rem;
}

.tree-count {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.14rem 0.42rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.tree-branch summary {
  cursor: pointer;
  list-style: none;
}

.tree-branch summary::-webkit-details-marker {
  display: none;
}

.tree-link,
.tree-leaf {
  color: var(--text-muted);
}

.tree-link.active,
.tree-leaf.active {
  color: var(--text);
  font-weight: 600;
}

.tree-subhead {
  color: var(--text-muted);
  font-size: 0.77rem;
  margin: 0.4rem 0 0.2rem;
}

.tree-list {
  margin: 0;
  padding-left: 0.8rem;
}

.tree-list li {
  margin-bottom: 0.2rem;
}

.split-empty {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.preview-state {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  background: var(--surface-soft);
}

.preview-state h4 {
  margin: 0 0 0.4rem;
  font-size: 0.98rem;
}

.preview-state.empty h4 {
  color: var(--ok-fg);
}

.preview-state.unavailable h4 {
  color: var(--warn-fg);
}

.tablekit-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.tablekit-search-input {
  width: min(320px, 100%);
}

.preview-grid {
  display: grid;
  gap: 0.4rem;
}

.preview-scrollbar {
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.preview-scrollbar-inner {
  height: 1px;
}

.preview-table-shell {
  max-height: 26rem;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.preview-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

.preview-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-strong);
}

th.sortable {
  cursor: pointer;
}

th.sortable[data-sort-direction="asc"]::after {
  content: " ↑";
}

th.sortable[data-sort-direction="desc"]::after {
  content: " ↓";
}

.stack-form {
  display: grid;
  gap: 0.65rem;
}

.stack-form label {
  display: grid;
  gap: 0.28rem;
  color: #9fb3d1;
  font-size: 0.87rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  display: inline-block;
  transition: all 0.18s ease;
}

.btn:hover {
  border-color: var(--brand);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
.tab:focus-visible,
.menu-item:focus-visible,
.context-tab:focus-visible,
.workspace-tab a:focus-visible,
.icon-btn:focus-visible,
.workspace-tab-close:focus-visible,
.modal-result-item:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.btn.full {
  width: 100%;
  text-align: center;
}

.btn-primary {
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-strong) 100%);
  border-color: var(--brand);
  color: #eff6ff;
}

.btn-danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-fg);
}

.btn-secondary {
  background: var(--surface);
}

.danger-panel {
  border-color: var(--danger-border);
}

.banner {
  border-radius: 10px;
  padding: 0.72rem 0.85rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface-soft);
}

.banner.error {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger-fg);
}

.banner.info {
  border-color: var(--brand);
  background: var(--surface-soft);
  color: var(--text);
}

code {
  background: #0b1427;
  border: 1px solid #27406a;
  padding: 0.18rem 0.38rem;
  border-radius: 6px;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #081020;
  color: #c9d7e8;
  border: 1px solid #22334f;
  border-radius: 10px;
  padding: 0.85rem;
  margin: 0;
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;
  font-size: 0.875em;
  line-height: 1.6;
}

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

th,
td {
  text-align: left;
  padding: 0.62rem;
  border-bottom: 1px solid #22334f;
}

th {
  color: #afc2df;
  font-weight: 600;
}

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  border: 1px solid #22334f;
  border-radius: 12px;
  padding: 1.5rem;
  width: min(480px, 100%);
  background: #0d172b;
}

.auth-kicker {
  margin: 0 0 0.5rem;
  color: #93c5fd;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.auth-subtitle {
  margin-top: 0;
  color: #b8cae5;
}

.auth-cta {
  width: 100%;
  text-align: center;
  font-weight: 600;
}

.auth-note {
  margin: 0.85rem 0 0;
  color: #8da2c2;
  font-size: 0.87rem;
}

.authz-panel {
  max-width: 900px;
}

.authz-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.authz-actions {
  display: flex;
  gap: 0.7rem;
}

@media (max-width: 1120px) {
  .split-layout {
    grid-template-columns: 240px 6px 1fr;
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-sidebar {
    border-right: none;
    border-bottom: 1px solid #1f2a3e;
  }

  .app-topbar,
  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .quick-grid,
  .grid.two,
  .authz-grid {
    grid-template-columns: 1fr;
  }

  .split-layout {
    grid-template-columns: 1fr;
  }

  .context-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .split-divider {
    display: none;
  }

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