*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --green: #16a34a;
  --red: #dc2626;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6e9ef;
  --bg: #f6f7fb;
  --nav-h: 64px;
  --radius: 12px;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  background-image: radial-gradient(circle at 12% -10%, #e8efff 0%, rgba(232, 239, 255, 0) 45%);
  overflow-wrap: break-word;
}

.hidden {
  display: none !important;
}

.center {
  text-align: center;
}

h1 {
  font-size: 1.375rem;
  margin: 0 0 4px;
}

h2 {
  font-size: 1.0625rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.optional {
  font-weight: 500;
  color: var(--muted);
}

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

.small {
  font-size: 0.8125rem;
}

/* ---------- forms ---------- */

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #334155;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: #fbfcfe;
  border: 1px solid #dfe3ea;
  border-radius: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2364748b'%3E%3Cpath d='M4.2 6.2a1 1 0 0 1 1.4 0L8 8.6l2.4-2.4a1 1 0 1 1 1.4 1.4l-3.1 3.1a1 1 0 0 1-1.4 0L4.2 7.6a1 1 0 0 1 0-1.4Z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}

input:focus,
select:focus {
  outline: none;
  background: #fff;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

button {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 13px 16px;
  min-height: 46px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  border: 1px solid transparent;
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.28);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.15s ease, transform 0.05s ease;
}

button:hover {
  filter: brightness(1.05);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
  filter: none;
}

.btn-secondary {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #c7d7fe;
  box-shadow: none;
}

.btn-success {
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  box-shadow: 0 1px 2px rgba(22, 163, 74, 0.28);
}

.btn-ghost {
  color: #475569;
  background: #fff;
  border-color: var(--line);
  box-shadow: none;
}

.btn-ghost-danger {
  color: #b91c1c;
  border-color: #fbd5d5;
}

.link-btn {
  display: inline;
  width: auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  font-size: inherit;
  font-weight: 600;
  color: var(--blue);
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link-btn:hover {
  color: var(--blue-dark);
  filter: none;
}

.card {
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 18px 32px -28px rgba(15, 23, 42, 0.5);
}

.card + .card {
  margin-top: 14px;
}

.card-head {
  margin-bottom: 6px;
}

.card-sub {
  margin: 4px 0 0;
  font-size: 0.8438rem;
  color: var(--muted);
}

.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 0.875rem;
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
}

.notice {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 0.875rem;
  color: #1e40af;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
}

/* ---------- login ---------- */

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 0;
}

.login-card {
  width: 100%;
  max-width: 390px;
  padding: 26px 22px;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: 14px;
  box-shadow: 0 8px 18px -8px rgba(37, 99, 235, 0.7);
}

.login-card h1 {
  text-align: center;
}

.login-card #loginSubtitle {
  margin: 4px 0 18px;
}

.switch-line {
  margin: 12px 0 0;
  font-size: 0.875rem;
  text-align: center;
  color: var(--muted);
}

/* ---------- app shell ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 -16px 14px;
  padding: 10px 16px;
  background: rgba(246, 247, 251, 0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(230, 233, 239, 0.9);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

/* ---------- profile menu ---------- */

.profile {
  position: relative;
  min-width: 0;
}

.profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  min-height: 40px;
  margin: 0;
  padding: 4px 10px 4px 4px;
  font-size: 0.8438rem;
  font-weight: 600;
  color: #334155;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.profile-btn:hover {
  background: #fff;
  border-color: #cbd5e1;
  filter: none;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  border-radius: 50%;
}

.avatar-lg {
  width: 40px;
  height: 40px;
  font-size: 0.875rem;
}

