/* ============ base ============ */
* { box-sizing: border-box; }
body { margin: 0; background: #F5F6F8; color: #1e293b; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
.mono { font-family: "Consolas", "Courier New", monospace; }
.muted { color: #94a3b8; }
a { color: #1560BD; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ app shell: sidebar + content ============ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex-shrink: 0; background: #fff; border-right: 1px solid #e2e8f0;
  padding: 18px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 18px 18px; border-bottom: 1px solid #f1f5f9; margin-bottom: 10px; }
.sidebar-brand .logo { width: 34px; height: 34px; border-radius: 8px; background: #1560BD; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 16px; flex-shrink: 0; }
.sidebar-brand .brand-name { font-weight: 800; font-size: 15px; line-height: 1.1; }
.sidebar-brand .brand-sub { font-size: 9px; color: #94a3b8; letter-spacing: .04em; }

.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; color: #475569; font-size: 13.5px; font-weight: 600; }
.nav-item i { width: 18px; text-align: center; color: #94a3b8; font-size: 14px; }
.nav-item:hover { background: #f1f5f9; text-decoration: none; }
.nav-item.active { background: #EFF6FF; color: #1560BD; }
.nav-item.active i { color: #1560BD; }

.app-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ============ top bar ============ */
.topbar {
  background: #fff; border-bottom: 1px solid #e2e8f0; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 30; flex-wrap: wrap;
}
.page-heading { font-size: 17px; font-weight: 800; letter-spacing: .01em; margin: 0; color: #1e293b; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #64748b; flex-wrap: wrap; }
.live-pill { display: flex; align-items: center; background: #ECFDF3; color: #166534; padding: 5px 12px; border-radius: 999px; font-weight: 600; font-size: 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #16a34a; display: inline-block; margin-right: 6px; animation: blink 2s infinite; }
@keyframes blink { 50% { opacity: .4; } }
.bell-btn { color: #64748b; font-size: 16px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #e2e8f0; display: flex; align-items: center; justify-content: center; color: #64748b; font-size: 12px; }
.logout-btn { background: #f1f5f9; padding: 6px 12px; border-radius: 6px; font-weight: 600; color: #475569; }

.page-wrap { max-width: 1600px; width: 100%; margin: 0 auto; padding: 18px 24px; display: flex; flex-direction: column; gap: 16px; }
.page-header { display: flex; justify-content: space-between; align-items: center; }
.site-footer { text-align: center; padding: 18px; color: #94a3b8; font-size: 12px; border-top: 1px solid #e2e8f0; background: #fff; }
.footer-logo { font-weight: 800; color: #1560BD; margin-right: 10px; }

/* ============ generic card ============ */
.card { background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 14px; min-width: 0; }
.card h2 { font-size: 12.5px; font-weight: 700; color: #475569; letter-spacing: .03em; margin: 0 0 10px; }

/* ============ KPI row — fixed, no more invalid "span 2.4" ============ */
.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi { cursor: pointer; transition: box-shadow .15s; display: flex; flex-direction: column; justify-content: space-between; }
.kpi:hover { box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.kpi.active { border-color: #94a3b8; box-shadow: 0 0 0 2px #e2e8f0; }
.kpi-top { display: flex; justify-content: space-between; align-items: flex-start; }
.kpi .label { font-size: 11px; text-transform: uppercase; color: #94a3b8; font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 6px; }
.kpi .sub { font-size: 11px; color: #94a3b8; }
.kpi-icon { font-size: 20px; }

/* ============ row layouts ============ */
.row-3col { display: grid; grid-template-columns: 1.5fr 1.3fr 1fr; gap: 14px; align-items: stretch; }
.row-2col { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; align-items: stretch; }
.row-4col { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: stretch; }
@media (max-width: 1300px) { .row-3col, .row-2col, .row-4col { grid-template-columns: 1fr; } }

/* Map and live readouts share the first dashboard row. */
.map-live-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(420px, 1.1fr); gap: 14px; align-items: stretch; height: 700px; }
.map-live-layout .map-card, .live-gauges-card { height: 700px; }
.live-gauges-card { overflow-y: auto; }
.map-live-layout .gauge-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; justify-content: initial; }
.map-live-layout .gauge { min-width: 0; padding-bottom: 4px; }
.map-live-layout .gauge svg { width: 68px; height: 68px; }
.details-layout .detail-card, .details-layout .fault-card, .fleet-health-card { min-height: 230px; }
@media (max-width: 1300px) { .map-live-layout { grid-template-columns: 1fr; height: auto; } .map-live-layout .map-card, .live-gauges-card { height: auto; } .map-live-layout #mapArea { height: 520px; flex: none; } .live-gauges-card { max-height: none; } .map-live-layout .gauge-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .map-live-layout .gauge-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ============ map (Leaflet) ============ */
.map-card { display: flex; flex-direction: column; }
.map-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.map-toolbar h2 { margin: 0; }
.map-toolbar .filters button { font-size: 11px; border: 1px solid #e2e8f0; background: #fff; color: #64748b; border-radius: 999px; padding: 4px 10px; margin-left: 5px; cursor: pointer; }
.map-toolbar .filters button.active { background: #1e293b; color: #fff; border-color: #1e293b; }
#mapArea { min-height: 0; border-radius: 10px; overflow: hidden; flex: 1; }

.tx-marker-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.tx-marker-dot.critical { animation: pulseRing 1.6s infinite; }
@keyframes pulseRing { 0% { box-shadow: 0 0 0 0 rgba(220,38,38,.55); } 70% { box-shadow: 0 0 0 12px rgba(220,38,38,0); } 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); } }
.leaflet-popup-content { font-size: 12.5px; }

/* ============ embedded detail panel (row 2, middle column) ============ */
.detail-card { display: flex; flex-direction: column; }
.detail-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #cbd5e1; gap: 10px; padding: 30px 16px; }
.detail-empty i { font-size: 34px; }
.detail-empty p { font-size: 12.5px; color: #94a3b8; max-width: 220px; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.detail-head .tx-title { font-weight: 800; font-size: 15px; }
.detail-head .tx-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.detail-health-badge { width: 70px; height: 70px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.detail-health-badge .pct { font-size: 20px; font-weight: 800; line-height: 1; }
.detail-health-badge .lbl { font-size: 8px; letter-spacing: .05em; margin-top: 3px; }
.detail-spec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 12px; margin-bottom: 12px; }
.detail-spec-grid .k { color: #94a3b8; }
.detail-spec-grid .v { font-weight: 600; }
.detail-fault-box { border-radius: 8px; padding: 10px; margin-bottom: 12px; }
.detail-fault-box .fault-label { font-size: 10px; font-weight: 700; text-transform: uppercase; }
.detail-fault-box .fault-name { font-weight: 700; font-size: 13px; margin-top: 2px; }
.detail-btn { width: 100%; background: #0f172a; color: #fff; border: none; padding: 10px; border-radius: 8px; font-weight: 600; font-size: 12.5px; cursor: pointer; margin-top: auto; }
.detail-btn:hover { background: #1e293b; }

/* ============ fault list ============ */
.fault-card { display: flex; flex-direction: column; max-height: 540px; }
#faultList { overflow-y: auto; flex: 1; margin: 0 -14px; }
.fault-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid #f1f5f9; border-left: 3px solid transparent; cursor: pointer; }
.fault-row:hover { background: #f8fafc; }
.fault-row .id { font-weight: 700; font-size: 13px; }
.fault-row .fault-name { font-size: 11px; font-weight: 600; margin-left: 6px; }
.fault-row .area { font-size: 11px; color: #94a3b8; }

/* ============ live parameter gauges ============ */
.gauge-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: space-between; }
.gauge { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-width: 90px; }
.gauge .glabel { font-size: 10px; color: #94a3b8; text-transform: uppercase; text-align: center; }
.gauge .gcaption { font-size: 9px; font-weight: 700; margin-top: 1px; }
.gauge small { color: #94a3b8; font-size: 9px; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
.gauge.electrical-gauge { background: #f8fbff; border: 1px solid #dbeafe; border-radius: 8px; padding: 8px 4px; }

/* ============ latest electrical and complete reading ============ */
.latest-reading-card { padding: 16px; }
.reading-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.reading-card-head h2 { margin-bottom: 4px; }
.reading-card-head p { margin: 0; font-size: 11px; }
.electrical-grid, .reading-groups { display: grid; grid-template-columns: repeat(5, minmax(145px, 1fr)); gap: 12px; }
.reading-groups { grid-template-columns: repeat(3, minmax(190px, 1fr)); }
.measurement-group { border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; min-width: 0; }
.measurement-group h3 { margin: 0; padding: 8px 10px; background: #f8fafc; color: #475569; font-size: 10px; letter-spacing: .04em; text-transform: uppercase; }
.measurement-list { padding: 4px 10px; }
.measurement { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f1f5f9; font-size: 11px; }
.measurement:last-child { border-bottom: 0; }
.measurement span { color: #64748b; }
.measurement b { color: #0f172a; white-space: nowrap; font-size: 12px; }
.measurement small { color: #94a3b8; font-size: 9px; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
.all-reading-heading { margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid #e2e8f0; color: #475569; font-size: 11px; font-weight: 700; letter-spacing: .05em; }
.raw-payload { margin-top: 12px; font-size: 12px; color: #475569; }
.raw-payload summary { cursor: pointer; font-weight: 600; }
.raw-payload pre { max-height: 260px; overflow: auto; margin: 8px 0 0; padding: 12px; border-radius: 8px; background: #0f172a; color: #cbd5e1; font-size: 11px; }
@media (max-width: 1300px) { .electrical-grid { grid-template-columns: repeat(3, minmax(145px, 1fr)); } }
@media (max-width: 800px) { .electrical-grid, .reading-groups { grid-template-columns: 1fr; } }

/* ============ fleet health ============ */
.fleet-health-body { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.fleet-status-list { display: flex; gap: 20px; flex-wrap: wrap; font-size: 12px; }

/* ============ hero voice announcer ============ */
.hero { border-radius: 16px; padding: 20px; color: #fff; position: relative; overflow: hidden; background: linear-gradient(120deg,#151233 0%,#241b52 55%,#3a1f66 100%); }
.hero-inner { position: relative; display: flex; flex-wrap: wrap; gap: 20px; }
.hero-left { display: flex; gap: 14px; width: 280px; flex-shrink: 0; }
.hero-icon { width: 54px; height: 54px; border-radius: 16px; background: rgba(255,255,255,.1); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; transition: background .2s; }
.hero-icon.speaking { background: #8b5cf6; }
.hero-eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #c4b5fd; font-weight: 700; }
.hero h2 { margin: 2px 0 4px; font-size: 18px; }
.hero p { margin: 0; font-size: 12px; color: rgba(224,214,255,.75); line-height: 1.4; }
.hero-right { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 10px; }
.hero-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.hero-btn { display: flex; align-items: center; gap: 6px; border: none; cursor: pointer; font-size: 12px; font-weight: 600; padding: 8px 12px; border-radius: 8px; color: #fff; background: rgba(255,255,255,.1); }
.hero-btn.on { background: #8b5cf6; }
.hero-status { margin-left: auto; display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.2); padding: 6px 10px; border-radius: 8px; font-size: 11px; }
.waveform { display: flex; align-items: flex-end; gap: 3px; height: 18px; }
.waveform span { width: 3px; border-radius: 2px; background: #a78bfa; height: 4px; }
.waveform.active span { animation: wf .9s ease-in-out infinite; }
.waveform.active span:nth-child(2) { animation-delay: .1s; }
.waveform.active span:nth-child(3) { animation-delay: .2s; }
.waveform.active span:nth-child(4) { animation-delay: .3s; }
.waveform.active span:nth-child(5) { animation-delay: .4s; }
@keyframes wf { 0%,100% { height: 4px; } 50% { height: 16px; } }
.caption-box { background: rgba(0,0,0,.25); border-radius: 8px; padding: 9px 12px; font-size: 13px; font-style: italic; min-height: 20px; }
#voiceLog { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 100px; overflow-y: auto; }
.log-entry { background: rgba(255,255,255,.06); border-radius: 6px; padding: 6px 8px; font-size: 11px; color: #ede9fe; }

/* ============ recent alarms table ============ */
table.alarm-table, table.data-table { width: 100%; border-collapse: collapse; font-size: 12px; background: #fff; }
table.alarm-table td, table.data-table td { padding: 7px 4px; border-bottom: 1px solid #f8fafc; }
table.data-table th { text-align: left; color: #94a3b8; font-weight: 600; padding: 8px 6px; border-bottom: 1px solid #f1f5f9; font-size: 12px; }
tr.alarm-row, tr.clickable { cursor: pointer; }
tr.alarm-row:hover, tr.clickable:hover { background: #f8fafc; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 600; white-space: nowrap; }
.badge.healthy { background: #ECFDF3; color: #16A34A; }
.badge.warning { background: #FFFBEB; color: #D97706; }
.badge.critical { background: #FEF2F2; color: #DC2626; }
.badge.offline { background: #F3F4F6; color: #6B7280; }

/* ============ vibration trend sparkline ============ */
#vibTrendChart svg { width: 100%; height: 150px; }

/* ============ event timeline ============ */
.event-timeline { display: flex; flex-direction: column; gap: 10px; max-height: 220px; overflow-y: auto; }
.event-item { display: flex; gap: 8px; font-size: 12px; }
.event-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.event-item .event-msg { font-weight: 600; }
.event-item .event-time { color: #94a3b8; font-size: 10.5px; }

/* ============ alarm summary donut ============ */
.alarm-donut-wrap { display: flex; align-items: center; gap: 18px; justify-content: center; }
.alarm-donut-legend { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.alarm-donut-legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ============ forms (transformers add/edit, users, reports) ============ */
.form-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 20px; max-width: 760px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid label { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 4px; }
.form-grid input, .form-grid select { width: 100%; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; }
.form-grid input:disabled { background: #f8fafc; color: #94a3b8; }
.btn-primary { background: #1560BD; color: #fff; border: none; padding: 10px 18px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-primary:hover { background: #124d99; }
.btn-danger { background: #fff; color: #DC2626; border: 1px solid #fca5a5; padding: 9px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-danger:hover { background: #FEF2F2; }
.key-box { display: block; background: #0f172a; color: #a7f3d0; padding: 10px 14px; border-radius: 8px; margin-top: 6px; font-size: 13px; word-break: break-all; }

.alert-box { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; background: #EFF6FF; color: #1e3a8a; }
.alert-box.error { background: #FEF2F2; color: #991B1B; }
.alert-box.success { background: #ECFDF3; color: #166534; }

/* ============ login page ============ */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg,#0f172a,#1e293b); margin: 0; }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 320px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-card .logo { width: 44px; height: 44px; border-radius: 10px; background: #1560BD; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 20px; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card label { display: block; text-align: left; font-size: 12px; font-weight: 600; margin: 14px 0 4px; color: #475569; }
.login-card input { width: 100%; padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; }
.login-card button { width: 100%; margin-top: 18px; background: #1560BD; color: #fff; border: none; padding: 10px; border-radius: 8px; font-weight: 700; cursor: pointer; }

/* ============ reports ============ */
.report-filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.report-filters .field label { display: block; font-size: 11px; font-weight: 600; color: #64748b; margin-bottom: 4px; }
.report-filters select, .report-filters input { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; }
.export-links a { display: inline-block; margin-right: 10px; background: #1e293b; color: #fff; padding: 8px 14px; border-radius: 6px; font-size: 12px; font-weight: 600; }

/* ============ generic placeholder page ============ */
.placeholder-card { background: #fff; border: 1px dashed #cbd5e1; border-radius: 12px; padding: 50px 20px; text-align: center; color: #94a3b8; }
.placeholder-card i { font-size: 32px; margin-bottom: 12px; display: block; }
