:root {
  --bg: #073f66;
  --panel: #ffffff;
  --text: #1a1f2c;
  --muted: #606a80;
   --border: #d8deeb;
  --status-success: #2f8f5f;
  --status-success-border: #bfe8d2;
  --status-success-bg: #eef8f1;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.dark {
  --bg: #073f66;
  --panel: #171e2a;
  --text: #eef3ff;
  --muted: #9eacc7;
  --border: #313f57;
  --status-success: #8fe3b8;
  --status-success-border: #3d6b52;
  --status-success-bg: color-mix(in srgb, #6dd4a8 14%, var(--panel));
}

.app-header,
.app-footer {
  display: none !important;
}

.app-header {
  flex-shrink: 0;
  padding: 5px 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
  z-index: 1050;
}

.app-nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  cursor: default;
}

.app-nav-overlay[hidden] {
  display: none !important;
}

.app-header h1 {
  margin: 0;
  line-height: 0;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.app-title-link {
  display: inline-flex;
  align-items: center;
  gap: 0;
  color: inherit;
  text-decoration: none;
}

.app-title-link:hover {
  opacity: 0.88;
}

.app-title-heading {
  display: inline-flex;
  align-items: center;
  gap: 0;
  margin: 0;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: default;
}

.app-logo-word {
  display: inline-block;
  font-family: Montserrat, Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.15rem;
  line-height: 1;
  letter-spacing: -0.01em;
  color: #fff;
}

.app-logo-complex {
  font-weight: 700;
}

.app-logo-charts {
  font-weight: 200;
}

.app-header-actions {
  position: relative;
  flex-shrink: 0;
  z-index: 1;
}

.app-nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-nav-toggle:hover {
  opacity: 0.85;
}

.app-nav-toggle:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.45);
  outline-offset: 2px;
}

.app-nav-toggle[aria-expanded="true"] {
  color: #fff;
  opacity: 1;
}

.app-nav-toggle-bars,
.app-nav-toggle-bars::before,
.app-nav-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  position: relative;
}

.app-nav-toggle-bars::before,
.app-nav-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.app-nav-toggle-bars::before {
  top: -6px;
}

.app-nav-toggle-bars::after {
  top: 6px;
}

.app-nav-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 228px;
  padding: 4px 0;
  margin: 0;
  background: #fff;
  border: 1px solid color-mix(in srgb, #1a1f2c 16%, #fff);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  z-index: 2;
}

