/* ── SPACEFLOW TOKENS — alias into DSYNTEC design system ──────────────────── */
:root {
  /* Surfaces → DS paper scale */
  --sand:       var(--ds-bg);              /* #f1f0eb vellum */
  --sand-deep:  var(--ds-surface-sunken);  /* #e7e5dd */
  --sand-soft:  var(--ds-surface);         /* #faf9f5 */
  --sand-light: var(--ds-surface-raised);  /* #ffffff */

  /* Text → DS ink scale */
  --ink:      var(--ds-text);           /* #15202b blue-black */
  --ink-soft: var(--ds-text-secondary); /* #45525f graphite */

  /* Border */
  --line: var(--ds-border); /* rgba(21,32,43,.14) */

  /* Brand accent → DS blueprint blue */
  --clay:      var(--ds-brand);        /* #1c5a99 */
  --clay-dark: var(--ds-brand-strong); /* #15406e */

  /* Typography → DS type stack */
  --serif: var(--ds-font-display); /* Space Grotesk */
  --sans:  var(--ds-font-body);    /* IBM Plex Sans */
  --mono:  var(--ds-font-mono);    /* IBM Plex Mono */

  /* Geometry → DS radii / shadows */
  --radius:    var(--ds-radius-md);  /* 5px */
  --radius-sm: var(--ds-radius-sm);  /* 3px */
  --shadow-sm: var(--ds-shadow-sm);
  --shadow:    var(--ds-shadow-md);
}

/* ── RESET ──────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  background: var(--sand);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── HEADER ─────────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--sand-light);
  border-bottom: 1px solid var(--ds-border-strong);
  padding: 0 var(--ds-space-4);   /* 16px — matches ds-topbar */
  height: var(--ds-topbar-h);     /* 52px */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ds-space-4);
  flex-shrink: 0;
  z-index: 10;
}

/* Brand lockup — AnchorMind pattern: mark · sep · toolname */
.brand-lockup {
  display: flex;
  align-items: center;
  gap: var(--ds-space-4);   /* 16px — matches ds-topbar gap */
  margin-right: var(--ds-space-3);
}

.brand-home {
  display: inline-flex;
  align-items: center;
  line-height: 1;
  cursor: pointer;
  color: var(--ds-text);
  text-decoration: none;
  transition: opacity var(--ds-dur-fast) var(--ds-ease);
}
.brand-home:hover { opacity: 0.72; text-decoration: none; }

/* Inline DSYNTEC mark SVG */
.ds-mark-svg {
  height: 24px;
  width: auto;
  display: block;
  fill: currentColor;
  flex-shrink: 0;
}

/* Vertical hairline separator — mirrors ds-topbar__sep */
.brand-sep {
  width: var(--ds-line);           /* 1px */
  align-self: stretch;
  margin-block: var(--ds-space-1); /* 4px — taller line, matches AnchorMind */
  background: var(--ds-border-strong);
  flex-shrink: 0;
}

/* Theme toggle — icon-only button */
.btn-icon-only {
  padding: 0;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Theme icons — CSS-driven visibility (no JS class toggling needed) */
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark  { display: flex; align-items: center; }

/* Exit modal — overlay positioning (display toggled by JS inline style) */
#exit-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(12,26,43,.55);
  align-items: center;
  justify-content: center;
}
.exit-modal-box {
  background: var(--ds-surface-raised);
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--ds-radius-lg);
  padding: var(--ds-space-5) var(--ds-space-5) var(--ds-space-4);
  max-width: 420px;
  width: 90%;
  box-shadow: var(--ds-shadow-lg);
}
.exit-modal-title {
  font-family: var(--serif);
  font-size: var(--ds-text-xl);   /* 24px */
  font-weight: var(--ds-weight-semibold);
  color: var(--ds-text);
  margin-bottom: var(--ds-space-3);
  letter-spacing: var(--ds-tracking-tight);
}
.exit-modal-body {
  color: var(--ds-text-secondary);
  font-size: var(--ds-text-base);   /* 15px */
  line-height: var(--ds-leading-body);
  margin-bottom: 0;
}
.exit-modal-actions {
  display: flex;
  gap: var(--ds-space-2);
  justify-content: flex-end;
  padding-top: var(--ds-space-4);
  margin-top: var(--ds-space-4);
  border-top: var(--ds-line) solid var(--ds-border);
}

