:root {
  /* Brand: Process Plant AI logo (deep navy -> teal gradient). Primary is a
     teal deep enough for white text on buttons (5.2:1); the logo's lighter
     teal and navy are kept as brand accents. */
  --color-brand-navy: #032040;
  --color-brand-teal: #30a1a9;
  --color-primary-50: #ecf8f9;
  --color-primary-100: #cdeef0;
  --color-primary-500: #137882;
  --color-primary-600: #0e5f67;
  --color-primary-700: #0b4d55;
  --color-primary: var(--color-primary-500);
  --color-primary-hover: var(--color-primary-600);
  --color-primary-tint: var(--color-primary-50);

  --color-secondary: #64748b;

  --color-success: #10b981;
  --color-success-tint: #ecfdf5;
  --color-warning: #f59e0b;
  --color-warning-tint: #fffbeb;
  --color-critical: #ef4444;
  --color-critical-tint: #fef2f2;
  --color-info: #3b82f6;
  --color-info-tint: #eff6ff;

  --color-neutral-900: #111827;
  --color-neutral-800: #1f2937;
  --color-neutral-700: #374151;
  --color-neutral-600: #4b5563;
  --color-neutral-500: #6b7280;
  --color-neutral-400: #9ca3af;
  --color-neutral-300: #d1d5db;
  --color-neutral-200: #e5e7eb;
  --color-neutral-100: #f3f4f6;
  --color-neutral-50: #f9fafb;

  --radius-sm: 8px;
  --radius-button: 10px;
  --radius-card: 16px;
  --radius-avatar: 9999px;

  --shadow-resting: 0 1px 2px rgba(17,24,39,.06), 0 1px 1px rgba(17,24,39,.04);
  --shadow-hover: 0 4px 12px rgba(17,24,39,.08);
  --shadow-elevated: 0 12px 32px rgba(17,24,39,.14);
}

.container { max-width: 1280px; }
.card { background: #fff; border-radius: var(--radius-card); box-shadow: var(--shadow-resting); }
.card-header { padding: 1rem; border-bottom: 1px solid var(--color-neutral-200); display: flex; align-items: center; justify-content: space-between; }
.card-body { padding: 1rem; }
/* Interactive cards get a gentle hover lift. Opt-in via .card-hover so static
   layout cards don't wiggle on cursor pass-over. */
.card-hover, .stat-tile { transition: transform .15s ease, box-shadow .15s ease; }
.card-hover:hover, .stat-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }

.btn { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; border-radius: var(--radius-button); padding: .4rem .75rem; font-size: .875rem; transition: filter .15s ease, box-shadow .15s ease; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-secondary { background: var(--color-secondary); color: #fff; }
.btn-outline { background: transparent; color: var(--color-neutral-800); border: 1px solid var(--color-neutral-300); }
.btn-danger { background: var(--color-critical); color: #fff; }
.btn-sm { padding: .25rem .5rem; font-size: .75rem; border-radius: var(--radius-sm); gap: .3rem; }
.btn:hover { filter: brightness(0.95); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-tint); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }

.input { width: 100%; border: 1px solid var(--color-neutral-300); border-radius: var(--radius-sm); padding: .375rem .625rem; font-size: .875rem; transition: border-color .15s ease, box-shadow .15s ease; }
.input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-tint); }

