/* Documenteditor — standalone build.
   No framework, no build step: this file is served as-is. */

:root {
  --line: #cbd5e1;
  --line-soft: #e2e8f0;
  --bg: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #2563eb;
  --warn-ink: #92400e;
  --warn-bg: #fffbeb;
  --warn-line: #fde68a;
}

* { box-sizing: border-box; }

/* The `hidden` attribute hides an element through a rule in the browser's own
   stylesheet, and *any* author rule that sets `display` beats it — which every
   `.pane`, `.group` and `.plain-notice` below does, because they are flex
   rows. Without this the ribbon tabs appear to do nothing: all four panes stay
   stacked on screen while the attribute dutifully toggles underneath.
   `!important` is what makes it survive a later, more specific rule. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* --- top bar ----------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  font-weight: 650;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.spacer { flex: 1 1 auto; }

/* --- tabs and panes ---------------------------------------------------- */

.tabs {
  display: flex;
  gap: 2px;
  padding: 6px 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

.tabs button {
  padding: 5px 14px;
  font: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  color: var(--ink);
  background: #fff;
  border-color: var(--line-soft);
  margin-bottom: -1px;
}

.pane {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 7px 10px;
  background: #fff;
  border-bottom: 1px solid var(--line-soft);
}

.group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 14px;
  border-right: 1px solid var(--line-soft);
}

.group:last-child { border-right: none; }
.group > label { color: var(--muted); }

/* --- controls ---------------------------------------------------------- */

button,
.file-button {
  padding: 4px 9px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

button:hover:not(:disabled),
.file-button:hover { background: #f1f5f9; }

button:active:not(:disabled) { background: #e2e8f0; }

button:disabled { opacity: .4; cursor: default; }

button.on { background: #dbeafe; border-color: #93c5fd; }

select,
input[type=text],
input[type=number],
input[type=search] {
  padding: 3px 5px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
}

input[type=number] { width: 66px; }
input.margin { width: 58px; }

input[type=color] {
  width: 30px;
  height: 25px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.readout { color: var(--muted); min-width: 46px; }

/* --- plain-text notice -------------------------------------------------- */

.plain-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 12px;
  color: var(--warn-ink);
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-line);
}

.plain-notice button {
  color: var(--warn-ink);
  border-color: #fcd34d;
}

.plain-notice button:hover { background: #fef3c7; }

/* --- body -------------------------------------------------------------- */

.body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  padding: 20px;
  overflow: auto;
  background: #e2e8f0;
}

/* A header or footer is drawn in the margin band, so without this nothing on
   screen tells the user that typing now goes into a different part. */
.stage.in-part { background: #e0e7ff; }
.stage.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }

canvas {
  display: block;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 1px 8px rgba(15, 23, 42, .25);
}

canvas:focus { outline: 2px solid var(--accent); outline-offset: 3px; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  background: rgba(226, 232, 240, .94);
  z-index: 2;
}

.overlay-inner { max-width: 34rem; color: #475569; }
.overlay.error .overlay-inner { color: #b91c1c; }
.overlay.error .spinner { display: none; }

.spinner {
  width: 24px;
  height: 24px;
  margin: 0 auto 10px;
  border: 3px solid #cbd5e1;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}

/* --- side panel --------------------------------------------------------- */

.side {
  flex: 0 0 250px;
  padding: 10px 12px;
  overflow: auto;
  background: var(--bg);
  border-left: 1px solid var(--line-soft);
}

.side section { margin-bottom: 18px; }

.side h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.side .row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 3px 0;
}

.side .row > label:first-child {
  flex: 0 0 88px;
  color: #475569;
}

.side .row select { flex: 1 1 auto; min-width: 0; }

.hint {
  margin: 4px 0 0;
  color: var(--faint);
  font-style: italic;
}

/* Amber when only the text is kept, so the one lossy mode reads at a glance
   rather than only on opening the dropdown. */
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.dot.plain { background: #d97706; }

/* --- properties readout -------------------------------------------------- */

#props .prop {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 1px 0;
  color: #475569;
}

#props .prop .value { color: var(--ink); text-align: right; }

/* The blue dot marks a property the text carries itself; without it the value
   comes from the style. */
#props .prop.set .name::after {
  content: '\2022';
  color: var(--accent);
  margin-left: 4px;
}

#props .prop.mixed .value { color: var(--faint); font-style: italic; }
#props .empty { color: var(--faint); font-style: italic; }

/* --- field palette ------------------------------------------------------- */

#fields .dataset {
  margin: 8px 0 3px;
  font-weight: 600;
  color: #334155;
}

#fields .field {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  margin: 2px 0;
  padding: 3px 6px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  cursor: grab;
}

#fields .field:hover { background: #e0f2fe; border-color: #7dd3fc; }
#fields .count { color: #475569; background: #e2e8f0; border-radius: 8px; padding: 0 6px; }
#fields .empty { color: var(--faint); font-style: italic; }

/* --- status bar ---------------------------------------------------------- */

.statusbar {
  display: flex;
  gap: 18px;
  padding: 4px 12px;
  font-size: 12px;
  color: #475569;
  background: #fff;
  border-top: 1px solid var(--line-soft);
}

.statusbar .hint-status { flex: 1 1 auto; color: var(--accent); }

@media (max-width: 860px) {
  .side { display: none; }
  .stage { padding: 10px; }
}

/* --- shape gallery -------------------------------------------------------- */

.pane.shapes { gap: 18px; align-items: flex-start; }

#shape-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.shape-lib { display: flex; flex-direction: column; gap: 3px; }

.shape-lib .lib-name {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.shape-row { display: flex; flex-wrap: wrap; gap: 3px; }

.shape-row .shape {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 3px;
}

.shape-row .shape svg { display: block; }
.shape-row .shape:hover { background: #e0f2fe; border-color: #7dd3fc; }

/* The "no fill" / "no line" toggles latch, so the state has to show. */
.shape-style button.on {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

#shape-gallery .empty { color: var(--faint); font-style: italic; }

/* --- table panel ---------------------------------------------------------- */

.pane .times { color: var(--faint); }

.pane input#new-rows,
.pane input#new-cols,
.pane input#tbl-rows,
.pane input#tbl-cols { width: 54px; }

.pane input#col-width,
.pane input#row-height,
.pane input#border-width { width: 62px; }

.pane label:has(input[type=checkbox]) {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}
