/* styles.css — CFEMS web dashboard design system.
   Light theme: white cards on cool-grey canvas, blue primary, soft shadows,
   rounded corners. Matches Visual/CMMS-WO.png. */

:root {
  color-scheme: light;
  --canvas: #f4f6f9;
  --card: #ffffff;
  --border: #e5e9f0;
  --text: #1f2733;
  --text-dim: #6b7686;
  --text-faint: #9aa4b2;
  --primary: #2f6bed;
  --primary-dark: #1f52c4;
  --red: #e5342b;
  --amber: #f2a53a;
  --green: #2fb35b;
  --blue: #2f6bed;
  --grey-dot: #9aa4b2;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.04), 0 4px 16px rgba(20, 30, 60, 0.06);
  --sidebar-w: 232px;
  --topbar-h: 52px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- App shell layout ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  min-height: 100vh;
}
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  overflow: hidden;
}
#sidebar {
  grid-area: sidebar;
  background: #ffffff;
  border-right: 1px solid var(--border);
  padding: 10px 0 24px;
  overflow-y: auto;
}
body.sidebar-collapsed #sidebar { display: none; }
body.sidebar-collapsed .app-shell { grid-template-columns: 0 1fr; }
main {
  grid-area: main;
  padding: 20px 24px 40px;
  min-width: 0;
}

/* ---------- Top bar ---------- */
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; flex: 0 0 auto; }
.icon-btn {
  border: none; background: transparent; color: var(--text-dim);
  font-size: 16px; padding: 4px 6px; border-radius: 8px; line-height: 1;
}
.icon-btn:hover { background: var(--canvas); }
/* Top-bar button icon rendered from a monochrome PNG via CSS mask (grey, blue on hover). */
.tb-icon {
  display: inline-block; width: 18px; height: 18px; vertical-align: middle;
  background-color: #8b93a7;
  -webkit-mask-image: var(--icon); mask-image: var(--icon);
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
  transition: background-color 0.15s ease;
}
.icon-btn:hover .tb-icon { background-color: var(--primary); }
.critical-badge {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--red); color: #fff; font-weight: 700; font-size: 11px;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.critical-dot { width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.ticker-wrap {
  flex: 1 1 auto; overflow: hidden; min-width: 0;
  mask-image: linear-gradient(to right, transparent, #000 24px, #000 calc(100% - 24px), transparent);
}
.ticker-track {
  display: inline-flex; gap: 0; white-space: nowrap;
  animation: ticker-scroll 22s linear infinite;
  color: var(--text-dim); font-size: 12px;
}
.ticker-item { padding: 0 6px; }
.ticker-sep { color: var(--red); padding: 0 4px; }
@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.conn-pill {
  font-size: 11px; padding: 3px 10px; border-radius: 999px;
  background: #eef1f6; color: var(--text-dim); white-space: nowrap;
}
.conn-pill.conn-open { background: #e6f7ec; color: var(--green); }
.conn-pill.conn-connecting { background: #fff4e2; color: var(--amber); }
.conn-pill.conn-closed { background: #fdeceb; color: var(--red); }
.avatar-block { display: flex; align-items: center; gap: 8px; padding-left: 6px; border-left: 1px solid var(--border); }
.avatar-circle {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
}
.avatar-text { font-size: 11px; color: var(--text-dim); line-height: 1.3; white-space: nowrap; }

/* ---------- Sidebar ---------- */
.sidebar-group { padding: 4px 0 10px; }
.sidebar-heading {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint); padding: 6px 18px; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; color: var(--text-dim); font-size: 12.5px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--canvas); color: var(--text); }
.nav-item.active {
  background: #eaf1ff; color: var(--primary); font-weight: 600;
  border-left-color: var(--primary);
}
/* Icon is a monochrome PNG used as a CSS mask, so its shape is painted with
   background-color — grey by default, blue (--primary) when the item is active. */
.nav-icon {
  width: 18px; height: 18px; flex: 0 0 auto; display: inline-block;
  background-color: #8b93a7;
  -webkit-mask-image: var(--icon); mask-image: var(--icon);
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center;
  -webkit-mask-size: contain; mask-size: contain;
  transition: background-color 0.15s ease;
}
.nav-item:hover .nav-icon { background-color: var(--text); }
.nav-item.active .nav-icon { background-color: var(--primary); }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.page-header h1 { font-size: 18px; margin: 0 0 4px; }
.page-subtitle { color: var(--text-dim); font-size: 12.5px; margin: 0; }
.page-header-actions { display: flex; align-items: center; gap: 10px; }
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: 9px; font-size: 12.5px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--canvas); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: #fdeceb; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px;
}
@media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; position: relative;
}
.kpi-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; display: flex; justify-content: space-between; align-items: center; }
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi-value.red { color: var(--red); }
.kpi-value.green { color: var(--green); }
.kpi-value.amber { color: var(--amber); }
.kpi-card.flash { animation: kpi-flash 900ms ease; }
@keyframes kpi-flash { 0% { box-shadow: 0 0 0 3px rgba(47,107,237,0.35); } 100% { box-shadow: var(--shadow); } }

