:root {
  --brand-navy: #1A237E;
  --brand-navy-light: #283593;
  --brand-navy-dark: #0D1660;
  --brand-red: #D71920;
  --brand-yellow: #FFC107;
  --bg-light: #FAFAFA;
  --bg-white: #FFFFFF;
  --border-gray: #E0E0E0;
  --text-dark: #212121;
  --text-gray: #616161;
  --text-light: #9E9E9E;
  --success: #2E7D32;
  --warning: #F57C00;
  --error: #C62828;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0; background: var(--bg-light); color: var(--text-dark);
  font-size: 14px; line-height: 1.5;
}

.config-banner {
  background: var(--brand-yellow); color: #5b4500;
  padding: 10px 16px; text-align: center; font-weight: 500;
}
.config-banner code { background: rgba(0,0,0,.08); padding: 1px 6px; border-radius: 4px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 20px;
  background: var(--bg-light);
}
.login-card {
  width: 100%; max-width: 440px; background: var(--bg-white);
  border: 1px solid var(--border-gray);
  border-radius: 12px; padding: 48px 40px; box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.login-logo { max-width: 220px; width: 100%; height: auto; object-fit: contain; display: block; margin: 0 auto 8px; }
.login-title { color: var(--brand-navy); text-align: center; font-size: 24px; font-weight: 800; margin: 0; }
.login-sub { text-align: center; color: var(--text-gray); margin: 6px 0 28px; font-size: 13px; }
.field-label { display: block; font-weight: 600; color: var(--text-dark); margin: 14px 0 6px; font-size: 13px; }
input[type=email], input[type=password] {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--border-gray);
  border-radius: var(--radius); font-size: 15px; font-family: inherit;
}
input:focus { outline: none; border-color: var(--brand-navy-light); }
.btn-primary {
  width: 100%; margin-top: 22px; padding: 12px; border: none;
  background: var(--brand-navy); color: #fff; font-weight: 700; font-size: 15px;
  border-radius: var(--radius); cursor: pointer; font-family: inherit;
}
.btn-primary:hover { background: var(--brand-navy-light); }
.login-error { color: var(--error); font-size: 13px; margin: 12px 0 0; min-height: 18px; }
.login-footer { color: var(--text-light); margin-top: 22px; font-size: 12px; }

