@font-face {
  font-family: 'Secular One';
  src: url('/assets/fonts/SecularOne-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
}
@font-face {
  font-family: 'Heebo';
  src: url('/assets/fonts/Heebo-Regular.ttf') format('truetype');
  font-weight: 400;
}
@font-face {
  font-family: 'Heebo';
  src: url('/assets/fonts/Heebo-500.ttf') format('truetype');
  font-weight: 500;
}
@font-face {
  font-family: 'Heebo';
  src: url('/assets/fonts/Heebo-600.ttf') format('truetype');
  font-weight: 600;
}
@font-face {
  font-family: 'Heebo';
  src: url('/assets/fonts/Heebo-700.ttf') format('truetype');
  font-weight: 700;
}
@font-face {
  font-family: 'Heebo';
  src: url('/assets/fonts/Heebo-800.ttf') format('truetype');
  font-weight: 800;
}

/* Light Theme (Warm Ivory & Latte - exact match to light_medtech_theme.dart) */
:root,
html[data-theme='light'] {
  --bg: #F7F4EC;
  --surface: #FFFFFF;
  --surface-variant: #F6F0E6;
  --surface-input: #EFE8DC;
  --sidebar-bg: #F0EAE0;
  --border: #E6DFD5;
  --text-primary: #1E1813;
  --text-secondary: #5A4D41;
  --text-muted: #8A7A6D;
  --grid-line: #E6DFD5;
  --raspberry: #D9005B;
  --raspberry-bg: #FDE8F1;
  --emerald: #167C43;
  --emerald-bg: #DCF3E5;
  --amber: #B45309;
  --amber-bg: #FCECD9;
  --red: #C02222;
  --red-bg: #FBE4E4;
  --violet: #6D28D9;
  --violet-bg: #EDE4FA;
  --shadow: 0 2px 8px rgba(61, 42, 24, 0.05);
}

/* Dark Theme (Dense Coffee-Graphite & Chocolate - exact match to light_medtech_theme.dart) */
html[data-theme='dark'] {
  --bg: #191513;
  --surface: #26211D;
  --surface-variant: #322B25;
  --surface-input: #3B322B;
  --sidebar-bg: #201B17;
  --border: #3D342C;
  --text-primary: #F4EDE4;
  --text-secondary: #ABA095;
  --text-muted: #7A6F65;
  --grid-line: #362E27;
  --raspberry: #E60067;
  --raspberry-bg: #421526;
  --emerald: #22C55E;
  --emerald-bg: #133823;
  --amber: #F59E0B;
  --amber-bg: #3D270C;
  --red: #EF4444;
  --red-bg: #421717;
  --violet: #A78BFA;
  --violet-bg: #2B1D47;
  --shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'Secular One', 'Heebo', sans-serif;
  -webkit-font-smoothing: antialiased;
}

.num-font {
  font-family: 'Heebo', sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }

.card {
  background: var(--surface);
  border: 0.8px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* LOGIN SCREEN */
.login-backdrop {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-header { text-align: center; margin-bottom: 22px; }
.login-logo { height: 76px; object-fit: contain; margin-bottom: 10px; }
.login-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--raspberry-bg);
  color: var(--raspberry);
  font-family: 'Heebo', sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
}
.login-title { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.login-subtitle { margin: 0; font-size: 14px; color: var(--text-secondary); }

.login-form { display: flex; flex-direction: column; gap: 10px; }
.field-label { font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.field-input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-input);
  color: var(--text-primary);
  font-family: 'Heebo', sans-serif;
  font-size: 15px;
  outline: none;
}
.field-input:focus { border-color: var(--raspberry); }
.ltr-input { direction: ltr; text-align: left; }

.login-error {
  padding: 9px 12px;
  border-radius: 6px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.btn-primary {
  background: var(--raspberry);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 11px 18px;
  font-family: 'Secular One', 'Heebo', sans-serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.login-btn { margin-top: 6px; }

.login-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Heebo', sans-serif;
}

.theme-mini-btn {
  background: var(--surface-variant);
  color: var(--text-secondary);
  border: 0.8px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: 'Secular One', sans-serif;
  font-size: 12px;
}

/* APP SHELL */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-left: 0.8px solid var(--border);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
}

.logo-wrap {
  padding: 4px;
  display: flex;
  justify-content: center;
  margin-bottom: 22px;
}
.sidebar-logo { height: 92px; max-width: 100%; object-fit: contain; }

.sidebar-nav { display: flex; flex-direction: column; gap: 8px; }
.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Secular One', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: right;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-btn.eng {
  font-family: 'Heebo', sans-serif;
  font-size: 15px;
  letter-spacing: 0.8px;
}
.nav-btn:hover { background: var(--surface-variant); }
.nav-btn.active {
  background: var(--raspberry-bg);
  color: var(--raspberry);
  font-weight: 800;
}
.nav-icon { font-size: 18px; width: 22px; text-align: center; }

