:root {
  --bg: #f3f7f9;
  --surface: #ffffff;
  --surface-2: #eaf2f6;
  --text: #142936;
  --muted: #627481;
  --line: #d6e2e8;
  --accent: #237f9d;
  --accent-2: #163c54;
  --warn: #a05d1c;
  --danger: #a23d42;
  --success: #207a4b;
  --surface-muted: #f7fafb;
  --shadow: 0 12px 32px rgba(12, 33, 45, 0.09);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: #fbfdfe;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 62px;
}

.brand-logo {
  display: block;
  width: 100%;
  max-width: 226px;
  height: auto;
  object-fit: contain;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item,
.ghost-button,
.primary-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

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

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.ghost-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.ghost-button:hover {
  border-color: #bac7bd;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 760;
}

.primary-button:hover {
  background: #1b6c87;
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #9bb4c0;
}

.primary-button.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.ghost-button.small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.icon-button {
  width: 36px;
  padding: 0;
  background: var(--surface-2);
  border-color: var(--line);
}

.workspace {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 690;
  white-space: nowrap;
}

.status-pill.online {
  color: var(--accent);
  border-color: #aad6e3;
  background: #edf8fb;
}

.status-pill.error {
  color: var(--danger);
  border-color: #ecc4c4;
  background: #fff2f2;
}

.auth-panel,
.surface,
.message-bar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: 18px;
  margin-bottom: 18px;
}

.auth-panel.hidden {
  display: none;
}

.auth-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(200px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(35, 127, 157, 0.12);
}

.message-bar {
  padding: 12px 14px;
  margin-bottom: 18px;
  color: var(--muted);
}

.message-bar.error {
  color: var(--danger);
  border-color: #ecc4c4;
  background: #fff8f8;
}

.message-bar.success {
  color: var(--accent);
  border-color: #b8dce7;
  background: #f0f8fb;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metric-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
}

.metric-label {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.two-column,
.race-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.surface {
  padding: 16px;
  min-width: 0;
}

.embedded-surface {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: none;
}

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

.view-toolbar p {
  margin-top: 5px;
}

.training-detail {
  margin-top: 16px;
}

.gps-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 14px;
}