/* ---------- App shell ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(100deg, var(--brand-navy-dark), var(--brand-navy) 55%, var(--brand-navy-light));
  color: #fff; padding: 12px 22px; box-shadow: 0 2px 8px rgba(13,22,96,.25);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo-chip { display: inline-flex; align-items: center; justify-content: center; background: #fff; border-radius: 10px; padding: 5px 9px; box-shadow: 0 1px 4px rgba(0,0,0,.18); }
.header-logo { height: 30px; width: auto; object-fit: contain; display: block; }
.brand-tag { font-size: 13px; font-weight: 500; color: rgba(255,255,255,.82); letter-spacing: .2px; border-left: 1px solid rgba(255,255,255,.28); padding-left: 14px; }
.header-right { display: flex; align-items: center; gap: 14px; }
.user-email { font-size: 13px; color: rgba(255,255,255,.9); }
.btn-ghost {
  background: rgba(255,255,255,.08); border: 1.5px solid rgba(255,255,255,.45); color: #fff;
  padding: 6px 14px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 500;
}
.btn-ghost:hover { background: rgba(255,255,255,.18); }
@media (max-width: 560px) { .brand-tag { display: none; } }

.tabs {
  display: flex; gap: 4px; padding: 10px 14px; background: var(--bg-white);
  border-bottom: 1px solid var(--border-gray); overflow-x: auto;
}
.tab {
  border: none; background: transparent; color: var(--text-gray);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-family: inherit;
  font-size: 14px; font-weight: 500; white-space: nowrap;
}
.tab:hover { background: var(--bg-light); }
.tab.on { background: #E8EAF6; color: var(--brand-navy); font-weight: 700; }

.main-content { padding: 18px; max-width: 1000px; margin: 0 auto; }
.view-card { background: var(--bg-white); border: 1px solid var(--border-gray); border-radius: 14px; padding: 22px; }
.view-title { color: var(--text-dark); border-bottom: 3px solid var(--brand-navy); padding-bottom: 10px; margin: 0 0 12px; font-size: 22px; font-weight: 700; }
.view-note { color: var(--text-gray); margin: 0 0 8px; }
.view-soon { display: inline-block; background: #E8EAF6; color: var(--brand-navy); font-weight: 600; padding: 4px 12px; border-radius: 8px; font-size: 13px; }

/* ---------- data views ---------- */
.loading { color: var(--text-gray); padding: 30px; text-align: center; }
.err { color: var(--error); padding: 16px; }
.muted { color: var(--text-light); }
.search { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border-gray); border-radius: 8px; font-size: 14px; margin-bottom: 14px; font-family: inherit; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar select, #ts-cust { padding: 9px 11px; border: 1.5px solid var(--border-gray); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; }
.lbl { font-size: 13px; color: var(--text-gray); margin: 12px 0 6px; font-weight: 600; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border-gray); }
.row-title { font-weight: 600; font-size: 14px; }
.row-sub { font-size: 12px; color: var(--text-gray); margin-top: 2px; }
.counts { display: flex; gap: 6px; flex-shrink: 0; }
.badge { font-size: 12px; background: #E8EAF6; color: var(--brand-navy); padding: 3px 9px; border-radius: 8px; white-space: nowrap; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 7px; font-weight: 600; }
.pill.transformer { background: #E8EAF6; color: var(--brand-navy); }
.pill.switchgear { background: #FFF3E0; color: #E65100; }
.pill.cable { background: #E0F2F1; color: #00695C; }

.subtabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.subtab { border: 1.5px solid var(--border-gray); background: #fff; color: var(--text-gray); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 500; }
.subtab.on { background: var(--brand-navy); color: #fff; border-color: var(--brand-navy); }

.split { display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 18px; margin-top: 6px; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }
.list.compact .eq-item { padding: 10px 12px; border: 1.5px solid var(--border-gray); border-left-width: 4px; border-radius: 8px; margin-bottom: 8px; cursor: pointer; background: #fff; transition: background .12s, border-color .12s; }
.eq-item:hover { background: var(--bg-light); }
.eq-item.on { border-color: var(--brand-navy); border-left-width: 4px; background: #EEF0FA; box-shadow: 0 1px 6px rgba(26,35,126,.15); }
.eq-item.on .row-title { color: var(--brand-navy); }

.detail-head { margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 12px; color: var(--text-gray); background: var(--bg-light); padding: 3px 9px; border-radius: 8px; }
.cap { font-size: 12px; color: var(--text-gray); margin: 12px 0 5px; }
.chart-wrap { position: relative; height: 230px; margin-bottom: 8px; }

.trow { padding: 10px 0 14px; border-bottom: 1px solid var(--border-gray); }
.trow.flat { display: flex; justify-content: space-between; align-items: center; }
.trow-head { display: flex; justify-content: space-between; align-items: center; }
.phase-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ph { background: var(--bg-light); border-radius: 8px; padding: 7px 8px; text-align: center; }
.ph-l { font-size: 11px; color: var(--text-gray); }
.ph-v { font-size: 14px; font-weight: 700; }
.ph-u { font-size: 11px; color: var(--text-light); }
.status { font-size: 12px; padding: 3px 10px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.ok { color: var(--success); } .warn { color: var(--warning); } .bad { color: var(--error); }
.status.ok { background: #E8F5E9; } .status.warn { background: #FFF3E0; } .status.bad { background: #FFEBEE; }
.ph-v.muted { color: var(--text-light); }

/* ---------- trends ---------- */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 8px; }
@media (max-width: 640px) { .metrics { grid-template-columns: repeat(2, 1fr); } }
.metric { background: var(--bg-light); border-radius: 10px; padding: 14px; text-align: center; }
.metric .n { font-size: 24px; font-weight: 800; color: var(--brand-navy); }
.metric .n.alert { color: var(--error); }
.metric .l { font-size: 12px; color: var(--text-gray); margin-top: 2px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--text-dark); margin: 20px 0 10px; }

/* ---------- inspection report ---------- */
.report-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-gray); margin-bottom: 4px; flex-wrap: wrap; gap: 6px; }
.rep-sec { font-size: 13px; font-weight: 700; color: var(--brand-navy); background: #E8EAF6; padding: 6px 10px; border-radius: 6px; margin: 16px 0 8px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
@media (max-width: 560px) { .kv-grid { grid-template-columns: 1fr; } }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border-gray); font-size: 13px; }
.kv-l { color: var(--text-gray); }
.kv-v { font-weight: 600; text-align: right; }
.report ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.report ul li { margin-bottom: 4px; }

/* ---------- editing: buttons, modal, forms ---------- */
.view-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid var(--brand-navy); padding-bottom: 10px; margin-bottom: 14px; }
.view-head .view-title { border: none; padding: 0; margin: 0; }
.btn-add { background: var(--brand-navy); color: #fff; border: none; border-radius: 8px; padding: 8px 14px; font-weight: 600; font-size: 13px; cursor: pointer; font-family: inherit; }
.btn-add:hover { background: var(--brand-navy-light); }
.btn-edit { background: #fff; color: var(--brand-navy); border: 1.5px solid var(--brand-navy); border-radius: 8px; padding: 7px 14px; font-weight: 600; font-size: 13px; cursor: pointer; font-family: inherit; }
.btn-edit:hover { background: #E8EAF6; }
.btn-edit.sm { padding: 4px 10px; font-size: 12px; }
.list-row.clickable { cursor: pointer; }
.list-row.clickable:hover { background: var(--bg-light); }
.actions { margin: 10px 0; }

.modal-overlay { position: fixed; inset: 0; background: rgba(13,22,96,.45); display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto; z-index: 1000; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; box-shadow: 0 16px 48px rgba(0,0,0,.3); margin: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-gray); font-weight: 700; font-size: 16px; color: var(--brand-navy); }
.modal-x { background: none; border: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--text-gray); }
.modal-body { padding: 16px 20px; max-height: 65vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border-gray); }
.modal-foot .btn-primary { width: auto; margin: 0; padding: 10px 20px; }
.modal-foot .btn-ghost { color: var(--text-gray); border-color: var(--border-gray); }
.modal-foot .btn-ghost:hover { background: var(--bg-light); }
.modal-err { color: var(--error); font-size: 13px; padding: 0 20px; min-height: 16px; }

.f-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-bottom: 8px; }
@media (max-width: 560px) { .f-grid { grid-template-columns: 1fr; } }
.f { display: flex; flex-direction: column; }
.f-l { font-size: 12px; color: var(--text-gray); font-weight: 600; margin-bottom: 4px; }
.f input, .f select, .modal-body textarea { padding: 9px 11px; border: 1.5px solid var(--border-gray); border-radius: 8px; font-size: 14px; font-family: inherit; width: 100%; }
.f input:focus, .f select:focus, .modal-body textarea:focus { outline: none; border-color: var(--brand-navy-light); }
.modal-body textarea { resize: vertical; }
.f-sec { font-size: 13px; font-weight: 700; color: var(--brand-navy); background: #E8EAF6; padding: 6px 10px; border-radius: 6px; margin: 14px 0 8px; }

/* six-reading cable grid */
.phase-grid.six { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 620px) { .phase-grid.six { grid-template-columns: repeat(3, 1fr); } }

/* users management */
.role-sel { padding: 6px 9px; border: 1.5px solid var(--border-gray); border-radius: 8px; font-family: inherit; font-size: 13px; margin-right: 4px; }
.counts .btn-add, .counts .btn-edit { margin-left: 4px; }

.approve-row { font-size: 12px; color: var(--text-gray); margin-top: 6px; }
.approve-row .cust-sel { padding: 5px 8px; border: 1.5px solid var(--border-gray); border-radius: 7px; font-family: inherit; font-size: 13px; margin-left: 4px; }
.counts { flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.f input.ro { background: var(--bg-light); color: var(--text-gray); cursor: not-allowed; }

/* login: sign in / sign up toggle + extras */
.auth-toggle { display: flex; gap: 6px; background: var(--bg-light); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.auth-tab { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 8px; font-family: inherit; font-size: 14px; font-weight: 600; color: var(--text-gray); cursor: pointer; }
.auth-tab.on { background: #fff; color: var(--brand-navy); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.login-msg { color: var(--success); font-size: 13px; margin: 10px 0 0; min-height: 16px; }
.link-btn { display: block; margin: 10px auto 0; background: none; border: none; color: var(--brand-navy); font-family: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: var(--brand-navy-light); }
.hide { display: none; }

/* modal delete button */
.btn-danger { background: var(--error); color: #fff; border: none; border-radius: 8px; padding: 10px 18px; font-weight: 700; font-size: 14px; cursor: pointer; font-family: inherit; }
.btn-danger:hover { background: #a51f1f; }
.foot-spacer { flex: 1; }
.modal-foot { align-items: center; }

/* review workflow */
.rev-badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 7px; }
.rev-badge.ok { background: #E8F5E9; color: var(--success); }
.rev-badge.warn { background: #FFF3E0; color: var(--warning); }
.rev-badge.bad { background: #FFEBEE; color: var(--error); }
.review-line { margin: 6px 0 4px; }
.btn-danger.sm { padding: 7px 12px; font-size: 13px; }
.btn-ghost-sm { background: #fff; color: var(--text-gray); border: 1.5px solid var(--border-gray); border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer; font-family: inherit; }
.btn-ghost-sm:hover { background: var(--bg-light); }
.view-note { color: var(--text-gray); font-size: 13px; margin: 0 0 16px; }

/* review tab count badge */
.tab-count { display: inline-block; background: var(--brand-red); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; padding: 1px 6px; border-radius: 9px; margin-left: 4px; vertical-align: middle; }

/* my-account header button */
.user-email-btn { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.25); cursor: pointer; font-family: inherit; padding: 5px 12px; border-radius: 8px; }
.user-email-btn:hover { background: rgba(255,255,255,.2); text-decoration: none; }