body.dark .app-nav-menu {
  background: var(--panel);
  border-color: color-mix(in srgb, var(--border) 85%, transparent);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.app-nav-menu[hidden] {
  display: none !important;
}

.app-nav-menu a {
  padding: 10px 16px;
  color: #1a1f2c;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

body.dark .app-nav-menu a {
  color: var(--text);
}

.app-nav-menu a:hover,
.app-nav-menu a:focus-visible {
  background: transparent;
}

body.dark .app-nav-menu a:hover,
body.dark .app-nav-menu a:focus-visible {
  background: transparent;
}

.app-nav-menu a:focus-visible {
  outline: none;
}

.app-nav-menu .app-nav-menu-link {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 16px;
  margin: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: #1a1f2c;
  text-align: left;
  text-decoration: none;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

body.dark .app-nav-menu .app-nav-menu-link {
  color: var(--text);
}

.app-nav-menu .app-nav-menu-link:hover,
.app-nav-menu .app-nav-menu-link:focus-visible {
  background: transparent;
}

body.dark .app-nav-menu .app-nav-menu-link:hover,
body.dark .app-nav-menu .app-nav-menu-link:focus-visible {
  background: transparent;
}

.app-nav-menu .app-nav-menu-link:focus-visible {
  outline: none;
}

.app-nav-sep {
  border: none;
  border-top: 1px solid color-mix(in srgb, #1a1f2c 12%, #fff);
  margin: 6px 10px;
}

body.dark .app-nav-sep {
  border-top-color: color-mix(in srgb, var(--border) 70%, transparent);
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.app-footer {
  flex-shrink: 0;
  padding: 8px 20px 12px;
}

.app-footer-nav {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.app-footer-link {
  cursor: pointer;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.92);
  font: inherit;
  font-size: inherit;
  text-decoration: none;
}

a.app-footer-link {
  display: inline;
}

.app-footer-link:hover {
  color: #fff;
}

.app-footer-sep {
  color: rgba(255, 255, 255, 0.45);
  user-select: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
}

.controls {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.controls-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
}

.controls-body > h2:first-child {
  margin-top: 0;
}

.controls-export {
  flex-shrink: 0;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
}

.controls-export h2 {
  margin-top: 0;
}

.export-hint {
  margin-top: 0;
  margin-bottom: 8px;
}

.export-scale-row {
  align-items: end;
}

.export-scale-label {
  margin: 0;
}

.export-scale-label select {
  margin-top: 6px;
}

.export-scale-custom {
  max-width: 110px;
}

h2 {
  margin: 14px 0 8px;
  font-size: 14px;
}

.flow-input-wrap {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: transparent;
}

.flow-line-numbers {
  margin: 0;
  width: 42px;
  flex-shrink: 0;
  min-height: 200px;
  padding: 8px 6px 8px 8px;
  border-right: 1px solid var(--border);
  color: var(--muted);
  text-align: right;
  line-height: 1.4;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  user-select: none;
  pointer-events: none;
  background: color-mix(in srgb, var(--panel) 88%, var(--border));
  overflow: hidden;
  white-space: pre;
}

textarea {
  width: calc(100% - 42px);
  min-height: 200px;
  border-radius: 0;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px;
  resize: vertical;
  line-height: 1.4;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

.inline-validation {
  margin: 8px 0 6px;
  padding: 8px 10px;
  border: 1px solid #e6b7be;
  border-radius: 8px;
  background: #fff4f6;
  color: #7f2331;
  font-size: 12px;
}

.inline-validation ul {
  margin: 0;
  padding-left: 1rem;
}

.inline-validation li + li {
  margin-top: 4px;
}

.inline-validation-link {
  display: inline;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.inline-validation-link:hover {
  color: #641a28;
}

.inline-validation strong {
  font-weight: 600;
}

label {
  display: block;
  margin: 8px 0;
  font-size: 13px;
}

.control-range-label .control-range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.control-range-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.control-range-num {
  width: 3.25rem;
  flex-shrink: 0;
  padding: 6px 8px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

label.disabled-option {
  color: var(--muted);
  opacity: 0.75;
}

input[type="text"],
select,
button,
input[type="file"] {
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 7px 9px;
}

.hidden-file-input {
  display: none;
}

.dropzone {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  margin: 8px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.dropzone strong {
  font-size: 13px;
}

.dropzone span {
  font-size: 12px;
  color: var(--muted);
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  border-color: #3265ff;
  background: color-mix(in srgb, #3265ff 8%, transparent);
  outline: none;
}

button {
  cursor: pointer;
  background: #0f233c;
  color: #fff;
  border: none;
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger {
  background: #cc3344;
}

.row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.row > * {
  flex: 1;
}

.controls-export .row.export-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.controls-export .row.export-grid > * {
  width: 100%;
  min-width: 0;
}

.hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.hint-link {
  font-size: inherit;
  font-weight: inherit;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.hint-link:hover {
  color: var(--text);
}

.layout-order-hint {
  margin: -4px 0 10px;
}

.color-editor {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
}

.color-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
}

.color-row span {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-field {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  min-height: 28px;
  cursor: pointer;
}

.color-swatch {
  width: 36px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.color-hex {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.color-field input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}

.theme-color-picker-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  min-width: 168px;
}

.theme-color-picker-wrap select {
  width: 100%;
}

.theme-custom-color {
  align-self: flex-start;
}

.chart-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
}

#chartWrap {
  overflow: hidden;
  padding: 10px;
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  max-width: 100%;
}

#chart {
  background: transparent;
  display: block;
  max-width: 100%;
  height: auto;
}

.status-toast {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--status-success-border);
  background: var(--status-success-bg);
  color: var(--status-success);
  font-size: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.status-toast.error {
  border-color: #cc3344;
  color: #cc3344;
}

.status-toast.loading::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: status-spin 0.8s linear infinite;
}

.hidden {
  display: none;
}

@keyframes status-spin {
  to {
    transform: rotate(360deg);
  }
}

.node rect {
  stroke: rgba(0, 0, 0, 0.25);
  stroke-width: 0.7;
}

.node text {
  font-size: 12px;
  dominant-baseline: middle;
}

.link {
  fill: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 29, 0.45);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  max-height: min(90vh, 560px);
  overflow: auto;
  padding: 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.modal-dialog h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.modal-dialog--docs {
  max-width: 520px;
  max-height: min(90vh, 640px);
}

.doc-body {
  font-size: 13px;
  line-height: 1.45;
}

.doc-body h4 {
  margin: 16px 0 6px;
  font-size: 13px;
  font-weight: 600;
}

.doc-body h4:first-child {
  margin-top: 0;
}

.doc-body p {
  margin: 0 0 10px;
}

.doc-body ul {
  margin: 0 0 10px;
  padding-left: 1.15rem;
}

.doc-body li {
  margin-bottom: 6px;
}

.doc-body code {
  font-size: 12px;
}

.doc-body--legal p {
  margin-bottom: 12px;
}

.doc-body a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.doc-body a:hover {
  color: var(--text);
}

.theme-picker-lead {
  margin: 0 0 8px;
}

.theme-picker-count {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.theme-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.theme-swatch-btn {
  width: 100%;
  aspect-ratio: 1;
  min-height: 40px;
  padding: 0;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.theme-swatch-btn:hover {
  transform: scale(1.04);
}

.theme-swatch-btn.selected {
  outline: 2px solid #3265ff;
  outline-offset: 2px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12), 0 0 0 1px #3265ff;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-actions button {
  flex: 0 0 auto;
}

@media (max-width: 960px) {
  body {
    height: auto;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-header {
    padding: 5px 16px;
  }

  .layout {
    grid-template-columns: 1fr;
    flex: 1 0 auto;
    min-height: 0;
    min-width: 0;
    padding: 10px;
    gap: 10px;
  }

  .chart-panel {
    order: -1;
    min-height: min(50dvh, 440px);
    height: auto;
    min-width: 0;
  }

  .controls {
    height: auto;
  }

  .controls-body {
    overflow-y: visible;
    flex: none;
    padding: 12px;
  }

  #chartWrap {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
    min-height: 220px;
    align-items: flex-start;
    justify-content: flex-start;
  }

  .row {
    flex-wrap: wrap;
  }

  .row > * {
    flex: 1 1 auto;
    min-width: min(100%, 132px);
  }

  textarea {
    min-height: 160px;
  }

  .status-toast {
    right: max(10px, env(safe-area-inset-right, 0px));
    left: auto;
    max-width: min(320px, calc(100vw - 20px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  }

  .app-footer {
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .modal {
    align-items: flex-end;
    padding: 12px 12px max(12px, env(safe-area-inset-bottom, 12px));
  }

  .modal-dialog,
  .modal-dialog--docs {
    max-height: min(85dvh, calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
  }
}

@media (max-width: 420px) {
  .row > * {
    flex: 1 1 100%;
    min-width: 0;
  }

  .row > select#projectList {
    flex: 1 1 100%;
  }
}

/* PowerPoint dialog (?embed=office): hide downloads; ribbon More menu for samples */
html.office-embed #downloadDataBtn,
html.office-embed #exportImageBtn,
html.office-embed .sample-download-links {
  display: none !important;
}

html:not(.office-embed) #insertSlideBtn,
html:not(.office-embed) #officeInsertHint {
  display: none !important;
}
