:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe4ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --shadow: 0 18px 38px rgba(15, 23, 42, 0.12);
  --radius: 18px;
  --sidebar: 320px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.10), transparent 30%),
    radial-gradient(circle at bottom right, rgba(22, 163, 74, 0.10), transparent 30%),
    var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100%;
  padding: 12px;
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  gap: 12px;
}

.sidebar {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 16px;
  overflow: auto;
  max-height: calc(100vh - 24px);
  position: sticky;
  top: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #0f766e);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.card-head h3,
.card-head p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p,
.muted,
.topbar p,
.card-head p,
.stat-card small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.panel,
.card,
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

label {
  display: block;
  margin: 10px 0 6px;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  color: var(--text);
  padding: 0 12px;
}

textarea {
  padding: 9px 12px;
}

input[type="file"] {
  padding: 9px 10px;
  height: auto;
}

.btn {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  min-height: 42px;
  border-radius: 12px;
  padding: 0 14px;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-color: transparent;
}

.btn.danger {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, #ef4444, var(--danger));
}

.btn.full {
  width: 100%;
  margin-top: 12px;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.legend-panel {
  margin-bottom: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.05);
}

.main {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.topbar {
  min-height: 76px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar h2 {
  font-size: 22px;
}

.topbar-actions,
.table-tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 16px;
  overflow: hidden;
  position: relative;
}

.stat-card::after {
  content: "";
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.07;
  position: absolute;
  top: -34px;
  right: -24px;
}

.stat-card span {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}

.stat-card strong {
  display: block;
  font-size: 32px;
  margin: 8px 0 2px;
  line-height: 1;
  color: var(--primary);
}

.stat-card.warning strong {
  color: var(--warning);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) 420px;
  gap: 12px;
  align-items: stretch;
}

.card {
  min-width: 0;
  overflow: hidden;
}

.card-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-head.compact,
.card-head.compact-head {
  padding: 11px 14px;
}

.card-head.compact {
  border-top: 1px solid var(--line);
}

.card-head h3 {
  font-size: 17px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  white-space: nowrap;
}

#map {
  height: 470px;
  width: 100%;
}

.side-card {
  display: grid;
  grid-template-rows: auto minmax(180px, auto) auto 1fr;
}

.bars {
  padding: 16px;
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 135px 1fr 42px;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}

.bar-track {
  height: 10px;
  background: #edf2f7;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  width: 0;
}

.engineer-list {
  padding: 12px 16px 16px;
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.engineer-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.engineer-item strong {
  font-size: 13px;
}

.engineer-item span {
  color: var(--muted);
  font-size: 12px;
}

.engineer-badge {
  min-width: 34px;
  text-align: center;
  border-radius: 999px;
  padding: 6px 10px;
  background: #eff6ff;
  color: var(--primary);
  font-weight: 800;
}

.table-card {
  min-height: 360px;
}

.table-wrap {
  max-height: 430px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 2;
  color: #334155;
  font-size: 12px;
}

tbody tr:hover td {
  background: #f8fbff;
}

tbody tr.active td {
  background: #eff6ff;
}

tbody tr.jump-focus td {
  background: #dbeafe !important;
  box-shadow: inset 0 0 0 9999px rgba(37, 99, 235, 0.07);
}

.status-pill,
.priority-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid transparent;
}

