:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --panel-soft: #faf9f6;
  --text: #1f2933;
  --muted: #697386;
  --line: #dedbd2;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --violet: #7c3aed;
  --amber: #b45309;
  --red: #b91c1c;
  --shadow: 0 10px 28px rgba(31, 41, 51, .08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin-bottom: 22px;
}

.brand-icon {
  width: 42px;
  height: 42px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: var(--text);
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 4px 10px;
  border-radius: 8px;
  text-align: left;
}

.nav-item:hover {
  background: var(--panel-soft);
}

.nav-item.active {
  background: #e7f2ef;
  color: var(--teal-dark);
  font-weight: 700;
}

.nav-icon {
  min-width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--teal-dark);
  background: #fff;
}

.workspace {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 245, 242, .9);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 25px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 14px;
}

.topbar p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.actions,
.row-actions,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.chip-button {
  border: 1px solid var(--line);
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

.primary-button {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button:hover,
.icon-button:hover,
.chip-button:hover {
  border-color: var(--teal);
}

.danger-button {
  color: var(--red);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-weight: 800;
}

.tab-panel {
  display: none;
  padding: 24px 28px 36px;
}

.tab-panel.active {
  display: block;
}

.dashboard-grid,
.two-column,
.templates-grid,
.assignments-grid,
.users-grid,
.integration-grid {
  display: grid;
  gap: 16px;
}

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

.two-column,
.templates-grid,
.assignments-grid,
.users-grid,
.integration-grid {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  align-items: start;
}

.panel,
.metric,
.list-item,
.preview-frame,
.inspector,
.builder-canvas {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel,
.metric,
.inspector,
.builder-canvas {
  padding: 16px;
}

.metric {
  min-height: 94px;
  display: grid;
  align-content: space-between;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
}

.metric strong {
  font-size: 30px;
}

.metric.teal {
  border-top: 4px solid var(--teal);
}

.metric.violet {
  border-top: 4px solid var(--violet);
}

.metric.amber {
  border-top: 4px solid var(--amber);
}

.metric.neutral {
  border-top: 4px solid #64748b;
}

.section-stack {
  display: grid;
  gap: 16px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.list-item.selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, .15);
}

.list-item header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.list-item strong {
  font-size: 14px;
}

.list-item span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

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

.form-grid.one {
  grid-template-columns: 1fr;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
}

input[type="color"] {
  padding: 4px;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.toggle-row input {
  width: auto;
}

.builder {
  display: grid;
  grid-template-columns: minmax(150px, 190px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.builder .inspector {
  grid-column: 1 / -1;
}

.table-builder {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: 14px;
  align-items: start;
}

.table-builder .inspector {
  grid-column: 1 / -1;
}

.signature-grid-canvas {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

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

.editor-cell {
  border: 1px dashed #a6b2c1;
  min-height: 96px;
  padding: 10px;
  vertical-align: top;
  background: #fff;
}

.editor-cell.selected {
  border: 2px solid var(--teal);
  box-shadow: inset 0 0 0 2px rgba(15, 118, 110, .12);
}

.editor-cell-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.editor-cell-blocks {
  display: grid;
  gap: 6px;
}

.cell-block-chip {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 8px;
  min-height: 36px;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text);
}

.cell-block-chip.selected {
  border-color: var(--teal);
  background: #eef8f5;
  font-weight: 700;
}

.palette,
.variable-bank {
  display: grid;
  gap: 8px;
}

.palette button,
.variable-bank button {
  text-align: left;
}

.block-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  min-height: 52px;
}

.block-row.selected {
  border-color: var(--teal);
  background: #eef8f5;
}

.block-type {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
}

.preview-tools {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.preview-frame {
  min-height: 240px;
  overflow: auto;
  padding: 20px;
  background: #fff;
}

.preview-frame iframe {
  width: 100%;
  min-height: 260px;
  border: 0;
  background: #fff;
}

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

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

.table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.checkbox-grid {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text);
}

.checkbox-grid input {
  width: auto;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
  gap: 4px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.split-line {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--red);
}

.dot.ok {
  background: var(--teal);
}

.code {
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 12px;
  background: #f1f0ea;
  padding: 2px 5px;
  border-radius: 5px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.hidden {
  display: none !important;
}

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

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 14px;
}

@media (max-width: 1180px) {
  .builder,
  .table-builder {
    grid-template-columns: 1fr;
  }

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

@media (min-width: 1500px) {
  .builder {
    grid-template-columns: 178px minmax(0, 1fr) 320px;
  }

  .builder .inspector {
    grid-column: auto;
  }

  .table-builder {
    grid-template-columns: minmax(0, 1fr) 190px 320px;
  }

  .table-builder .inspector {
    grid-column: auto;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .nav-item {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .nav-item span:last-child {
    display: none;
  }

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

  .two-column,
  .templates-grid,
  .assignments-grid,
  .users-grid,
  .integration-grid,
  .dashboard-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