.sidebar-spacer { flex: 1; }

.theme-toggle {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-variant);
  border: 0.8px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
}
.theme-opt {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 4px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: 'Secular One', sans-serif;
  font-size: 13px;
  cursor: pointer;
}
.theme-opt.active {
  background: var(--surface);
  color: var(--text-primary);
  font-weight: 800;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.logout-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: 6px;
  border: 0.8px solid var(--border);
  background: var(--surface-variant);
  color: var(--text-secondary);
  font-family: 'Secular One', sans-serif;
  font-size: 13px;
  cursor: pointer;
}
.logout-btn:hover { border-color: var(--red); color: var(--red); }

.version-tag {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* WORKSPACE */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 10px 16px 0;
  overflow: hidden;
}

/* TOP HEADER */
.top-header {
  height: 64px;
  flex-shrink: 0;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.brand-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 1.5px;
  line-height: 1;
}
.header-spacer { flex: 1; }
.status-pills {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.status-pill {
  padding: 7px 14px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  min-width: 145px;
}
.pill-title { font-size: 13px; font-weight: 700; line-height: 1.2; }
.pill-sub { font-size: 11px; font-weight: 600; opacity: 0.86; }
.pill-green { background: var(--emerald-bg); color: var(--emerald); }
.pill-amber { background: var(--amber-bg); color: var(--amber); }
.pill-red { background: var(--red-bg); color: var(--red); }

.clock-pill {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--surface-variant);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

/* LIVE / SIMULATE DATA MODE SWITCH */
.mode-switch {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 20px;
  background: var(--surface-variant);
  border: 0.8px solid var(--border);
}
.mode-opt {
  border: none;
  border-radius: 16px;
  padding: 6px 12px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.mode-opt:disabled { opacity: 0.45; cursor: not-allowed; }
.mode-opt.active-live {
  background: var(--emerald);
  color: #fff;
}
.mode-opt.active-sim {
  background: var(--amber);
  color: #fff;
}

/* SYSTEM & ROUTER STATS TAB */
.sys-section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 17px;
  font-weight: 700;
  padding: 2px 4px;
}
.sys-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.sys-kpi-card {
  height: 136px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.sys-kpi-val {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
}
.sys-kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
}
.sys-kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface-variant);
  font-size: 13px;
}
.sys-kv-k { color: var(--text-secondary); font-weight: 600; }
.sys-kv-v { color: var(--text-primary); font-weight: 700; font-family: 'Heebo', sans-serif; direction: ltr; text-align: left; }

@media (max-width: 1180px) {
  .sys-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .sys-kv-grid, .sys-kpi-grid { grid-template-columns: 1fr; }
}

/* TAB CONTAINER */
.tab-container {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 16px;
}
.tab-pane { display: none; flex-direction: column; gap: 14px; }
.tab-pane.active { display: flex; }

