/* Data Editor demo — the product window, reproduced from summaintool.client/src/css/site.css:
   the slate rail and white top bar, the dataset dialog's action bar of text buttons, and the
   data grid's look (uppercase 12px headers, 13px cells on a slate-50 surface, the read-only
   wash) with its row-state colours exactly as DataGridContent paints them. Loaded only by the
   pages that embed the demo. */

.de {
  display: grid;
  /* The mission rail and the grid scroll inside their own boxes; without minmax(0, ...) their
     content would set the column's minimum and widen a phone-width page. */
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  font-family: var(--font-sans);
}

/* ---------- Demo controls: affordances the product does not have, marked as such ---------- */

.de-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding: 10px 14px;
  border: 1px dashed var(--action-300);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 0.875rem;
  color: var(--ink-700);
}
.de-controls__label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  background: var(--action-50);
  color: var(--action-700);
}
.de-controls__note { color: var(--text-subtle); font-size: 0.82rem; }
.de-controls__pending {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  background: var(--ink-100);
  color: var(--ink-600);
}
.de-controls__pending.is-pending { background: var(--cell-changed); color: var(--changed-ink); }
.de-controls__hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-subtle);
}

.de-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--ink-800);
  cursor: pointer;
}
.de-switch__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.de-switch__track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--ink-300);
  transition: background var(--transition);
}
.de-switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition);
}
.de-switch__input:checked + .de-switch__track { background: var(--action-500); }
.de-switch__input:checked + .de-switch__track::after { transform: translateX(14px); }
.de-switch__input:focus-visible + .de-switch__track { outline: 3px solid var(--action-300); outline-offset: 2px; }

/* ---------- The window ---------- */

.de-window {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-window);
  overflow: hidden;
  font-size: 13px;
  color: #1e293b;
}

.de-app {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
}

.de-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
}
.de-rail__logo { width: 28px; height: 28px; }
.de-rail__divider { width: 24px; height: 1px; margin: 8px 0; background: #e2e8f0; }
.de-rail__item {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: #64748b;
}
.de-rail__item.is-active { background: #eff6ff; color: #2563eb; }

.de-shell { display: flex; flex-direction: column; min-width: 0; }

.de-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 48px;
  padding: 0 18px;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
}
.de-topbar__name {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.018em;
  color: #1e293b;
}
.de-topbar__user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: #334155;
  font-weight: 500;
}
.de-topbar__avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e2e8f0;
  color: #64748b;
}
.de-topbar__avatar .de-icon svg { width: 15px; height: 15px; }

.de-icon { display: inline-flex; line-height: 0; }

