@font-face {
  font-family: "Vazirmatn";
  src: url("fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e3e8ee;
  --text: #17212b;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0b5f59;
  --danger: #c2410c;
  --live: #16a34a;
  --warn: #d97706;
  --off: #94a3b8;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.12);
  font-family: "Vazirmatn", Tahoma, "Segoe UI", sans-serif;
  color: var(--text);
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); }
button, input, select, textarea { font-family: inherit; }
h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #f1f5f9; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: #fed7aa; }
.btn-danger:hover { background: #fff7ed; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.icon-btn {
  border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: #f1f5f9; color: var(--text); }
input, select {
  font: inherit; color: inherit; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; background: #fff; width: 100%;
}
input:focus { outline: 2px solid rgba(15, 118, 110, .25); border-color: var(--primary); }
label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
label input { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; font-weight: 500; }
label.check input { width: auto; margin: 0; }
.form-error { color: var(--danger); margin: 0; }

/* Login */
.login-page { display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0f766e 0%, #134e4a 100%); }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 16px; padding: 28px;
  box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-card p { margin: 0; }

/* App layout */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand-lg { font-size: 20px; }
.app-page { display: grid; grid-template-columns: 360px 1fr; height: 100vh; overflow: hidden; }
.sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column;
  min-height: 0; z-index: 2;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel.period { position: relative; }
.panel-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); background: #f1f5f9; border-radius: 8px; padding: 3px; gap: 3px; }
.segmented button {
  border: 0; background: transparent; padding: 6px 4px; border-radius: 6px; font: inherit; font-size: 13px;
  cursor: pointer; color: var(--muted); font-weight: 600;
}
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.range-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.range-field { display: grid; gap: 4px; min-width: 0; }
.range-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.date-btn {
  font: inherit; font-size: 12px; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 8px; cursor: pointer; text-align: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.date-btn:hover { border-color: #cbd5e1; }
.date-btn[aria-expanded="true"] { border-color: var(--primary); outline: 2px solid rgba(15, 118, 110, .25); }

/* Shamsi (Persian calendar) date picker */
.picker {
  position: absolute; inset-inline: 12px; top: calc(100% - 6px); z-index: 1000; background: var(--surface);
  border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--border); padding: 12px; display: grid; gap: 10px;
}
.picker-head { display: flex; align-items: center; justify-content: space-between; }
.picker-head b { font-size: 15px; }
.picker-head .icon-btn { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; }
.pk-week, .pk-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.pk-week span { font-size: 12px; color: var(--muted); font-weight: 700; padding: 2px 0; }
.pk-days button {
  font: inherit; font-size: 13px; border: 0; background: transparent; border-radius: 8px; height: 34px; cursor: pointer; color: var(--text);
}
.pk-days button:hover { background: #f1f5f9; }
.pk-days button.today { box-shadow: inset 0 0 0 1px var(--primary); }
.pk-days button.selected { background: var(--primary); color: #fff; font-weight: 700; }
.pk-days button.fri { color: var(--danger); }
.pk-days button.selected.fri { color: #fff; }
.pk-time { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pk-time select { margin-top: 4px; padding: 6px 8px; }

.mode-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--border); }
.mode-tabs button {
  border: 0; background: transparent; padding: 11px; font: inherit; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
}
.mode-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.list-tools { padding: 12px 16px 6px; display: grid; gap: 8px; }
.counts { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.counts b { color: var(--text); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 5px; vertical-align: middle; }
.dot.live { background: var(--live); box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.dot.no-signal { background: var(--warn); }
.dot.off, .dot.disabled { background: var(--off); }

.visitor-list { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.visitor {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 8px; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
}
.visitor:hover { background: #f8fafc; }
.visitor.selected { background: #f0fdfa; border-color: #99f6e4; }
.visitor.disabled-account { opacity: .55; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 14px; flex: none;
}
.visitor-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visitor-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visitor-meta { text-align: end; font-size: 12px; color: var(--muted); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.pill.live { background: #dcfce7; color: #166534; }
.pill.no-signal { background: #fef3c7; color: #92400e; }
.pill.off { background: #f1f5f9; color: #475569; }
.pill.disabled { background: #fee2e2; color: #991b1b; }
.empty-hint { padding: 16px 20px; color: var(--muted); line-height: 1.5; }

/* Map area */
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 500;
  background: var(--surface); border-radius: 999px; padding: 8px 16px; box-shadow: var(--shadow); font-weight: 600;
}

.detail, .legend {
  position: absolute; z-index: 500; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
}
.detail {
  top: 12px; inset-inline-end: 12px; width: 340px; max-height: calc(100% - 24px); overflow-y: auto; padding: 16px;
  display: grid; gap: 12px; align-content: start;
}
.detail-head { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; }
.detail-title h2 { font-size: 17px; }
.detail-title a { font-size: 13px; text-decoration: none; }
.detail-status { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: #f8fafc; border-radius: 10px; padding: 10px; }
.stat-value { font-size: 18px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.warn { background: #fff7ed; }
.stat.warn .stat-value { color: var(--danger); }
.playback { display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: center; }
.playback .play { font-size: 16px; background: #f1f5f9; width: 34px; height: 34px; border-radius: 50%; }
.playback input { padding: 0; accent-color: var(--primary); }
.playback span { grid-column: 2; }
.shifts { list-style: none; margin: -4px 0 0; padding: 0; display: grid; gap: 6px; }
.shifts li { font-size: 13px; display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; background: #f8fafc; border-radius: 8px; }
.shifts li.empty { color: var(--muted); }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.legend { inset-inline-start: 12px; bottom: 24px; padding: 12px 14px; max-height: 45%; overflow-y: auto; min-width: 220px; }
.legend ul { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .swatch { width: 18px; height: 6px; border-radius: 3px; flex: none; }
.legend .km { margin-inline-start: auto; color: var(--muted); padding-inline-start: 12px; }

/* Map markers */
.marker-pin {
  position: relative;
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 12px; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.marker-pin.no-signal { opacity: .75; }
.marker-pin.off { filter: grayscale(.9); opacity: .6; }
.marker-pin.live::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 3px solid currentColor;
  animation: pulse 2s infinite; color: inherit;
}
@keyframes pulse { 0% { transform: scale(1); opacity: .7; } 100% { transform: scale(1.8); opacity: 0; } }
.end-marker { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.leaflet-container { font-family: "Vazirmatn", Tahoma, sans-serif; }
.leaflet-tooltip { direction: rtl; font-family: "Vazirmatn", Tahoma, sans-serif; }
.leaflet-tooltip.name-tip { font-weight: 600; }
.leaflet-control-attribution { direction: ltr; }

dialog {
  border: 0; border-radius: 14px; padding: 0; box-shadow: var(--shadow); width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(15, 23, 42, .4); }
dialog form { padding: 20px; display: grid; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }

@media (max-width: 820px) {
  .app-page { grid-template-columns: 1fr; grid-template-rows: 48vh 1fr; }
  .sidebar { border-inline-end: 0; border-bottom: 1px solid var(--border); }
  .detail { inset-inline: 8px; top: auto; bottom: 8px; width: auto; max-height: 60%; }
  .legend { display: none; }
}

/* Header actions, today's shifts and the online / no-signal / offline bar */
.head-actions { display: flex; align-items: center; gap: 6px; }
.shifts-title { display: flex; justify-content: space-between; align-items: baseline; }
.shifts-title a { font-weight: 600; color: var(--primary); text-decoration: none; font-size: 12px; }
.shifts-title a:hover { text-decoration: underline; }
.shifts li.shift { display: grid; gap: 6px; }
.shift-head { display: flex; justify-content: space-between; gap: 8px; }
.status-bar { position: relative; height: 10px; border-radius: 5px; background: #e2e8f0; overflow: hidden; }
.status-bar .seg { position: absolute; top: 0; bottom: 0; }
.seg.online, .sdot.online { background: #16a34a; }
.seg.no-signal, .sdot.no-signal { background: #f59e0b; }
.seg.offline, .sdot.offline { background: #475569; }
.status-line { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.status-line span { display: inline-flex; align-items: center; gap: 5px; }
.sdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* ---------- Reports page ---------- */
.report-page { min-height: 100vh; }
.report-page.loading .report-main > section:not(.filters) { opacity: .55; transition: opacity .15s; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topnav { display: flex; gap: 4px; margin-inline-start: 12px; flex: 1; }
.topnav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; text-decoration: none; }
.topnav a:hover { background: #f1f5f9; color: var(--text); }
.topnav a.active { background: #f0fdfa; color: var(--primary); }
.report-main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; display: grid; gap: 16px; }
.report-title h1 { margin: 0; font-size: 22px; }
.report-title p { margin: 4px 0 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; }
.filters { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(300px, 2fr) minmax(280px, 1.6fr); gap: 16px; align-items: start; }
.filter { display: grid; gap: 6px; min-width: 0; position: relative; }
.filter-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.filter .range-row { margin-top: 2px; }
.filter-period .picker { inset-inline: 0; top: calc(100% + 6px); max-width: 340px; }
.segmented.seg-5 { grid-template-columns: repeat(5, 1fr); }
.segmented.seg-4 { grid-template-columns: repeat(4, auto); }
.status-filter button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap; padding-inline: 8px; }
.report-error { padding: 10px 14px; background: #fff7ed; border-radius: 10px; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; display: grid; gap: 4px; }
.kpi.focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 800; }
.kpi-note { font-size: 12px; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th { text-align: start; font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.report-table td { padding: 9px 8px; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
.report-table tbody tr:hover { background: #f8fafc; }
.report-table tr.idle td { color: var(--muted); }
.report-table td.hl { font-weight: 800; }
.report-table .col-bar { width: 22%; min-width: 120px; }
.report-table .empty-cell { text-align: center; color: var(--muted); padding: 24px; }
.report-table .pill { margin-inline-start: 6px; }
.link-btn { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; }
.link-btn:hover { color: var(--primary); text-decoration: underline; }
.pill.st-online { background: #dcfce7; color: #166534; }
.pill.st-no-signal { background: #fef3c7; color: #92400e; }
.pill.st-offline { background: #e2e8f0; color: #334155; }
.more-btn { margin-top: 12px; }
.shift-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.shift-list li { display: grid; gap: 6px; padding: 10px 12px; background: #f8fafc; border-radius: 10px; font-size: 13px; }
.legend-card { display: grid; gap: 6px; padding: 4px 4px 0; line-height: 1.9; }
.legend-card p { margin: 0; }
.legend-card .sdot { margin-inline-end: 6px; vertical-align: middle; }
.legend-card b { color: var(--text); margin-inline-end: 4px; }

@media (max-width: 980px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filter-period { grid-column: 1 / -1; grid-row: 2; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .filters { grid-template-columns: 1fr; }
  .filter-period { grid-row: auto; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .segmented.seg-4 { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 10px 16px; }
  .topnav { margin-inline-start: 0; order: 3; flex-basis: 100%; }
}

/* Person colour picker (edit dialog) */
.color-field { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: grid; gap: 10px; }
.color-field legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 4px; }
.color-current { display: flex; align-items: center; gap: 12px; }
.color-current > div { display: grid; gap: 2px; }
.custom-color { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--primary); cursor: pointer; }
.custom-color input { width: 32px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; background: none; margin: 0; }
.swatches { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.swatch-btn { aspect-ratio: 1; min-width: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; }
.swatch-btn:hover { transform: scale(1.1); }
.swatch-btn[aria-checked="true"] { box-shadow: 0 0 0 2px var(--text); }
.swatch-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.name-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-inline-end: 6px; vertical-align: middle; flex: none; }

/* Outbound and return (details panel and map) */
.trip { display: grid; gap: 10px; }
.trip-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.trip-head select { width: auto; max-width: 62%; padding: 4px 8px; font-size: 12px; }
#d-trip-show { grid-template-columns: repeat(3, 1fr); }
.trip-bar { display: flex; height: 24px; border-radius: 7px; overflow: hidden; gap: 2px; }
.trip-bar > div { position: relative; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; min-width: 0; overflow: hidden; white-space: nowrap; }
.trip-bar .b-out { background: #2563eb; }
.trip-bar .b-back { background: #ea580c; }
.trip-bar .b-turn { background: repeating-linear-gradient(135deg, #f1f5f9 0 5px, #e2e8f0 5px 10px); color: var(--text); }
.trip-bar .tick { position: absolute; top: 0; bottom: 0; background: rgba(255,255,255,.45); }
.trip-times { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.trip-cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.trip-cmp th { font-size: 12px; text-align: start; padding: 4px; }
.trip-cmp td { padding: 5px 4px; border-top: 1px solid var(--border); vertical-align: top; }
.trip-cmp td:first-child { color: var(--muted); font-size: 12px; white-space: nowrap; }
.trip-cmp .h-out { color: #2563eb; } .trip-cmp .h-back { color: #ea580c; }
.trip-cmp tr.diff-row { cursor: pointer; }
.trip-cmp tr.diff-row:hover td, .trip-cmp tr.diff-row.on td { background: #fff7ed; }
.trip-cmp tr.diff-row td:last-child { text-decoration: underline dotted; }
.trip-stops { display: grid; gap: 2px; }
.trip-stops .panel-title { margin-bottom: 2px; }
.trip-stop { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px; border: 0; background: transparent; border-radius: 8px; font: inherit; color: inherit; text-align: start; cursor: pointer; }
.trip-stop:hover, .trip-stop:focus-visible { background: #f1f5f9; outline: none; }
.trip-stop .grow { flex: 1; min-width: 0; display: grid; font-size: 13px; }
.trip-stop small { color: var(--muted); font-variant-numeric: tabular-nums; }
.trip-stop b { font-size: 12px; white-space: nowrap; }
.stop-badge { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 800; flex: none; }
.stop-marker { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 800 11px "Vazirmatn", Tahoma, sans-serif; border: 2.5px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); transition: transform .15s; }
.turn-marker { width: 20px; height: 20px; margin: 1px; background: #17212b; border: 2.5px solid #fff; transform: rotate(45deg); border-radius: 3px; box-shadow: 0 1px 4px rgba(0,0,0,.4); transition: transform .15s; }
.stop-marker.hl { transform: scale(1.35); }
.turn-marker.hl { transform: rotate(45deg) scale(1.35); }
.leaflet-tooltip.trip-tip { font-size: 11px; font-weight: 600; padding: 2px 6px; }
@media (prefers-reduced-motion: reduce) { .stop-marker, .turn-marker { transition: none; } }
