/* Mece app shell: base reset, buttons, toolbar, file:// guard (PLAN 6.2, 6.7, 8.1). */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 20px;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* Stage = everything below the (P1) top bar: headers strip + canvas. */
.stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }

.canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
  touch-action: none;          /* pointer events only, panels keep scrolling */
  cursor: grab;
}
.canvas.is-panning { cursor: grabbing; }

.btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: 600 13px/1 var(--font-sans);
  cursor: pointer;
}
.btn:hover { border-color: var(--line); box-shadow: var(--shadow-hover); }
.btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
.btn--primary { background: var(--navy); border-color: var(--navy); color: #FFFFFF; }
.btn--primary:hover { background: var(--navy-hover); border-color: var(--navy-hover); }
.btn--icon { width: 32px; padding: 0; display: grid; place-items: center; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* file:// guard (PLAN 8.1): modules cannot load from a null origin. */
.fileguard {
  max-width: 460px;
  margin: 12vh auto 0;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-node);
  background: var(--surface);
}
.fileguard h1 { font: 600 18px/26px var(--font-serif); margin: 0 0 8px; }
.fileguard p { margin: 0 0 8px; }
.fileguard code {
  display: inline-block; padding: 2px 6px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
}

/* P1 screens: the dashboard scrolls, the board view is top bar + (canvas | panel). */
.screen { position: absolute; inset: 0; }
.screen--dash { overflow: auto; padding: 24px; }
.screen--board { display: flex; flex-direction: column; }
.board { flex: 1 1 auto; min-height: 0; display: flex; }
.board__main { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* Top bar (§6.7), 56px. Undo/Redo (P2), Export (P5) and Settings (P4) are not built yet. */
.topbar {
  flex: 0 0 56px; height: 56px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.topbar__back { display: inline-flex; align-items: center; gap: 6px; }
.topbar__title {
  max-width: 38vw; padding: 4px 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  border: 1px solid transparent; border-radius: 8px; background: none; cursor: text;
  color: var(--ink); font: 600 18px/24px var(--font-serif); text-align: left;
}
.topbar__title:hover { border-color: var(--border); background: var(--surface); }
.topbar__title-input {
  max-width: 38vw; padding: 4px 8px;
  border: 1px solid var(--teal); border-radius: 8px;
  font: 600 18px/24px var(--font-serif); color: var(--ink);
}
.topbar__type { position: relative; }
.topbar__spacer { flex: 1 1 auto; }
.topbar__mece { position: relative; width: 36px; height: 36px; padding: 0; border-radius: 50%; }
.topbar__avatar {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--teal); color: #FFFFFF; font: 700 13px/1 var(--font-sans);
}
.topbar__count {
  position: absolute; top: -4px; right: -4px; min-width: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--bad); color: #FFFFFF;
  font: 700 10px/16px var(--font-sans); text-align: center;
}
.topbar__count[hidden] { display: none; }

/* Popover menu (the tree-type chip of §6.7). */
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
  min-width: 168px; padding: 4px; display: flex; flex-direction: column; gap: 2px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-hover);
}
.menu[hidden] { display: none; }
.menu__item {
  padding: 8px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer;
  color: var(--ink); font: 400 14px/20px var(--font-sans); text-align: left;
}
.menu__item:hover { background: var(--surface); }

/* Chips: tree type on a card, in the top bar and in the panel (§6.7). */
.chip {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  border: 1px solid transparent; border-radius: 11px;
  background: var(--teal-tint); color: var(--ink);
  font: 600 11px/1 var(--font-sans); letter-spacing: .04em; text-transform: uppercase;
  white-space: nowrap;
}
.chip--btn { cursor: pointer; }
.chip--btn:hover { border-color: var(--teal); }
.chip--btn.is-on { background: var(--teal); color: #FFFFFF; }

/* Primary CTA: floating pill, bottom-center of the canvas column (§6.7). */
.cta { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 45; }
.cta[hidden] { display: none; }
.cta__btn {
  height: 48px; padding: 0 24px; border-radius: 24px;
  font: 600 15px/1 var(--font-sans); box-shadow: var(--shadow-hover);
}

/* Dashboard (§5 F1). */
.dash { max-width: 960px; margin: 0 auto; }
.dash__head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 20px; }
.dash__title { margin: 0; font: 600 20px/28px var(--font-serif); }
.dash__tagline { flex: 1 1 auto; margin: 0; color: var(--muted); }
.dash__actions { display: flex; gap: 8px; }
.dash__empty { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 10px; padding: 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-node);
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.card:hover { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-hover); }
.card__name { font: 600 16px/22px var(--font-serif); overflow-wrap: anywhere; }
.card__row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card__meta { color: var(--muted); font-size: 12px; }
.card--error { background: var(--bad-bg); border-color: var(--bad); cursor: default; }
.card--error:hover { box-shadow: none; background: var(--bad-bg); }

/* Dialogs (§4.1 stage `name`, §4.3 confirm). */
.backdrop {
  position: fixed; inset: 0; z-index: 100; padding: 16px;
  display: grid; place-items: center; background: rgba(11, 31, 51, .35);
}
.dialog {
  width: min(420px, 100%); padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-node);
  box-shadow: var(--shadow-hover);
}
.dialog__title { margin: 0; font: 600 18px/26px var(--font-serif); }
.dialog__label { color: var(--muted); font-size: 13px; font-weight: 600; }
.dialog__hint { margin: 0; color: var(--muted); font-size: 12px; }
.dialog__message { margin: 0; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; }
.input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
  color: var(--ink); font: 400 16px/22px var(--font-sans);   /* >= 16px: no iOS zoom (§21.17) */
}
.input:focus { border-color: var(--teal); }

/* Toasts (§9.3, §18.2). */
.toasts {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 120;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  max-width: min(520px, 92vw); padding: 10px 12px;
  background: var(--navy); color: #FFFFFF; border-radius: 10px; box-shadow: var(--shadow-hover);
}
.toast__text { flex: 1 1 auto; }
.toast__action { background: #FFFFFF; border-color: #FFFFFF; color: var(--navy); }
.toast__close { background: none; border-color: transparent; color: #FFFFFF; }
.toast__close:hover { border-color: transparent; box-shadow: none; color: var(--teal-tint); }

@media (max-width: 767px) {
  .btn { height: 44px; padding: 0 14px; font-size: 16px; }  /* tap target, no iOS zoom */
  .btn--icon { width: 44px; }
  .fileguard { margin: 8vh 16px 0; }
  /* Phone: the panel stacks under the canvas instead of drawing over it (§7, P5 polishes). */
  .screen--dash { padding: 16px; }
  .topbar { flex: 0 0 52px; height: 52px; padding: 0 8px; gap: 6px; }
  .topbar__title, .topbar__title-input { max-width: 34vw; font-size: 16px; }
  .topbar__back span { display: none; }
  .board { flex-direction: column; }
  .board__main { flex: 1 1 auto; min-height: 38vh; }
  .cta { bottom: 12px; }
  .cta__btn { width: 100%; }
  .cta { left: 12px; right: 12px; transform: none; }
  .toasts { bottom: 76px; }
}