/* Toolname — primary text color, same as AnchorMind */
.brand-product {
  font-family: var(--mono);                    /* IBM Plex Mono */
  font-size: var(--ds-text-base);              /* 15px */
  font-weight: var(--ds-weight-medium);        /* 500 */
  font-style: normal;
  letter-spacing: var(--ds-tracking-wide);     /* 0.08em */
  text-transform: uppercase;
  color: var(--ds-text);                       /* near-white in dark, ink in light */
  white-space: nowrap;
}

.project-name-input {
  border: 1px solid transparent;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  min-width: 200px;
  transition: border-color 0.15s, background 0.15s;
}
.project-name-input:hover { border-color: var(--line); background: var(--sand-soft); }
.project-name-input:focus { border-color: var(--clay); background: var(--sand-soft); outline: none; }

.header-left  { display: flex; align-items: center; gap: var(--ds-space-3); } /* 12px */
.header-right { display: flex; align-items: center; gap: var(--ds-space-2); } /* 8px */

.header-divider {
  width: 1px;
  height: 18px;
  background: var(--ds-border-strong);
  flex-shrink: 0;
}

/* ── TAB NAV ────────────────────────────────────────────────────────────────── */
.tab-nav {
  background: var(--sand-light);
  border-bottom: 1px solid var(--ds-border-strong);
  padding: 0 24px;
  display: flex;
  flex-shrink: 0;
}

.tab-btn {
  padding: 11px 18px;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  margin-bottom: -1px;
  letter-spacing: 0.01em;
}
.tab-btn:hover { color: var(--clay); }
.tab-btn.active { color: var(--clay); border-bottom-color: var(--clay); }

/* ── PANELS ─────────────────────────────────────────────────────────────────── */
.app-main { flex: 1; overflow: hidden; position: relative; }

.panel { display: none; height: 100%; flex-direction: column; overflow: hidden; }
.panel.active { display: flex; }

.panel-toolbar {
  background: var(--sand-soft);
  border-bottom: 1px solid var(--ds-border);
  padding: 9px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ── BUTTONS ────────────────────────────────────────────────────────────────── */
.btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

/* Primary: brand blue fill → brand-strong on hover */
.btn-primary {
  background: var(--clay);
  color: var(--sand-light);
  border-color: var(--clay);
}
.btn-primary:hover:not(:disabled) {
  background: var(--clay-dark);
  border-color: var(--clay-dark);
  color: var(--sand-light);
}

/* Ghost: ink text + hairline border → clay on hover */
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn-ghost:hover:not(:disabled) { color: var(--clay); border-color: var(--clay); background: transparent; }
.btn-ghost.active {
  background: var(--ds-brand-soft);
  color: var(--clay);
  border-color: var(--ds-brand-soft);
}

.btn-group { display: flex; }
.btn-group .btn { border-radius: 0; border-right-width: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; border-right-width: 1px; }

/* ── FORM CONTROLS ──────────────────────────────────────────────────────────── */
.select {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--sans);
  background: var(--sand-light);
  color: var(--ink);
  cursor: pointer;
  height: 32px;
}
.select:focus { outline: none; border-color: var(--clay); }

