/* ModeCalc (with care), web GUI. Copyright (c) 2023-2026 Gadi Lahav, RF With Care (https://rfwithcare.com). */
/* ModeCalc web GUI: the desktop program's look (Qt Fusion, light) with its
   dark drawing canvas. */
:root {
  --window: #efefef;
  --base: #ffffff;
  --text: #1b1b1b;
  --muted: #6b7078;
  --locked: #8a8f98;
  --error: #e05252;
  --line: #c9c9c9;
  --grid-line: #dcdcdc;
  --highlight: #308cc6;
  --highlight-soft: #cfe3f2;
  --button-hover: #e2e2e2;
  --button-checked: #d3d3d3;
  --canvas: #1e1f22;
  --font: system-ui, -apple-system, "Segoe UI", "DejaVu Sans", Roboto, Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--window);
  color: var(--text);
  font: 13px/1.35 var(--font);
  overflow: hidden;
}
#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr); /* long content (a status message) never widens the page */
}
button { font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---- menu bar ---- */
.topbar { display: flex; align-items: center; border-bottom: 1px solid #dadada; min-height: 26px; }
.menubar { display: flex; padding-left: 2px; }
.menu-title {
  background: none; border: 0; padding: 3px 8px; border-radius: 2px; cursor: default;
}
.menu-title:hover, .menu-title.open { background: var(--highlight); color: #fff; }
.hamburger {
  display: none; background: none; border: 0; font-size: 20px; line-height: 1; padding: 4px 10px;
  cursor: pointer;
}
.hamburger.open, .hamburger:hover { background: var(--button-hover); }
.dock-toggles { display: none; }

/* ---- popup menus ---- */
.menu {
  position: fixed; z-index: 1000; min-width: 170px; padding: 3px 0;
  background: var(--base); border: 1px solid #b9b9b9; border-radius: 3px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.menu-item {
  display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 8px;
  white-space: nowrap; cursor: default; user-select: none;
}
.menu-item:hover:not(.disabled) { background: var(--highlight); color: #fff; }
.menu-item.disabled { color: #a3a3a3; }
.menu-item.disabled .menu-icon { opacity: 0.35; }
.menu-check { width: 14px; text-align: center; }
.menu-icon { width: 20px; height: 20px; display: inline-flex; }
.menu-icon svg { width: 20px; height: 20px; }
.menu-item:hover:not(.disabled) .menu-icon svg { filter: drop-shadow(0 0 1px #fff); }
.menu-label { flex: 1; }
.menu-shortcut { color: var(--muted); padding-left: 24px; font-size: 12px; }
.menu-item:hover:not(.disabled) .menu-shortcut { color: #e7f1f9; }
.menu-sep { height: 1px; margin: 3px 0; background: #e1e1e1; }

/* ---- tabs and toolbars ---- */
.ribbon { display: flex; align-items: stretch; border-bottom: 1px solid #d0d0d0; }
.ribbon-main { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 0; padding: 4px 4px 0; border-bottom: 1px solid #c4c4c4; }
.tab {
  background: #e3e3e3; border: 1px solid #c4c4c4; border-bottom: 0; margin-right: -1px;
  padding: 3px 12px 4px; border-radius: 3px 3px 0 0; cursor: default; position: relative; top: 1px;
}
.tab:hover:not(:disabled) { background: #ececec; }
.tab.current { background: var(--window); padding-bottom: 5px; z-index: 1; }
.tab:disabled { color: #a9a9a9; }
.toolbar-holder { overflow-x: auto; scrollbar-width: thin; }
.toolbar { display: flex; align-items: center; padding: 3px 4px; gap: 1px; min-height: 50px; }
.tb {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; height: 40px; padding: 3px; background: none;
  border: 1px solid transparent; border-radius: 3px; cursor: default; flex: none;
}
.tb.wide { padding-right: 14px; }
.tb:hover:not(.disabled) { background: var(--button-hover); border-color: #c9c9c9; }
.tb.checked { background: var(--button-checked); border-color: #b2b2b2; box-shadow: inset 0 1px 2px rgba(0,0,0,0.15); }
.tb.disabled .tb-icon { opacity: 0.3; }
.tb.disabled { cursor: default; }
.tb-icon, .tb-icon svg { width: 32px; height: 32px; display: block; }
.tb-text { font-size: 12px; padding-left: 2px; }
.tb-arrow { position: absolute; right: 2px; bottom: 1px; font-size: 9px; color: #444; }
.tb-sep { width: 1px; align-self: stretch; margin: 4px 5px; background: #cfcfcf; flex: none; }
.logo-frame { display: flex; align-items: center; padding: 3px 8px 3px 12px; }
.logo-frame a {
  display: block; padding: 3px 7px; border-radius: 3px;
  border: 1px solid; border-color: #b1b1b1 #fafafa #fafafa #b1b1b1;
}
.logo-frame img { height: 50px; display: block; }

/* ---- workspace ---- */
.workspace {
  --left: 255px; --right: 255px;
  display: grid; min-height: 0;
  grid-template-columns: var(--left) 5px minmax(0, 1fr) 5px var(--right);
}
.center {
  --bottom: 200px;
  display: grid; min-height: 0; min-width: 0;
  grid-template-rows: minmax(0, 1fr) 5px var(--bottom);
}
.splitter { background: var(--window); }
.splitter-v { cursor: col-resize; }
.splitter-h { cursor: row-resize; }
.splitter:hover { background: #d8d8d8; }
.dock { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--window); }
.dock-title { padding: 3px 4px 2px; font-size: 13px; }
.dock-body { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--window); }
.dock-left .dock-body { background: var(--base); border: 1px solid var(--line); overflow: auto; }

.canvas-wrap { position: relative; min-height: 0; min-width: 0; background: var(--canvas); border: 1px solid #8f8f8f; overflow: hidden; }
.cad-canvas { position: absolute; inset: 0; display: block; touch-action: none; outline: none; }
.welcome {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  color: #c9ced6; background: rgba(30, 31, 34, 0.85); border: 1px solid #3a3d42;
  padding: 10px 16px; border-radius: 6px; font-size: 14px; text-align: center; pointer-events: auto;
  max-width: calc(100% - 32px);
}
.link-btn { background: none; border: 0; padding: 0; color: #7fd1ff; text-decoration: underline; cursor: pointer; }

/* ---- object tree ---- */
.tree { padding: 2px 0; user-select: none; }
.tree-row { display: flex; align-items: center; gap: 3px; height: 21px; padding-right: 6px; white-space: nowrap; cursor: default; }
.tree-row:hover { background: #eef5fb; }
.tree-row.selected { background: var(--highlight); color: #fff; }
.tree-row.error .node-name { color: var(--error); }
.tree-row.selected.error .node-name { color: #ffd6d6; }
.tree-row.link .node-name { font-style: italic; color: var(--locked); }
.tree-row.selected.link .node-name { color: #e6eef5; }
.twisty { width: 14px; text-align: center; color: #555; font-size: 11px; flex: none; }
.tree-row.selected .twisty { color: #fff; }
.twisty.leaf { visibility: hidden; }
.node-icon, .node-icon svg { width: 16px; height: 16px; display: inline-block; flex: none; }
.tree-row.selected .node-icon svg { filter: drop-shadow(0 0 1px #fff); }
.tree-edit { font: inherit; height: 19px; padding: 0 3px; border: 1px solid var(--highlight); flex: 1; min-width: 60px; }

/* ---- tables ---- */
.table-scroll { flex: 1; min-height: 0; overflow: auto; background: var(--base); border: 1px solid var(--line); }
table.grid { border-collapse: collapse; width: 100%; table-layout: fixed; background: var(--base); }
table.grid th {
  position: sticky; top: 0; z-index: 1; font-weight: normal; text-align: center;
  background: linear-gradient(#fbfbfb, #ececec); border: 1px solid var(--grid-line); border-top: 0;
  padding: 2px 4px; color: #333;
}
table.grid td { border: 1px solid var(--grid-line); padding: 0; height: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.grid tr:first-child td { border-top: 0; }
table.grid td:first-child, table.grid th:first-child { border-left: 0; }
.props-table td { height: 26px; }
.props-table.disabled th { color: #aaa; }
.prop-label { padding: 0 6px !important; }
.cell-input {
  width: 100%; height: 100%; border: 0; padding: 0 5px; background: transparent; outline: none;
}
.cell-input:focus { background: #fffbe6; box-shadow: inset 0 0 0 1px var(--highlight); }
.cell-input.error { color: var(--error); }
.cell-select { width: 100%; height: 100%; border: 0; background: transparent; padding: 0 2px; }
.cell-flex { display: flex; align-items: center; gap: 6px; padding: 0 6px; height: 100%; }
.cell-flex.spread { justify-content: space-between; padding-right: 2px; }
.cell-flex .cell-select { flex: 1; }
.swatch { width: 14px; height: 14px; flex: none; border: 1px solid rgba(0, 0, 0, 0.3); }
.locked { color: var(--locked); padding: 0 6px; display: block; overflow: hidden; text-overflow: ellipsis; }
.locked.center { text-align: center; }
.error-text { color: var(--error); }
.muted { color: var(--muted); }
.props-header { padding: 0 4px 4px; font-size: 13px; min-height: 20px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 3px; width: 24px; height: 24px; padding: 1px; display: inline-flex; }
.icon-btn:hover { background: var(--button-hover); border-color: #c9c9c9; }
.icon-btn svg { width: 20px; height: 20px; }
.params-table .row-remove { border-left: 0; text-align: center; }
.remove-btn { visibility: hidden; background: none; border: 0; color: #999; font-size: 16px; cursor: pointer; width: 100%; height: 100%; }
.params-table tr:hover .remove-btn { visibility: visible; }
.remove-btn:hover { color: var(--error); }
.add-row td { height: 28px; }
.flat-btn { background: none; border: 1px solid transparent; border-radius: 3px; padding: 3px 10px; cursor: pointer; }
.flat-btn:hover { background: var(--button-hover); border-color: #c9c9c9; }
.add-row .flat-btn { width: 100%; height: 100%; }

/* ---- status bar ---- */
.statusbar { display: flex; align-items: center; gap: 16px; padding: 2px 6px 2px 8px; min-height: 24px; border-top: 1px solid #dadada; }
.status-message { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-coords { font-variant-numeric: tabular-nums; white-space: pre; color: #333; }
.units-btn { background: none; border: 1px solid transparent; border-radius: 3px; padding: 1px 6px; cursor: default; }
.units-btn:hover { background: var(--button-hover); border-color: #c9c9c9; }

/* ---- dialogs ---- */
.overlay { position: fixed; inset: 0; z-index: 900; background: rgba(0, 0, 0, 0.25); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog {
  background: var(--window); border: 1px solid #a9a9a9; border-radius: 6px; min-width: 300px;
  max-width: 100%; max-height: 100%; display: flex; flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.dialog-title { display: flex; align-items: center; justify-content: space-between; padding: 7px 8px 7px 14px; font-weight: 600; border-bottom: 1px solid #d6d6d6; }
.dialog-x { background: none; border: 0; font-size: 20px; line-height: 1; padding: 0 6px; cursor: pointer; color: #555; }
.dialog-x:hover { color: var(--text); }
.dialog-body { padding: 12px 14px; overflow: auto; }
.dialog-body p { margin: 0 0 10px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 14px 12px; }
.btn { min-width: 80px; padding: 4px 14px; border: 1px solid #a9a9a9; border-radius: 3px; background: linear-gradient(#fdfdfd, #ececec); cursor: default; }
.btn:hover { background: linear-gradient(#fff, #f2f2f2); }
.btn.primary { border-color: var(--highlight); }
.btn:focus-visible { outline: 2px solid var(--highlight); outline-offset: 1px; }
.message { display: flex; gap: 14px; align-items: flex-start; max-width: 460px; }
.message-icon { flex: none; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 18px; color: #fff; background: #e0a32e; }
.message.info .message-icon { background: var(--highlight); font-style: italic; font-family: Georgia, serif; }
.message-text p { margin: 4px 0 8px; white-space: pre-wrap; }
.line-input { border: 1px solid #b4b4b4; border-radius: 2px; padding: 3px 5px; background: var(--base); width: 100%; }
.line-input:focus { outline: none; border-color: var(--highlight); }
.line-input.error { color: var(--error); border-color: var(--error); }
.bbox-grid { display: grid; grid-template-columns: repeat(3, minmax(110px, 1fr)); grid-template-rows: auto auto auto; gap: 10px; margin: 8px 0 10px; align-items: center; }
.bbox-cell { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.bbox-top { grid-column: 2; grid-row: 1; }
.bbox-left { grid-column: 1; grid-row: 2; }
.bbox-right { grid-column: 3; grid-row: 2; }
.bbox-bottom { grid-column: 2; grid-row: 3; }
.bbox-sketch { grid-column: 2; grid-row: 2; min-height: 60px; display: flex; align-items: center; justify-content: center; color: var(--locked); border: 1px dashed #b9b27e; }
.bbox-preview { min-height: 20px; }
.save-note { margin: 8px 0 0 !important; font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: auto 110px auto; gap: 8px 10px; align-items: center; }
.spin { width: 100%; padding: 3px 4px; border: 1px solid #b4b4b4; border-radius: 2px; background: var(--base); }
.coord-scroll { max-height: 50vh; min-height: 120px; }
.coord-table th:first-child, .coord-table td:first-child { width: 42px; }
.popup-panel { padding: 10px 12px; min-width: 260px; }
.freq-grid { display: grid; grid-template-columns: auto minmax(120px, 1fr) auto; gap: 6px 8px; align-items: center; }
.freq-title { grid-column: 1 / -1; }
.freq-unit { grid-column: 3; grid-row: 2 / span 2; }
.freq-message { margin-top: 8px; min-width: 220px; }
.about { text-align: center; }
.about-logo { width: 260px; max-width: 100%; }
.about h2 { margin: 10px 0 6px; }
.about a { color: var(--highlight); }

/* ---- hover help ---- */
.hover-banner {
  position: fixed; z-index: 1100; pointer-events: none; max-width: 340px;
  background: #2b2d31; color: #e6e8eb; border: 1px solid #5a6270; border-radius: 4px;
  padding: 6px 8px; font-size: 12.5px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.hover-key { color: #9aa0a8; }

/* ---- results: corner notes, graph page, solver window ---- */
.corner-note {
  position: absolute; z-index: 2; pointer-events: none; color: #e1e4eb;
  background: rgba(30, 31, 34, 0.78); padding: 3px 8px; border-radius: 3px; font-size: 12.5px;
}
.corner-br { right: 8px; bottom: 8px; }
.corner-bl { left: 8px; bottom: 8px; line-height: 1.35; }
.corner-bl table { border-collapse: collapse; }
.corner-bl td { padding: 0; }
.corner-bl td.value { padding-left: 12px; }
.corner-note .na { color: #9aa0a8; }
.corner-tr { right: 8px; top: 8px; padding: 0; }
.mode-select { height: 28px; min-width: 9em; margin: 0 4px; }
.tb-label { padding: 0 2px 0 6px; }
.graph-page { position: absolute; inset: 0; z-index: 3; background: var(--canvas); color: #e1e4eb; }
.graph-body { position: absolute; left: 10px; right: 10px; top: 170px; bottom: 10px; display: flex; flex-direction: column; }
.graph-mini { position: absolute; top: 10px; right: 10px; width: 240px; height: 150px; border: 1px solid #5a6270; pointer-events: none; }
.mini-canvas { position: absolute; inset: 0; display: block; }
.graph-plot { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.plot-title { text-align: center; font-size: 14px; padding-bottom: 6px; }
.plot-row { flex: 1; min-height: 0; display: flex; }
.plot-ytitle { writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; font-size: 13px; padding-left: 2px; }
.plot-area { flex: 1; min-width: 0; position: relative; }
.plot-svg { position: absolute; inset: 0; }
.plot-xtitle { text-align: center; font-size: 13px; padding-top: 2px; }
.plot-legend { display: flex; justify-content: center; gap: 14px; font-size: 12.5px; }
.legend-swatch { display: inline-block; width: 14px; height: 3px; margin-right: 5px; vertical-align: middle; }
.plot-grid line { stroke: #3a3d42; stroke-width: 1; }
.plot-frame { fill: none; stroke: #3a3d42; }
.plot-labels text { fill: #e1e4eb; font-size: 12px; }
.graph-table { flex: 1; min-height: 0; overflow: auto; }
.results-table { border-collapse: collapse; width: 100%; color: #e1e4eb; }
.results-table th { background: #2a2c30; border-bottom: 1px solid #5a6270; border-right: 1px solid #3a3d42; padding: 4px; font-weight: 600; }
.results-table td { border: 1px solid #3a3d42; padding: 4px 8px; text-align: right; font-variant-numeric: tabular-nums; }
.results-table td.left { text-align: left; }
.results-table tr.highlight td { font-weight: bold; }
.solver-window {
  position: fixed; z-index: 800; right: 24px; bottom: 40px; width: min(780px, calc(100vw - 32px));
  background: var(--window); border: 1px solid #a9a9a9; border-radius: 6px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column;
}
.solver-window.flash { animation: flash 0.6s 2; }
@keyframes flash { 50% { box-shadow: 0 0 0 3px var(--highlight); } }
.terminal {
  margin: 0; height: min(400px, 55vh); overflow: auto; background: #000; color: #33ff66; padding: 6px 8px;
  font: 12.5px/1.35 ui-monospace, "DejaVu Sans Mono", Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}
.dialog .terminal { height: min(320px, 50vh); }
.terminal .error { color: #ff5555; }
.terminal .note { color: #ffcc33; }
.terminal-status { padding: 4px 10px; font-size: 12.5px; min-height: 1.6em; }

/* ---- phones and narrow windows: one panel at a time (Objects, Properties or
   Parameters, picked on the bar right above it), below the canvas when upright,
   left of it when sideways. Nothing scrolls the page: the canvas takes what is
   left. ---- */
@media (max-width: 900px), (max-height: 540px) and (pointer: coarse) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto clamp(110px, 38%, 330px);
    grid-template-areas: "canvas" "switch" "panel";
  }
  .center { display: contents; }
  .canvas-wrap { grid-area: canvas; }
  .splitter { display: none; }
  .dock { display: none; grid-area: panel; padding: 0 4px 4px; }
  .dock.open { display: flex; }
  .dock-title { display: none; } /* the bar above names the panel */
  .dock-toggles {
    display: flex; grid-area: switch; gap: 2px; padding: 3px 4px;
    border-top: 1px solid #c4c4c4; background: var(--window);
  }
  .dock-toggles .flat-btn { flex: 1; padding: 4px 2px; }
  .dock-toggles .flat-btn.current { background: var(--button-checked); border-color: #b2b2b2; }
  .logo-frame { display: none; }
  .status-coords { display: none; }
  .toolbar-holder { overflow: hidden; }
  .toolbar { flex-wrap: wrap; min-height: 0; padding: 2px; }
  .tb { min-width: 34px; height: 34px; padding: 2px; }
  .tb-icon, .tb-icon svg { width: 28px; height: 28px; }
  .graph-mini { width: 150px; height: 94px; }
  .graph-body { top: 112px; }
  .corner-note { font-size: 11.5px; }
}
@media (max-width: 900px) and (orientation: landscape),
       (max-height: 540px) and (pointer: coarse) and (orientation: landscape) {
  .workspace {
    grid-template-columns: clamp(190px, 38%, 340px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "switch canvas" "panel canvas";
  }
  .dock, .dock-toggles { border-right: 1px solid #c4c4c4; }
  .dock { padding: 0 4px 4px 0; }
  .dock-toggles { border-top: 0; padding-left: 0; }
  .tabs { padding-top: 2px; }
}
@media (max-width: 640px) {
  .menubar { display: none; }
  .hamburger { display: block; }
  .logo-frame { display: none; }
}
