:root {
  --bg: #f5f7fa;
  --ink: #0f1419;
  --muted: #667085;
  --brand: #1f5a99;
  --brand-2: #0684d7;
  --border: #d6dce2;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
  opacity: 0;
  transition: opacity 0.2s ease-in;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.loaded {
  opacity: 1;
}

h1,
h2,
p {
  margin: 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1rem;
  background: linear-gradient(110deg, #ffffff 0%, #dcecf4 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 5;
}

.backend-header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.backend-header-actions .btn {
  position: relative;
  z-index: 6;
  pointer-events: auto;
}

.app-header p {
  color: var(--muted);
  margin-top: 0.2rem;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  background: linear-gradient(125deg, var(--brand-2) 0%, var(--brand) 100%);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn.secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--brand);
}

.admin-layout {
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
  max-width: 1540px;
  margin: 0 auto;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tab-btn {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.4rem 0.75rem;
  background: #fff;
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: linear-gradient(125deg, var(--brand-2) 0%, var(--brand) 100%);
  color: #fff;
  border-color: transparent;
}

.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
}

.panel h2 {
  margin-bottom: 0.6rem;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.row.actions {
  margin-top: 0.6rem;
}

label {
  display: grid;
  gap: 0.2rem;
  font-size: 0.85rem;
  color: #2f465b;
}

input,
select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  font: inherit;
}

textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  font: inherit;
  resize: vertical;
}

.inline-form,
.vehicle-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 0.7rem;
}

.inline-form input[type="text"] {
  min-width: 220px;
}

.vehicle-form #vehicleName {
  min-width: 220px;
}

.small-check {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.inline-field {
  display: grid;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: #2f465b;
}

.list {
  display: grid;
  gap: 0.4rem;
}

.item {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.45rem 0.55rem;
  background: #f9fcff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.item small {
  color: var(--muted);
}

.item-actions {
  display: flex;
  gap: 0.35rem;
}

.mini-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
}

.mini-btn.danger {
  border-color: #df9a9a;
  color: #a82f2f;
}

dialog {
  border: none;
  padding: 0;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(7, 29, 49, 0.1);
  width: min(420px, 92vw);
}

#editVehicleDialog {
  width: min(620px, 96vw);
  max-height: 92vh;
}

dialog::backdrop {
  background: rgba(8, 19, 30, 0.45);
}

.alert-form {
  display: grid;
  gap: 0.7rem;
  padding: 1.5rem;
  background: #fff;
  min-width: 300px;
  text-align: center;
}

.alert-form p {
  font-size: 0.95rem;
  line-height: 1.4;
  margin: 0;
  color: var(--ink);
}