.de-sheet {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 14px 16px 16px;
  background: #fff;
}
.de-sheet__title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.de-crumbs { margin: 0; font-family: var(--font-mono); font-size: 11.5px; color: #64748b; }
.de-sheet__name { margin: 0; font-family: var(--font-sans); font-size: 17px; font-weight: 600; letter-spacing: -0.01em; color: #1e293b; }

/* ---------- Operation messages ---------- */

.de-messages { display: grid; gap: 6px; }
.de-messages:empty { display: none; }
.de-message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid #e2e8f0;
  border-left-width: 3px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.45;
  animation: de-message-in 200ms var(--ease-out);
}
.de-message > span { flex: 1; padding-top: 4px; overflow-wrap: anywhere; }
.de-message--success { border-color: #117344; background: #e2f3e9; color: #117344; }
.de-message--error { border-color: #b3261e; background: #fce8e6; color: #8a1d17; }
.de-message--info { border-color: #2563eb; background: #eff6ff; color: #1e40af; }
.de-message__close {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.de-message__close .de-icon svg { width: 14px; height: 14px; }
/* The countdown ring of an auto-closing message. */
.de-message__ring {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: conic-gradient(currentColor var(--p, 100%), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 9px, #000 9.5px);
  mask: radial-gradient(circle, transparent 9px, #000 9.5px);
  opacity: 0.45;
  animation: de-countdown 7s linear forwards;
}
@property --p {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 100%;
}
@keyframes de-countdown { to { --p: 0%; } }
@keyframes de-message-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- Action bar ---------- */

.de-actionbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
  font-size: 13.5px;
}
.de-actionbar__spacer { flex: 1; }
.de-check { display: inline-flex; align-items: center; gap: 7px; color: #334155; cursor: pointer; padding-right: 8px; }
.de-check input { width: 16px; height: 16px; accent-color: #2563eb; }

.de-textbutton {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: #334155;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}
.de-textbutton:hover { background: #f1f5f9; color: #1e293b; }
.de-textbutton.is-primary { color: #1d4ed8; font-weight: 600; }
.de-textbutton.is-primary:hover { background: #eff6ff; }
.de-textbutton:disabled { color: #cbd5e1; cursor: default; background: transparent; }

/* ---------- The grid ---------- */

.de-gridwrap {
  overflow: auto;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  background: #f8fafc;
  -webkit-overflow-scrolling: touch;
}
.de-gridwrap:focus-visible { outline: 3px solid var(--action-300); outline-offset: 2px; }

/* The table's width is set inline from the configured column widths (see view.ts renderGrid). */
.de-grid {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 13px;
  line-height: 32px;
  color: #1e293b;
}

.de-grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 34px;
  padding: 0 10px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  border-right: 1px solid #e2e8f0;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.de-grid th .de-icon { display: inline-flex; vertical-align: -2px; margin-right: 3px; color: #94a3b8; }
.de-grid th .de-icon svg { width: 14px; height: 14px; }
.de-grid th.is-readonly,
.de-grid td.is-readonly { background-image: linear-gradient(rgba(15, 23, 42, 0.045), rgba(15, 23, 42, 0.045)); }
.de-grid th.is-error { color: #8a1d17; }

.de-grid__filters th {
  top: 34px;
  height: 36px;
  padding: 0 6px;
  text-transform: none;
  letter-spacing: 0;
}
.de-filter {
  width: 100%;
  height: 26px;
  padding: 0 8px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-xs);
  background: #f8fafc;
  color: #334155;
  font: inherit;
  font-size: 12.5px;
}
.de-filter:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22); }
.de-filter.is-invalid { border-color: #b3261e; background: #fce8e6; color: #8a1d17; }

.de-grid td {
  height: 33px;
  padding: 0;
  border-bottom: 1px solid #e2e8f0;
  border-right: 1px solid #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.de-grid tbody tr:hover td { background-color: #eff6ff; }

.de-cell__button,
.de-cell__text {
  display: block;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 32px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.de-cell__button { cursor: pointer; }
.de-cell__button:focus-visible { outline: 2px solid #2563eb; outline-offset: -2px; border-radius: 0; }
.de-cell.is-readonly { color: #475569; cursor: not-allowed; }
.de-cell__button.is-null { color: #64748b; }

/* Row states — DataGridContent.renderRow / renderCell. A changed cell outranks its row. The
   product sets these colours as inline styles, which no hover rule can override, so the hover
   case is listed here too: pointing at a new row must not hide that it is new. */
.de-row.is-inserted td,
.de-grid tbody tr.de-row.is-inserted:hover td { background-color: var(--row-inserted); }
.de-row.is-deleted td,
.de-grid tbody tr.de-row.is-deleted:hover td { background-color: var(--row-deleted); }
.de-grid td.is-changed,
.de-grid tbody tr.de-row td.is-changed,
.de-grid tbody tr.de-row:hover td.is-changed { background-color: var(--cell-changed); }
.de-grid td.de-cell-error { background-color: var(--cell-error); color: #8a1d17; font-size: 12px; padding: 0 10px; }

.de-grid__menu { width: 40px; text-align: center; }
.de-grid th.de-grid__menu { padding: 0; }
.de-rowmenu {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #64748b;
  cursor: pointer;
  vertical-align: top;
}
.de-rowmenu:hover,
.de-rowmenu:focus-visible { background: #e2e8f0; color: #1e293b; }

.de-grid__empty { padding: 24px !important; text-align: center; color: #64748b; white-space: normal !important; }

.de-checkbox {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  border: 2px solid #94a3b8;
  border-radius: 3px;
  background: #fff;
  color: #fff;
}
.de-checkbox.is-checked { background: #2563eb; border-color: #2563eb; }
.de-checkbox .de-icon svg { width: 12px; height: 12px; }
/* NULL: the indeterminate state of the product's tri-state checkbox. */
.de-checkbox.is-null { border-color: #2563eb; }
.de-checkbox.is-null::after { content: ''; width: 8px; height: 2px; background: #2563eb; }

/* Group and totals rows */
.de-group td { background: #fff; font-weight: 600; }
.de-group__cell { padding: 0 10px !important; }
.de-group__toggle {
  height: 32px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.de-group__toggle:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.de-aggregate--sum { font-weight: 700; }
.de-adjust {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-left: 4px;
  vertical-align: -6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #2563eb;
  cursor: pointer;
}
.de-adjust:hover,
.de-adjust:focus-visible { background: #dbeafe; }
.de-adjust .de-icon svg { width: 16px; height: 16px; }
.de-groupbool { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 500; }
.de-groupbool input { width: 16px; height: 16px; accent-color: #2563eb; }
.de-groupbool__count { color: #64748b; font-size: 12px; }

.de-total td {
  background: #fff;
  border-top: 2px solid #cbd5e1;
  border-bottom: 0;
  padding: 0 10px;
}
.de-total__label { font-weight: 600; }
.de-total__count { margin-left: 6px; color: #64748b; font-size: 12px; }

/* Cell editors */
.de-editor {
  display: block;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 2px solid #2563eb;
  border-radius: 0;
  background: #fff;
  color: #1e293b;
  font: inherit;
  outline: none;
}

/* ---------- Menu, dialogs, tooltip ---------- */

.de-overlay { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.de-overlay > * { pointer-events: auto; }

.de-menu {
  position: absolute;
  min-width: 190px;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.de-menu__item {
  display: block;
  width: 100%;
  padding: 7px 12px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: #1e293b;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.de-menu__item:hover,
.de-menu__item:focus-visible { background: #f1f5f9; outline: none; }

.de-backdrop {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 19, 34, 0.32);
}
.de-dialog {
  width: min(540px, 100%);
  max-height: calc(100% - 16px);
  overflow: auto;
  padding: 20px 22px 14px;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: de-message-in 160ms var(--ease-out);
}
.de-dialog__title { margin: 0 0 14px; font-family: var(--font-sans); font-size: 18px; font-weight: 600; color: #1e293b; }
.de-dialog__body { display: grid; gap: 14px; color: #334155; }
.de-dialog__body p { margin: 0; }
.de-dialog__actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 18px; }
.de-field { display: grid; gap: 4px; }
.de-field__label { font-size: 12px; color: #475569; }
.de-field__control {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #fff;
  color: #1e293b;
  font: inherit;
}
.de-field__control:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22); }
.de-field__control--short { max-width: 120px; }

.de-tooltip {
  position: absolute;
  z-index: 6;
  max-width: 340px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--tooltip-bg);
  color: #fff;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.de-tooltip[hidden] { display: none; }

/* ---------- What the save sent ---------- */

.de-statements {
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  color: var(--text-on-inverse-subtle);
  background:
    linear-gradient(to right, var(--gridline-inverse) 1px, transparent 1px) 0 0 / 132px 40px,
    linear-gradient(to bottom, var(--gridline-inverse) 1px, transparent 1px) 0 0 / 132px 40px,
    var(--surface-inverse);
}
.de-statements__title { margin: 0 0 4px; color: #fff; font-size: 1.3rem; font-weight: 700; }
.de-statements__lede,
.de-statements__empty,
.de-statements__batch { margin: 0; font-size: 0.875rem; }
.de-statements__batch { margin-top: 12px; font-family: var(--font-mono); font-size: 0.75rem; color: var(--action-300); }
.de-statements__empty { margin-top: 12px; opacity: 0.8; }
.de-statements__list { display: grid; gap: 8px; margin: 10px 0 0; padding: 0; list-style: none; }
.de-statement {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(16, 28, 48, 0.9);
  border: 1px solid var(--navy-700);
}
.de-statement__kind {
  justify-self: start;
  padding: 1px 7px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--navy-700);
  color: #fff;
}
.de-statement--delete .de-statement__kind { background: var(--row-deleted); color: #4a0f06; }
.de-statement--update .de-statement__kind { background: var(--cell-changed); color: var(--changed-ink); }
.de-statement--insert .de-statement__kind { background: var(--row-inserted); color: #0b3d0b; }
.de-statement--rule-per-record .de-statement__kind,
.de-statement--rule-after-save .de-statement__kind { background: var(--action-200); color: var(--action-800); text-transform: none; letter-spacing: 0; }
.de-statement__sql {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.55;
  color: #e6edf6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.de-statement__params { margin: 0; font-family: var(--font-mono); font-size: 0.72rem; color: var(--navy-300); overflow-wrap: anywhere; }
.de-statement__rejected { margin: 4px 0 0; padding: 6px 10px; border-left: 3px solid #f09090; background: rgba(240, 144, 144, 0.1); color: #ffc2c2; font-size: 0.8rem; }
.de-statement.is-rejected { border-color: #7a2a2a; }
.de-sql-kw { color: #93c5fd; font-weight: 500; }
.de-sql-id { color: var(--cell-changed); }
.de-sql-param { color: var(--row-inserted); }

/* ---------- Missions (playground) ---------- */

.de-missions {
  padding: 18px 20px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.de-missions__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 14px; }
.de-missions__title { margin: 0; font-size: var(--text-xl); }
.de-missions__progress {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  background: var(--positive-100);
  color: var(--positive-500);
}
.de-missions__reset {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--text-subtle);
  font: inherit;
  font-size: 0.82rem;
  text-decoration: underline;
  cursor: pointer;
}
.de-missions__rail {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0 0 4px;
  list-style: none;
  overflow-x: auto;
}
.de-missions__step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink-800);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.de-missions__step[aria-current='step'] { border-color: var(--action-500); background: var(--action-50); color: var(--action-700); }
.de-missions__num {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--ink-100);
  font-size: 0.78rem;
  font-weight: 700;
}
.de-missions__step.is-done .de-missions__num { background: var(--positive-500); color: #fff; }

.de-mission {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-tinted);
  border: 1px solid var(--action-100);
}
.de-mission__title { margin: 0 0 4px; font-size: var(--text-lg); }
.de-mission__brief { margin: 0; color: var(--text-body); font-size: var(--text-sm); }
.de-mission__hints { margin: 10px 0 0; padding-left: 20px; font-size: 0.875rem; color: var(--ink-700); }
.de-mission__hints li { margin-bottom: 4px; }
.de-mission__hint {
  margin-top: 10px;
  padding: 6px 12px;
  border: 1px solid var(--action-300);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--action-700);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.de-mission__hint:disabled { opacity: 0.6; cursor: default; }
.de-mission.is-done { background: var(--positive-100); border-color: rgba(17, 115, 68, 0.3); }
.de-mission__reward { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(17, 115, 68, 0.25); font-size: var(--text-sm); }
.de-mission__reward p { margin: 0 0 6px; }
.de-mission__reward-title { font-weight: 700; color: var(--positive-500); }
.de-mission--complete { background: var(--surface); border: 2px solid var(--positive-500); }
.de-mission--complete h3 { margin: 0 0 6px; font-size: var(--text-2xl); }
.de-mission__ctas { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 0; }

/* ---------- The static table shown before (or instead of) the live demo ---------- */

.demo-mount:not(.is-live) .de-static-note {
  margin: 0;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: var(--text-subtle);
}

/* ---------- Responsive ---------- */

@media (max-width: 639px) {
  .de-app { grid-template-columns: minmax(0, 1fr); }
  .de-rail { display: none; }
  .de-topbar { height: 44px; padding: 0 12px; }
  .de-topbar__user { font-size: 0; gap: 0; }
  .de-sheet { padding: 10px; }
  .de-actionbar { font-size: 13px; }
  .de-textbutton { padding: 6px 8px; }
  .de-controls__pending { margin-left: 0; }
  .de-statements { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .de-message,
  .de-dialog { animation: none; }
  .de-message__ring { animation: none; }
}
