/* ==========================================================================
   Water-Methanol Controller — design tokens
   Theme: instrument-cluster inspired (dark default), boost-gauge accent.
   ========================================================================== */

/* فونت وزیرمتن - فایل‌های آن را در پوشه fonts/ قرار دهید (به fonts/README.md مراجعه کنید) */
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("../fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --accent: #FF7A1A;      /* رنگ اصلی قابل تغییر توسط کاربر */
  --accent-rgb: 255, 122, 26;
  --teal: #2DD4BF;
  --danger: #FF4D4D;
  --warning: #FFB020;

  --radius: 14px;
  --font-ui: "Vazirmatn", "Tahoma", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0B0F14;
  --surface: #131A22;
  --surface-2: #1B2530;
  --text: #E7EDF3;
  --text-dim: #8A97A5;
  --border: #232E3A;
}

[data-theme="light"] {
  --bg: #F3F5F7;
  --surface: #FFFFFF;
  --surface-2: #ECEFF2;
  --text: #14181D;
  --text-dim: #5B6672;
  --border: #DDE2E7;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 6px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 12px; height: 12px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.7);
  transform: rotate(45deg);
}

.brand-text { font-weight: 700; letter-spacing: 0.2px; font-size: 17px; }

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* ---------- connect bar ---------- */
.connect-bar { padding: 6px 18px 14px; }

.connect-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: border-color .2s ease;
}

.connect-btn.connected { border-color: var(--teal); }
.connect-btn.connected .dot { background: var(--teal); box-shadow: 0 0 10px rgba(45,212,191,.8); }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-dim);
  transition: background .2s ease;
}

.ble-warning {
  display: block;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--warning);
  text-align: center;
}
.hidden { display: none !important; }

/* ---------- main / tabs ---------- */
#mainContent { flex: 1; padding: 4px 18px 100px; }

.tab-panel { display: none; animation: fadein .25s ease; }
.tab-panel.active { display: block; }

@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- gauge ---------- */
.gauge-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0 6px;
}

.gauge-svg { width: 100%; max-width: 300px; }

.gauge-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 14;
  stroke-linecap: round;
}

.gauge-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 251.2; /* approx arc length */
  stroke-dashoffset: 251.2;
  transition: stroke-dashoffset .35s ease;
  filter: drop-shadow(0 0 6px rgba(var(--accent-rgb), .55));
}

.gauge-needle {
  stroke: var(--text);
  stroke-width: 3;
  stroke-linecap: round;
  transform-origin: 100px 110px;
  transition: transform .35s ease;
}

.gauge-hub { fill: var(--text); }

.gauge-readout {
  margin-top: -34px;
  font-family: var(--font-mono);
  font-size: 34px;
  font-weight: 700;
}
.gauge-readout .unit { font-size: 16px; color: var(--text-dim); margin-inline-start: 2px; }

.gauge-label { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

/* ---------- status chip ---------- */
.status-row { display: flex; justify-content: center; margin: 10px 0 18px; }

.status-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text-dim);
}

.status-chip .chip-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim);
}

.status-chip.active { color: var(--text); border-color: var(--accent); }
.status-chip.active .chip-dot {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(var(--accent-rgb), .8);
}

/* ---------- stat grid ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat-icon { font-size: 20px; margin-bottom: 4px; }

.stat-value {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 700;
}
.stat-value .unit { font-size: 12px; color: var(--text-dim); margin-inline-start: 3px; }

.stat-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.stat-card.warn { border-color: var(--danger); }
.stat-card.warn .stat-value { color: var(--danger); }
.stat-card.ok .stat-value { color: var(--teal); }

/* ---------- settings ---------- */
.section-title { font-size: 17px; margin: 10px 0 16px; }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field output {
  display: block;
  text-align: center;
  font-family: var(--font-mono);
  margin-top: 4px;
  color: var(--accent);
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
  margin-top: 14px;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #10131a;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.save-status { text-align: center; font-size: 13px; color: var(--teal); min-height: 18px; margin-top: 8px; }

.advanced {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.advanced summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------- appearance tab ---------- */
.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.segmented button {
  flex: 1;
  padding: 10px;
  border: none;
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font-ui);
  cursor: pointer;
  font-size: 14px;
}
.segmented button.active {
  background: var(--accent);
  color: #10131a;
  font-weight: 700;
}

.palette-row { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
}
.swatch.selected { border-color: var(--text); }

.color-input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 4px;
  cursor: pointer;
}

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11.5px;
  font-family: var(--font-ui);
  padding: 6px 0;
  cursor: pointer;
}
.nav-icon { font-size: 19px; }
.nav-btn.active { color: var(--accent); }

@media (min-width: 480px) {
  #app { border-inline: 1px solid var(--border); }
}
