/*
 * base.css — App shell and global defaults.
 * Load after tokens.css.
 */

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

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto,
             "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- App bar (bottom navigation) ---------- */

.app-bar {
  flex: 0 0 auto;
  z-index: 10;
  height: var(--app-bar-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.brand {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.brand__version {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  padding: 2px 7px;
  border-radius: 999px;
  vertical-align: middle;
  position: relative;
  top: -1px;
  overflow: hidden;
  animation: version-glow 3s ease-in-out infinite;
}

.brand__version::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: version-shimmer 4s ease-in-out infinite;
}

@keyframes version-glow {
  0%, 100% { box-shadow: 0 0 4px rgba(168, 85, 247, 0.25); }
  50% { box-shadow: 0 0 12px rgba(168, 85, 247, 0.5); }
}

@keyframes version-shimmer {
  0% { left: -100%; }
  40% { left: 100%; }
  100% { left: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .brand__version {
    animation: none;
  }
  .brand__version::after {
    animation: none;
    display: none;
  }
}

.app-bar__quote {
  font-size: 0.8125rem;
  font-style: italic;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 1.5s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
  margin-left: auto;
}

.app-bar__quote--visible {
  opacity: 1;
}

/* Keyboard-shortcuts help button (desktop only; hidden on mobile) */
.app-bar__help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.app-bar__help-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Keyboard-shortcuts help popover (anchored above the app bar, right side) */
.shortcuts-help {
  position: fixed;
  bottom: calc(var(--app-bar-h) + 12px);
  right: 24px;
  z-index: 30;
  min-width: 260px;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.18));
  padding: 12px 14px;
}

.shortcuts-help[hidden] { display: none; }

.shortcuts-help__title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.shortcuts-help__list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shortcuts-help__row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8125rem;
}

.shortcuts-help__key {
  min-width: 22px;
  text-align: center;
  padding: 1px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--text);
}

.shortcuts-help__label { color: var(--text); }

.shortcuts-help__close {
  margin-top: 10px;
  width: 100%;
  padding: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.8125rem;
}

.shortcuts-help__close:hover {
  color: var(--text);
  border-color: var(--accent);
}


/* ---------- Panels (tab content) ---------- */

.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  /* Setting overflow-y: auto implicitly makes overflow-x compute to `auto`,
   * so a panel would scroll horizontally whenever any child is wider than the
   * viewport (dragging the whole header + body with it). Clip horizontal
   * overflow here; views that genuinely need to scroll do so in their own
   * inner scroller (e.g. the day timeline). */
  overflow-x: hidden;
}

.panel__title {
  margin: 0 0 20px;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.panel__placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.panel__placeholder h2 {
  margin: 0 0 8px;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
}

.panel__placeholder p {
  margin: 0;
  font-size: 0.875rem;
}

/* ---------- Settings ---------- */

.settings__section {
  margin-bottom: 24px;
}

.settings__section-title {
  margin: 0 0 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.settings__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.settings__row:last-child {
  border-bottom: none;
}

.settings__label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.settings__theme-toggle {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  font-size: 0.875rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.settings__theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.settings__theme-toggle:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.settings__btn--danger {
  color: var(--danger, #ef4444);
  border-color: var(--danger, #ef4444);
}

/* Multiple actions in one settings row (e.g. Export + Import) */
.settings__actions {
  display: flex;
  gap: 8px;
}

.settings__btn--danger:hover {
  color: #fff;
  background: var(--danger, #ef4444);
  border-color: var(--danger, #ef4444);
}

/* Settings hint text */
.settings__hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: -4px 0 8px;
}

/* Settings input (for lat/lng) */
.settings__input {
  width: 120px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
}

.settings__input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Selects (e.g. mobile-nav style) need a little more width than text inputs
 * so the full option label is visible without truncation. */
.settings__select {
  width: 170px;
  cursor: pointer;
}

/* Settings value (for sync status, etc.) */
.settings__value {
  font-size: 0.875rem;
  color: var(--text);
  font-weight: 500;
}

/* Sync widget container — center the RemoteStorage connect widget */
#sync-widget-container {
  display: flex;
  justify-content: center;
  margin: 8px 0;
}

/* Cap the widget's z-index so it doesn't cover our overlays (changelog,
   welcome messages, etc). The widget injects z-index: 21000000 by default. */
.rs-connect,
.rs-modal,
.rs-backdrop {
  z-index: 500 !important;
}

/* Sync profile picker options (buttons in the overlay) */
.sync-profile-option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin: 4px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.sync-profile-option:hover {
  border-color: var(--accent);
  background: var(--surface-hover, rgba(0,0,0,0.04));
}

/* Poll interval + test-push inputs (narrower than the default settings input) */
#sync-poll-interval,
#push-test-seconds {
  width: 70px;
}

/* ---------- About ---------- */
.about {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.about__version {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}

.about__release-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.about__section-heading {
  margin: 8px 0 2px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.about__items {
  margin: 0;
  padding-left: 18px;
  font-size: 0.8125rem;
  color: var(--text);
  line-height: 1.5;
}

.about__items li {
  margin: 2px 0;
}

.about__toggle {
  align-self: flex-start;
  margin-top: 4px;
}

/* ---------- Content ---------- */

.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

/* ---------- Welcome-back freeze toast ---------- */
.welcome-back {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 1000;
  max-width: 90%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  font-size: 0.9rem;
  line-height: 1.4;
}
.welcome-back__msg { margin-bottom: 10px; }
.welcome-back__actions { display: flex; gap: 8px; }
.welcome-back__btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}
.welcome-back__btn--primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Phase 5 "delight": confetti + celebration toast (goal-confetti.js) ---------- */
/* A burst is a zero-size fixed point at the anchor; particles radiate from it. */
.celebrate-burst {
  position: fixed;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 10000;
}
.celebrate-p {
  position: absolute;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  opacity: 0;
  animation: celebrate-pop var(--d, 0.9s) ease-out forwards;
}
@keyframes celebrate-pop {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  70% { opacity: 1; }
  100% {
    transform: translate(var(--dx, 0), var(--dy, -80px)) rotate(var(--rot, 360deg));
    opacity: 0;
  }
}

/* Non-blocking celebration toast (bottom-centre, auto-dismisses). Distinct
   from the undo toast, which carries an action button. */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10001;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.app-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* PWA install banner */
.install-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 9000;
  font-size: 0.8125rem;
  color: var(--text);
}

.install-banner__btn {
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--on-accent, #fff);
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  cursor: pointer;
}

.install-banner__btn:hover {
  opacity: 0.9;
}

.install-banner__dismiss {
  font: inherit;
  font-size: 0.875rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
}

.install-banner__dismiss:hover {
  color: var(--text);
}

.install-banner--update {
  border-color: var(--success, #22c55e);
}

.install-banner--update .install-banner__btn {
  background: var(--success, #22c55e);
}
