/* Process Mining console - layout and theme.
 * Light and dark are both first-class; the map canvas stays light in both
 * because Graphviz renders black-on-white text we do not control. */

:root {
  --bg: #f5f5f7;
  --paper: #ffffff;
  --paper-2: #fafafc;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #dedee3;
  --line-soft: rgba(0, 0, 0, 0.08);
  --blue: #0071e3;
  --blue-soft: rgba(0, 113, 227, 0.1);
  --green: #34a853;
  --amber: #b26b00;
  --red: #b42318;
  --red-bg: #fff0ef;
  --red-line: #f3c7c4;
  --amber-bg: #fff8e6;
  --amber-line: #f0dca6;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.05);
  --radius: 20px;
  --radius-sm: 12px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --header-h: 60px;
}

:root[data-theme="dark"] {
  --bg: #0e0e11;
  --paper: #17171b;
  --paper-2: #1d1d22;
  --ink: #f2f2f5;
  --muted: #9a9aa2;
  --line: #2c2c33;
  --line-soft: rgba(255, 255, 255, 0.09);
  --blue: #4a9dff;
  --blue-soft: rgba(74, 157, 255, 0.14);
  --green: #4ac26b;
  --amber: #e0a94a;
  --red: #ff6b60;
  --red-bg: #2a1614;
  --red-line: #5b2b26;
  --amber-bg: #2a2312;
  --amber-line: #574a20;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------------------------------------------------------------- header */
.header {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(16px, 4vw, 48px);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(160%) blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; white-space: nowrap; }
.logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center; font-size: 10px; font-weight: 800;
}
.tools-top { display: flex; gap: 8px; align-items: center; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted); white-space: nowrap;
  padding: 5px 10px; border-radius: 999px; background: var(--paper-2);
  border: 1px solid var(--line);
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="online"] .dot { background: var(--green); }
.status[data-state="auth"] .dot,
.status[data-state="nographviz"] .dot { background: var(--amber); }
.status[data-state="offline"] .dot { background: var(--red); }
.status[data-state="checking"] .dot { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.field-top, .select-top {
  border: 1px solid var(--line); background: var(--paper-2);
  border-radius: 9px; padding: 7px 10px; min-height: 34px;
}
.field-top { width: 150px; }
.field-top:focus, .select-top:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.field-top.needed { border-color: var(--amber); background: var(--amber-bg); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--paper-2);
  display: grid; place-items: center; font-size: 15px; line-height: 1;
}
.icon-btn:hover { border-color: var(--muted); }

/* ------------------------------------------------------------------ page */
.main { max-width: 1320px; margin: auto; padding: 48px clamp(16px, 4vw, 48px) 80px; }

.hero { margin-bottom: 34px; }
.eyebrow {
  color: var(--blue); font-size: 12px; font-weight: 650;
  letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 12px;
}
.hero h1 {
  font-size: clamp(34px, 5vw, 58px); line-height: 1.05;
  letter-spacing: -0.045em; font-weight: 650; margin: 0;
}
.hero p { color: var(--muted); font-size: 17px; max-width: 62ch; margin: 14px 0 0; }

/* ------------------------------------------------------------- workbench */
.workbench {
  display: grid; grid-template-columns: 340px minmax(0, 1fr);
  gap: 20px; align-items: start;
}

.card {
  background: var(--paper); border: 1px solid var(--line-soft);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card-head {
  padding: 16px 18px 0;
  font-size: 12px; font-weight: 650; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.card-body { padding: 14px 18px 18px; }

/* dropzone */
.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
  background: var(--paper-2); padding: 22px 16px; text-align: center;
  cursor: pointer; transition: border-color 0.18s, background 0.18s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--blue); background: var(--blue-soft); outline: none; }
.dropzone.dragover { border-color: var(--blue); background: var(--blue-soft); border-style: solid; }
.dropzone .dz-icon { font-size: 22px; display: block; margin-bottom: 8px; opacity: 0.65; }
.dropzone .dz-title { font-weight: 600; font-size: 14px; }
.dropzone .dz-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.dropzone input[type="file"] { display: none; }

