:root {
  --text: #37352f;
  --muted: #9b9a97;
  --faint: #787774;
  --bg: #ffffff;
  --side: #f7f7f5;
  --hover: rgba(55, 53, 47, 0.06);
  --hover-strong: rgba(55, 53, 47, 0.1);
  --line: rgba(55, 53, 47, 0.09);
  --blue: #2383e2;
  --danger: #c4554d;
  --ok: #0f7b4c;
  --ok-bg: #edf7f1;
  --bad-bg: #fdecec;
  --solid: #37352f;
  --on-solid: #ffffff;
  --field: #ffffff;
  --bar: rgba(255, 255, 255, 0.92);
  --shadow: rgba(15, 15, 15, 0.12);
  --backdrop: rgba(15, 15, 15, 0.25);
  --radius: 4px;
  --side-w: 240px;
}

html[data-theme="dark"] {
  --text: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.46);
  --faint: rgba(255, 255, 255, 0.38);
  --bg: #191919;
  --side: #202020;
  --hover: rgba(255, 255, 255, 0.055);
  --hover-strong: rgba(255, 255, 255, 0.095);
  --line: rgba(255, 255, 255, 0.094);
  --blue: #529cca;
  --danger: #e16259;
  --ok: #6fbf8b;
  --ok-bg: rgba(80, 160, 110, 0.18);
  --bad-bg: rgba(225, 98, 89, 0.18);
  --solid: rgba(255, 255, 255, 0.9);
  --on-solid: #191919;
  --field: #252525;
  --bar: rgba(25, 25, 25, 0.92);
  --shadow: rgba(0, 0, 0, 0.45);
  --backdrop: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 16px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(35, 131, 226, 0.18); }

a { color: var(--blue); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--text);
  color: var(--bg);
  padding: 6px 10px;
  border-radius: var(--radius);
  z-index: 30;
}
.skip:focus { top: 12px; }

.nav-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.shell {
  display: flex;
  height: 100%;
  min-height: 100%;
}

.sidebar {
  width: var(--side-w);
  flex: none;
  background: var(--side);
  display: flex;
  flex-direction: column;
  padding: 14px 10px 12px;
  overflow: hidden;
  min-height: 0;
}

.workspace {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 6px 14px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.mark {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: none; }

.side-lists {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 14px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.side-group summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 4px 8px;
  border-radius: var(--radius);
}
.side-group summary::-webkit-details-marker { display: none; }
.side-group summary::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
  border-left: 5px solid var(--muted);
}
.side-group[open] summary::before { transform: rotate(90deg); }
.side-group summary:hover { background: var(--hover); color: var(--text); }
.side-sub { list-style: none; margin: 0; padding: 0; }
.side-sub .side-link { min-width: 0; font-size: 13px; font-weight: 400; }
.side-sub .side-link.is-on { font-weight: 600; }
.side-sub .side-link > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.side-empty {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  padding: 2px 8px 6px 22px;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.side-link:hover { background: var(--hover); }
.side-link.is-on { background: var(--hover-strong); font-weight: 600; }

.glyph {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-foot { margin-top: auto; padding-top: 8px; }
.theme-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  padding: 6px 8px;
  color: var(--faint);
  font-size: 14px;
}
.theme-toggle:hover { background: var(--hover); color: var(--text); }
.theme-moon, .theme-sun { display: inline-flex; align-items: center; gap: 8px; }
.theme-sun { display: none; }
html[data-theme="dark"] .theme-moon { display: none; }
html[data-theme="dark"] .theme-sun { display: inline-flex; }
.theme-float {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
  width: auto;
  background: var(--side);
}
.theme-compact { width: auto; margin-left: auto; padding: 6px; }

.side-exit {
  padding: 0 6px;
}
.side-exit button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  padding: 6px 8px;
  color: var(--faint);
}
.side-exit button:hover { background: var(--hover); color: var(--text); }

.backdrop, .canvas-bar { display: none; }
.menu-btn { display: none; }

.burger {
  width: 14px;
  height: 10px;
  background:
    linear-gradient(currentColor, currentColor) 0 0 / 100% 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) 0 50% / 100% 1.5px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 100% 1.5px no-repeat;
}