.gps-map-column {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.gps-map-card {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf8;
}

.maplibre-map {
  position: absolute;
  inset: 0;
  min-height: 360px;
}

.replay-controls {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.replay-controls[hidden] {
  display: none;
}

.replay-actions,
.replay-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.replay-actions {
  flex-wrap: wrap;
}

.replay-speed-label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.replay-speed-label select {
  width: auto;
  min-width: 74px;
  padding: 7px 28px 7px 9px;
}

.replay-progress {
  width: 100%;
  accent-color: var(--accent);
}

.replay-status {
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.replay-status strong {
  color: var(--ink);
}

.live-dashboard {
  display: grid;
  grid-template-columns: minmax(250px, 0.34fr) minmax(460px, 1fr);
  gap: 14px;
  align-items: start;
}

.live-session-list {
  display: grid;
  gap: 9px;
}

.live-session-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.live-session-item.active {
  border-color: var(--accent);
  background: #eef8f3;
}

.live-session-item span,
.live-session-item small {
  color: var(--muted);
}

.live-session-state {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--success);
  font-size: 11px;
  font-weight: 800;
}

.live-status-badge {
  padding: 6px 9px;
  border: 1px solid #b8dfca;
  border-radius: 999px;
  background: #eef8f3;
  color: var(--success);
  font-size: 11px;
  font-weight: 800;
}

.live-status-badge.stale {
  border-color: #f0c4c0;
  background: #fff4f3;
  color: var(--danger);
}

.live-map-wrap {
  position: relative;
  min-height: 430px;
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf4f7;
}

.live-map,
.live-map-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 430px;
}

.live-map-svg {
  display: block;
}

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

.live-stat-grid article {
  display: grid;
  gap: 5px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.live-stat-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

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

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

.gps-map {
  display: block;
  width: 100%;
  min-height: 360px;
}

.gps-label {
  fill: var(--text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.gps-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(234, 242, 246, 0.9));
}

.gps-empty[hidden] {
  display: none;
}

.gps-stats {
  display: grid;
  gap: 10px;
  align-content: start;
}

.mini-stat {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mini-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0;
}

.mini-stat strong {
  font-size: 18px;
}

.comparison-panel h3 {
  margin: 0;
  font-size: 16px;
}

.comparison-list {
  display: grid;
  gap: 8px;
}

.comparison-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) repeat(4, minmax(92px, 1fr));
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.comparison-row:first-child {
  border-top: 0;
}

.comparison-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.comparison-row strong {
  display: block;
  margin-top: 2px;
}

.detail-list {
  display: grid;
  gap: 10px;
}

.detail-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.detail-row:first-child {
  border-top: 0;
}

.detail-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.detail-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.table-shell {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-shell.embedded {
  box-shadow: none;
}

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

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #fafbfa;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

td {
  font-size: 14px;
}

tbody tr:hover {
  background: #f7fbfd;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.tag.good {
  color: var(--accent);
  background: #eaf7fb;
}

.tag.warn {
  color: var(--warn);
  background: #fff5eb;
}

.notification-list {
  display: grid;
  gap: 12px;
}

.notification {
  padding: 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.notification-title {
  font-weight: 760;
}

.notification-body {
  margin-top: 6px;
  color: var(--muted);
}

.settings-dialog {
  width: min(560px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.wide-dialog {
  width: min(760px, calc(100vw - 28px));
}

.settings-dialog::backdrop {
  background: rgba(12, 33, 45, 0.38);
}

.settings-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

#shareDogsDialog {
  max-height: calc(100vh - 28px);
  overflow: hidden;
}

#shareDogsDialog .settings-card {
  max-height: calc(100vh - 28px);
  overflow-y: auto;
}

.dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.beta-note {
  padding: 12px;
  border: 1px solid #b8dce7;
  border-radius: 8px;
  background: #f0f8fb;
  color: var(--accent);
  font-size: 13px;
  font-weight: 680;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.plan-card {
  position: relative;
  display: grid;
  gap: 8px;
  align-content: start;
  min-height: 230px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.plan-card:hover {
  border-color: #bac7bd;
}

.plan-card:has(input:checked) {
  border-color: #a5d5e4;
  background: #f5fbfd;
  box-shadow: 0 0 0 3px rgba(35, 127, 157, 0.12);
}

.plan-card input {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 18px;
  height: 18px;
}

.plan-title {
  padding-right: 26px;
  font-size: 16px;
  font-weight: 800;
}

.plan-price {
  color: var(--accent);
  font-size: 14px;
  font-weight: 760;
}

.plan-summary {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.plan-feature-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.plan-feature-list li::before {
  content: "- ";
}

.plan-current {
  align-self: end;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.dog-photo-field {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.dog-photo-preview {
  width: 112px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-align: center;
}

.dog-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dog-sharing-panel h3 {
  margin: 0;
  font-size: 16px;
}

.share-list {
  display: grid;
  gap: 8px;
}

.share-user-search,
.share-user-results {
  display: grid;
  gap: 8px;
}

.share-user-result,
.share-user-selected {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.share-user-result {
  cursor: pointer;
}

.share-user-result:hover,
.share-user-result:focus-visible,
.share-user-selected {
  border-color: var(--accent);
  background: #f0f8fb;
}

.share-user-result small,
.share-user-selected small {
  color: var(--muted);
}

.share-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(180px, 1fr) minmax(90px, auto) minmax(140px, auto) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.share-row:first-child {
  border-top: 0;
}

.share-row strong,
.share-row span {
  overflow-wrap: anywhere;
}

.share-dog-fieldset {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.share-dog-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.share-dog-selection {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.share-dog-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.share-dog-option:has(input:checked) {
  border-color: #a5d5e4;
  background: #f5fbfd;
}

.share-dog-option input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--accent);
}

.share-dog-option span {
  display: grid;
  min-width: 0;
}

.share-dog-option strong,
.share-dog-option small {
  overflow-wrap: anywhere;
}

.share-dog-option small {
  color: var(--muted);
}

.field-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
}

.selection-list {
  display: grid;
  gap: 8px;
}

.dog-pick-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 130px 110px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.dog-pick-row.selected {
  border-color: #a5d5e4;
  background: #f5fbfd;
}

.activity-dog {
  display: grid;
  gap: 2px;
}

.activity-dog + .activity-dog {
  margin-top: 7px;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.table-action {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  font-weight: 690;
}

.table-action:hover {
  border-color: #bac7bd;
  background: #f7fbfd;
}

.empty-state {
  color: var(--muted);
  padding: 22px;
}

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

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .metric-grid,
  .two-column,
  .race-layout,
  .gps-layout,
  .form-grid,
  .form-grid.two-fields,
  .plan-grid,
  .checkbox-grid,
  .dog-photo-field,
  .share-dog-selection,
  .share-row,
  .dog-pick-row {
    grid-template-columns: 1fr;
  }

  .replay-speed-label {
    margin-left: 0;
  }

  .topbar {
    display: grid;
  }

  .panel-header {
    align-items: flex-start;
  }

  .panel-actions {
    justify-content: flex-start;
  }

  .view-toolbar {
    display: grid;
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 18px;
  }

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

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