.input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--sand-light);
  transition: border-color 0.15s;
}
.input::placeholder { color: var(--ink-soft); }
.input:focus { outline: none; border-color: var(--clay); }
textarea.input { resize: vertical; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 500; color: var(--ink); }
.required { color: var(--clay); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── SUMMARY CARDS ──────────────────────────────────────────────────────────── */
.summary-cards {
  padding: 14px 24px;
  display: flex;
  gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  background: var(--sand);
}

.summary-card {
  background: var(--sand-light);
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 130px;
  box-shadow: var(--shadow-sm);
}
.summary-card .s-label {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-bottom: 3px;
  font-family: var(--mono);
}
.summary-card .s-value {
  font-size: 20px;
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.summary-card .s-sub { font-size: 11px; color: var(--ink-soft); margin-top: 1px; font-family: var(--mono); }

/* ── SPACES TABLE ───────────────────────────────────────────────────────────── */
.table-container {
  flex: 1;
  overflow: auto;
  padding: 16px 24px;
  background: var(--sand);
}

.spaces-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--sand-light);
  border: 1px solid var(--ds-border-strong);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.spaces-table th {
  background: var(--sand-soft);
  padding: 9px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ds-text-muted);
  border-bottom: 1px solid var(--ds-border-strong);
  white-space: nowrap;
  font-family: var(--mono);
}

.spaces-table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(26,23,20,.1);
  vertical-align: middle;
  color: var(--ink);
}

.spaces-table tbody tr:last-child td { border-bottom: none; }
.spaces-table tbody tr:hover { background: var(--ds-brand-soft); }

.dept-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── DEPT GROUP ROWS ────────────────────────────────────────────────────────── */
.dept-group-header {
  cursor: pointer;
  user-select: none;
}
.dept-group-header td {
  padding: 7px 14px;
  background: var(--sand-soft);
  border-top: 1px solid var(--ds-border-strong);
  border-bottom: 1px solid var(--ds-border);
}
.dept-group-header:first-child td { border-top: none; }
.dept-group-header:hover td { background: var(--ds-brand-soft); }

.dept-group-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dept-chevron {
  display: flex;
  align-items: center;
  color: var(--ink-soft);
  transition: transform 0.18s;
  flex-shrink: 0;
}
.dept-chevron.is-collapsed { transform: rotate(-90deg); }

.dept-group-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dept-group-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
}

.dept-group-meta {
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}

.space-row td:first-child { padding-left: 36px; }

.action-btns { display: flex; gap: 5px; }
.action-btn {
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: transparent;
  font-size: 12px;
  font-family: var(--sans);
  cursor: pointer;
  color: var(--ink-soft);
  transition: all 0.12s;
}
.action-btn:hover { color: var(--clay); border-color: var(--clay); background: transparent; }
.action-btn.danger:hover { color: #b91c1c; border-color: #fca5a5; background: #fee2e2; }

.empty-state {
  display: none;
  text-align: center;
  padding: 64px 20px;
  color: var(--ink-soft);
  margin: 16px 0;
  border: 1.5px dashed var(--ds-border-strong);
  border-radius: var(--ds-radius-md);
  background-image: var(--ds-hatch);
  background-color: var(--sand-soft);
}
.empty-state.visible { display: block; }
.empty-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.3; }
.empty-state p { font-size: 15px; margin-bottom: 6px; font-family: var(--serif); font-weight: 600; }
.empty-sub { font-size: 13px; font-family: var(--sans); font-weight: 400; color: var(--ds-text-muted); }

/* ── MATRIX TOOLBAR & LEGEND ────────────────────────────────────────────────── */
.matrix-legend {
  display: flex;
  gap: 5px;
  align-items: center;
  margin-left: auto;
  flex-wrap: wrap;
}

.legend-item {
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--sans);
}

