/* RAVAD Tools skin — loaded last on webserial/ and modbus/ pages.
   Visual-only overrides scoped under body.rv-tool. It does not rename or hide any element the
   application scripts use; state classes (btn-state-*, is-stale, cluster_*, term-*) keep their meaning. */

@font-face { font-family: "Manrope"; src: url("../ds/fonts/manrope-latin-wght-normal.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "DM Sans"; src: url("../ds/fonts/dm-sans-latin-wght-normal.woff2") format("woff2"); font-weight: 100 1000; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("../ds/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }

:root {
  --rv-brand: #0082c6;
  --rv-brand-600: #006aa6;
  --rv-brand-700: #063a63;
  --rv-brand-50: #e4f0f9;
  --rv-ink: #0c2236;
  --rv-muted: #5a6670;
  --rv-line: #e2eaf1;
  --rv-surface: #f3f8fc;
  --rv-navy: #071a2b;
  --rv-navy-2: #0a2c47;
  --rv-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --rv-head: "Manrope", "DM Sans", system-ui, sans-serif;
  --rv-body: "DM Sans", system-ui, sans-serif;

  /* Re-map the tool's own design variables to the brand palette (clusters.css / custom.css). */
  --dash-bg: #f3f8fc;
  --card-bg: #ffffff;
  --card-border: #dde5ee;
  --card-shadow: 0 10px 24px -12px rgba(11, 31, 51, .18);
  --card-shadow-strong: 0 16px 30px -14px rgba(11, 31, 51, .26);
  --ink-strong: #0b1f33;
  --ink-soft: #4a5b6e;
  --line-soft: rgba(11, 31, 51, .1);
  --accent: #006aa6;
  --accent-soft: #d2eaf8;
  --help-accent: #006aa6;
  --help-ink: #0b1f33;
  --help-muted: #4a5b6e;
}

body.rv-tool {
  margin: 0;
  margin: 0;
  font-family: var(--rv-body);
  color: var(--rv-ink);
  background: var(--rv-surface);
  -webkit-font-smoothing: antialiased;
}
.rv-tool h1, .rv-tool h2, .rv-tool h3, .rv-tool h4 { font-family: var(--rv-head); color: var(--rv-ink); letter-spacing: -.02em; font-weight: 700; }
.rv-tool a { color: var(--rv-brand-600); }
.rv-tool :focus-visible { outline: 3px solid #5fb2e3; outline-offset: 2px; }

/* ---------- Brand bar & footer ---------- */
.rv-bar {
  position: sticky; top: 0; z-index: 1500;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px clamp(16px, 3vw, 32px);
  background: var(--rv-navy);
  color: #e8f1f9; border-bottom: 1px solid rgba(160, 200, 235, .14);
}
.rv-bar__brand { display: inline-flex; align-items: center; gap: 10px; color: #fff !important; text-decoration: none !important; font-family: var(--rv-body); font-weight: 700; letter-spacing: .04em; }
.rv-bar__brand em { font-family: var(--rv-head); font-style: italic; font-weight: 400; color: #9cc9e3; letter-spacing: 0; font-size: 1.1em; }
.rv-bar__title { margin: 0; font: 600 14px/1 var(--rv-body); letter-spacing: 0; text-transform: none; color: #a9bccd; padding-left: 18px; border-left: 1px solid rgba(160, 200, 235, .2); }
.rv-bar__links { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.rv-bar__links a { color: #e2edf6 !important; text-decoration: none !important; font-family: var(--rv-body); font-weight: 500; font-size: 14px; padding: 8px 12px; border-radius: 0; transition: background .15s ease; }
.rv-bar__links a:hover { background: rgba(255, 255, 255, .08); color: #fff !important; }
@media (max-width: 720px) { .rv-bar__title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } .rv-bar__links { margin-left: 0; width: 100%; } }

.rv-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; padding: 18px clamp(16px, 3vw, 32px); margin-top: 32px; border-top: 1px solid var(--rv-line); font-size: 13px; color: var(--rv-muted); background: #fff; }

/* ---------- Bootstrap surface tweaks ---------- */
.rv-webserial .container.my-5 { max-width: 1320px; margin-top: 28px !important; background: #fff; border: 1px solid var(--rv-line); border-radius: 20px; padding: 20px clamp(16px, 2.4vw, 32px) 28px; box-shadow: 0 20px 40px -28px rgba(11, 31, 51, .35); }

/* Tabs → segmented control */
.rv-tool .nav-tabs { border: 1px solid var(--rv-line); background: var(--rv-surface); border-radius: 6px; padding: 6px; gap: 6px; }
.rv-tool .nav-tabs .nav-link { border: 0 !important; border-radius: 999px; color: var(--rv-muted); font-family: var(--rv-body); font-weight: 600; padding: 9px 18px; transition: background .15s ease, color .15s ease; }
.rv-tool .nav-tabs .nav-link:hover { color: var(--rv-ink); background: rgba(255, 255, 255, .6); }
.rv-tool .nav-tabs .nav-link.active { background: #fff !important; color: var(--rv-brand-600) !important; box-shadow: 0 1px 3px rgba(11, 31, 51, .12); }
.rv-tool .tab-pane > h2.mb-3 { font-size: 1.6rem; margin-top: 8px; }

/* Buttons (state classes from the app keep working: they add colors on top of these) */
.rv-tool .btn { font-family: var(--rv-body); font-weight: 600; border-radius: 10px; letter-spacing: -.005em; transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease; }
.rv-tool .btn:active { transform: scale(.97); }
.rv-tool .btn-primary:not([class*="btn-state"]):not([class*="btn-blink"]) { background: var(--rv-brand-600); border-color: var(--rv-brand-600); }
.rv-tool .btn-primary:not([class*="btn-state"]):not([class*="btn-blink"]):hover { background: var(--rv-brand-700); border-color: var(--rv-brand-700); }
/* Only neutral buttons are re-skinned; buttons carrying an app state class keep the app's state colors. */
.rv-tool .btn-outline:not([class*="btn-state"]):not([class*="btn-blink"]) { border: 1.5px solid #cbd8e3; color: var(--rv-ink); background: #fff; }
.rv-tool .btn-outline:not([class*="btn-state"]):not([class*="btn-blink"]):hover { border-color: var(--rv-ink); background: var(--rv-surface); }
.rv-tool .btn-secondary { background: #5d6f82; border-color: #5d6f82; }
.rv-tool .btn-warning { background: #fbf1dc; border-color: #e9c77c; color: #6b4a0f; }
.rv-tool .btn:disabled, .rv-tool .btn.disabled { opacity: .45; }

/* Serial toolbar & input */
.rv-tool .serial-toolbar { background: var(--rv-surface); border: 1px solid var(--rv-line); border-radius: 14px; padding: 10px 14px; }
.rv-tool select, .rv-tool input[type="text"], .rv-tool input[type="number"], .rv-tool .form-select {
  border: 1.5px solid #cbd8e3; border-radius: 10px; padding: 6px 10px; background: #fff; color: var(--rv-ink); font-family: var(--rv-body);
}
.rv-tool select:focus, .rv-tool input:focus { border-color: var(--rv-brand); box-shadow: 0 0 0 3px rgba(0, 102, 156, .15); outline: none; }
.rv-tool .serial-input-label, .rv-tool .serial-status-label, .rv-tool .serial-baudrate-label { font-family: var(--rv-body); font-weight: 600; color: var(--rv-ink); }
.rv-tool #status { font-family: var(--rv-mono); font-size: 13px; }

/* Terminal → navy console */
.rv-tool .terminal-window {
  background: var(--rv-navy) !important;
  color: #e2edf6 !important; border: 1px solid #1e3a55 !important; border-radius: 14px !important;
  font-family: var(--rv-mono) !important; font-size: 13px !important; line-height: 1.55 !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04), 0 18px 36px -24px rgba(7, 26, 44, .6);
}
.rv-tool .terminal-window:focus { border-color: #5fb2e3 !important; box-shadow: 0 0 0 3px rgba(95, 178, 227, .25) !important; }
.rv-tool .term-remote { color: #9cc9e3 !important; }
.rv-tool .term-local-echo { color: #ffd27a !important; }
.rv-tool .term-meta { color: #7f95ab !important; }

/* History popup */
.rv-tool .history-panel { border-radius: 16px; border: 1px solid var(--rv-line); box-shadow: 0 24px 48px -20px rgba(11, 31, 51, .35); }

/* Parser table */
.rv-tool .table { font-size: 14px; }
.rv-tool .table thead th { font-family: var(--rv-mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--rv-muted); border-top: 0; border-bottom: 1px solid var(--rv-line); }
.rv-tool .table td, .rv-tool .table th { border-color: #edf2f7; }
.rv-tool .table-hover tbody tr:hover { background: var(--rv-brand-50); }

/* Graphics */
.rv-tool .dashboard-persist-bar { border-radius: 14px; }
.rv-tool .gauge-card-name { font-family: var(--rv-body); font-weight: 600; }
.rv-tool .varvalue, .rv-tool .gauge-range { font-family: var(--rv-mono); font-variant-numeric: tabular-nums; }

/* Splash & help use the tool's own variables (re-mapped above); tune typography only. */
.rv-tool .splash-card { border-radius: 22px; }
.rv-tool .help-kicker { font-family: var(--rv-mono); letter-spacing: .08em; }
.rv-tool .help-code, .rv-tool code, .rv-tool kbd { font-family: var(--rv-mono); }

/* ---------- Modbus page (originally unstyled) ---------- */
.rv-modbus__main {
  max-width: 1320px; margin: 28px auto 0; background: #fff; border: 1px solid var(--rv-line); border-radius: 20px;
  padding: 22px clamp(16px, 2.4vw, 32px) 28px; box-shadow: 0 20px 40px -28px rgba(11, 31, 51, .35); line-height: 1.7;
}
.rv-modbus button {
  font-family: var(--rv-body); font-weight: 600; font-size: 14px; min-height: 36px; padding: 0 14px;
  border-radius: 4px !important; border: 1px solid #cbd8e3 !important; background: #fff !important; color: var(--rv-ink) !important;
  cursor: pointer; transition: background .15s ease, border-color .15s ease;
}
.rv-modbus button:hover:not(:disabled) { border-color: var(--rv-ink) !important; background: var(--rv-surface) !important; }
.rv-modbus button#ConnectButton { background: var(--rv-brand-600) !important; border-color: var(--rv-brand-600) !important; color: #fff !important; width: auto !important; }
.rv-modbus button#ConnectButton:hover:not(:disabled) { background: var(--rv-brand-700) !important; }
.rv-modbus button:disabled { opacity: .45; cursor: not-allowed; }
.rv-modbus fieldset { border: 1px solid var(--rv-line); border-radius: 14px; padding: 10px 16px 14px; margin: 12px 0; background: var(--rv-surface); }
.rv-modbus legend { font-family: var(--rv-head); font-weight: 700; color: var(--rv-ink); padding: 0 6px; width: auto; }
.rv-modbus textarea, .rv-modbus pre {
  background: var(--rv-navy); color: #e2edf6; border: 1px solid #1e3a55; border-radius: 12px; font-family: var(--rv-mono); font-size: 13px; padding: 10px;
}
.rv-modbus table { border-collapse: collapse; }
.rv-modbus th, .rv-modbus td { border-bottom: 1px solid #edf2f7; padding: 4px 8px; }

/* Section titles inside the tool stay serif; UI labels and tables use the UI sans. */
.rv-tool .table, .rv-tool label, .rv-tool .dashboard-status { font-family: var(--rv-body); }
.rv-tool .tab-pane > h2.mb-3 { font-size: 2rem; }

/* ---------- Modbus help as a modal (display is still toggled by the app via style.display) ---------- */
.rv-backdrop { position: fixed; inset: 0; z-index: 2000; background: rgba(21, 31, 40, .55); }
.rv-backdrop[hidden] { display: none; }
body.rv-modal-open { overflow: hidden; }
.rv-modbus #help.rv-modal {
  position: fixed !important; z-index: 2001; top: 50% !important; left: 50% !important; transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px)) !important; max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--rv-surface) !important; color: var(--rv-ink); text-align: left !important;
  box-sizing: border-box; border: 1px solid var(--rv-line); border-radius: 6px; padding: clamp(24px, 4vw, 36px) clamp(20px, 4vw, 40px) 28px;
  box-shadow: 0 30px 60px -30px rgba(21, 31, 40, .6); font-family: var(--rv-body); line-height: 1.65;
}
.rv-modbus #help.rv-modal:focus { outline: none; }
.rv-modbus #help.rv-modal h1, .rv-modbus #help.rv-modal h2, .rv-modbus #help.rv-modal h3,
.rv-modbus #help.rv-modal > b:first-of-type, .rv-modbus #help.rv-modal center { font-family: var(--rv-head); font-weight: 400; }
.rv-modbus #help.rv-modal p { margin: 0 0 12px; }
.rv-modbus #help.rv-modal a { color: var(--rv-brand-600); }
.rv-modbus #help.rv-modal a[onclick*="close"] {
  display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 18px; margin-top: 8px;
  background: var(--rv-ink); color: #fff !important; text-decoration: none; border-radius: 4px; font-weight: 600;
}
.rv-modbus .rv-modal-close {
  position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50% !important;
  border: 1px solid var(--rv-line) !important; background: #fff !important; color: var(--rv-ink) !important;
  font-size: 22px !important; line-height: 1; padding: 0 !important; min-height: 0 !important; cursor: pointer;
}
.rv-modbus .rv-modal-close:hover { border-color: var(--rv-ink) !important; background: #fff !important; }

.rv-bar__brand img { height: 38px; width: auto; display: block; }
.rv-tool .tab-pane > h2.mb-3 { font-size: 1.6rem; }
.rv-modbus #help.rv-modal h2 { font-weight: 700; }