.status-not-assigned { color: #475569; background: #f1f5f9; border-color: #e2e8f0; }
.status-assigned { color: #1d4ed8; background: #dbeafe; border-color: #bfdbfe; }
.status-in-progress { color: #b45309; background: #fef3c7; border-color: #fde68a; }
.status-completed { color: #15803d; background: #dcfce7; border-color: #bbf7d0; }
.status-issue-found { color: #b91c1c; background: #fee2e2; border-color: #fecaca; }
.status-reinspection-required { color: #7e22ce; background: #f3e8ff; border-color: #e9d5ff; }
.status-overdue { color: #991b1b; background: #fecaca; border-color: #fca5a5; }

.priority-high { color: #b91c1c; background: #fee2e2; }
.priority-medium { color: #b45309; background: #fef3c7; }
.priority-low { color: #15803d; background: #dcfce7; }

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.site-form {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.site-form .btn {
  grid-column: span 2;
}

.popup-card {
  min-width: 210px;
}

.popup-card-compact {
  min-width: 220px;
  max-width: 280px;
}

.popup-title {
  display: block;
  font-size: 15px;
  margin-bottom: 8px;
}

.popup-site-link {
  display: block;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid #bfdbfe;
  border-radius: 9px;
  background: #eff6ff;
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
}

.popup-site-link:hover {
  background: #dbeafe;
}

.popup-hint {
  margin: 5px 0 8px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.popup-body {
  font-size: 12px;
  line-height: 1.65;
}

.popup-body-compact {
  line-height: 1.48;
}

.direction-btn {
  display: block;
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff !important;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
}

.direction-btn:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
}

.action-buttons,
.table-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.table-tools .btn {
  white-space: nowrap;
}

.action-btn {
  border: none;
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.action-view { background: #dbeafe; color: #1d4ed8; }
.action-edit { background: #fef3c7; color: #92400e; }
.action-delete { background: #fee2e2; color: #991b1b; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(620px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-head h3 {
  margin: 0;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: #f1f5f9;
  font-size: 22px;
}

.edit-form {
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.edit-form label {
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}

.edit-form input,
.edit-form select,
.edit-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #dbe1ea;
  border-radius: 10px;
  font: inherit;
}

.edit-form textarea,
.modal-actions {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* ================= Engineer Page Full Width + Compact Table ================= */

.engineer-shell {
  display: block !important;
  width: 100vw !important;
  min-height: 100vh !important;
  padding: 14px !important;
  background: #eef4fb;
  overflow-x: hidden;
}

.engineer-main {
  width: 100% !important;
  max-width: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

.engineer-topbar,
.engineer-main .topbar {
  width: 100%;
  margin-bottom: 12px;
  min-height: 64px;
  padding: 12px 16px;
}

.engineer-main .card {
  width: 100%;
}

.engineer-content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 360px;
  gap: 12px;
  margin-bottom: 12px;
}

.engineer-status-card.side-card {
  display: grid;
  grid-template-rows: auto 1fr;
}

.compact-bars {
  padding: 12px 14px;
  gap: 8px;
}

.compact-bars .bar-row {
  grid-template-columns: 128px 1fr 34px;
  gap: 8px;
}

#engineerMap {
  width: 100%;
  height: 430px;
  border-radius: 0 0 16px 16px;
}

.engineer-table-card {
  width: 100%;
  overflow: hidden;
}

.engineer-table-wrap {
  width: 100%;
  max-height: 430px;
  overflow: auto;
}

.engineer-table {
  width: 100%;
  min-width: 980px;
  table-layout: fixed;
  font-size: 12px;
}

.engineer-table th,
.engineer-table td {
  padding: 7px 8px;
  line-height: 1.25;
  vertical-align: middle;
}

.engineer-table th {
  font-size: 11px;
  letter-spacing: .01em;
}

.engineer-table .col-site { width: 150px; }
.engineer-table .col-sector { width: 70px; }
.engineer-table .col-plot { width: 70px; }
.engineer-table .col-area { width: 150px; }
.engineer-table .col-type { width: 145px; }
.engineer-table .col-priority { width: 80px; }
.engineer-table .col-date { width: 88px; }
.engineer-table .col-status { width: 140px; }
.engineer-table .col-notes { width: 210px; }
.engineer-table .col-action { width: 78px; }

.clipped-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-site-btn {
  width: 100%;
  border: none;
  background: transparent;
  color: #172033;
  font-weight: 900;
  text-align: left;
  padding: 0;
  line-height: 1.2;
}

.table-site-btn:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

.engineer-status-select,
.engineer-notes-input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid #dbe1ea;
  border-radius: 9px;
  font-size: 12px;
}

.engineer-notes-input {
  height: 34px;
  resize: vertical;
  line-height: 1.25;
}

.engineer-notes-input:focus {
  min-height: 70px;
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.compact-save-btn {
  min-height: 34px;
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  font-size: 12px;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .site-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .engineer-content-grid {
    grid-template-columns: 1fr;
  }

  #engineerMap {
    height: 380px;
  }
}

@media (max-width: 760px) {
  .topbar,
  .card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .stats-grid,
  .site-form {
    grid-template-columns: 1fr;
  }

  .site-form .btn {
    grid-column: auto;
  }

  #map {
    height: 360px;
  }

  .engineer-shell {
    padding: 8px !important;
  }

  .engineer-topbar,
  .engineer-main .topbar {
    padding: 11px 12px;
    border-radius: 18px;
  }

  .engineer-table {
    min-width: 820px;
    font-size: 11.5px;
  }

  .engineer-table th,
  .engineer-table td {
    padding: 6px 6px;
  }

  .engineer-table .col-site { width: 140px; }
  .engineer-table .col-sector { width: 62px; }
  .engineer-table .col-plot { width: 62px; }
  .engineer-table .col-area { width: 125px; }
  .engineer-table .col-type { width: 125px; }
  .engineer-table .col-priority { width: 72px; }
  .engineer-table .col-date { width: 82px; }
  .engineer-table .col-status { width: 125px; }
  .engineer-table .col-notes { width: 165px; }
  .engineer-table .col-action { width: 68px; }

  #engineerMap {
    height: 330px;
  }

  .bar-row,
  .compact-bars .bar-row {
    grid-template-columns: 118px 1fr 30px;
  }
}

@media (max-width: 520px) {
  .engineer-table {
    min-width: 760px;
    font-size: 11px;
  }

  #engineerMap {
    height: 300px;
  }

  .card-head h3,
  .topbar h2 {
    font-size: 18px;
  }
}

@media (max-width: 700px) {
  .edit-form {
    grid-template-columns: 1fr;
  }
}

/* ================= Admin Compact Table + Popup Row Focus ================= */

.main:not(.engineer-main) .table-card .card-head {
  padding: 10px 14px;
}

.main:not(.engineer-main) .table-card .table-wrap {
  max-height: 520px;
  overflow: auto;
}

.main:not(.engineer-main) .table-card table {
  min-width: 1280px;
  table-layout: fixed;
}

.main:not(.engineer-main) .table-card th,
.main:not(.engineer-main) .table-card td {
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.25;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main:not(.engineer-main) .table-card tbody tr {
  height: 42px;
}

.main:not(.engineer-main) .table-card th:nth-child(1),
.main:not(.engineer-main) .table-card td:nth-child(1) {
  width: 44px;
  text-align: center;
}

.main:not(.engineer-main) .table-card th:nth-child(2),
.main:not(.engineer-main) .table-card td:nth-child(2) {
  width: 170px;
}

.main:not(.engineer-main) .table-card th:nth-child(3),
.main:not(.engineer-main) .table-card td:nth-child(3) {
  width: 80px;
}

.main:not(.engineer-main) .table-card th:nth-child(4),
.main:not(.engineer-main) .table-card td:nth-child(4) {
  width: 95px;
}

.main:not(.engineer-main) .table-card th:nth-child(5),
.main:not(.engineer-main) .table-card td:nth-child(5) {
  width: 240px;
}

.main:not(.engineer-main) .table-card th:nth-child(6),
.main:not(.engineer-main) .table-card td:nth-child(6) {
  width: 180px;
}

.main:not(.engineer-main) .table-card th:nth-child(7),
.main:not(.engineer-main) .table-card td:nth-child(7) {
  width: 90px;
}

.main:not(.engineer-main) .table-card th:nth-child(8),
.main:not(.engineer-main) .table-card td:nth-child(8) {
  width: 105px;
}

.main:not(.engineer-main) .table-card th:nth-child(9),
.main:not(.engineer-main) .table-card td:nth-child(9) {
  width: 170px;
}

.main:not(.engineer-main) .table-card th:nth-child(10),
.main:not(.engineer-main) .table-card td:nth-child(10) {
  width: 120px;
}

.main:not(.engineer-main) .table-card th:nth-child(11),
.main:not(.engineer-main) .table-card td:nth-child(11) {
  width: 260px;
}

.main:not(.engineer-main) .table-card tbody tr.active td {
  background: #eff6ff !important;
}

.main:not(.engineer-main) .table-card tbody tr.row-flash td {
  animation: rowFlash 1.8s ease;
}

@keyframes rowFlash {
  0% { background: #bfdbfe; }
  40% { background: #dbeafe; }
  100% { background: transparent; }
}

.main:not(.engineer-main) .cell-site,
.main:not(.engineer-main) .cell-notes {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main:not(.engineer-main) .table-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.main:not(.engineer-main) .table-tools .btn {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .main:not(.engineer-main) .table-card table {
    min-width: 1180px;
  }

  .main:not(.engineer-main) .table-card th,
  .main:not(.engineer-main) .table-card td {
    padding: 7px 8px;
    font-size: 11.5px;
  }

  .main:not(.engineer-main) .table-tools {
    gap: 6px;
  }

  .main:not(.engineer-main) .table-tools .btn {
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }
}

@media (max-width: 600px) {
  .main:not(.engineer-main) .table-card table {
    min-width: 1080px;
  }
  /* ================= User Management Page ================= */
.users-shell {
  display: block !important;
  width: 100vw !important;
  min-height: 100vh !important;
  padding: 14px !important;
  background: #eef4fb;
  overflow-x: hidden;
}

.users-main {
  width: 100% !important;
  max-width: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

.users-topbar {
  margin-bottom: 12px;
}

.users-form-card {
  margin-bottom: 12px;
}

.user-form {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.user-form-actions {
  display: flex;
  gap: 10px;
  align-items: end;
}

.user-search {
  width: 260px;
  min-height: 38px;
}

.users-table-wrap {
  max-height: 520px;
  overflow: auto;
}

.users-table {
  min-width: 980px;
  table-layout: fixed;
}

.users-table th,
.users-table td {
  padding: 9px 10px;
  font-size: 12px;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.users-table th:nth-child(1),
.users-table td:nth-child(1) { width: 260px; }

.users-table th:nth-child(2),
.users-table td:nth-child(2) { width: 180px; }

.users-table th:nth-child(3),
.users-table td:nth-child(3) { width: 130px; }

.users-table th:nth-child(4),
.users-table td:nth-child(4) { width: 130px; }

.users-table th:nth-child(5),
.users-table td:nth-child(5) { width: 190px; }

.users-table th:nth-child(6),
.users-table td:nth-child(6) { width: 360px; }

@media (max-width: 1100px) {
  .user-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .user-form-actions {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .users-shell {
    padding: 8px !important;
  }

  .user-form {
    grid-template-columns: 1fr;
  }

  .user-form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .user-search {
    width: 100%;
  }

  .users-table {
    min-width: 860px;
  }
}
}