.canvas {
  flex: 1;
  min-width: 0;
  overflow: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.sheet {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: min(900px, calc(100% - 96px));
  margin: 0 auto;
  padding: 48px 0 96px;
}

.page-head { margin-bottom: 18px; }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); text-decoration: underline; }
.sep { color: var(--muted); }

.page-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  color: var(--faint);
}
.page-icon .glyph { width: 32px; height: 32px; stroke-width: 1.4; }

h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.title-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.title-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.title-view { cursor: text; }
.title-view h1:hover { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--blue) 45%, transparent); }

.title-download {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.title-download:hover { color: var(--text); }

.title-rename,
.title-cancel {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.title-form { display: none; align-items: center; gap: 8px; }
.title-block:has(.title-toggle:checked) .title-line { display: none; }
.title-block:has(.title-toggle:checked) .title-form { display: flex; }

.title-field {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 40px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  outline: none;
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--blue) 70%, transparent);
}

.title-form button,
.rename button {
  border: 0;
  border-radius: var(--radius);
  background: var(--hover-strong);
  color: var(--text);
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 600;
}

@media (hover: hover) {
  .title-rename { opacity: 0; }
  .title-block:hover .title-rename,
  .title-block:focus-within .title-rename { opacity: 1; }
}

.lede {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.flash, .callout {
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 16px;
  font-size: 14px;
}
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.erro { background: var(--bad-bg); color: var(--danger); }
.callout { background: var(--side); color: var(--text); }

.composer { margin: 8px 0 8px; }

.new-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin: 0 -8px;
  padding: 2px 8px;
  border-radius: var(--radius);
}
.new-row:hover { background: var(--hover); }

.plus {
  width: 18px;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.new-row input[type="text"],
.new-row input:not([type]),
.new-row input[name="nome"] {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 6px 0;
  outline: none;
}
.new-row input::placeholder { color: var(--muted); }

.new-row button,
.prop-actions button,
.gate-card button {
  border: 0;
  border-radius: var(--radius);
  background: var(--solid);
  color: var(--on-solid);
  padding: 5px 10px;
  font-size: 14px;
  font-weight: 500;
}
.new-row button { background: transparent; color: var(--faint); padding: 4px 8px; }
.new-row:focus-within button,
.new-row:hover button { background: var(--hover-strong); color: var(--text); }

.pick {
  position: relative;
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 16px;
}
.pick input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.pick-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collection {
  flex: 1;
  margin-top: 12px;
  min-height: 180px;
}

.details { display: contents; }

.colhead, .row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 120px 140px auto;
  gap: 12px;
  align-items: center;
}
.colhead {
  padding: 4px 8px 6px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}

.listing { list-style: none; margin: 0; padding: 0; }

.row {
  min-height: 36px;
  margin: 1px -8px;
  padding: 2px 8px;
  border-radius: var(--radius);
}
.row:hover { background: var(--hover); }
.row.is-selected,
.row.is-selected:hover {
  background: color-mix(in srgb, var(--blue) 18%, transparent);
}
.listing .name { cursor: default; }
.marquee {
  position: fixed;
  z-index: 40;
  border: 1px solid var(--blue);
  background: color-mix(in srgb, var(--blue) 16%, transparent);
  pointer-events: none;
}
body.is-marquee { user-select: none; cursor: default; }
.select-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: var(--hover);
  font-size: 14px;
}
.select-bar[hidden] { display: none; }
.select-count { color: var(--text); font-weight: 600; }
.select-bar .ask { opacity: 1; }
.select-download {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 600;
}
.select-download:hover { color: var(--blue); }
.select-bar > button[type="submit"] { display: none; }
.select-bar .ask:has(input:checked) + button {
  display: inline-flex;
  background: transparent;
  color: var(--danger);
  border: 0;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 600;
}
.select-clear {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--faint);
  padding: 4px 6px;
  font-size: 13px;
}
.select-clear:hover { color: var(--text); }
.row.is-dragging { opacity: 0.4; }
.row.is-drop, .drop-target.is-drop {
  background: var(--hover-strong);
  box-shadow: inset 0 0 0 2px var(--blue);
}

.name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name:hover { background: transparent; }
.name-slot { min-width: 0; }
.ico { color: var(--faint); display: grid; }