.file-chip {
  display: none; align-items: center; gap: 10px; margin-top: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper-2);
}
.file-chip.show { display: flex; }
.file-chip .fc-name {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-chip .fc-size { font-size: 12px; color: var(--muted); flex: none; }
.file-chip .fc-remove {
  border: 0; background: transparent; color: var(--muted);
  font-size: 17px; line-height: 1; padding: 2px 4px; border-radius: 6px; flex: none;
}
.file-chip .fc-remove:hover { color: var(--red); background: var(--red-bg); }

.link-btn {
  border: 0; background: transparent; color: var(--blue);
  font-size: 13px; font-weight: 600; padding: 8px 0 0;
}
.link-btn:hover { text-decoration: underline; }

/* form controls */
.control { margin-top: 14px; }
.control:first-child { margin-top: 0; }
.control > label {
  display: block; font-size: 12px; font-weight: 650; color: var(--muted);
  margin-bottom: 6px;
}
.control select, .control input[type="text"] {
  width: 100%; border: 1px solid var(--line); background: var(--paper-2);
  border-radius: 10px; padding: 9px 10px; min-height: 38px;
}
.control select:focus, .control input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.control .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.4; }
.range-row { display: flex; align-items: center; gap: 10px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--blue); }
.range-row output {
  font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted);
  min-width: 34px; text-align: right;
}
details.advanced > summary {
  cursor: pointer; font-size: 12px; font-weight: 650; color: var(--muted);
  margin-top: 16px; list-style: none;
}
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary::before { content: "▸ "; display: inline-block; transition: transform 0.15s; }
details.advanced[open] > summary::before { content: "▾ "; }