.alert-form menu {
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.export-choice-form {
  display: grid;
  gap: 1rem;
  padding: 1.4rem;
  background: #fff;
  text-align: center;
}

.export-choice-form h3 {
  margin: 0;
  font-size: 1.08rem;
  color: #183042;
}

.export-choice-actions {
  display: grid;
  gap: 0.6rem;
  justify-items: center;
}

.export-choice-actions .btn {
  width: min(280px, 100%);
}

.export-choice-form menu {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
}

.dialog-form {
  display: grid;
  gap: 0.55rem;
  padding: 1rem;
  background: #fff;
}

.dialog-form h3 {
  margin: 0;
}

.general-access-form {
  padding: 1.1rem;
  min-width: min(360px, 92vw);
}

.general-access-form menu {
  margin: 0.45rem 0 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.general-access-error {
  margin: 0;
  color: #a82f2f;
  font-size: 0.86rem;
}

.vehicle-dialog-form {
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  overflow-x: hidden;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.vehicle-dialog-form input,
.vehicle-dialog-form select,
.vehicle-dialog-form textarea {
  width: 100%;
}

.vehicle-dialog-form h3,
.vehicle-dialog-form .inline-field,
.vehicle-dialog-form input[type="file"],
.vehicle-dialog-form .small-check,
.vehicle-dialog-form textarea,
.vehicle-dialog-form menu {
  grid-column: 1 / -1;
}

.vehicle-dialog-form .small-check {
  margin-top: -0.15rem;
}

@media (max-width: 640px) {
  .vehicle-dialog-form {
    grid-template-columns: 1fr;
  }
}

.vehicle-dialog-form menu {
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.analytics-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: end;
  margin-bottom: 1.2rem;
  padding: 0.9rem;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.is-hidden {
  display: none;
}

.analytics-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.analytics-showcase {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.analytics-kpi {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 1.2rem;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(15, 20, 25, 0.08);
  animation: analyticsCardLift 0.55s ease;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.analytics-kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(15, 20, 25, 0.12);
}

.analytics-kpi::after {
  content: "";
  position: absolute;
  width: 100px;
  height: 100px;
  right: -30px;
  top: -40px;
  border-radius: 50%;
  background: rgba(6, 132, 215, 0.06);
  filter: blur(1px);
}

.analytics-kpi--not-assigned {
  border-left: 3px solid #0684d7;
}

.analytics-kpi--costs {
  border-left: 3px solid #10b981;
}

.analytics-kpi-label {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.analytics-kpi-value {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 1.8rem;
  line-height: 1.1;
  color: var(--ink);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.analytics-kpi-sub {
  position: relative;
  z-index: 1;
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.analytics-range-pill {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  background: var(--surface-alt);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.5;
}
.analytics-debug-pill {
  margin-top: 0.25rem;
  border-radius: 999px;
  border: 1px solid #d8e8fb;
  background: linear-gradient(90deg, #f7fbff 0%, #f2f8ff 100%);
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
  color: #355176;
}
.analytics-debug-pill.is-ok {
  border-color: #b8e0c6;
  background: linear-gradient(90deg, #f4fff8 0%, #ecfbf3 100%);
  color: #1f6a3c;
}
.analytics-debug-pill.is-warn {
  border-color: #f1d48a;
  background: linear-gradient(90deg, #fff8eb 0%, #fff3dd 100%);
  color: #8b5a12;
  font-weight: 700;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 0.7rem;
}

.analytics-subtabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.analytics-subtab-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.analytics-subtab-btn:hover {
  color: var(--brand-2);
  background: var(--surface-alt);
}

.analytics-subtab-btn.is-active {
  color: #ffffff;
  background: linear-gradient(135deg, #0684d7 0%, #1f5a99 100%);
  box-shadow: 0 2px 8px rgba(6, 132, 215, 0.3);
  border-color: transparent;
}

.analytics-subtab-panels {
  display: grid;
}

.analytics-subtab-panel {
  display: none;
}

.analytics-subtab-panel.is-active {
  display: block;
  animation: analyticsCardLift 0.42s ease;
}

.analytics-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(15, 20, 25, 0.08);
  min-width: 0;
  animation: analyticsCardLift 0.6s ease;
}

.analytics-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, #0684d7 0%, #1f5a99 100%);
}

.analytics-card--costs::before {
  background: linear-gradient(90deg, #10b981 0%, #059669 100%);
}

.analytics-results {
  overflow-x: auto;
  padding: 0.5rem;
}

.chat-admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.chat-admin-list {
  display: grid;
  gap: 0.5rem;
}

.chat-admin-entry {
  display: grid;
  gap: 0.3rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f9fcff;
}

.chat-admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.chat-admin-author {
  font-weight: 700;
}

.chat-admin-time {
  font-size: 0.8rem;
  color: var(--muted);
}

.chat-admin-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: #20384f;
}

.chat-admin-actions {
  display: flex;
  justify-content: flex-end;
}

.analytics-card h3 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  font-weight: 700;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
}

.analytics-table th,
.analytics-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0.9rem;
  text-align: left;
  vertical-align: top;
}

.analytics-table th {
  background: var(--surface-alt);
  color: var(--ink);
  position: sticky;
  top: 0;
  z-index: 1;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.analytics-table tbody tr {
  transition: background-color 0.2s ease;
}

.analytics-table tbody tr:hover {
  background-color: var(--surface-alt);
}

.analytics-main-row {
  cursor: pointer;
  user-select: none;
}

.analytics-main-row td:first-child {
  font-weight: 700;
  color: var(--brand);
}

.analytics-main-row:focus {
  outline: 2px solid var(--brand-2);
  outline-offset: -2px;
}

.analytics-main-row[aria-expanded="true"] {
  background-color: rgba(6, 132, 215, 0.08);
}

.analytics-detail-row td {
  background: var(--surface-alt);
  border-top: 2px solid var(--border);
  padding: 1rem;
}

.analytics-row-details {
  display: grid;
  gap: 0.5rem;
  color: var(--ink);
}

.analytics-row-details strong {
  font-size: 0.9rem;
  color: var(--brand);
  font-weight: 700;
  display: block;
  margin-bottom: 0.5rem;
}

.analytics-date-groups {
  display: grid;
  gap: 0.75rem;
}

.analytics-date-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 0.65rem;
}

.analytics-date-group-title {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.analytics-days-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.4rem;
}

.analytics-days-list li {
  padding: 0.36rem 0.55rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--ink);
}

.analytics-days-details {
  width: 100%;
}

.analytics-days-details summary {
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-weight: 600;
  color: var(--brand-2);
  user-select: none;
  transition: background-color 0.2s ease;
}

.analytics-days-details summary:hover {
  background-color: rgba(6, 132, 215, 0.08);
}

.analytics-days-details[open] summary {
  margin-bottom: 0.6rem;
}

.analytics-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  background: var(--surface-alt);
  border-radius: 8px;
  border: 2px dashed var(--border);
}

@keyframes analyticsCardLift {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 980px) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

.guide-dialog {
  width: min(1220px, 98vw);
  max-height: 96vh;
}

.guide-shell {
  position: relative;
  display: grid;
  gap: 0.85rem;
  padding: 1.2rem;
  background:
    radial-gradient(circle at 12% 10%, rgba(0, 125, 184, 0.2), transparent 34%),
    radial-gradient(circle at 88% 85%, rgba(15, 58, 115, 0.17), transparent 32%),
    linear-gradient(140deg, #f7fbff 0%, #e9f4fb 55%, #f5fbff 100%);
  overflow: hidden;
}

.guide-shell::before {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  right: -90px;
  top: -120px;
  border-radius: 50%;
  background: rgba(0, 125, 184, 0.14);
  filter: blur(2px);
  pointer-events: none;
}

.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.guide-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.guide-brand img {
  width: 110px;
  height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 7px 14px rgba(7, 29, 49, 0.25));
}

.guide-brand h3 {
  margin: 0;
  font-size: 1.05rem;
}

.guide-brand p {
  margin: 0.2rem 0 0;
  color: #35546f;
  font-size: 0.88rem;
}

.guide-track-tabs {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0.3rem;
  border: 1px solid rgba(145, 175, 200, 0.58);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.76);
  width: fit-content;
}

.guide-track-btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.34rem 0.68rem;
  background: transparent;
  color: #35546f;
  font-weight: 700;
  cursor: pointer;
}

.guide-track-btn.is-active {
  color: #ffffff;
  background: linear-gradient(125deg, #00a1e1 0%, #0f3a73 100%);
  box-shadow: 0 9px 16px rgba(7, 29, 49, 0.18);
}

.guide-progress {
  display: grid;
  gap: 0.35rem;
}

.guide-progress span {
  font-size: 0.82rem;
  color: #35546f;
  font-weight: 700;
}

.guide-progress-bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(150, 184, 210, 0.44);
  overflow: hidden;
}

#guideProgressFill {
  display: block;
  width: 25%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #00a1e1 0%, #0f3a73 100%);
  transition: width 0.28s ease;
}

.guide-slide {
  display: none;
}

.guide-slide.is-active {
  display: block;
  animation: guideReveal 0.32s ease;
}

@keyframes guideReveal {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.guide-card {
  border: 1px solid rgba(142, 176, 203, 0.55);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.75rem;
  box-shadow: 0 12px 22px rgba(7, 29, 49, 0.08);
}

.guide-card h4 {
  margin: 0 0 0.5rem;
  color: #0f3a73;
  font-size: 0.95rem;
}

.guide-card p {
  margin: 0;
  color: #26445e;
  font-size: 0.87rem;
  line-height: 1.45;
}

.guide-card ul {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.28rem;
  color: #26445e;
  font-size: 0.87rem;
  line-height: 1.4;
}

.guide-card-primary {
  background: linear-gradient(150deg, rgba(0, 125, 184, 0.13) 0%, rgba(255, 255, 255, 0.96) 75%);
}

.guide-card-highlight {
  background: linear-gradient(150deg, rgba(15, 58, 115, 0.12) 0%, rgba(255, 255, 255, 0.96) 78%);
}

.guide-stat-card strong {
  display: inline-block;
  margin-bottom: 0.4rem;
  color: #0f3a73;
}

.guide-metric-card {
  background: linear-gradient(145deg, rgba(13, 70, 135, 0.12) 0%, rgba(255, 255, 255, 0.95) 78%);
}

.guide-kpi-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.guide-kpi-row div {
  border: 1px solid rgba(140, 176, 203, 0.6);
  border-radius: 10px;
  padding: 0.52rem;
  background: rgba(255, 255, 255, 0.88);
  display: grid;
  gap: 0.22rem;
}

.guide-kpi-row strong {
  color: #0f3a73;
  font-size: 1.05rem;
}

.guide-kpi-row span {
  color: #35546f;
  font-size: 0.8rem;
  line-height: 1.3;
}

.guide-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  border-top: 1px solid rgba(148, 177, 201, 0.58);
  padding-top: 0.72rem;
}

.guide-actions {
  display: flex;
  gap: 0.45rem;
}

.guide-footer small {
  color: #496781;
  font-size: 0.8rem;
}

@media (max-width: 760px) {
  .guide-head {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .guide-kpi-row {
    grid-template-columns: 1fr;
  }

  .guide-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}