/* Relationship colors — functional, not brand */
.rel-5 { background: #14532d; color: #ffffff; }
.rel-4 { background: #16a34a; color: #ffffff; }
.rel-3 { background: #86efac; color: #14532d; }
.rel-2 { background: #fef08a; color: #713f12; }
.rel-1 { background: var(--sand-deep); color: var(--ink-soft); }
.rel-0 { background: #ef4444; color: #ffffff; }

.matrix-indicators {
  padding: 7px 24px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: var(--sand);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  align-items: center;
  min-height: 38px;
}

.indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--sans);
}
.indicator-info { background: var(--ds-surface-sunken); color: var(--ds-text-secondary); }
.indicator-warn { background: var(--ds-warning-soft); color: var(--ds-warning); }
.indicator-ok   { background: var(--ds-success-soft); color: var(--ds-success); }

.matrix-container { flex: 1; overflow: auto; padding: 24px; background: var(--sand); }

/* ── MATRIX TABLE — DETAIL ──────────────────────────────────────────────────── */
.matrix-table { border-collapse: collapse; font-size: 12px; }

.matrix-table th, .matrix-table td {
  width: 42px;
  min-width: 42px;
  height: 42px;
  text-align: center;
  vertical-align: middle;
  border: 1px solid var(--line);
}

.matrix-table th { background: var(--sand-soft); font-weight: 500; font-size: 11px; }

.matrix-table th.corner { position: sticky; top: 0; left: 0; z-index: 3; background: var(--sand-soft); }

.matrix-table th.col-header {
  position: sticky;
  top: 0;
  z-index: 1;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  height: 100px;
  padding: 6px 4px;
  white-space: nowrap;
  cursor: default;
  max-width: 42px;
}

.matrix-table th.row-header {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: right;
  width: 130px;
  min-width: 130px;
  padding: 4px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
  background: var(--sand-soft);
}

.matrix-cell {
  cursor: pointer;
  transition: filter 0.1s;
  user-select: none;
  font-weight: 700;
  font-size: 13px;
}
.matrix-cell:hover { filter: brightness(0.88); }
.matrix-cell-disabled { background: var(--sand-deep) !important; cursor: default; }

/* ── MATRIX TABLE — ROLLUP ──────────────────────────────────────────────────── */
.rollup-table { border-collapse: collapse; font-size: 13px; }

.rollup-table th, .rollup-table td {
  border: 1px solid var(--line);
  text-align: center;
  vertical-align: middle;
}

.rollup-table th {
  background: var(--sand-soft);
  font-weight: 500;
  padding: 10px 14px;
  white-space: nowrap;
  font-size: 11px;
  color: var(--ds-text-muted);
  font-family: var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rollup-table td {
  width: 90px;
  min-width: 90px;
  height: 54px;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  transition: filter 0.1s;
}
.rollup-table td:hover:not(.rollup-cell-disabled) { filter: brightness(0.88); }
.rollup-cell-disabled { background: var(--sand-deep) !important; cursor: default !important; }

.rollup-row-header {
  text-align: right !important;
  padding: 8px 14px !important;
  min-width: 130px !important;
  background: var(--sand-soft);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--ink);
}

/* ── RELATIONSHIP PICKER ────────────────────────────────────────────────────── */
.rel-picker {
  position: fixed;
  z-index: 1000;
  background: var(--sand-light);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
  min-width: 195px;
}
.rel-picker.visible { display: block; }

.rel-picker-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  padding: 4px 8px 6px;
  font-family: var(--sans);
}

.rel-opt {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  transition: opacity 0.1s;
  font-family: var(--sans);
  margin-bottom: 2px;
}
.rel-opt:last-child { margin-bottom: 0; }
.rel-opt:hover { opacity: 0.82; }
.rel-opt.rel-5 { color: #ffffff; background: #14532d; }
.rel-opt.rel-4 { color: #ffffff; background: #16a34a; }
.rel-opt.rel-3 { color: #14532d; background: #86efac; }
.rel-opt.rel-2 { color: #713f12; background: #fef08a; }
.rel-opt.rel-1 { color: var(--ink-soft); background: var(--sand-deep); }
.rel-opt.rel-0 { color: #ffffff; background: #ef4444; }

/* ── DIAGRAM ────────────────────────────────────────────────────────────────── */
.diagram-wrapper { flex: 1; display: flex; overflow: hidden; }

.diagram-canvas {
  flex: 1;
  background: var(--sand);
  overflow: hidden;
  position: relative;
}

#diagram-svg { width: 100%; height: 100%; }

.diagram-analysis {
  width: 230px;
  flex-shrink: 0;
  background: var(--sand-soft);
  border-left: 1px solid var(--ds-border-strong);
  padding: 18px;
  overflow-y: auto;
}

.diagram-analysis h3 {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ds-text-muted);
  margin-bottom: 16px;
  font-family: var(--mono);
}

.analysis-section { margin-bottom: 20px; }

.analysis-section h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}

.analysis-item {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 4px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.analysis-item .a-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.analysis-item .a-count { font-weight: 700; color: var(--ink); flex-shrink: 0; }

/* ── MODAL ──────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12,26,43,.55);
  z-index: 500;
  display: none;
}
.modal-backdrop.visible { display: block; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 600;
  background: var(--sand-light);
  border: 1px solid var(--ds-border-strong);
  border-top: 2px solid var(--clay);
  border-radius: var(--radius);
  box-shadow: var(--ds-shadow-lg);
  width: 500px;
  max-width: 95vw;
  display: none;
  flex-direction: column;
  max-height: 85vh;
}
.modal.visible { display: flex; }

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--sand-light);
  border-radius: 0;
}
.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
  font-family: var(--serif);
  color: var(--ink);
  letter-spacing: -0.01em;
}

.modal-close {
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--ink-soft);
  line-height: 1;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.12s;
}
.modal-close:hover { color: var(--clay); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: var(--sand-soft);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── DEPT LIST ──────────────────────────────────────────────────────────────── */
.dept-add-row { display: flex; gap: 8px; margin-bottom: 12px; }

.dept-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }

.dept-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--ds-border);
  border-radius: var(--radius-sm);
  background: var(--sand-soft);
}

.dept-color { width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; }
.dept-name  { flex: 1; font-size: 13px; font-weight: 500; color: var(--ink); }
.dept-count { font-size: 11px; color: var(--ink-soft); white-space: nowrap; }

/* ── TOOLTIP ────────────────────────────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 900;
  background: var(--ink);
  color: var(--sand);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--sans);
  pointer-events: none;
  display: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

/* ── NOTIFICATION ───────────────────────────────────────────────────────────── */
.notification {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ds-ink-900);
  color: var(--sand-light);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--sans);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
  border: 1px solid rgba(231,236,241,.12);
}

/* ── D3 DIAGRAM ─────────────────────────────────────────────────────────────── */
.node-circle {
  stroke: var(--ds-border-strong);
  stroke-width: 2;
  cursor: grab;
}
.node-circle:active { cursor: grabbing; }
.node-label {
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  fill: #fff;
  font-weight: 700;
  font-family: "Inter", system-ui, sans-serif;
}
.link { stroke-opacity: 0.5; }

/* ── SCROLLBAR ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sand-deep); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-soft); }

/* ── DARK MODE — SpaceFlow-specific overrides ────────────────────────────────── */
[data-theme="dark"] .rel-picker {
  background: var(--ds-navy-700);
  border-color: var(--ds-border-strong);
}

[data-theme="dark"] .rel-opt.rel-1 {
  background: var(--ds-navy-600);
  color: var(--ds-text-secondary);
}

[data-theme="dark"] .tooltip {
  background: var(--ds-ink-900);
  color: var(--ds-paper-50);
  border: 1px solid var(--ds-border-strong);
}

[data-theme="dark"] .notification {
  background: var(--ds-navy-700);
  border-color: var(--ds-border);
}

[data-theme="dark"] .node-label {
  fill: var(--ds-paper-50);
}

/* ── RESPONSIVE — TABLET (iPad, 768–1024 px) ────────────────────────────────── */
@media (max-width: 1024px) {
  .app-header { padding: 0 18px; }

  .brand-logo { height: 14px; }

  /* slim the analysis panel on iPad */
  .diagram-analysis { width: 200px; }

  /* tight padding on all panels */
  .panel-toolbar { padding: 8px 18px; }
  .summary-cards { padding: 12px 18px; }
  .table-container { padding: 14px 18px; }
  .matrix-container { padding: 16px 18px; }

  /* let summary cards scroll horizontally when they don't all fit */
  .summary-cards {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .summary-cards::-webkit-scrollbar { display: none; }
  .summary-card { flex-shrink: 0; }

  /* hide the least-critical export button on narrower tablets */
  #btn-export-csv { display: none; }
}

/* ── RESPONSIVE — MOBILE (iPhone, < 768 px) ─────────────────────────────────── */
@media (max-width: 767px) {

  /* ── Header ─────────────────────────────── */
  .app-header {
    height: auto;
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  .header-left {
    flex: 1 1 100%;
    gap: 8px;
  }

  .header-right {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .header-divider { display: none; }

  .brand-logo { height: 13px; }

  .project-name-input {
    flex: 1;
    min-width: 100px;
    max-width: unset;
  }

  /* ── Tab nav — scrollable row ─────────── */
  .tab-nav {
    padding: 0 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tab-nav::-webkit-scrollbar { display: none; }

  .tab-btn {
    font-size: 12px;
    padding: 10px 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Panel toolbar ────────────────────── */
  .panel-toolbar {
    padding: 8px 14px;
    gap: 6px;
    flex-wrap: wrap;
  }

  /* ── Summary cards — horizontal scroll ── */
  .summary-cards {
    padding: 10px 14px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px;
  }
  .summary-cards::-webkit-scrollbar { display: none; }

  .summary-card {
    flex-shrink: 0;
    min-width: 108px;
    padding: 9px 13px;
  }
  .summary-card .s-value { font-size: 18px; }

  /* ── Spaces table — horizontal scroll ─── */
  .table-container { padding: 10px 14px; }
  .spaces-table { min-width: 580px; }

  /* ── Matrix ──────────────────────────── */
  .matrix-indicators { padding: 6px 14px; }
  .matrix-container { padding: 10px 14px; }

  /* hide the legend chips — too much clutter in the toolbar */
  .matrix-legend { display: none; }

  /* ── Diagram — hide sidebar, full canvas ─ */
  .diagram-analysis { display: none; }

  /* ── Modals — full screen ─────────────── */
  .modal {
    inset: 0;
    top: 0; left: 0; right: 0; bottom: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  .modal-header {
    border-radius: 0;
    padding: 14px 16px;
  }

  .modal-body { padding: 16px; }

  .modal-footer {
    border-radius: 0;
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-footer .btn { flex: 1; text-align: center; justify-content: center; }

  /* stack the two-column form row on mobile */
  .form-row { grid-template-columns: 1fr; gap: 10px; }

  /* ── Exit modal ──────────────────────── */
  .exit-modal-box {
    max-width: 95vw;
    padding: var(--ds-space-4);
  }
  .exit-modal-actions {
    flex-direction: column-reverse;
    gap: var(--ds-space-2);
  }
  .exit-modal-actions .btn { width: 100%; justify-content: center; }

  /* ── Rel picker — tighter ────────────── */
  .rel-picker { min-width: 172px; }

  /* ── Buttons — min touch target ─────── */
  .btn { min-height: 36px; padding: 7px 13px; }
  .action-btn { min-height: 30px; padding: 4px 10px; }
}

/* ── RESPONSIVE — SMALL IPHONE (< 390 px) ───────────────────────────────────── */
@media (max-width: 389px) {
  /* hide the full-width wordmark logo, keep only the icon */
  .brand-logo { display: none; }

  .summary-card { min-width: 94px; }
  .summary-card .s-value { font-size: 16px; }

  .tab-btn { font-size: 11px; padding: 10px 11px; }
}
