/* ONS Manufacturing Operations Platform */
:root {
  --accent: #d97706;
  --accent-soft: #f59e0b;
  --accent-bg: #fef3c7;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --purple: #7c3aed;
}

[data-theme="light"] {
  --bg: #fafaf7;
  --bg-2: #f4f3ee;
  --panel: #ffffff;
  --panel-2: #fafaf7;
  --panel-3: #f4f3ee;
  --line: #e7e5dc;
  --line-2: #d8d6cc;
  --text: #1a1a17;
  --text-2: #595955;
  --text-3: #8a8a82;
  --text-4: #b5b3a8;
  --shadow: 0 1px 2px rgba(20,18,10,0.04);
  --shadow-lg: 0 4px 16px rgba(20,18,10,0.08);
}

[data-theme="dark"] {
  --bg: #0b0d10;
  --bg-2: #0f1216;
  --panel: #14171c;
  --panel-2: #1a1e24;
  --panel-3: #20252c;
  --line: #252a32;
  --line-2: #323843;
  --text: #e8e9eb;
  --text-2: #a8acb3;
  --text-3: #6f747d;
  --text-4: #4a4e57;
  --shadow: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* Layout */
.app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 0 14px;
  gap: 12px;
  height: 44px;
  flex-shrink: 0;
  z-index: 10;
}
.sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 8px 0;
}
.main {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  position: relative;
}

/* Top bar */
.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
  width: 220px;
  padding-right: 14px;
  border-right: 1px solid var(--line);
  margin: 0 14px 0 0;
  height: 100%;
  margin-left: -14px;
  padding-left: 14px;
}
.brand-mark {
  width: 22px; height: 22px;
  border-radius: 4px;
  background: var(--text);
  color: var(--bg);
  display: grid; place-items: center;
  font-weight: 700; font-size: 11px;
  position: relative;
}
.brand-mark::after { display: none; }
.brand-name { font-weight: 600; }
.brand-sub { color: var(--text-3); font-weight: 400; font-size: 11px; }

.topbar-search {
  flex: 0 1 320px;
  min-width: 0;
  display: flex; align-items: center; gap: 8px;
  height: 26px; padding: 0 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-3);
  font-size: 12px;
  overflow: hidden;
}
.topbar-search > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.topbar-search kbd {
  margin-left: auto;
  font-family: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  color: var(--text-3);
}
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.tb-btn {
  height: 26px;
  padding: 0 8px;
  display: flex; align-items: center; gap: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}
.tb-btn:hover { background: var(--panel-2); color: var(--text); }
.tb-btn.outlined { border-color: var(--line); }
.tb-pill {
  display: flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 8px;
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  flex-shrink: 0;
}
.tb-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent);
}

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 0 6px 0 8px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
.user-chip > div { flex-shrink: 0; }
.user-chip:hover { background: var(--panel-2); }
.avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d97706, #92400e);
  color: white;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 600;
}

/* Sidebar */
.nav-section {
  padding: 12px 12px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 500;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px;
  margin: 1px 6px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-2);
  font-size: 12.5px;
  position: relative;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  background: var(--panel-2);
  color: var(--text);
  font-weight: 500;
}
.nav-item.active::before {
  content: ''; position: absolute;
  left: -6px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.nav-icon {
  width: 14px; height: 14px;
  flex: 0 0 14px;
  color: var(--text-3);
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  padding: 1px 5px;
  background: var(--panel-3);
  color: var(--text-2);
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
}
.nav-badge.alert {
  background: var(--red);
  color: white;
}

.plant-switch {
  margin: 8px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.plant-switch:hover { border-color: var(--line-2); }
.plant-switch-icon {
  width: 24px; height: 24px;
  border-radius: 4px;
  background: var(--panel-3);
  display: grid; place-items: center;
  color: var(--text-2);
}
.plant-switch-meta { flex: 1; min-width: 0; }
.plant-switch-name { font-size: 12px; font-weight: 500; color: var(--text); }
.plant-switch-id { font-size: 10px; color: var(--text-3); font-family: 'JetBrains Mono', monospace; }

/* Page */
.page-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-end;
  gap: 16px;
  background: var(--panel);
}
.page-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}
.page-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 3px;
}
.page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.btn {
  height: 28px;
  padding: 0 12px;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
}
.btn:hover { background: var(--panel-2); border-color: var(--line-2); }
.btn.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.btn.primary:hover { opacity: 0.9; background: var(--text);}
.btn.accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn.ghost { border-color: transparent; }
.btn.sm { height: 24px; padding: 0 8px; font-size: 11px; }
.btn.icon { padding: 0; width: 28px; justify-content: center; }
.btn.icon.sm { width: 24px; }

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 0 24px;
}
.tab {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 500;
}
.tab .count {
  margin-left: 6px;
  font-size: 10px;
  padding: 1px 5px;
  background: var(--panel-3);
  color: var(--text-2);
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
}