.actions { display: flex; gap: 8px; margin-top: 18px; }
.btn {
  border: 0; border-radius: 999px; padding: 11px 18px; min-height: 42px;
  font-weight: 600; background: var(--blue); color: #fff;
  box-shadow: 0 5px 14px rgba(0, 113, 227, 0.22);
  transition: transform 0.18s var(--ease), filter 0.18s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.07); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn.secondary { background: var(--paper-2); color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.btn.grow { flex: 1; }
.btn.loading::before {
  content: ""; display: inline-block; width: 12px; height: 12px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; margin-right: 8px; vertical-align: -2px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* messages */
.message {
  display: none; margin-top: 14px; padding: 11px 13px;
  border-radius: var(--radius-sm); font-size: 13px; white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.show { display: block; }
.message.error { color: var(--red); background: var(--red-bg); border: 1px solid var(--red-line); }
.message.warn { color: var(--amber); background: var(--amber-bg); border: 1px solid var(--amber-line); }
.message ul { margin: 6px 0 0; padding-left: 18px; }
.message .msg-title { font-weight: 650; }
.message code { font-size: 12px; opacity: 0.85; }

/* --------------------------------------------------------------- metrics */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.metric {
  background: var(--paper); border: 1px solid var(--line-soft);
  border-radius: 16px; padding: 14px 16px;
}
.metric .label {
  font-size: 11px; color: var(--muted); font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.07em;
}
.metric .value {
  font-size: 26px; font-weight: 650; letter-spacing: -0.035em;
  margin-top: 6px; font-variant-numeric: tabular-nums;
}
.metric .sub {
  font-size: 12px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; gap: 3px; padding: 5px; background: var(--paper-2); border-radius: 12px; }
.tab {
  border: 0; background: transparent; border-radius: 9px;
  padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-sm); }
.tab .count {
  font-size: 11px; opacity: 0.65; margin-left: 5px;
  font-variant-numeric: tabular-nums;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.panel-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-search {
  border: 1px solid var(--line); background: var(--paper-2);
  border-radius: 9px; padding: 7px 10px; width: 160px; min-height: 34px; font-size: 13px;
}
.map-search:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.zoom-tools { display: flex; gap: 2px; background: var(--paper-2); padding: 3px; border-radius: 10px; }
.zoom-tools button {
  width: 34px; height: 30px; border: 0; background: transparent;
  border-radius: 7px; font-size: 15px; line-height: 1;
}
.zoom-tools button:hover { background: var(--paper); box-shadow: var(--shadow-sm); }

.tabpanel { display: none; }
.tabpanel.active { display: block; }

/* ------------------------------------------------------------ map canvas */
.viewport {
  height: min(64vh, 620px); position: relative; overflow: hidden;
  background: #f8f8fa; cursor: grab; touch-action: none;
}
.viewport.dragging { cursor: grabbing; }
.viewport:fullscreen { height: 100vh; }
.stage {
  position: absolute; left: 0; top: 0; transform-origin: 0 0;
  will-change: transform;
}
/* visible, not hidden: if a graph ever paints a hair outside its declared box,
   we would rather show it than silently crop the map */
.stage svg { display: block; overflow: visible; }
/* highlight for the search box */
.stage .pm-hit ellipse, .stage .pm-hit polygon, .stage .pm-hit path {
  stroke: #0071e3 !important; stroke-width: 3px !important;
}
.stage .pm-dim { opacity: 0.25; }

.empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  text-align: center; color: #6e6e73; padding: 30px;
}
.empty strong { display: block; color: #1d1d1f; font-size: 17px; margin-bottom: 5px; }
.zoom-readout {
  position: absolute; left: 14px; bottom: 12px; padding: 5px 9px;
  background: rgba(255, 255, 255, 0.94); border: 1px solid #dedee3;
  border-radius: 9px; color: #6e6e73; font-size: 11px;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.map-foot {
  padding: 10px 16px 14px; color: var(--muted); font-size: 12px;
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; max-height: min(64vh, 620px); overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
table.data th {
  position: sticky; top: 0; background: var(--paper); z-index: 1;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 650;
}
table.data tbody tr:hover { background: var(--paper-2); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.seq { white-space: normal; min-width: 320px; }
.seq-step {
  display: inline-block; padding: 2px 7px; margin: 2px 3px 2px 0;
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 6px; font-size: 12px;
}
.seq-arrow { color: var(--muted); font-size: 11px; margin-right: 3px; }
.bar {
  position: relative; display: block; height: 5px; border-radius: 3px;
  background: var(--line); margin-top: 4px; overflow: hidden;
}
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--blue); border-radius: 3px; }
.table-empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.subhead {
  padding: 14px 14px 6px; font-size: 12px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
  border-top: 1px solid var(--line-soft);
}

/* -------------------------------------------------------------- glossary */
.glossary {
  margin-top: 48px; padding-top: 22px; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 1.2fr repeat(4, 1fr); gap: 20px;
}
.glossary h2 { font-size: 20px; margin: 0; letter-spacing: -0.02em; }
.glossary h3 { font-size: 14px; margin: 0 0 4px; }
.glossary p { font-size: 12.5px; color: var(--muted); margin: 0; }

.footer {
  margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--line);
  display: flex; gap: 18px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap;
}

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  background: var(--ink); color: var(--paper);
  padding: 11px 15px; border-radius: 12px; font-size: 13.5px; font-weight: 550;
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1080px) {
  .workbench { grid-template-columns: 1fr; }
  .glossary { grid-template-columns: 1fr 1fr 1fr; }
  .glossary h2 { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .main { padding-top: 34px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .glossary { grid-template-columns: 1fr 1fr; }
  .viewport { height: 58vh; }
  .brand span { display: none; }
  .field-top { width: 118px; }
}
@media (max-width: 560px) {
  .header { padding: 0 12px; gap: 8px; }
  .status { display: none; }
  .hero h1 { font-size: 36px; }
  .glossary { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .map-search { width: 110px; }
  .panel-head { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