/* ---------- Card ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }

/* ---------- Table ---------- */
.table-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table.wo-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.wo-table thead th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-faint); padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 700;
  white-space: nowrap;
}
table.wo-table tbody td { padding: 10px 14px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
table.wo-table tbody tr:last-child td { border-bottom: none; }
table.wo-table tbody tr.clickable { cursor: pointer; }
table.wo-table tbody tr.clickable:hover { background: #f8faff; }
table.wo-table tbody tr.flash { animation: row-flash 1400ms ease; }
@keyframes row-flash {
  0% { background: #fff4d6; }
  100% { background: transparent; }
}
.wo-id { font-weight: 600; color: var(--primary-dark); }
.title-cell { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-row td { text-align: center; color: var(--text-dim); padding: 32px; }

/* ---------- Priority badge ---------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; padding: 2px 8px; border-radius: 6px; font-weight: 700; font-size: 11px; color: #fff;
}
.badge-p1 { background: var(--red); }
.badge-p2 { background: #f0743a; }
.badge-p3 { background: var(--amber); }
.badge-p4 { background: #9aa4b2; }

/* ---------- Status pill ---------- */
.status-plain { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); }
.status-fill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 11px; color: #fff; }
.status-amber { background: var(--amber); }
.status-blue { background: var(--blue); }
.dot-grey, .dot-green, .dot-blue, .dot-amber, .dot-red {
  width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 auto;
}
.dot-grey { background: var(--grey-dot); }
.dot-green { background: var(--green); }
.dot-blue { background: var(--blue); }
.dot-amber { background: var(--amber); }
.dot-red { background: var(--red); }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f2733; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 12.5px; box-shadow: var(--shadow); animation: toast-in 200ms ease; max-width: 320px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Detail page ---------- */
.breadcrumb { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; display: inline-flex; align-items: center; gap: 6px; }
.breadcrumb:hover { color: var(--primary); }
.detail-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-header .wo-id-lg { font-size: 20px; font-weight: 700; }
.detail-header .title-lg { font-size: 15px; color: var(--text-dim); }
.detail-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card h2 { font-size: 13px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.kv-list { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; padding: 4px 0; border-bottom: 1px dashed #eef1f6; }
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--text-dim); }
.kv-row .v { font-weight: 600; text-align: right; }
#siteMap { width: 100%; height: 220px; border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 10px; background: #dfe7f2; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed #eef1f6; font-size: 12px; }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 4px; flex: 0 0 auto; }
.timeline-body .t-event { font-weight: 600; }
.timeline-body .t-detail { color: var(--text-dim); }
.timeline-body .t-at { color: var(--text-faint); font-size: 11px; }
.resolution-timer { font-size: 26px; font-weight: 700; color: var(--primary); }
.resolution-sub { font-size: 11px; color: var(--text-dim); }

/* ---------- Trigger config page ---------- */
.form-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.form-row label { font-size: 12px; color: var(--text-dim); min-width: 90px; }
select, input[type=number], input[type=text], textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; font-family: inherit; background: #fff; color: var(--text);
}
table.trigger-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.trigger-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; color: var(--text-faint); padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.trigger-table td { padding: 8px 10px; border-bottom: 1px solid #f1f3f7; }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #d5dbe4; border-radius: 999px; transition: 0.15s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(16px); }
.watch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-top: 6px; }
.watch-tile { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.watch-tile .p-id { font-size: 11px; color: var(--text-dim); }
.watch-tile .p-label { font-size: 12px; font-weight: 600; margin: 2px 0 4px; }
.watch-tile .p-asset { font-size: 10px; color: var(--text-dim); font-family: ui-monospace, monospace; margin-bottom: 6px; }
.watch-tile .p-value { font-size: 18px; font-weight: 700; color: var(--primary); }
.watch-tile.live-flash { animation: kpi-flash 700ms ease; }
.section-title { font-size: 15px; font-weight: 700; margin: 24px 0 10px; }
.section-title:first-child { margin-top: 0; }
.demo-controls { display: flex; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.empty-state { text-align: center; padding: 40px; color: var(--text-dim); }
.leaflet-legend { display: flex; gap: 14px; font-size: 11px; color: var(--text-dim); margin-top: 6px; flex-wrap: wrap; }
.leaflet-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