.badge { display: inline-flex; align-items: center; border-radius: 9999px; padding: .125rem .5rem; font-size: .75rem; font-weight: 600; }
.badge-normal { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-critical { background: #fee2e2; color: #991b1b; }
.badge-unknown { background: #e5e7eb; color: #374151; }

.status-dot { width: .5rem; height: .5rem; border-radius: 9999px; }
.status-normal { background: #22c55e; }
.status-warning { background: #f59e0b; }
.status-critical { background: #ef4444; }
.status-unknown { background: #9ca3af; }

.table { width: 100%; border-collapse: collapse; }
.table th { background: var(--color-neutral-100); color: var(--color-neutral-600); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; padding: .875rem 1.25rem; text-align: left; }
.table td { padding: .875rem 1.25rem; font-size: .875rem; color: var(--color-neutral-800); }
.table tr + tr td { border-top: 1px solid var(--color-neutral-200); }

.nav { background: #fff; border-bottom: 1px solid var(--color-neutral-200); }
.nav .logo { font-family: 'Pacifico', cursive; font-size: 1.25rem; color: var(--color-neutral-800); }
.icon { width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center; border-radius: 9999px; background: var(--color-neutral-100); color: var(--color-neutral-700); border: none; cursor: pointer; transition: background-color .15s ease; }
.icon:hover { background: var(--color-neutral-200); }
.icon:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-tint); }

.tab-active { color: var(--color-primary); border-bottom: 2px solid var(--color-primary); }
.asset-item:hover { background-color: var(--color-neutral-100); }

/* Sidebar nav: keyboard focus ring + a touch of icon lift on hover */
#appSidebar a:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--color-primary-tint); }
#appSidebar a i { transition: transform .15s ease; }
#appSidebar a:hover i { transform: translateX(1px); }

.stat-tile { background: #fff; border-radius: var(--radius-card); box-shadow: var(--shadow-resting); padding: 1.25rem; }
.stat-tile-compact { padding: .75rem; }
.stat-tile-icon { width: 2.5rem; height: 2.5rem; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; }
.stat-tile-icon.tone-primary { background: var(--color-primary-tint); color: var(--color-primary-600); }
.stat-tile-icon.tone-success { background: var(--color-success-tint); color: var(--color-success); }
.stat-tile-icon.tone-warning { background: var(--color-warning-tint); color: var(--color-warning); }
.stat-tile-icon.tone-critical { background: var(--color-critical-tint); color: var(--color-critical); }
.stat-tile-icon.tone-info { background: var(--color-info-tint); color: var(--color-info); }
.stat-tile-label { font-size: .8rem; color: var(--color-neutral-500); font-weight: 500; }
.stat-tile-value { font-size: 1.75rem; font-weight: 700; color: var(--color-neutral-900); line-height: 1.2; }
.stat-tile-compact .stat-tile-value { font-size: 1.125rem; }
.stat-tile-unit { font-size: .875rem; font-weight: 500; color: var(--color-neutral-500); margin-left: .25rem; }

.banner { border-radius: var(--radius-sm); padding: .75rem 1rem; font-size: .8125rem; border: 1px solid transparent; display: flex; align-items: flex-start; gap: .5rem; }
.banner-info { background: var(--color-info-tint); border-color: #bfdbfe; color: #1e40af; }
.banner-success { background: var(--color-success-tint); border-color: #a7f3d0; color: #065f46; }
.banner-warning { background: var(--color-warning-tint); border-color: #fde68a; color: #92400e; }
.banner-critical { background: var(--color-critical-tint); border-color: #fecaca; color: #991b1b; }

.chip { display:inline-flex; align-items:center; gap:.35rem; background:#e5e7eb; color:#374151; border-radius:9999px; padding:.125rem .5rem; font-size:.75rem; }
.chip-close { background:transparent; border:none; color:#111827; cursor:pointer; font-size:.9rem; line-height:1; }
.chip-close:hover { color:#ef4444; }

/* Donut/pie legend rows (financial cost distribution) */
.legend-row { display:flex; align-items:center; gap:.5rem; padding:.375rem 0; font-size:.8125rem; }
.legend-swatch { width:.625rem; height:.625rem; border-radius:3px; flex-shrink:0; }
.legend-name { color:var(--color-neutral-700); }
.legend-value { margin-left:auto; font-weight:600; color:var(--color-neutral-900); }
.legend-pct { color:var(--color-neutral-500); font-size:.75rem; min-width:2.75rem; text-align:right; }

/* Proportional share bar (history status breakdown) */
.share-track { height:.375rem; border-radius:9999px; background:var(--color-neutral-100); overflow:hidden; margin-top:.25rem; }
.share-fill { height:100%; border-radius:9999px; }

/* Empty-state placeholder inside a chart/panel */
.empty-state { display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; color:var(--color-neutral-400); gap:.5rem; height:100%; padding:2rem 1rem; }
.empty-state i { font-size:2rem; color:var(--color-neutral-300); }
.empty-state-text { font-size:.875rem; color:var(--color-neutral-500); max-width:22rem; }

.toast { position:fixed; bottom:1rem; right:1rem; background:#111827; color:#fff; padding:.5rem .75rem; border-radius:8px; box-shadow:0 4px 12px rgba(0,0,0,.15); opacity:0; transform:translateY(8px); transition:opacity .2s ease, transform .2s ease; z-index:50; }
.toast-show { opacity:1; transform:translateY(0); }

.chart-card { transition: transform .15s ease, width .15s ease, height .15s ease; border:1px solid var(--color-neutral-200); box-shadow:0 4px 12px rgba(0,0,0,0.08); }
.chart-card:hover { box-shadow:0 8px 20px rgba(0,0,0,0.10); }
.chart-card { min-width: 280px; min-height: 200px; }
.chart-card .card-header { flex-wrap: wrap; gap: .5rem; }
.chart-handle { position:absolute; width:10px; height:10px; background:#e5e7eb; border:1px solid #9ca3af; border-radius:2px; }
.chart-handle.nw { left:2px; top:2px; cursor:nwse-resize; }
.chart-handle.ne { right:2px; top:2px; cursor:nesw-resize; }
.chart-handle.sw { left:2px; bottom:2px; cursor:nesw-resize; }
.chart-handle.se { right:2px; bottom:2px; cursor:nwse-resize; }

.dropdown { position:relative; display:inline-block; }
.dropdown-menu { position:absolute; top:100%; left:0; min-width:220px; background:#fff; border:1px solid var(--color-neutral-200); border-radius:8px; box-shadow:0 8px 20px rgba(0,0,0,.08); padding:.5rem; z-index:30; }
.dropdown-item { display:flex; align-items:center; gap:.5rem; padding:.25rem .25rem; border-radius:6px; font-size:.875rem; color:#374151; }
.dropdown-item:hover { background:#f3f4f6; }

.charts-full { background: var(--color-neutral-100); }

/* Drag/resize chart workspaces (monitoring's Charts tab, optimization's
   Compare tab) can't work on narrow viewports - fixed-pixel absolutely
   positioned cards don't translate to touch/small screens. Below md, stack
   cards into normal flow and hide the now-nonfunctional resize handles;
   the corresponding page JS also gates interact() init behind the same
   breakpoint so pointer listeners never attach here. */
@media (max-width: 767px) {
  .charts-full { overflow-y: auto; }
  .charts-full .chart-card { position: static !important; width: 100% !important; height: 260px !important; margin-bottom: 1rem; transform: none !important; }
  .charts-full .chart-handle { display: none; }
}

/* Sidebar mobile drawer: desktop keeps it permanently on-screen; below md
   it's translated off-screen and slid in via JS toggling .open. */
#sidebarBackdrop { display: none; }
#sidebarBackdrop.open { display: block; }
@media (max-width: 767px) {
  #appSidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-elevated); }
  #appSidebar.open { transform: translateX(0); }
}
@media (min-width: 768px) {
  #sidebarBackdrop { display: none !important; }
}

/* Process Stream & Optimization Page additions */
.process-column { position: relative; display: flex; flex-direction: column; gap: 1rem; }
.process-arrow { display: flex; align-items: center; justify-content: center; color: var(--color-primary); font-size: 1.5rem; font-weight: bold; margin: 0.25rem 0; }
.badge-optimizer-on { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.badge-optimizer-off { background: #f3f4f6; color: #6b7280; border: 1px solid #d1d5db; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { filter: brightness(0.92); }
.power-savings-badge { background: linear-gradient(135deg, #10b981 0%, #059669 100%); color: #fff; border-radius: var(--radius-sm); padding: 0.5rem 0.75rem; display: flex; align-items: center; gap: 0.5rem; font-weight: 600; box-shadow: 0 2px 8px rgba(16,185,129,0.25); }


/* Plant model canvas (assets/plant_canvas.js) -- shared by the builder and
   the Settings preview. Card size must match CARD_W/CARD_H in the JS. */
:root {
  --stream-liquid: #3b82f6;
  --stream-sludge: #b45309;
  --stream-air: #0ea5e9;
  --stream-gas: #10b981;
  --stream-any: #64748b;
}
.pc-root { position: relative; overflow: hidden; background-color: #fbfcfd; background-image: radial-gradient(var(--color-neutral-300) 1px, transparent 1px); background-size: 20px 20px; cursor: grab; user-select: none; touch-action: none; outline: none; }
.pc-root.pc-panning { cursor: grabbing; }
.pc-world { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.pc-edges { position: absolute; pointer-events: none; overflow: visible; }
.pc-edge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.pc-edge-line { fill: none; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.pc-edge-selected .pc-edge-line { filter: drop-shadow(0 0 3px rgba(19,120,130,.7)); }
.pc-edge-label { font: 600 10px Inter, system-ui, sans-serif; paint-order: stroke; stroke: #fff; stroke-width: 4px; pointer-events: none; }
.pc-edge-temp { fill: none; stroke-width: 2; stroke-dasharray: 4 4; }
.pc-sensor-link { stroke: var(--color-neutral-400); stroke-width: 1.5; stroke-dasharray: 2 4; }
.pc-nodes { position: absolute; left: 0; top: 0; }
.pc-unit { position: absolute; width: 200px; height: 104px; background: #fff; border: 1px solid var(--color-neutral-200); border-radius: 12px; box-shadow: var(--shadow-resting); cursor: pointer; display: flex; flex-direction: column; }
.pc-editable .pc-unit { cursor: move; }
.pc-unit:hover { box-shadow: var(--shadow-hover); }
.pc-unit.pc-selected { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(19,120,130,.25), var(--shadow-hover); }
.pc-unit-head { display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem .35rem; border-bottom: 1px solid var(--color-neutral-100); }
.pc-unit-icon { flex: none; width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: var(--color-primary-tint); color: var(--color-primary-600); font-size: 1rem; }
.pc-unit[data-category="Source / Sink"] .pc-unit-icon { background: var(--color-info-tint); color: var(--color-info); }
.pc-unit[data-category="Biological"] .pc-unit-icon { background: var(--color-success-tint); color: var(--color-success); }
.pc-unit[data-category="Sludge"] .pc-unit-icon { background: #fef3c7; color: var(--stream-sludge); }
.pc-unit[data-category="Flow Control"] .pc-unit-icon,
.pc-unit[data-category="Instrument"] .pc-unit-icon { background: var(--color-neutral-100); color: var(--color-neutral-600); }
.pc-unit-titles { min-width: 0; }
.pc-unit-name { font-size: .78rem; font-weight: 600; color: var(--color-neutral-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-unit-sub { font-size: .65rem; color: var(--color-neutral-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-unit-metrics { padding: .3rem .6rem; display: flex; flex-direction: column; gap: .15rem; }
.pc-metric { display: flex; justify-content: space-between; gap: .5rem; font-size: .68rem; }
.pc-metric-label { color: var(--color-neutral-500); white-space: nowrap; }
.pc-metric-value { color: var(--color-neutral-800); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-port { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 9999px; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--color-neutral-300); background: var(--stream-any); z-index: 2; transition: transform .1s ease; }
.pc-port[data-stream="liquid"] { background: var(--stream-liquid); }
.pc-port[data-stream="sludge"] { background: var(--stream-sludge); }
.pc-port[data-stream="air"] { background: var(--stream-air); }
.pc-port[data-stream="gas"] { background: var(--stream-gas); }
.pc-port-in { border-radius: 3px; }
.pc-editable .pc-port-out { cursor: crosshair; }
.pc-editable .pc-port:hover { transform: scale(1.35); }
.pc-port.pc-port-ok { transform: scale(1.5); box-shadow: 0 0 0 3px rgba(16,185,129,.45); }
.pc-port.pc-port-dim { opacity: .25; }
.pc-empty-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 2rem; color: var(--color-neutral-400); font-size: .875rem; pointer-events: none; }

/* Plant builder page (plant_builder.php) */
.pb-shell { display: grid; grid-template-columns: 210px minmax(0, 1fr) 270px; gap: .75rem; height: calc(100vh - 12rem); min-height: 520px; }
.pb-panel { background: #fff; border: 1px solid var(--color-neutral-200); border-radius: var(--radius-card); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.pb-panel-body { overflow-y: auto; padding: .75rem; flex: 1; min-height: 0; }
.pb-canvas { border: 1px solid var(--color-neutral-200); border-radius: var(--radius-card); min-height: 0; }
.pb-category-title { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--color-neutral-500); margin: .75rem 0 .35rem; }
.pb-category-title:first-child { margin-top: 0; }
.pb-palette-item { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .4rem .5rem; border: 1px solid var(--color-neutral-200); border-radius: var(--radius-sm); background: #fff; font-size: .8rem; color: var(--color-neutral-700); cursor: grab; margin-bottom: .35rem; text-align: left; }
.pb-palette-item:hover { border-color: var(--color-primary); background: var(--color-primary-tint); }
.pb-palette-item i { color: var(--color-primary-600); font-size: 1rem; }
.pb-issue { display: flex; align-items: flex-start; gap: .4rem; font-size: .75rem; padding: .25rem .4rem; border-radius: 6px; cursor: pointer; }
.pb-issue:hover { background: var(--color-neutral-50); }
.pb-issue-error i { color: var(--color-critical); }
.pb-issue-warning i { color: var(--color-warning); }
.pb-legend { display: flex; flex-wrap: wrap; gap: .75rem; font-size: .7rem; color: var(--color-neutral-500); }
.pb-legend span::before { content: ''; display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: .3rem; vertical-align: middle; background: var(--sw); }
.pb-template { text-align: left; }
.pb-template:hover { border-color: var(--color-primary); }
