/* =============================================
   Plane Spotter — Mobile-First Styles
   ============================================= */

:root {
  --color-primary:    #1a73e8;
  --color-header:     #0f4c8f;
  --color-accent:     #ff6d00;
  --color-accent-dk:  #e65100;
  --color-bg:         #f0f4ff;
  --color-surface:    #ffffff;
  --color-text:       #1a1a2e;
  --color-text-muted: #5a6a85;
  --color-border:     #dce6f5;
  --color-danger:     #d32f2f;
  --color-unique:     #43a047;

  --radius:    12px;
  --radius-sm:  8px;
  --shadow:    0 2px 12px rgba(15, 76, 143, 0.12);
  --shadow-lg: 0 6px 24px rgba(15, 76, 143, 0.18);

  --header-h: 72px;
  --tabbar-h: calc(56px + env(safe-area-inset-bottom));

  --tap: 48px;
}

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

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  overscroll-behavior: none;
}

/* ── Auth screen ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 16px;
  background: linear-gradient(160deg, #0f4c8f 0%, #1a73e8 100%);
}

.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-plane-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-header);
}

.auth-toggle {
  display: flex;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.auth-toggle-btn {
  flex: 1;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  padding: 10px 0;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.auth-toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#auth-form input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.2s;
}

#auth-form input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #fff;
}

.auth-submit-btn {
  min-height: var(--tap);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.auth-submit-btn:hover  { background: #1558b0; }
.auth-submit-btn:active { transform: scale(0.97); }

.auth-error {
  font-size: 0.875rem;
  color: var(--color-danger);
  text-align: center;
  min-height: 1.2em;
  line-height: 1.4;
}

/* ── App wrapper ── */
#app {
  min-height: 100dvh;
  padding-top: var(--header-h);
  padding-bottom: var(--tabbar-h);
}

/* ── Offline banner ── */
.offline-banner {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  z-index: 90;
  background: #f59e0b;
  color: #1a1a00;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  padding: 6px 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}

/* Shift main down when offline banner is showing */
.offline-mode main {
  padding-top: calc(16px + 30px);
}

/* ── Header ── */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--header-h);
  padding-top: env(safe-area-inset-top);
  background: var(--color-header);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}

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

.stats {
  display: flex;
  gap: 8px;
}

.stats span {
  background: rgba(255,255,255,0.18);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.15s, background 0.15s;
}

.btn-signout {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  padding: 5px 10px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-signout:hover { background: rgba(255,255,255,0.28); }

/* ── Celebrate animation (new unique type) ── */
@keyframes celebrate {
  0%   { transform: scale(1);    background: rgba(255,255,255,0.18); }
  20%  { transform: scale(1.35); background: rgba(255, 109, 0, 0.85); }
  50%  { transform: scale(1.2);  background: rgba(67, 160, 71, 0.85); }
  80%  { transform: scale(1.1);  background: rgba(255, 109, 0, 0.6); }
  100% { transform: scale(1);    background: rgba(255,255,255,0.18); }
}

.stats span.celebrate {
  animation: celebrate 0.7s ease-in-out;
}

/* ── Pop animation (new card) ── */
@keyframes pop {
  0%   { transform: scale(0.88) translateY(-8px); opacity: 0; }
  60%  { transform: scale(1.04) translateY(2px);  opacity: 1; }
  100% { transform: scale(1)    translateY(0);    opacity: 1; }
}

.card-new {
  animation: pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* ── Main content ── */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Tabs ── */
.tab { display: none; }
.tab.active { display: block; }

/* ── Add form ── */
#add-form {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

#add-form input[type="text"],
#add-form textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.2s;
  resize: none;
}

#add-form input[type="text"]:focus,
#add-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #fff;
}

#add-form button[type="submit"] {
  min-height: var(--tap);
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

#add-form button[type="submit"]:hover   { background: var(--color-accent-dk); }
#add-form button[type="submit"]:active  { transform: scale(0.97); }

