:root {
  --bg: #f3f1ea;
  --bg-strong: #e9e4d9;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-soft: rgba(250, 248, 242, 0.96);
  --line: #ddd6c8;
  --line-strong: #cfc6b5;
  --text: #1f1e1a;
  --muted: #6d675c;
  --accent: #1a7f5a;
  --accent-soft: #d7efe5;
  --accent-strong: #135d42;
  --warn: #c46b2d;
  --danger: #b64040;
  --shadow: 0 18px 48px rgba(46, 35, 10, 0.08);
  --mono: "IBM Plex Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Instrument Sans", sans-serif;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(26, 127, 90, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.8), transparent 36%),
    linear-gradient(180deg, #f7f4ec 0%, #f0ebe0 100%);
}

body.detail-open {
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(207, 198, 181, 0.32) 1px, transparent 1px),
    linear-gradient(90deg, rgba(207, 198, 181, 0.24) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 88%);
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(560px, 100%);
  padding: 28px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 244, 236, 0.94)),
    var(--panel);
  box-shadow: 0 28px 72px rgba(28, 22, 10, 0.16);
  display: grid;
  gap: 22px;
}

.auth-brand h1 {
  margin: 10px 0 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-message {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid #ebc0c0;
  background: #f6dfdf;
  color: var(--danger);
  font-size: 0.92rem;
}

.workspace-shell {
  width: min(1500px, calc(100% - 28px));
  margin: 14px auto;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  gap: 18px;
}

.workspace-sidebar,
.workspace-main {
  min-height: calc(100vh - 28px);
}

.workspace-sidebar {
  position: sticky;
  top: 14px;
  align-self: start;
  display: grid;
  gap: 14px;
}

.brand-block,
.sidebar-card,
.panel-card,
.metric-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.brand-block {
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(247, 244, 236, 0.92)),
    var(--panel);
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.brand-block h1,
.workspace-topbar h2,
.panel-head h3 {
  margin: 10px 0 0;
  letter-spacing: -0.05em;
}

.brand-block h1 {
  font-size: 2rem;
  line-height: 0.95;
}

.sidebar-copy,
.sidebar-note,
.panel-copy,
.metric-note {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.sidebar-card {
  padding: 18px;
  display: grid;
  gap: 14px;
  background: var(--panel-soft);
}

.sidebar-card-head,
.panel-head,
.workspace-topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.workspace-topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.section-label,
.metric-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.state-pill,
.panel-tag,
.mini-meta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #faf6ec;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.state-pill {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: #b8dece;
}

.state-pill.danger {
  background: #f6dfdf;
  color: var(--danger);
  border-color: #ebc0c0;
}

.hidden {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.field.compact {
  gap: 7px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 11px 13px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fffef9;
  color: var(--text);
  font: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: #8ebfaa;
  box-shadow: 0 0 0 3px rgba(26, 127, 90, 0.12);
}

.field-note {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

.primary-button,
.secondary-button {
  border: 0;
  min-height: 44px;
  padding: 11px 15px;
  border-radius: 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.primary-button {
  background: var(--accent);
  color: white;
  box-shadow: 0 12px 24px rgba(26, 127, 90, 0.18);
}

.secondary-button {
  background: #f4efe4;
  color: var(--text);
  border: 1px solid var(--line);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.6;
  transform: none;
}

.sidebar-actions {
  display: grid;
  gap: 10px;
}

.workspace-main {
  display: grid;
  gap: 16px;
  align-content: start;
}

.workspace-topbar,
.metric-row,
.workspace-grid,
.database-panel {
  position: relative;
  z-index: 1;
}

.workspace-topbar {
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.workspace-topbar h2 {
  font-size: clamp(1.7rem, 2.6vw, 2.5rem);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  padding: 18px 20px;
}

.metric-value {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.8rem, 2.5vw, 2.8rem);
  letter-spacing: -0.05em;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(320px, 0.82fr);
  gap: 16px;
}

.panel-card {
  padding: 18px;
  background: rgba(255, 255, 255, 0.94);
}

.panel-head h3 {
  font-size: 1.15rem;
}

.panel-copy {
  font-size: 0.92rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.db-toolbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar-actions {
  display: flex;
  align-items: end;
}

.toolbar-actions .secondary-button {
  width: 100%;
}

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

.log-console {
  height: 100%;
  min-height: 360px;
  max-height: 620px;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f8f4eb;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.45;
}

.log-entry {
  display: grid;
  grid-template-columns: 84px 76px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}

.log-entry:last-child {
  border-bottom: 0;
}

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

.log-level {
  color: var(--warn);
  font-weight: 600;
}

.log-level.error {
  color: var(--danger);
}

.log-level.warning {
  color: #9d6a28;
}

.artifact-list {
  display: grid;
  gap: 8px;
}

.artifact-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fffef9;
}

.artifact-row a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

.artifact-row a:hover {
  color: var(--accent);
}

.table-host {
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: #fffefb;
}

.table-scroll {
  overflow: auto;
}

.pagination-bar {
  display: grid;
  grid-template-columns: auto minmax(180px, auto) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
}

.pagination-summary {
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.pagination-numbers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.page-number {
  min-width: 40px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffef9;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.page-number.active {
  background: var(--accent-soft);
  border-color: #b8dece;
  color: var(--accent-strong);
}

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

.data-table thead {
  background: #f5f0e5;
}

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

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.data-table tbody tr:hover {
  background: #faf7f0;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.row-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}

.row-title:hover {
  color: var(--accent);
}

.row-primary {
  display: grid;
  gap: 8px;
}

.row-detail-trigger {
  display: inline-flex;
  width: fit-content;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.row-detail-trigger:hover {
  color: var(--accent);
}

.row-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-source-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
}

.row-source-link:hover {
  color: var(--accent);
}

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

.cpv-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cpv-chip {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef5f2;
  color: var(--accent-strong);
  border: 1px solid #d4e7dd;
  font-size: 0.76rem;
}

.cpv-chip.subtle-chip {
  background: #f3efe6;
  color: var(--muted);
  border-color: var(--line);
}

.status-chip {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f2efe7;
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 0.78rem;
}

.mono {
  font-family: var(--mono);
  font-size: 0.82rem;
}

.empty-state {
  padding: 26px 18px;
  color: var(--muted);
}

.detail-shell {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 18, 12, 0.42);
  backdrop-filter: blur(10px);
}

.detail-panel {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100vw - 28px));
  height: calc(100vh - 24px);
  margin: 12px auto;
  padding: 20px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.97), rgba(249, 246, 239, 0.96)),
    var(--panel);
  box-shadow: 0 30px 90px rgba(28, 22, 10, 0.24);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 16px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.detail-title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

.detail-title-row h3 {
  margin: 0;
  font-size: clamp(1.45rem, 2vw, 2.2rem);
  letter-spacing: -0.05em;
}

.detail-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.detail-head-actions .secondary-button {
  text-decoration: none;
}

.detail-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.detail-kv-card {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fffef9;
  display: grid;
  gap: 8px;
}

.detail-kv-card span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-kv-card strong {
  font-size: 0.98rem;
  line-height: 1.45;
}

.detail-tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 4px;
}

.detail-tab-button {
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #f7f2e8;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.detail-tab-button.active {
  background: var(--accent-soft);
  border-color: #b8dece;
  color: var(--accent-strong);
}

.detail-panels {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.detail-tab-panel {
  display: none;
  gap: 14px;
}

.detail-tab-panel.active {
  display: grid;
}

.detail-section {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fffefb;
  overflow: hidden;
}

.detail-section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #f7f2e7;
}

.detail-section-head h4 {
  margin: 0;
  font-size: 0.94rem;
}

.detail-attachment-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.detail-attachment {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  background: #fffef9;
}

.detail-attachment:hover {
  color: var(--accent);
}

.detail-richtext {
  padding: 18px;
  line-height: 1.65;
  color: var(--text);
}

.detail-richtext table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
}

.detail-richtext th,
.detail-richtext td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

.detail-richtext a {
  color: var(--accent);
}

.detail-richtext ul,
.detail-richtext ol {
  padding-left: 24px;
}

.detail-text-block {
  margin: 0;
  padding: 18px;
  overflow: auto;
  font: inherit;
  line-height: 1.65;
  white-space: pre-wrap;
}

.detail-table-scroll {
  border-top: 0;
}

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

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

.detail-table th:last-child,
.detail-table td:last-child {
  border-right: 0;
}

.detail-table thead {
  background: #f3eee1;
}

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

  .workspace-sidebar {
    position: static;
    order: 2;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .workspace-main {
    order: 1;
  }

  .brand-block {
    display: none;
  }

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

  .metric-row,
  .db-toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-panel {
    width: min(100vw - 20px, 1240px);
  }

  .detail-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pagination-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pagination-summary,
  .pagination-numbers {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .workspace-shell {
    width: min(100% - 16px, 1500px);
    margin: 8px auto;
  }

  .workspace-sidebar,
  .metric-row,
  .db-toolbar,
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .brand-block,
  .sidebar-card,
  .workspace-topbar,
  .panel-card,
  .metric-card {
    border-radius: 18px;
  }

  .data-table {
    min-width: 720px;
  }

  .log-entry {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .row-inline-actions {
    gap: 6px;
  }

  .detail-panel {
    width: calc(100vw - 12px);
    height: calc(100vh - 12px);
    margin: 6px auto;
    padding: 14px;
    border-radius: 22px;
  }

  .detail-head,
  .detail-section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .detail-head-actions {
    width: 100%;
    justify-content: stretch;
  }

  .detail-head-actions .secondary-button {
    width: 100%;
    text-align: center;
  }

  .detail-summary-grid {
    grid-template-columns: 1fr;
  }

  .detail-table {
    min-width: 560px;
  }

  .pagination-bar {
    grid-template-columns: 1fr;
  }

  .pagination-summary,
  .pagination-numbers {
    grid-column: auto;
  }
}
