/* SHMS shared stylesheet — fully offline: system fonts only, no external assets. */

:root {
  --up: #16a34a;
  --down: #dc2626;
  --unknown: #9ca3af;
  --blue: #2563eb;
  --blue-dark: #1e40af;
  --amber: #d97706;
  --purple: #7c3aed;
  --bg: #f3f4f6;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #111827;
  --muted: #6b7280;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

h1 { font-size: 1.35rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.6rem; }
h3 { font-size: 1rem; margin: 0; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.mono { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: 0.92em; }

/* ---------- Top navigation ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #1f2937;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
/* admin panel gets a distinct (indigo) bar so the operator never confuses it
   with a client dashboard */
.topnav-admin { background: #3730a3; }

.tab-panel { padding-top: 6px; }
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 14px;
  min-height: 52px;
}
.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: #fff;
  padding: 8px 0;
}
.brand:hover { text-decoration: none; }
.nav-links { display: flex; flex-wrap: wrap; gap: 2px; }
.nav-links a {
  color: #d1d5db;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
}
.nav-links a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); text-decoration: none; }
.nav-links a.active { color: #fff; background: rgba(255, 255, 255, 0.16); font-weight: 600; }

/* current-user chip + logout (injected by app.js) */
.nav-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.nav-who { color: #d1d5db; font-size: 0.88rem; }
.nav-tenant { color: #9ca3af; }
.nav-logout {
  font: inherit; font-size: 0.85rem; cursor: pointer;
  background: rgba(255, 255, 255, 0.10); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 8px; padding: 5px 12px;
}
.nav-logout:hover { background: rgba(255, 255, 255, 0.18); }

/* ---------- Login page ---------- */
.login-body { background: #0f172a; }
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--card); border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  padding: 30px 28px; width: 380px; max-width: 100%;
}
.login-brand { font-weight: 700; letter-spacing: 0.14em; font-size: 1.5rem; color: var(--navy, #152840); }
.login-sub { color: var(--muted); margin: 2px 0 20px; font-size: 0.9rem; }
.login-card form label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.login-card input { width: 100%; }
.login-foot { margin: 16px 0 0; text-align: center; }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 18px 16px 60px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat { padding: 14px 16px; margin-bottom: 0; }
.stat-label { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.stat-value.small-stat { font-size: 1.05rem; font-weight: 600; padding-top: 8px; }
.stat-sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.stat-value.up { color: var(--up); }
.stat-value.down { color: var(--down); }

/* ---------- Banners & toasts ---------- */
.banner {
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.95rem;
  border: 1px solid;
}
.banner-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.banner-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.banner-ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

.toast-wrap {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: #374151;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  font-size: 0.92rem;
  animation: toast-in 0.15s ease-out;
}
.toast-error { background: #b91c1c; }
.toast-success { background: #15803d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* ---------- Status dots, tiles, badges ---------- */
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--unknown);
}
.dot-up { background: var(--up); }
.dot-down { background: var(--down); }
.dot-unknown { background: var(--unknown); }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 6px;
}
.tile {
  display: block;
  padding: 8px 6px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.tile:hover { text-decoration: none; filter: brightness(1.12); }
.tile-up { background: var(--up); }
.tile-down { background: var(--down); }
.tile-unknown { background: var(--unknown); }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-work_in_progress { background: #fef3c7; color: #92400e; }
.badge-in_review { background: #dbeafe; color: #1e40af; }
.badge-under_observation { background: #ede9fe; color: #5b21b6; }
.badge-completed { background: #dcfce7; color: #166534; }
.badge-open { background: #fee2e2; color: #991b1b; }
.badge-closed { background: #e5e7eb; color: #374151; }

/* complaint-status select styled like a badge */
.cs-select {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
}
.cs-work_in_progress { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.cs-in_review { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.cs-under_observation { background: #ede9fe; color: #5b21b6; border-color: #c4b5fd; }
.cs-completed { background: #dcfce7; color: #166534; border-color: #86efac; }

.pct-ok { color: var(--up); font-weight: 700; }
.pct-warn { color: var(--amber); font-weight: 700; }
.pct-bad { color: var(--down); font-weight: 700; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  background: #f9fafb;
  position: sticky;
  top: 0;
}
tbody tr:hover { background: #f5f7fb; }
td.wrap { white-space: normal; }

/* Row-based status colouring (client request): the whole row is tinted. */
tbody tr.row-up { background: #f1faf4; }
tbody tr.row-down { background: #fdeeee; }
tbody tr.row-up:hover { background: #e6f6ec; }
tbody tr.row-down:hover { background: #fbe0e0; }
tbody tr.row-up td:first-child { box-shadow: inset 3px 0 0 var(--up); }
tbody tr.row-down td:first-child { box-shadow: inset 3px 0 0 var(--down); }
tbody tr.row-unknown td:first-child { box-shadow: inset 3px 0 0 var(--unknown); }

.empty {
  padding: 22px 12px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Forms & buttons ---------- */
input[type="text"], input[type="number"], input[type="password"], input[type="email"],
select, textarea {
  font: inherit;
  color: inherit;
  padding: 7px 10px;
  border: 1px solid #cbd2dc;
  border-radius: 8px;
  background: #fff;
  max-width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--blue);
}
textarea { resize: vertical; }
label { font-size: 0.88rem; color: #374151; }

.btn {
  font: inherit;
  font-size: 0.92rem;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid #cbd2dc;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: #f3f4f6; }
a.btn { display: inline-block; color: var(--text); }
a.btn:hover, a.btn:focus { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-danger { background: #fff; border-color: #fca5a5; color: var(--down); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 3px 10px; font-size: 0.82rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar .grow { flex: 1 1 220px; }
.toolbar input[type="text"] { width: 100%; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.form-grid label { display: flex; flex-direction: column; gap: 4px; }
.form-grid .span2 { grid-column: 1 / -1; }
.check-label { flex-direction: row !important; align-items: center; gap: 8px !important; padding-top: 18px; }

/* "Other details" custom-field editor (device modal) */
.other-fields {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  margin-top: 14px;
  padding-top: 12px;
}
.other-head { display: flex; align-items: center; justify-content: space-between; }
.other-head h4 { margin: 0; font-size: 0.95rem; }
.extra-row { display: flex; gap: 6px; margin-bottom: 6px; }
.extra-row .extra-k { flex: 0 0 40%; min-width: 0; }
.extra-row .extra-v { flex: 1; min-width: 0; }
.extra-row .extra-del { flex: 0 0 auto; color: var(--down); border-color: #fca5a5; }

/* ---------- Connectivity graph ---------- */
.graph-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfcfe;
  padding: 4px;
}
.graph-legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 2px 0; font-size: 0.82rem; color: var(--muted); }
.graph-legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg-swatch { width: 12px; height: 12px; border-radius: 3px; border: 1px solid; display: inline-block; }
.lg-up { background: #bbf7d0; border-color: #16a34a; }
.lg-down { background: #fecaca; border-color: #dc2626; }
.lg-unknown { background: #e5e7eb; border-color: #9ca3af; }
.lg-external { background: #e0e7ff; border-color: #6366f1; }

.g-edge { stroke: #9aa4b2; stroke-width: 1.5; }
.g-edge-label { fill: var(--muted); font-size: 10px; }
.g-node text { font-size: 11px; fill: #111827; }
.g-node .g-sub { fill: var(--muted); font-size: 9.5px; }
.g-node .g-shape { stroke-width: 1.2; cursor: pointer; }
.g-node:hover .g-shape { filter: brightness(0.97); }
.g-up .g-shape { fill: #bbf7d0; stroke: #16a34a; }
.g-down .g-shape { fill: #fecaca; stroke: #dc2626; }
.g-unknown .g-shape { fill: #e5e7eb; stroke: #9ca3af; }
.g-external .g-shape { fill: #e0e7ff; stroke: #6366f1; }

.chip {
  font: inherit;
  font-size: 0.85rem;
  background: #eef2ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  padding: 3px 12px;
  cursor: pointer;
  margin: 2px 4px 2px 0;
}
.chip:hover { background: #e0e7ff; }

/* ---------- Progress bar ---------- */
.progress {
  height: 12px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  flex: 1 1 160px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--blue);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tab {
  font: inherit;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab:hover { color: var(--text); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 12px;
  overflow-y: auto;
}
.modal {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  width: 560px;
  max-width: 100%;
  padding: 18px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.modal-x {
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 8px;
}
.modal-x:hover { color: var(--text); }
.modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
}
.modal-actions .spacer { flex: 1; }
.modal-context {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

/* ---------- Settings / lookup lists ---------- */
.settings-grid label { display: flex; flex-direction: column; gap: 4px; }
.lookup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.lookup-card { margin-bottom: 0; }
.lookup-list { list-style: none; margin: 0 0 10px; padding: 0; }
.lookup-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #f0f1f4;
  font-size: 0.92rem;
}
.lookup-list li.inactive span { color: var(--muted); text-decoration: line-through; }
.add-row { display: flex; gap: 6px; }
.add-row input { flex: 1; min-width: 0; }

.recurring-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}
.recurring-grid .card { margin-bottom: 0; }

.top-devices { list-style: none; margin: 0; padding: 0; }
.top-devices li {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid #f0f1f4;
  font-size: 0.92rem;
}
.count-pill {
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 0 10px;
  font-weight: 700;
  font-size: 0.82rem;
}

.inline-result { font-size: 0.9rem; margin-left: 10px; }
.inline-result.ok { color: var(--up); }
.inline-result.err { color: var(--down); }

.section-note { color: var(--muted); font-size: 0.85rem; margin: 4px 0 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .container { padding: 12px 10px 50px; }
  .form-grid { grid-template-columns: 1fr; }
  .check-label { padding-top: 0; }
  .stat-value { font-size: 1.4rem; }
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); }
  th, td { padding: 7px 8px; }
  .modal-overlay { padding: 16px 8px; }
}