/* ── Photo input row ── */
.photo-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-camera {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-camera:hover { background: rgba(26, 115, 232, 0.08); }

.offline-photo-note {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ── Photo preview (in form) ── */
.photo-preview-wrap {
  position: relative;
  display: inline-block;
  align-self: flex-start;
}

.photo-preview-img {
  display: block;
  max-height: 160px;
  max-width: 100%;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.btn-remove-photo {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* ── Sighting cards ── */
#sightings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sighting-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.sighting-card:hover { box-shadow: var(--shadow-lg); }

/* Photo thumbnail — shown above content when present */
.sighting-photo {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
}

/* Content area inside card */
.sighting-body {
  position: relative;
  padding: 14px 48px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sighting-type {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-primary);
}

.sighting-airline {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-accent);
}

.sighting-time {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.sighting-notes {
  font-size: 0.88rem;
  color: var(--color-text);
  margin-top: 4px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  line-height: 1.4;
}


/* ── Pending sync indicator ── */
.sync-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  margin-left: 6px;
  vertical-align: middle;
  flex-shrink: 0;
  title: "Pending sync";
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--color-text-muted);
}

.empty-state .empty-icon {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1rem;
  line-height: 1.5;
}

/* ── Collection grid ── */
#collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.collection-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 16px 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  transition: box-shadow 0.2s, transform 0.15s;
}

.collection-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.collection-card .plane-icon {
  font-size: 2rem;
  line-height: 1;
}

.collection-card .type-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}

.collection-card .count-badge {
  background: var(--color-primary);
  color: #fff;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 36px;
}

.collection-card.top-card .count-badge {
  background: var(--color-accent);
}

/* ── Bottom tab bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  box-shadow: 0 -2px 8px rgba(15, 76, 143, 0.08);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: none;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 8px 0;
  min-height: 56px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn .tab-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.tab-btn.active {
  color: var(--color-primary);
}

/* ── Collection toggle ── */
.collection-toggle {
  display: flex;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--color-surface);
}

.collection-toggle-btn {
  flex: 1;
  min-height: var(--tap);
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.collection-toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
}

/* ── Collection cards — tappable ── */
.collection-card {
  cursor: pointer;
}
.collection-card:active {
  transform: scale(0.96);
}

/* ── Type detail overlay ── */
.type-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.type-detail-sheet {
  background: var(--color-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

.type-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.type-detail-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-primary);
}

.type-detail-count {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.type-detail-close {
  min-width: var(--tap);
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--color-text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.type-detail-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-entry {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  flex-shrink: 0;
}

.detail-photo {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
}

.detail-no-photo {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: 0.82rem;
}

.detail-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-meta-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.detail-date {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
}

.detail-time {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-primary);
  white-space: nowrap;
}

.detail-aircraft {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--color-primary);
}

.detail-airline {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-accent);
}

.detail-notes {
  font-size: 0.88rem;
  color: var(--color-text);
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  line-height: 1.5;
}

/* ── Day navigator ── */
.day-nav {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.day-nav-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  border: none;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--color-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.day-nav-btn:hover:not(:disabled) { background: var(--color-bg); }
.day-nav-btn:disabled { color: var(--color-border); cursor: default; }

.day-nav-label {
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  padding: 0 4px;
}

/* ── Three-dot button ── */
.btn-more {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-more:hover { background: var(--color-bg); }

/* ── Card context menu ── */
.card-menu {
  position: fixed;
  z-index: 400;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
  overflow: hidden;
  min-width: 160px;
}

.card-menu button {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.card-menu button:hover { background: var(--color-bg); }
#card-menu-delete { color: var(--color-danger); }

/* ── Edit sheet form ── */
#edit-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#edit-form input,
#edit-form textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-bg);
  transition: border-color 0.2s;
  resize: none;
}

#edit-form input:focus,
#edit-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: #fff;
}

.edit-current-photo-wrap {
  position: relative;
  display: inline-block;
  align-self: flex-start;
}

.edit-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.confirm-btn-save {
  background: var(--color-primary);
  color: #fff;
}

.confirm-btn-save:hover { background: #1558b0; }

/* ── Confirm dialog ── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.confirm-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 300px;
  box-shadow: var(--shadow-lg);
}

.confirm-msg {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 20px;
  color: var(--color-text);
}

.confirm-buttons {
  display: flex;
  gap: 10px;
}

.confirm-btn {
  flex: 1;
  min-height: var(--tap);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.confirm-btn-cancel {
  background: var(--color-bg);
  color: var(--color-text);
  border: 2px solid var(--color-border);
}

.confirm-btn-ok {
  background: var(--color-danger);
  color: #fff;
}


/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox-img {
  max-width: 96vw;
  max-height: 92vh;
  border-radius: var(--radius-sm);
  object-fit: contain;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* ── Responsive tweaks ── */
@media (min-width: 480px) {
  main { padding: 20px; }
  #collection-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
