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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f2f0;
  color: #1a1a1a;
  min-height: 100vh;
}


/* ── Header ── */

.app-header {
  background: #1a1a2e;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-icon {
  font-size: 1.3rem;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

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

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e05c1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

/* ── Tab bar ── */

.tab-bar {
  display: flex;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 8px 0;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.tab-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.tab-btn.active {
  color: #fff;
  box-shadow: inset 0 -2px 0 #e05c1a;
}

/* ── Upload button ── */

.upload-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.upload-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: #fff;
  transition: background 0.15s;
}

.upload-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.clear-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}

.clear-btn:hover {
  background: rgba(255, 60, 40, 0.35);
  border-color: rgba(255, 100, 80, 0.5);
}


/* ── Map view ── */

.map-view {
  width: 100%;
  /* Fill viewport below the sticky header (~58px) and tab bar (~32px). */
  height: calc(100vh - 90px);
  isolation: isolate;
}

/* ── Feed ── */

.feed {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.activity-feed {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.load-more-btn {
  align-self: center;
  padding: 10px 28px;
  border-radius: 20px;
  border: 1px solid #d0d4e8;
  background: #fff;
  color: #3d5cc8;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.load-more-btn:hover {
  background: #eef2ff;
  border-color: #3d5cc8;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
  line-height: 1.8;
}

.empty-state code {
  background: #eee;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ── Activity card ── */

.activity-card {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.card-header {
  padding: 16px 16px 12px;
}

.activity-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.activity-type-badge {
  background: #eef2ff;
  color: #3d5cc8;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.activity-date {
  color: #999;
  font-size: 0.8rem;
}

.s3-badge {
  margin-left: auto;
  font-size: 0.75rem;
  line-height: 1;
}

.s3-synced {
  color: #4caf50;
  opacity: 0.75;
}

.s3-unsynced {
  color: #bbb;
}

.activity-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #111;
  line-height: 1.3;
}

/* ── Map ── */

.leaflet-map {
  height: 200px;
  width: 100%;
  isolation: isolate;
  pointer-events: none;
}

.leaflet-map-large {
  height: 400px;
  pointer-events: auto;
}

.map-no-gps {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7f7f7;
  color: #bbb;
  font-size: 0.82rem;
}

/* ── Activity card — clickable ── */

.activity-card {
  cursor: pointer;
}

.activity-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.13);
  transition: box-shadow 0.15s;
}

/* ── Detail view ── */

.activity-detail {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: #3d5cc8;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0 16px;
  letter-spacing: 0.2px;
}

.back-btn:hover {
  text-decoration: underline;
}

.detail-header {
  background: #fff;
  padding: 16px 16px 12px;
  border-radius: 14px 14px 0 0;
}

.detail-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: #111;
  line-height: 1.3;
}

.detail-title-editable {
  cursor: text;
  border-radius: 4px;
  margin: 0 -4px;
  padding: 0 4px;
  transition: background 0.1s;
}

.detail-title-editable:hover {
  background: #f0f2f0;
}

.detail-title-input {
  font-size: 1.25rem;
  font-weight: 800;
  color: #111;
  line-height: 1.3;
  width: 100%;
  border: none;
  border-bottom: 2px solid #3d5cc8;
  border-radius: 0;
  background: transparent;
  outline: none;
  padding: 0;
  font-family: inherit;
}

/* ── Charts ── */

.chart-section {
  background: #fff;
  padding: 14px 16px 10px;
  border-top: 1px solid #f0f0f0;
}

.chart-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #999;
  margin-bottom: 6px;
}

.line-chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart-tick {
  font-size: 9px;
  fill: #aaa;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Stats bar ── */

.activity-stats {
  display: flex;
  border-top: 1px solid #f0f0f0;
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  gap: 2px;
}

.stat-item + .stat-item {
  border-left: 1px solid #f0f0f0;
}

.detail-device {
  margin: 8px 16px 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.detail-description {
  margin: 12px 16px 0;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  cursor: text;
  border-radius: 4px;
  padding: 4px 6px;
}

.detail-description-editable:hover {
  background: #f0f2f0;
}

.detail-description-empty {
  color: var(--muted);
  font-style: italic;
}

.detail-description-empty:hover {
  background: #f0f2f0;
}

.detail-description-textarea {
  display: block;
  margin: 12px 16px 0;
  width: calc(100% - 32px);
  min-height: 80px;
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.5;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: vertical;
  box-sizing: border-box;
}

/* ── Photo gallery ────────────────────────────────────────────── */

.photo-section {
  padding: 12px 16px;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

@media (max-width: 400px) {
  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.photo-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
}

.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.15s;
}

.photo-thumb:hover {
  transform: scale(1.03);
}

.photo-item-video::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-40%, -50%);
  border-style: solid;
  border-width: 10px 0 10px 18px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.85);
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.4));
}

.photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: none;
}

.photo-item:hover .photo-remove {
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-uploading {
  opacity: 0.6;
}

.photo-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.add-photo-btn {
  margin-top: 8px;
  background: none;
  border: 1px dashed #ccc;
  border-radius: 8px;
  padding: 8px 16px;
  color: #666;
  font-size: 0.85rem;
  cursor: pointer;
  width: 100%;
}

.add-photo-btn:hover {
  border-color: #3d5cc8;
  color: #3d5cc8;
}

/* ── Lightbox ─────────────────────────────────────────────────── */

.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
  touch-action: none;
}

.lightbox-overlay:focus {
  outline: none;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: none;
  font-size: 2rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.lightbox-nav:hover {
  background: rgba(0, 0, 0, 0.7);
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

.lightbox-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: #111;
}

.stat-label {
  font-size: 0.68rem;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ── You view ── */

.you-view {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px;
}

.you-total {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.85rem;
}

.you-summary {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.you-disc-card {
  flex: 1;
  min-width: 100px;
  background: #fff;
  border-radius: 12px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.you-disc-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.you-disc-name {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
}

.you-disc-dist {
  font-size: 1.05rem;
  font-weight: 800;
  color: #111;
}

.you-disc-dur {
  font-size: 0.78rem;
  color: #aaa;
}

.you-year-section {
  margin-bottom: 24px;
}

.you-year-heading {
  font-size: 1rem;
  font-weight: 800;
  color: #555;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.you-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  font-size: 0.82rem;
}

.you-th {
  background: #f8f8f8;
  padding: 8px 12px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #888;
  border-bottom: 1px solid #f0f0f0;
}

.you-th-month {
  width: 48px;
}

.you-month {
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #aaa;
  border-right: 1px solid #f4f4f4;
  white-space: nowrap;
}

.you-cell {
  padding: 6px 12px;
  border-left: 1px solid #f4f4f4;
}

tbody tr + tr .you-month,
tbody tr + tr .you-cell {
  border-top: 1px solid #f7f7f7;
}

.you-cell-dist {
  font-weight: 700;
  color: #111;
}

.you-cell-dur {
  font-size: 0.72rem;
  color: #aaa;
}

.you-cell-empty {
  color: #ddd;
  text-align: center;
}

/* ── Progress banner ── */

.progress-banner {
  background: #1a1a2e;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 32px;
  overflow: hidden;
  transition: height 0.2s ease;
  position: sticky;
  top: 90px;
  z-index: 99;
}

.progress-banner.hidden {
  height: 0;
  padding: 0;
}

.progress-banner.done {
  background: #0d2a1a;
}

.progress-bar {
  flex: 1;
  max-width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #e05c1a;
  border-radius: 2px;
}

.progress-banner.done .progress-fill {
  background: #2ecc71;
}

.progress-label {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ── Toast notifications ── */

.toast-stack {
  position: fixed;
  bottom: 24px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 500;
  pointer-events: none;
}

.toast {
  background: #1a1a2e;
  color: #fff;
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  animation: toast-life 3s ease forwards;
  white-space: nowrap;
}

@keyframes toast-life {
  0%   { opacity: 0; transform: translateX(10px); }
  12%  { opacity: 1; transform: translateX(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}

.toast.error {
  background: #c0392b;
}

/* ── Auth page ── */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f0;
  padding: 24px;
}

.auth-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 32px;
}

.auth-brand .brand-icon {
  font-size: 1.6rem;
}

.auth-brand .brand-name {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #1a1a2e;
}

.auth-tabs {
  display: flex;
  border-bottom: 2px solid #e8e8e8;
  margin-bottom: 28px;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #999;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.auth-tab.active {
  color: #3d5cc8;
  border-bottom-color: #3d5cc8;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
}

.auth-field input {
  padding: 10px 12px;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.auth-field input:focus {
  border-color: #3d5cc8;
}

.auth-error {
  color: #c0392b;
  font-size: 0.88rem;
  background: #fdf0ee;
  border: 1px solid #f5c6c0;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 0;
}

.auth-submit {
  background: #3d5cc8;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.auth-submit:hover:not(:disabled) {
  background: #2f4aad;
}

.auth-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.avatar {
  border: none;
  cursor: pointer;
}
