:root {
  --navy: #062A4E;
  --blue: #0E5FA4;
  --blue-light: #E7F1FA;
  --saffron: #FF7A00;
  --green: #1E8E5A;
  --red: #D23B3B;
  --amber: #E0A300;
  --grey: #6B7785;
  --surface: #F5F7FA;
  --line: #E1E8EF;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--surface);
  color: #11212F;
}
.topbar {
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 42px; height: 42px; border-radius: 11px; background: var(--saffron);
  display: grid; place-items: center; font-size: 22px;
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar p { margin: 2px 0 0; font-size: 12px; opacity: .75; }
.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.pill { color: #7CFFB2; font-size: 12px; font-weight: 600; }
.powered { font-size: 11px; opacity: .65; }

.sync-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 50px;
  background: rgba(255,255,255,.12);
  font-size: 12px; font-weight: 600; color: #7CC2FF;
}
.sync-icon { flex-shrink: 0; display: block; }
.sync-chip.syncing .sync-icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 4px; padding: 0 24px; background: #fff; border-bottom: 1px solid var(--line); }
.tab {
  border: none; background: none; padding: 14px 18px; cursor: pointer;
  font-size: 14px; color: var(--grey); border-bottom: 3px solid transparent;
}
.tab.active { color: var(--navy); border-bottom-color: var(--saffron); font-weight: 600; }

main { padding: 24px; max-width: 1180px; margin: 0 auto; }
.view.hidden { display: none; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: #fff; border-radius: 14px; padding: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.stat-val { font-size: 32px; font-weight: 700; color: var(--navy); }
.stat-val.green { color: var(--green); }
.stat-val.blue { color: var(--blue); }
.stat-val.amber { color: var(--saffron); }
.stat-val.red { color: var(--red); }
.stat-lbl { color: var(--grey); font-size: 13px; margin-top: 4px; }
.stat-sub { color: var(--grey); font-size: 11px; margin-top: 2px; opacity: .85; }

/* Chart layout */
.chart-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h3 { margin: 0; }
.muted.center { text-align: center; }
.donut-wrap { position: relative; height: 190px; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center span { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1; }
.donut-center small { font-size: 11px; color: var(--grey); margin-top: 2px; }
.gauge-wrap { position: relative; height: 190px; }
.gauge-center { position: absolute; left: 0; right: 0; bottom: 42px; text-align: center; font-size: 30px; font-weight: 700; color: var(--green); }
.bar-wrap { position: relative; height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: 7px 14px; margin-top: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #11212F; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-item strong { font-weight: 700; }

/* Heatmap */
.heat-legend { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--grey); white-space: nowrap; }
.heat-scale { width: 84px; height: 10px; border-radius: 5px;
  background: linear-gradient(90deg, rgba(14,95,164,.12), rgba(14,95,164,.92)); }
.heatmap { display: grid; gap: 5px; margin-top: 12px; }
.heat-corner { }
.heat-col-h { font-size: 11px; font-weight: 600; color: var(--grey); text-align: center; align-self: end; padding-bottom: 4px; line-height: 1.2; }
.heat-row-h { font-size: 12.5px; color: #11212F; display: flex; align-items: center; padding-right: 10px; }
.heat-cell { min-height: 38px; border-radius: 7px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; background: #F0F3F7; transition: transform .12s ease; }
.heat-cell:hover { transform: scale(1.06); cursor: default; }
.heat-cell.clickable { cursor: pointer; }

.btn-clear { padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--red); font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-clear:hover { background: #FDEBEB; }

@media (max-width: 900px) {
  .chart-row { grid-template-columns: 1fr; }
}

.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: #fff; border-radius: 14px; padding: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 14px; font-size: 15px; color: var(--navy); }
.muted { color: var(--grey); font-size: 13px; margin-top: -6px; }

.bar-row { margin: 9px 0; }
.bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.bar-top .val { font-weight: 600; }
.bar-track { height: 8px; background: #E3E9EF; border-radius: 50px; overflow: hidden; }
.bar-fill { height: 8px; border-radius: 50px; }

.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; background: #fff;
}
.toolbar input { flex: 1; min-width: 220px; }

.table-wrap { background: #fff; border-radius: 14px; overflow: auto; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--grey); font-weight: 600; background: #FAFBFC; position: sticky; top: 0; }
tbody tr:hover { background: var(--blue-light); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--blue); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 50px; font-size: 12px; font-weight: 600; }
.chip .dot { width: 7px; height: 7px; border-radius: 50px; }
.tag-yes { color: var(--green); font-weight: 600; }
.tag-no { color: var(--saffron); font-weight: 600; }

.foot { text-align: center; color: var(--grey); font-size: 12px; padding: 24px; }

/* Login gate */
.login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-overlay.hidden { display: none; }
.login-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 18px; padding: 32px 28px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px; border-radius: 16px; background: var(--saffron);
  display: grid; place-items: center; font-size: 32px; color: #fff;
  margin: 0 auto 18px;
}
.login-card h1 { margin: 0; font-size: 22px; color: var(--navy); }
.login-sub { margin: 6px 0 24px; font-size: 13px; color: var(--grey); }
.login-field { display: block; text-align: left; margin-bottom: 16px; }
.login-field span { display: block; font-size: 12px; color: var(--grey); margin-bottom: 6px; font-weight: 600; }
.login-field input {
  width: 100%; padding: 12px 14px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.login-field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light); }
.login-error { color: var(--red); font-size: 13px; margin: -4px 0 14px; font-weight: 600; }
.login-error.hidden { display: none; }
.login-btn {
  width: 100%; padding: 14px; border: none; border-radius: 50px; cursor: pointer;
  background: var(--navy); color: #fff; font-size: 16px; font-weight: 700;
}
.login-btn:hover { background: #0a3a68; }
.login-foot { margin: 20px 0 0; font-size: 11px; color: var(--grey); }

.logout-btn {
  margin-top: 2px; padding: 4px 12px; cursor: pointer;
  background: rgba(255,255,255,.12); color: #fff;
  border: 1px solid rgba(255,255,255,.25); border-radius: 50px;
  font-size: 11px; font-weight: 600;
}
.logout-btn:hover { background: rgba(255,255,255,.22); }

@media (max-width: 820px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: 1fr; }
}

/* Responsive tables: each row becomes a label/value card on phones */
@media (max-width: 700px) {
  .toolbar input, .toolbar select, .btn-clear { width: 100%; flex: 1 1 100%; min-width: 0; }
  .table-wrap { overflow: visible; background: transparent; box-shadow: none; }
  #assetTable thead, #rfidTable thead { display: none; }
  #assetTable tr, #rfidTable tr { display: block; background: #fff; border-radius: 12px;
    margin-bottom: 10px; padding: 6px 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
  #assetTable td, #rfidTable td { display: flex; justify-content: space-between; align-items: center;
    gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); white-space: normal; text-align: right; }
  #assetTable tr td:last-child, #rfidTable tr td:last-child { border-bottom: none; }
  #assetTable td::before, #rfidTable td::before { content: attr(data-label);
    color: var(--grey); font-weight: 600; font-size: 12px; text-align: left; flex-shrink: 0; }
  tbody tr:hover { background: #fff; }
}
