:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #eef5ff;
  --text: #152033;
  --muted: #667085;
  --line: #d9e2ee;
  --primary: #1167d8;
  --primary-strong: #0a4aa3;
  --success: #0f9f6e;
  --warning: #d97706;
  --danger: #d92d20;
  --shadow: 0 18px 45px rgba(18, 35, 61, 0.12);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body.auth-locked .app-shell {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: none;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at top right, rgba(17, 103, 216, 0.18), transparent 34%),
    var(--bg);
}

body.auth-locked .login-screen {
  display: grid;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: grid;
  gap: 16px;
}

.login-brand {
  color: var(--text);
  margin-bottom: 4px;
}

.login-brand p {
  color: var(--muted);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.app-header {
  background: #0f172a;
  color: white;
  padding: 14px 22px 0;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  font-weight: 800;
  font-size: 24px;
}

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

.brand p,
.quick-card span,
.quick-card h2 {
  color: #cbd5e1;
}

.nav-list {
  display: flex;
  align-items: end;
  gap: 4px;
  overflow-x: auto;
}

.nav-item {
  border: 0;
  background: transparent;
  color: #dbeafe;
  text-align: right;
  padding: 12px 18px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.nav-item.active,
.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-link {
  display: block;
}

.quick-card {
  background: #0f172a;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 16px;
}

.quick-card h2 {
  font-size: 16px;
  margin: 0 0 16px;
}

.mini-stat {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.workspace {
  padding: 26px;
  display: grid;
  gap: 22px;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow,
.panel-head p,
.stat-tile small {
  color: var(--muted);
}

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

.top-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

.search-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: var(--text);
  min-width: 0;
}

.primary-btn {
  border: 0;
  border-radius: 8px;
  padding: 12px 18px;
  color: white;
  background: var(--primary);
  cursor: pointer;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--primary-strong);
}

.wide {
  width: 100%;
}

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

.stat-tile,
.map-panel,
.form-panel,
.tasks-panel,
.responsibles-panel,
.managers-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-tile {
  padding: 18px;
  display: grid;
  gap: 8px;
}

.stat-tile span {
  color: var(--muted);
}

.stat-tile strong {
  font-size: 34px;
}

.stat-tile.alert strong {
  color: var(--danger);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.map-panel,
.form-panel,
.tasks-panel,
.responsibles-panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.map-canvas {
  position: relative;
  min-height: 430px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background:
    linear-gradient(30deg, transparent 46%, rgba(17, 103, 216, 0.18) 47%, rgba(17, 103, 216, 0.18) 51%, transparent 52%),
    linear-gradient(120deg, transparent 43%, rgba(15, 159, 110, 0.16) 44%, rgba(15, 159, 110, 0.16) 48%, transparent 49%),
    linear-gradient(#dfeaf6 1px, transparent 1px),
    linear-gradient(90deg, #dfeaf6 1px, transparent 1px),
    #eef5ff;
  background-size: 100% 100%, 100% 100%, 42px 42px, 42px 42px, auto;
}

.map-canvas.leaflet-ready {
  background: #eef5ff;
}

.map-canvas.leaflet-ready .leaflet-container,
.map-canvas.leaflet-ready {
  direction: ltr;
}

.map-canvas .leaflet-popup-content {
  direction: rtl;
  text-align: right;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.7;
}

.map-canvas .map-tooltip {
  direction: rtl;
  text-align: right;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.7;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.18);
}

.map-canvas .worker-name-tooltip {
  direction: rtl;
  text-align: center;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-weight: 800;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.18);
}

.map-canvas::before {
  content: "Idlib FTTH Service Zone";
  position: absolute;
  left: 16px;
  bottom: 14px;
  color: rgba(21, 32, 51, 0.38);
  font-weight: 800;
  letter-spacing: 0;
}

.map-canvas.leaflet-ready::before {
  display: none;
}

.worker-pin,
.task-pin {
  position: absolute;
  transform: translate(50%, -50%);
  border: 0;
  cursor: pointer;
  border-radius: 999px;
}

.worker-pin {
  width: 34px;
  height: 34px;
  color: white;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(17, 103, 216, 0.28);
  font-size: 12px;
  font-weight: 800;
}

.worker-pin::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(50%);
  width: max-content;
  max-width: 220px;
  padding: 9px 11px;
  border-radius: 8px;
  background: #0f172a;
  color: white;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  white-space: pre-line;
  z-index: 5;
}

.worker-pin:hover::after,
.worker-pin:focus-visible::after {
  opacity: 1;
  transform: translateX(50%) translateY(-2px);
}

.worker-pin.busy {
  background: var(--warning);
}

.worker-pin.tracking {
  background: #175cd3;
  box-shadow: 0 0 0 6px rgba(23, 92, 211, 0.16), 0 8px 20px rgba(17, 103, 216, 0.28);
}

.worker-pin.offline {
  background: #64748b;
}

.task-pin {
  width: 14px;
  height: 14px;
  background: var(--danger);
  border: 2px solid white;
  box-shadow: 0 6px 15px rgba(217, 45, 32, 0.3);
}

.task-pin::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 50%;
  bottom: calc(100% + 10px);
  transform: translateX(50%);
  width: max-content;
  max-width: 260px;
  padding: 9px 11px;
  border-radius: 8px;
  background: #0f172a;
  color: white;
  font-weight: 700;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  white-space: normal;
  z-index: 5;
}

.task-pin:hover::after,
.task-pin:focus-visible::after {
  opacity: 1;
  transform: translateX(50%) translateY(-2px);
}

.leaflet-worker-marker {
  width: 34px !important;
  height: 34px !important;
  margin-right: -17px !important;
  margin-top: -17px !important;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(17, 103, 216, 0.28);
  font-size: 12px;
  font-weight: 800;
  border: 2px solid white;
}

.leaflet-worker-marker.busy {
  background: var(--warning);
}

.leaflet-worker-marker.tracking {
  background: #175cd3;
  box-shadow: 0 0 0 6px rgba(23, 92, 211, 0.16), 0 8px 20px rgba(17, 103, 216, 0.28);
}

.leaflet-worker-marker.offline {
  background: #64748b;
}

.leaflet-task-marker {
  width: 16px !important;
  height: 16px !important;
  margin-right: -8px !important;
  margin-top: -8px !important;
  border-radius: 999px;
  background: var(--danger);
  border: 2px solid white;
  box-shadow: 0 6px 15px rgba(217, 45, 32, 0.3);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  background: var(--primary);
}

.legend-dot.busy {
  background: var(--warning);
}

.legend-dot.tracking {
  background: #175cd3;
  box-shadow: 0 0 0 4px rgba(23, 92, 211, 0.14);
}

.legend-dot.offline {
  background: #64748b;
}

.legend-dot.task {
  background: var(--danger);
  border: 2px solid white;
  box-shadow: 0 0 0 1px var(--line);
}

.worker-readout {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
  color: #1e3a5f;
}

.task-form {
  display: grid;
  gap: 13px;
}

.task-form label,
.responsible-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.responsible-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.responsibles-table {
  min-width: 720px;
}

.form-message {
  min-height: 24px;
  margin: 0 0 12px;
  color: var(--success);
  font-weight: 700;
}

.form-message.error {
  color: var(--danger);
}

.reports-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(160px, 0.8fr) minmax(160px, 0.8fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.reports-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.report-summary-grid article {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 6px;
}

.report-summary-grid span {
  color: var(--muted);
}

.report-summary-grid strong {
  font-size: 28px;
}

.reports-table {
  min-width: 760px;
}

.building-lookup {
  padding: 11px 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px dashed var(--line);
  color: var(--muted);
  line-height: 1.7;
}

.building-lookup.found {
  background: #e8fff6;
  color: #075f45;
  border-color: #a7f3d0;
}

.building-lookup.missing {
  background: #fff7e6;
  color: #92400e;
  border-color: #fed7aa;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.status-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-tab {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.status-tab.active {
  background: #e7f0ff;
  color: var(--primary);
  border-color: #b7d2ff;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  text-align: right;
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
}

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

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafc;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
}

.badge.new {
  color: #175cd3;
  background: #e7f0ff;
}

.badge.progress {
  color: #b45309;
  background: #fff7e6;
}

.badge.done {
  color: #047857;
  background: #e8fff6;
}

.completion-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.completion-pill.ready {
  color: #047857;
  background: #e8fff6;
}

.completion-pill.waiting {
  color: #92400e;
  background: #fff7e6;
}

.row-action {
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

@media (max-width: 1100px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

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

@media (max-width: 720px) {
  .workspace,
  .app-header {
    padding: 16px;
  }

  .topbar,
  .top-actions,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .main-grid,
  .stats-grid,
  .report-summary-grid,
  .split,
  .responsible-form,
  .reports-form {
    grid-template-columns: 1fr;
  }

  .map-canvas {
    min-height: 340px;
  }
}