.profile-email {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chev {
  font-size: 0.625rem;
  color: var(--muted);
}

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  width: 260px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 40px -20px rgba(15, 23, 42, 0.45), 0 2px 6px rgba(15, 23, 42, 0.06);
  animation: menu-in 0.13s ease-out;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.menu-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 12px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.menu-id {
  min-width: 0;
}

.menu-id strong {
  display: block;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-item {
  width: 100%;
  margin: 0;
  padding: 10px 10px;
  min-height: 40px;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: left;
  color: #334155;
  background: none;
  border: none;
  border-radius: 9px;
  box-shadow: none;
}

.menu-item:hover {
  background: #f1f5f9;
  filter: none;
}

.menu-item-danger {
  color: #b91c1c;
}

.menu-item-danger:hover {
  background: #fef2f2;
}

.container {
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- nav: bottom bar on mobile, sidebar on desktop ---------- */

.nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: flex;
  gap: 4px;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.nav-item {
  flex: 1 1 0;
  width: auto;
  min-height: 48px;
  margin: 0;
  padding: 8px 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 10px;
  box-shadow: none;
  text-align: center;
}

.nav-item:hover {
  color: var(--ink);
  background: #f1f5f9;
  filter: none;
}

.nav-item.active {
  color: var(--blue);
  background: var(--blue-soft);
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  margin: 12px 0 6px;
  padding: 4px;
  background: #f1f4f9;
  border-radius: 12px;
}

.tab-btn {
  flex: 1 1 0;
  width: auto;
  min-height: 40px;
  margin: 0;
  padding: 8px 6px;
  font-size: 0.8438rem;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 9px;
  box-shadow: none;
}

.tab-btn:hover {
  color: var(--ink);
  filter: none;
}

.tab-btn.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.pin-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
}

.pin-line .link-btn {
  font-size: 0.8125rem;
}

.pin-line:empty {
  display: none;
}

.route-result {
  margin: 12px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.route-result strong {
  color: var(--ink);
}

/* ---------- vehicles ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  min-height: 38px;
  margin: 0;
  padding: 8px 14px;
  font-size: 0.8438rem;
  font-weight: 600;
  color: #334155;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: none;
}

.chip:hover {
  border-color: #cbd5e1;
  filter: none;
}

.chip.active {
  color: var(--blue-dark);
  background: var(--blue-soft);
  border-color: #bfd3fe;
}

.chip-tag {
  padding: 1px 7px;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #15803d;
  background: #dcfce7;
  border-radius: 999px;
}

.check-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  margin-top: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 6px 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
  border-bottom: 1px solid #f1f4f9;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
}

.move-group {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  min-height: 0;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1;
  font-weight: 600;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
}

.icon-btn:disabled {
  opacity: 0.35;
}

.check-row input[type="checkbox"] {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  accent-color: var(--blue);
  border-radius: 5px;
}

.mileage-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 0.8125rem;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid #eef2f7;
  border-radius: 10px;
}

.hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--muted);
}

.mileage-line strong {
  font-size: 0.9375rem;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn-row button {
  flex: 1 1 0;
  width: auto;
  margin-top: 0;
}

/* ---------- table ---------- */

.export-block {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.section-label {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #334155;
}

.summary {
  margin: 0 0 12px;
  font-size: 0.9375rem;
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  white-space: nowrap;
}

th,
td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid #f1f4f9;
}

th {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.claim-col {
  width: 46px;
  text-align: center;
}

.claim-box {
  width: 20px;
  height: 20px;
  margin: 0;
  padding: 0;
  cursor: pointer;
  accent-color: var(--blue);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td {
  border-bottom: none;
}

td button {
  width: auto;
  min-height: 0;
  margin: 0;
  padding: 5px 10px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--red);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  box-shadow: none;
}

td button:hover {
  background: #fee2e2;
  filter: none;
}

/* ---------- toast ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  width: 100%;
  max-width: 430px;
  padding: 22px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 60px -20px rgba(15, 23, 42, 0.5);
}

.mode-option {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 16px;
  text-align: left;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: none;
}

.mode-option strong {
  display: block;
  margin-bottom: 2px;
  font-size: 0.9375rem;
}

.mode-option span {
  display: block;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--muted);
}

.mode-option:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  font-size: 0.8438rem;
  font-weight: 500;
  color: #fff;
  background: #0f172a;
  border-radius: 999px;
  box-shadow: 0 10px 24px -10px rgba(15, 23, 42, 0.7);
}

.toast.toast-error {
  background: var(--red);
}

/* ---------- desktop ---------- */

@media (min-width: 900px) {
  body {
    padding: 0 32px 48px 300px;
  }

  .topbar {
    margin: 0 -32px 18px;
    padding: 12px 32px;
  }

  .nav {
    top: 0;
    right: auto;
    gap: 4px;
    width: 260px;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    padding: 22px 14px;
    background: #fff;
    border-top: none;
    border-right: 1px solid var(--line);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .nav-item {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 11px 14px;
    font-size: 0.9375rem;
    text-align: left;
  }

  .container {
    margin: 0;
    max-width: 1120px;
  }

  #view-add,
  #view-settings {
    max-width: 760px;
  }

  table,
  th,
  td {
    white-space: normal;
  }

  th.num,
  td.num {
    white-space: nowrap;
  }

  .toast {
    bottom: 24px;
  }


  .menu {
    width: 280px;
  }

  .profile-email {
    max-width: 240px;
  }
}

@media (max-width: 640px) {
  .profile-email {
    display: none;
  }

  .profile-btn {
    padding: 4px;
  }

  .chev {
    padding-right: 4px;
  }
}

@media (max-width: 420px) {
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .btn-row {
    flex-direction: column;
  }


  .tab-btn {
    font-size: 0.75rem;
    padding: 8px 4px;
  }
}

@media (max-width: 359px) {
  body {
    padding-left: 12px;
    padding-right: 12px;
  }

  .nav-item,
  .tab-btn {
    font-size: 0.6875rem;
  }

  th,
  td {
    padding: 8px 6px;
  }
}

@media (max-width: 640px) {
  .table-wrap {
    overflow-x: visible;
  }

  .stack-table thead {
    display: none;
  }

  .stack-table,
  .stack-table tbody {
    display: block;
  }

  .stack-table tr {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 10px;
    padding: 7px 0;
    border-bottom: 1px solid #eef2f8;
  }

  .stack-table tbody tr:last-child {
    border-bottom: none;
  }

  .stack-table td {
    padding: 0;
    border: none;
    white-space: normal;
    text-align: left;
    line-height: 1.35;
  }

  .stack-table td.cell-dest,
  .stack-table td.cell-end {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .stack-table td.cell-distance {
    order: 2;
    flex: 0 0 auto;
    margin-left: auto;
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--blue);
    white-space: nowrap;
  }

  .stack-table td.cell-distance::after {
    content: "km";
    margin-left: 1px;
    font-size: 0.75rem;
    font-weight: 600;
  }

  .stack-table td.cell-date {
    order: 3;
    font-size: 0.6875rem;
    color: var(--muted);
  }

  .stack-table td.cell-claimed {
    order: 4;
    width: auto;
    margin-left: auto;
  }

  .stack-table td.cell-startodo,
  .stack-table td.cell-endodo,
  .stack-table td.cell-odometer,
  .stack-table td.cell-start {
    order: 5;
    font-size: 0.6875rem;
    color: var(--muted);
  }

  .stack-table td.cell-purpose,
  .stack-table td.cell-category,
  .stack-table td.cell-vehicle {
    order: 6;
    font-size: 0.6875rem;
    color: var(--muted);
  }

  .stack-table td.cell-del {
    order: 7;
    margin-left: auto;
  }

  .stack-table td.cell-notes {
    order: 8;
    flex: 1 0 100%;
    overflow: hidden;
    font-size: 0.6875rem;
    color: var(--muted);
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .stack-table td button {
    padding: 3px 8px;
    font-size: 0.75rem;
  }

  .stack-table td[data-label]:not(.cell-date):not(.cell-dest):not(.cell-end):not(.cell-distance):not(.cell-claimed)::before {
    content: attr(data-label) " ";
    font-weight: 700;
  }
}