/* Movement Everywhere Lab — operational workspace on the Cicada four-colour
   system (DESIGN-DIRECTION.md): deep purple #300950, vibrant purple #7540F5,
   persimmon #ED6942, bone #F7F4ED, with tints taken from the parent site
   tokens. Operational surface: restrained light, shadow and motion. */

:root {
  --cw-purple: #7540F5;
  --cw-violet: #300950;
  --cw-persimmon: #ED6942;
  --cw-bone: #F7F4ED;
  --violet-tint: #B9A9F2;
  --violet-wash: #E9E3FC;
  --persimmon-deep: #B94324;
  --persimmon-light: #FFC1AA;
  --bone-deep: #EFEAE0;
  --ink: #300950;
  --muted: #635B8C;
  --line: #E4DCF6;
  --panel: #FFFFFF;
  --ok: #2F7D5B;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --shadow-1: 0 2px 10px rgba(21,3,38,.07);
  --shadow-1-hover: 0 8px 22px rgba(21,3,38,.14);
  --side-w: 232px;
  --banner-h: 40px;
  --grad-violet: radial-gradient(115% 90% at 50% -10%, rgba(117,64,245,.30) 0%, transparent 55%), linear-gradient(172deg, #3B0F66 0%, #300950 58%, #24063C 100%);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14.5px/1.5 var(--sans); color: var(--ink); background: var(--cw-bone); }
a { color: var(--cw-purple); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cw-persimmon); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- disclaimer banner — always visible ---------- */
.mel-banner {
  position: sticky; top: 0; z-index: 2000; min-height: var(--banner-h);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 14px;
  padding: 8px 16px; background: var(--persimmon-deep); color: #fff; text-align: center; font-size: 13.5px;
  box-shadow: 0 2px 8px rgba(48,9,80,.25);
}
.mel-banner-sub { opacity: .9; font-size: 12.5px; }

/* ---------- shell ---------- */
.mel-shell { display: flex; min-height: calc(100vh - var(--banner-h)); }
.mel-side {
  position: sticky; top: var(--banner-h); height: calc(100vh - var(--banner-h)); width: var(--side-w); flex: 0 0 var(--side-w);
  background: var(--grad-violet); color: var(--cw-bone); display: flex; flex-direction: column; padding: 18px 12px; overflow-y: auto;
}
.mel-brand { display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--cw-bone); padding: 4px 8px 18px; }
.mel-brand img { filter: brightness(0) invert(1); }
.mel-word { display: block; font-family: var(--serif); font-size: 24px; line-height: 1; }
.mel-sub { display: block; font-size: 11.5px; letter-spacing: .04em; color: var(--violet-tint); margin-top: 3px; }
.mel-nav { display: flex; flex-direction: column; gap: 2px; }
.mel-nav a {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px; color: rgba(247,244,237,.86); text-decoration: none; font-weight: 500;
}
.mel-nav a:hover { background: rgba(117,64,245,.28); }
.mel-nav a[aria-current="page"] { background: var(--cw-persimmon); color: #fff; box-shadow: inset 0 1px 0 rgba(255,193,170,.5); }
.mel-nav .count { font-size: 11.5px; padding: 0 7px; border-radius: 999px; background: rgba(247,244,237,.14); }
.mel-side-foot { margin-top: auto; font-size: 11.5px; color: var(--violet-tint); padding: 12px 8px 0; }

.mel-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mel-top {
  position: sticky; top: var(--banner-h); z-index: 900; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px;
  padding: 14px 28px; background: rgba(247,244,237,.95); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.mel-top h1 { font-size: 26px; }
.mel-top-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.mel-search input { width: 220px; }
.mel-view { padding: 22px 28px 60px; max-width: 1560px; width: 100%; outline: none; }

/* ---------- controls ---------- */
input[type="text"], input[type="search"], input[type="date"], select, textarea {
  border: 1px solid #D5CBEF; border-radius: 9px; padding: 7px 10px; background: #fff; min-width: 0;
}
textarea { width: 100%; min-height: 70px; resize: vertical; }
.mel-field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.mel-field > input, .mel-field > select, .mel-field > textarea { color: var(--ink); font-weight: 400; font-size: 14px; }
.mel-field-inline { flex-direction: row; align-items: center; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 999px; padding: 7px 15px;
  background: var(--cw-persimmon); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; font-size: 13.5px; white-space: nowrap;
}
.btn:hover { background: var(--persimmon-deep); }
.btn-purple { background: var(--cw-purple); }
.btn-purple:hover { background: #5B2FE0; }
.btn-quiet { background: #fff; color: var(--ink); border-color: #D5CBEF; }
.btn-quiet:hover { background: var(--violet-wash); }
.btn-sm { padding: 4px 11px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkish { background: none; border: 0; padding: 0; color: var(--cw-purple); cursor: pointer; text-align: left; font-weight: 600; text-decoration: underline; text-decoration-color: rgba(117,64,245,.35); text-underline-offset: 2px; }
.linkish:hover { text-decoration-color: currentColor; }

.chip { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--violet-wash); color: var(--ink); font-weight: 600; white-space: nowrap; }
.chip-synth { background: transparent; border: 1px dashed var(--persimmon-deep); color: var(--persimmon-deep); }
.chip-persimmon { background: #FDE3D9; color: var(--persimmon-deep); }
.chip-purple { background: var(--cw-purple); color: #fff; }
.chip-deep { background: var(--cw-violet); color: var(--cw-bone); }
.chip-ok { background: #DDF0E6; color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.status-todo { background: var(--violet-wash); }
.status-in_progress { background: #E0D4FD; color: #4A1FD0; }
.status-blocked { background: #FDE3D9; color: var(--persimmon-deep); }
.status-done { background: #DDF0E6; color: var(--ok); }

/* ---------- layout primitives ---------- */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; gap: 16px; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-1); min-width: 0; }
.card > h2, .card > h3 { margin-bottom: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.kpi { text-decoration: none; color: inherit; display: block; transition: box-shadow .15s; }
.kpi:hover { box-shadow: var(--shadow-1-hover); }
.kpi .n { font-family: var(--serif); font-size: 30px; line-height: 1.1; color: var(--cw-violet); }
.kpi .l { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi.alert .n { color: var(--persimmon-deep); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.notice { border-left: 4px solid var(--cw-persimmon); background: #FFF6F2; padding: 9px 12px; border-radius: 6px; font-size: 13px; margin: 0 0 14px; }
.notice-purple { border-left-color: var(--cw-purple); background: #F5F1FE; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.list > li:last-child { border-bottom: 0; }
.list .meta { font-size: 12.5px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.is-selected td { background: #F5F1FE; }
.form-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.empty { color: var(--muted); font-style: italic; padding: 8px 0; }
.bar { height: 8px; border-radius: 999px; background: var(--violet-wash); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--cw-purple); }

/* ---------- ally cards ---------- */
.ally-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.ally-card { text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: box-shadow .15s, border-color .15s; }
.ally-card:hover { box-shadow: var(--shadow-1-hover); border-color: var(--violet-tint); }
.ally-card .name { font-weight: 700; font-size: 15px; }
.kind-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.kind-organisation { background: var(--cw-violet); }
.kind-group { background: var(--cw-purple); }
.kind-person { background: var(--cw-persimmon); }

/* ---------- projects ---------- */
.project-tile { cursor: pointer; text-align: left; width: 100%; }
.project-tile[aria-pressed="true"] { border-color: var(--cw-purple); box-shadow: 0 0 0 2px var(--cw-purple); }

/* ---------- network ---------- */
.net-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.net-canvas { position: relative; height: calc(100vh - 250px); min-height: 440px; padding: 0; overflow: hidden; background: #FBFAFE; }
.net-canvas svg { width: 100%; height: 100%; display: block; cursor: grab; }
.net-canvas .node { cursor: pointer; }
.net-canvas .node text { font-size: 10.5px; fill: var(--ink); pointer-events: none; paint-order: stroke; stroke: #FBFAFE; stroke-width: 3px; }
.net-canvas .node.dim, .net-canvas line.dim { opacity: .15; }
.net-legend { position: absolute; left: 10px; bottom: 10px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 11.5px; display: grid; gap: 3px; }
.legend-line { display: inline-block; width: 26px; height: 0; border-top: 2px solid var(--cw-violet); vertical-align: middle; margin-right: 6px; }
.legend-line.possible { border-top-style: dashed; border-color: var(--muted); }
.legend-line.proposed { border-top: 3px dotted var(--cw-persimmon); }
.net-zoom { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; }

/* ---------- map ---------- */
.map-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.map-canvas { height: calc(100vh - 250px); min-height: 440px; padding: 0; overflow: hidden; }
#mel-map { width: 100%; height: 100%; background: #DCD3F5; }
.map-side { max-height: calc(100vh - 250px); min-height: 440px; overflow-y: auto; }
.mk { display: block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(48,9,80,.45); }
.mk.org { border-radius: 3px; width: 12px; height: 12px; background: var(--cw-violet); }
.mk.is-focus { outline: 3px solid var(--cw-persimmon); outline-offset: 2px; }
.leaflet-container { font: inherit; }
.leaflet-tooltip { font-size: 12px; }

/* ---------- operations ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--cw-violet); color: var(--cw-bone); }
.pipeline { display: grid; gap: 12px; grid-template-columns: repeat(5, minmax(200px, 1fr)); overflow-x: auto; padding-bottom: 6px; }
.pipe-col { background: #F3EFFB; border-radius: var(--radius); padding: 10px; min-width: 200px; }
.pipe-col h3 { font-family: var(--sans); font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 2px 4px 10px; }
.pipe-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13px; display: grid; gap: 6px; }
.steps { display: flex; gap: 4px; }
.steps span { flex: 1; height: 5px; border-radius: 3px; background: var(--violet-wash); }
.steps span.on { background: var(--cw-purple); }

/* ---------- matching ---------- */
.match { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }
.match.top { border-color: var(--cw-purple); }
.reasons { margin: 0; padding-left: 18px; font-size: 13px; }
.reasons .neg { color: var(--persimmon-deep); }
.score { font-family: var(--serif); font-size: 22px; color: var(--cw-purple); }
.selectable { cursor: pointer; }
.selectable:hover { background: #FAF8FF; }
.selectable.is-selected { background: #F0EAFE; }

/* ---------- journey ---------- */
.journey ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.journey li.done { color: var(--ok); }
.journey li.done::marker { content: "✓  "; }

/* ---------- drawer ---------- */
.mel-drawer-scrim { position: fixed; inset: 0; background: rgba(48,9,80,.28); z-index: 1500; }
.mel-drawer {
  position: fixed; top: var(--banner-h); right: 0; bottom: 0; width: min(560px, 100vw); z-index: 1600; background: var(--cw-bone);
  box-shadow: -12px 0 40px rgba(48,9,80,.25); overflow-y: auto; padding: 0 0 40px;
}
.drawer-head { position: sticky; top: 0; z-index: 2; background: var(--grad-violet); color: var(--cw-bone); padding: 16px 20px; display: grid; gap: 6px; }
.drawer-head h2 { font-size: 22px; }
.drawer-head .chip { background: rgba(247,244,237,.16); color: var(--cw-bone); }
.drawer-head .chip-synth { border-color: var(--persimmon-light); color: var(--persimmon-light); background: transparent; }
.drawer-close { position: absolute; right: 12px; top: 12px; background: rgba(247,244,237,.14); color: var(--cw-bone); border: 0; border-radius: 999px; width: 32px; height: 32px; font-size: 18px; cursor: pointer; }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.drawer-actions .btn-quiet { background: transparent; color: var(--cw-bone); border-color: rgba(247,244,237,.4); }
.drawer-actions .btn-quiet:hover { background: rgba(247,244,237,.12); }
.drawer-body { padding: 16px 20px; display: grid; gap: 14px; }
.drawer-body .card { padding: 14px 16px; }
dl.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; font-size: 13.5px; }
dl.kv dt { color: var(--muted); font-weight: 600; }
dl.kv dd { margin: 0; }

/* ---------- toast ---------- */
.mel-toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 2100; background: var(--cw-violet); color: var(--cw-bone); padding: 10px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(48,9,80,.35); display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 30px); }
.mel-toast .btn { padding: 3px 12px; }

/* ---------- responsive ---------- */
@media (max-width: 1200px) {
  .net-wrap, .map-wrap { grid-template-columns: minmax(0, 1fr) 290px; }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  :root { --banner-h: 56px; }
  .mel-shell { flex-direction: column; }
  .mel-side { position: sticky; top: var(--banner-h); z-index: 1000; height: auto; width: 100%; flex: none; flex-direction: row; align-items: center; padding: 8px 10px; gap: 8px; overflow: visible; }
  .mel-brand { padding: 0 6px 0 2px; }
  .mel-sub, .mel-side-foot { display: none; }
  .mel-nav { flex-direction: row; overflow-x: auto; scrollbar-width: thin; flex: 1; }
  .mel-nav a { white-space: nowrap; padding: 6px 10px; }
  .mel-nav .count { display: none; }
  .mel-top { position: static; padding: 12px 16px; }
  .mel-view { padding: 16px 16px 60px; }
  .split, .net-wrap, .map-wrap, .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
  .net-canvas, .map-canvas { height: 60vh; min-height: 340px; }
  .map-side { max-height: none; min-height: 0; }
}
@media (max-width: 560px) {
  :root { --banner-h: 74px; }
  .mel-banner { font-size: 12.5px; }
  .mel-top h1 { font-size: 22px; }
  .mel-search input { width: 100%; }
  .mel-top-tools, .mel-search { width: 100%; }
  .mel-top-tools select { max-width: 200px; }
  dl.kv { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(5, 82vw); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