/* Cards / surfaces */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.card-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}
.card-body { padding: 14px; }
.card-meta {
  font-size: 11px; color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  margin-left: auto;
}

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px;
  font-weight: 500;
  height: 18px;
  padding: 0 7px;
  border-radius: 3px;
  background: var(--panel-3);
  color: var(--text-2);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.pill .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.running { background: color-mix(in srgb, var(--green) 12%, transparent); color: var(--green); }
.pill.idle { background: color-mix(in srgb, var(--blue) 12%, transparent); color: var(--blue); }
.pill.down { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.pill.warn { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.pill.maint { background: var(--panel-3); color: var(--text-2); }

/* Stat */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.stat {
  background: var(--panel);
  padding: 14px 16px;
}
.stat-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.stat-value {
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-top: 6px;
  font-feature-settings: 'tnum';
}
.stat-value .unit {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 400;
  margin-left: 2px;
}
.stat-delta {
  font-size: 11px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-3);
}
.stat-delta.up { color: var(--green); }
.stat-delta.down { color: var(--red); }
.stat-spark { margin-top: 8px; height: 22px; }

/* Table */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.tbl th, .tbl td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.tbl th {
  font-weight: 500;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  background: var(--panel-2);
  position: sticky; top: 0;
}
.tbl tr:hover td { background: var(--panel-2); }
.tbl tr.selected td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.tbl td.mono { font-family: 'JetBrains Mono', monospace; font-size: 11.5px; color: var(--text-2); }

/* Progress / bar */
.bar {
  height: 4px;
  background: var(--panel-3);
  border-radius: 2px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}
.bar-fill.green { background: var(--green); }
.bar-fill.red { background: var(--red); }

/* Generic icons */
.icn { width: 14px; height: 14px; flex: 0 0 14px; }
.icn-sm { width: 12px; height: 12px; flex: 0 0 12px; }
.icn-lg { width: 18px; height: 18px; flex: 0 0 18px; }

/* Drawer */
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 20;
}
.drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 480px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 21;
  display: flex; flex-direction: column;
  box-shadow: -8px 0 24px rgba(0,0,0,0.1);
}

/* Page body padding helper */
.page-body { padding: 16px 24px; }
.row { display: flex; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 12px; }

/* Section Heading */
.sec-heading {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 500;
}
.sec-heading::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* Responsive topbar — hide secondary elements when narrow (e.g. inside landing iframe) */
@media (max-width: 1100px) {
  .topbar-search { display: none; }
  .tb-pill { display: none; }
  .user-chip > div:not(.avatar) { display: none; }
  .tb-btn span { display: none; }
  .demo-banner-msg-2 { display: none; }
  .demo-banner-back span { display: none; }
}
@media (max-width: 820px) {
  .demo-banner-msg { display: none; }
}

/* Sparkline */
.spark { display: block; }

/* For workflow / canvas */
.dotgrid {
  background-image: radial-gradient(circle at 1px 1px, var(--line-2) 1px, transparent 0);
  background-size: 16px 16px;
}

/* Switch */
.switch {
  width: 28px; height: 16px;
  background: var(--line-2);
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: ''; position: absolute;
  width: 12px; height: 12px;
  background: white;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: left 0.15s;
}
.switch.on { background: var(--accent); }
.switch.on::after { left: 14px; }

/* Inputs */
.input {
  height: 26px;
  padding: 0 8px;
  font-size: 12px;
  font-family: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  outline: none;
}
.input:focus { border-color: var(--text-3); }
.select {
  height: 26px;
  padding: 0 24px 0 8px;
  font-size: 12px;
  font-family: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='10' viewBox='0 0 10 10' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M2 4l3 3 3-3' stroke='%238a8a82' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

/* Splash icons (rectangles for charts) */
.placeholder-img {
  background-image: repeating-linear-gradient(45deg, var(--panel-2), var(--panel-2) 6px, var(--panel-3) 6px, var(--panel-3) 12px);
  display: grid; place-items: center;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}

/* Toast */
.toast {
  position: fixed; bottom: 16px; right: 16px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 12px;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

/* Workflow node */
.wf-node {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  width: 200px;
  font-size: 12px;
  cursor: grab;
  position: absolute;
  user-select: none;
  box-shadow: var(--shadow);
}
.wf-node.selected { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.wf-node-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  margin-bottom: 6px;
  font-weight: 500;
}
.wf-node-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}
.wf-node.trigger .wf-node-head { color: var(--accent); }
.wf-node.condition .wf-node-head { color: var(--blue); }
.wf-node.action .wf-node-head { color: var(--green); }
.wf-port {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--line-2);
}
.wf-port.in { left: -6px; top: 50%; transform: translateY(-50%); }
.wf-port.out { right: -6px; top: 50%; transform: translateY(-50%); }
.wf-port:hover { border-color: var(--accent); }