.rename { display: none; align-items: center; gap: 8px; min-width: 0; }
.row:has(.edit-toggle:checked) .name { display: none; }
.row:has(.edit-toggle:checked) .rename { display: flex; }
.rename-field {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 2px 0;
  font-weight: 500;
  outline: none;
  box-shadow: inset 0 -1px 0 var(--blue);
}

.meta { color: var(--faint); font-size: 13px; }
.when { font-variant-numeric: tabular-nums; }

.row-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}
.row-delete { display: flex; justify-content: flex-end; }
.row:has(.edit-toggle:checked) .row-delete { display: none; }
.row:has(.row-delete .ask input:checked) .edit-ask { display: none; }

.ask, .edit-ask {
  position: relative;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.ask input, .edit-ask input {
  position: absolute;
  opacity: 0;
  inset: 0;
  cursor: pointer;
}
.edit-ask .when-on { display: none; }
.row:has(.edit-toggle:checked) .edit-ask .when-off { display: none; }
.row:has(.edit-toggle:checked) .edit-ask .when-on { display: inline; color: var(--text); }
.row-delete button { display: none; }
.ask:has(input:checked) { display: none; }
.ask:has(input:checked) + button {
  display: inline-flex;
  background: transparent;
  color: var(--danger);
  border: 0;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 600;
}

.row-download, .quiet {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.row-download:hover, .quiet:hover { color: var(--text); }
.title-line .quiet { align-self: center; }

.stage { margin: 8px 0 0; }
.stage img, .stage video {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 240px);
  margin: 0 auto;
  background: var(--side);
  border-radius: 6px;
}
.viewer-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  font-size: 14px;
}
.viewer-bar a { color: var(--muted); text-decoration: none; }
.viewer-bar a:hover { color: var(--text); }

@media (hover: hover) {
  .ask, .edit-ask { opacity: 0; }
  .row:hover .ask,
  .row:hover .edit-ask,
  .row:focus-within .ask,
  .row:focus-within .edit-ask,
  .ask:has(input:checked),
  .ask:has(input:checked) + button,
  .row:has(.edit-toggle:checked) .edit-ask { opacity: 1; }
}

.empty {
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.props { max-width: 640px; }

.prop {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.prop span { color: var(--faint); }
.prop input {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 6px;
  border-radius: var(--radius);
  outline: none;
}
.prop input:hover { background: var(--hover); }
.prop input:focus { background: var(--hover); box-shadow: inset 0 0 0 1px var(--blue); }

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.prop-actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}
.prop-actions .ghost,
.gate-card button.ghost {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px 64px;
  background: var(--bg);
}
.gate-card {
  width: min(420px, 100%);
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.gate-card label {
  display: block;
  margin: 18px 0 6px;
  color: var(--faint);
  font-size: 12px;
}
.gate-card input {
  width: 100%;
  border: 0;
  box-shadow: inset 0 0 0 1px var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--field);
  color: var(--text);
  outline: none;
}
.gate-card input:focus { box-shadow: inset 0 0 0 1px var(--blue); }
.gate-card button { margin-top: 16px; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  body.app { overflow: auto; }
  .shell { display: block; height: auto; }
  .canvas { overflow: visible; }
  .sidebar {
    position: fixed;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    width: min(280px, 86vw);
    box-shadow: 0 12px 40px var(--shadow);
  }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; }
  .nav-toggle:checked ~ .shell .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: var(--backdrop);
  }
  .canvas-bar {
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 8px 12px;
    background: var(--bar);
    border-bottom: 1px solid var(--line);
  }
  .menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 0 8px;
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
  }
  .sheet {
    width: min(900px, calc(100% - 40px));
    padding-top: 20px;
  }
  h1, .title-field { font-size: 32px; }
  .colhead { display: none; }
  .details {
    display: flex;
    gap: 6px;
    grid-area: details;
    color: var(--muted);
    font-size: 12px;
  }
  .when::before { content: "· "; }
  .collection { min-height: 50vh; }
  .row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name action"
      "details action";
  }
  .name-slot { grid-area: name; }
  .row-actions { grid-area: action; align-self: center; }
  .prop { grid-template-columns: 1fr; gap: 0; padding: 8px 0; }
}

@media (hover: none) {
  .ask, .edit-ask, .title-rename, .row-download { opacity: 1; }
}
