:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #64748b;
  --border: #e2e8f0;
  --soft: #eef4ff;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --teal: #0f766e;
  --green: #16a34a;
  --amber: #d97706;
  --dark: #151a24;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  position: relative;
  overflow: visible;
}

.view {
  min-height: 100vh;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.view.hidden {
  opacity: 0;
  pointer-events: none;
  position: absolute;
  inset: 0;
  transform: translateY(8px);
}

.login-view {
  display: grid;
  grid-template-columns: minmax(360px, 480px) minmax(520px, 1fr);
  gap: 64px;
  align-items: center;
  padding: 56px clamp(24px, 6vw, 96px);
}

.login-panel,
.login-preview,
.content-band,
.summary-grid article {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  padding: 36px;
}

.brand-row,
.sidebar-brand,
.dialog-heading,
.topbar,
.section-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-row {
  justify-content: flex-start;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  font-weight: 800;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 13px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  margin-bottom: 6px;
  font-size: 28px;
}

h3 {
  margin-bottom: 4px;
  font-size: 18px;
}

.login-copy {
  margin: 48px 0 28px;
}

.login-copy p,
.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.form-stack {
  display: grid;
  gap: 18px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fbfdff;
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

input,
select {
  height: 44px;
}

textarea {
  min-height: 96px;
  padding-top: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.primary-button,
.secondary-button,
.ghost-button,
.nav-item,
.icon-button {
  border: 0;
  border-radius: 7px;
  min-height: 42px;
  font-weight: 800;
}

.primary-button {
  background: var(--blue);
  color: white;
  padding: 0 18px;
}

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

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.primary-button.compact {
  min-height: 38px;
}

.secondary-button.compact {
  min-height: 38px;
}

.secondary-button {
  background: #eef2f7;
  color: var(--ink);
  padding: 0 16px;
}

.ghost-button {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  background: #eef2f7;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.form-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.two-factor-group {
  display: grid;
  gap: 8px;
}

.two-factor-group[hidden] {
  display: none;
}

.login-error {
  margin: 0;
  border: 1px solid #fecaca;
  border-radius: 7px;
  background: #fef2f2;
  color: #b91c1c;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 700;
}

.login-error[hidden] {
  display: none;
}

.login-preview {
  min-height: 560px;
  padding: 28px;
  overflow: hidden;
}

.preview-topbar,
.preview-card,
.preview-grid div,
.preview-table {
  border-radius: 8px;
  background: #f1f5f9;
  border: 1px solid var(--border);
}

.preview-topbar {
  height: 62px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
}

.preview-topbar span {
  width: 72px;
  height: 12px;
  border-radius: 999px;
  background: #cbd5e1;
}

.preview-card {
  height: 150px;
  margin-top: 24px;
  background: linear-gradient(135deg, #eef4ff, #eefdf8);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 16px 0;
}

.preview-grid div {
  height: 110px;
}

.preview-table {
  height: 180px;
  display: grid;
  gap: 14px;
  padding: 20px;
}

.preview-table span {
  height: 18px;
  border-radius: 999px;
  background: #dbe4ef;
}

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

.sidebar {
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--dark);
  color: white;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  justify-content: flex-start;
  margin-bottom: 42px;
}

.sidebar-brand span,
.sidebar-footer span {
  display: block;
  color: #a6b0c3;
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  background: transparent;
  color: #a6b0c3;
  text-align: left;
  padding: 0 14px;
}

.nav-item.active {
  background: var(--soft);
  color: var(--blue);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.workspace {
  min-width: 0;
  padding: 24px;
  overflow: hidden;
}

.workspace-view {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 160ms ease, transform 160ms ease;
}

.workspace-view.hidden-panel {
  display: none;
  opacity: 0;
  transform: translateY(6px);
}

.topbar .hidden-panel {
  display: none;
}

.topbar {
  min-height: 64px;
}

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

.summary-grid article {
  padding: 18px;
  box-shadow: none;
}

.summary-grid span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.content-band {
  padding: 22px;
  box-shadow: none;
}

.project-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.project-card,
.empty-state {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  padding: 18px;
}

.project-card {
  display: grid;
  gap: 14px;
}

.project-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.project-card h4 {
  margin: 0 0 4px;
  font-size: 16px;
}

.project-card p,
.empty-state p {
  margin: 0;
  color: var(--muted);
}

.status-pill {
  align-self: flex-start;
  border-radius: 999px;
  background: #ecfdf3;
  color: var(--green);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.project-meta {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
}

.text-button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: white;
  color: var(--blue);
  padding: 0 12px;
  font-weight: 800;
}

.muted-line {
  margin: 0;
  color: var(--muted);
}

.builder-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}

.builder-grid {
  display: grid;
  grid-template-columns: minmax(210px, 260px) minmax(0, 1fr) minmax(220px, 280px);
  gap: 16px;
  align-items: start;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.builder-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.main-builder-panel {
  min-height: 520px;
}

.form-stack.tight {
  gap: 14px;
  margin-top: 18px;
}

.menu-item-list,
.selected-menu-details {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.menu-item-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.menu-item-card.active {
  border-color: #b8cdff;
  background: #f6f9ff;
}

.menu-item-top,
.field-row,
.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.menu-item-top {
  align-items: flex-start;
}

.menu-item-top > div:first-child {
  min-width: 0;
}

.menu-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.menu-item-card h4 {
  margin: 0 0 4px;
}

.menu-item-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field-tag,
.script-tag,
.database-tag {
  max-width: 100%;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.field-tag {
  background: #eef4ff;
  color: var(--blue);
}

.script-tag {
  background: #ecfdf8;
  color: var(--teal);
}

.database-tag {
  background: #fff7ed;
  color: var(--amber);
}

.detail-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
  padding: 14px;
}

.detail-card h4 {
  margin: 0 0 12px;
}

.field-row,
.detail-row {
  padding: 9px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.field-row strong,
.detail-row strong {
  color: var(--ink);
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.script-upload {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: grid;
  gap: 12px;
}

.script-upload input[type="file"] {
  height: auto;
  padding: 10px;
}

.upload-status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.placeholder-view {
  min-height: 360px;
  display: grid;
  align-items: center;
}

.placeholder-view h3 {
  font-size: 26px;
}

.work-list-panel {
  min-height: 560px;
}

.record-table {
  margin-top: 18px;
  overflow: auto;
}

.record-table table,
.admin-table table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

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

.record-table th,
.admin-table th {
  color: var(--muted);
  font-weight: 800;
  background: #f8fafc;
}

.record-table td,
.admin-table td {
  color: var(--ink);
}

.record-table tr:hover td,
.admin-table tr:hover td {
  background: #fbfdff;
}

.admin-table {
  margin-top: 18px;
  overflow: auto;
}

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

.danger-button {
  min-height: 34px;
  border: 1px solid #fecaca;
  border-radius: 7px;
  background: #fef2f2;
  color: #b91c1c;
  padding: 0 12px;
  font-weight: 800;
}

.inline-message {
  margin: 16px 0 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fbfdff;
  color: var(--muted);
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 700;
}

.inline-message.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #15803d;
}

.inline-message.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.record-empty {
  min-height: 280px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

.dynamic-fields {
  display: grid;
  gap: 14px;
}

.record-dialog {
  width: min(620px, calc(100vw - 32px));
}

.boolean-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fbfdff;
  padding: 12px 14px;
}

.boolean-field input {
  width: 18px;
  height: 18px;
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
}

.project-dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.project-dialog::backdrop {
  background: rgba(15, 23, 42, 0.28);
}

@media (max-width: 900px) {
  .login-view,
  .main-view {
    grid-template-columns: 1fr;
  }

  .login-preview {
    display: none;
  }

  .sidebar {
    min-height: auto;
    height: auto;
    position: static;
  }

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

  .builder-header,
  .builder-grid,
  .work-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .builder-grid {
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  }

  .builder-grid > .builder-panel:last-child {
    grid-column: 1 / -1;
  }
}