/* ROW 1: KPI CARDS */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.kpi-card {
  height: 155px;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.kpi-title {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.kpi-val {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.5px;
}
.kpi-unit { font-size: 21px; font-weight: 700; }
.kpi-bottom { display: flex; flex-direction: column; gap: 5px; }
.progress-track {
  height: 4px;
  border-radius: 3px;
  background: var(--surface-input);
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.25s ease; }
.kpi-sub { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ROW 2: CHART + STATUS */
.row-2-grid {
  display: grid;
  grid-template-columns: 6fr 4fr;
  gap: 14px;
  min-height: 340px;
}
.chart-card, .status-card {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
}
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.card-title { font-size: 18px; font-weight: 700; }

.legend-row { display: flex; align-items: center; gap: 5px; }
.legend-box { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.legend-lbl { font-size: 14px; font-weight: 600; }
.legend-val { font-size: 15px; font-weight: 700; }
.legend-unit { font-size: 13px; font-weight: 700; }
.legend-gap { width: 14px; }

.canvas-wrap { flex: 1; min-height: 270px; position: relative; }
.canvas-wrap canvas { width: 100%; height: 100%; display: block; }

.badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-neutral { background: var(--surface-variant); color: var(--text-secondary); }
.badge-green { background: var(--emerald-bg); color: var(--emerald); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-raspberry { background: var(--raspberry-bg); color: var(--raspberry); }

.op-tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.op-tile {
  background: var(--surface-variant);
  border-radius: 6px;
  padding: 8px 10px;
}
.op-tile-hdr {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.op-val { font-size: 15px; font-weight: 700; }

.section-sub-lbl {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.sensor-matrix {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  flex: 1;
}
.sensor-tile {
  background: var(--surface-input);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
}
.sensor-pill {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
}

/* ROW 3: CONSUMABLES + CONTROLS */
.row-3-grid {
  display: grid;
  grid-template-columns: 55fr 45fr;
  gap: 14px;
}
.consumables-card, .control-card {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
}
.consumables-list { display: flex; flex-direction: column; gap: 10px; flex: 1; justify-content: space-evenly; }
.cons-row-top { display: flex; justify-content: space-between; font-size: 15px; font-weight: 600; margin-bottom: 4px; }

.ctrl-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.ctrl-btn {
  height: 52px;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: 'Secular One', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.ctrl-btn[data-color='emerald'] { background: var(--emerald); }
.ctrl-btn[data-color='red'] { background: var(--red); }
.ctrl-btn[data-color='raspberry'] { background: var(--raspberry); }
.ctrl-btn[data-color='amber'] { background: var(--amber); }
.ctrl-btn:disabled {
  background: var(--surface-variant) !important;
  color: var(--text-muted);
  cursor: not-allowed;
}
.ctrl-btn:not(:disabled):active { transform: scale(0.98); }

.cmd-ack-bar {
  margin-top: auto;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface-variant);
  font-size: 13px;
  font-family: 'Heebo', sans-serif;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ROW 4: RAW REGISTERS + AUDIT MINI */
.raw-regs-card, .audit-mini-card { padding: 14px 18px; }
.raw-regs-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}
.reg-cell {
  min-width: 102px;
  flex: 0 0 auto;
  background: var(--surface-variant);
  border-radius: 6px;
  padding: 8px 10px;
}
.reg-name { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.reg-dec { font-size: 17px; font-weight: 800; }
.reg-hex { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.raw-regs-footer { margin-top: 8px; font-size: 12px; color: var(--text-muted); }

.audit-mini-list { display: flex; flex-direction: column; gap: 6px; }
.audit-mini-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--surface-variant);
  border-radius: 6px;
  font-size: 13px;
  font-family: 'Heebo', sans-serif;
}

/* OTHER TABS */
.bar-card {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.bar-controls { display: flex; align-items: center; gap: 10px; }
.select-ctrl, .search-input {
  background: var(--surface-variant);
  color: var(--text-primary);
  border: 0.8px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-family: 'Secular One', 'Heebo', sans-serif;
  font-size: 14px;
  font-weight: 600;
}
.search-input { width: 250px; background: var(--surface); }

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 0.8px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-family: 'Secular One', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn-outline.active { background: var(--surface-variant); color: var(--text-primary); }
.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-family: 'Secular One', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.hist-graphs-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.mini-chart-card { height: 210px; padding: 12px 16px; display: flex; flex-direction: column; }
.mini-chart-title { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.mini-chart-card canvas { flex: 1; width: 100%; height: 150px; }

.table-card { padding: 16px; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: right;
  padding: 10px 8px;
  border-bottom: 1.5px solid var(--grid-line);
  font-weight: 700;
}
.data-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--surface-variant);
  color: var(--text-secondary);
  font-family: 'Heebo', sans-serif;
}

.integration-list { display: flex; flex-direction: column; gap: 8px; }
.int-row {
  min-height: 52px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.int-icon {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--surface-variant);
  border: 0.8px solid var(--border);
  color: var(--raspberry);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.int-title { font-size: 16px; font-weight: 700; white-space: nowrap; }
.int-desc { flex: 1; font-size: 14px; color: var(--text-secondary); }

.filter-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chips-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn {
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  font-family: 'Secular One', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip-btn.active { background: var(--raspberry-bg); color: var(--raspberry); font-weight: 800; }

/* MODAL & TOAST */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card { width: 100%; max-width: 420px; padding: 22px; }
.modal-title { margin: 0 0 10px; font-size: 19px; }
.modal-body { margin: 0 0 18px; color: var(--text-secondary); font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  padding: 12px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  z-index: 200;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-2-grid, .row-3-grid, .hist-graphs-row { grid-template-columns: 1fr; }
  .top-header { height: auto; padding: 10px 14px; flex-wrap: wrap; }
  .status-pills { flex-wrap: wrap; }
}
@media (max-width: 820px) {
  .app-shell { flex-direction: column; height: auto; overflow: auto; }
  .sidebar { width: 100%; border-left: none; border-bottom: 1px solid var(--border); }
}
