/* ===========================
   CSS Custom Properties
   =========================== */
:root {
  --bg-primary: #0a0f1e;
  --bg-secondary: #0f172a;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-hover: rgba(255, 255, 255, 0.10);
  --border: rgba(255, 255, 255, 0.10);
  --border-glow: rgba(99, 179, 237, 0.3);

  --accent-1: #38bdf8;
  --accent-2: #818cf8;
  --accent-3: #34d399;
  --accent-warn: #f59e0b;
  --accent-error: #f87171;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --shadow-glow: 0 0 40px rgba(56, 189, 248, 0.15);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);

  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ===========================
   Background Orbs
   =========================== */
.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  animation: float 8s ease-in-out infinite;
}

.orb-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #1e40af 0%, transparent 70%);
  top: -20%;
  left: -10%;
  animation-delay: 0s;
}

.orb-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #5b21b6 0%, transparent 70%);
  top: 30%;
  right: -15%;
  animation-delay: -3s;
}

.orb-3 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, #065f46 0%, transparent 70%);
  bottom: -10%;
  left: 20%;
  animation-delay: -5s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(20px, -20px) scale(1.05); }
  66% { transform: translate(-10px, 15px) scale(0.97); }
}

/* ===========================
   Layout
   =========================== */
.container {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  gap: 24px;
}

/* ===========================
   Header
   =========================== */
.header {
  padding-top: 8px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  font-size: 2.5rem;
  filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.6));
  animation: pulse-icon 2s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.6)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 20px rgba(56, 189, 248, 0.9)); }
}

.logo-text h1 {
  font-size: 1.75rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-1) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}

.logo-text p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: 2px;
}

/* ===========================
   Main
   =========================== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===========================
   Glass Card
   =========================== */
.card.glass {
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px 28px;
  box-shadow: var(--shadow-card);
  transition: var(--transition);
  min-height: 260px;
}

.card.glass:hover {
  border-color: var(--border-glow);
  box-shadow: var(--shadow-card), var(--shadow-glow);
}

.card-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
}

/* ===========================
   State: Idle
   =========================== */
.idle-state,
.loading-state,
.result-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  width: 100%;
}

.idle-state h2,
.loading-state h2,
.result-state h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.idle-state p,
.loading-state p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 280px;
}

/* Pulse ring animation */
.pulse-ring {
  position: relative;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.pulse-ring::before,
.pulse-ring::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--accent-1);
  animation: ripple 2s ease-out infinite;
}

.pulse-ring::after {
  animation-delay: 0.5s;
}

@keyframes ripple {
  0% { width: 30px; height: 30px; opacity: 1; }
  100% { width: 72px; height: 72px; opacity: 0; }
}

.pulse-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.8);
}

/* ===========================
   State: Loading
   =========================== */
.spinner-wrapper {
  position: relative;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.spinner {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--accent-1);
  border-right-color: var(--accent-2);
  animation: spin 1s linear infinite;
}

.spinner-icon {
  font-size: 1.8rem;
  animation: counter-spin 2s linear infinite;
}

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

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

/* ===========================
   State: Result
   =========================== */
.result-icon {
  font-size: 2.5rem;
  margin-bottom: 4px;
  animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop-in {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.coords-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  margin-top: 8px;
}

.coord-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.coord-item:last-child {
  grid-column: 1 / -1;
}

.coord-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.coord-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-1);
  font-variant-numeric: tabular-nums;
}

.coord-value.small {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 400;
}

/* ===========================
   State: Error
   =========================== */
.error-icon {
  font-size: 2.5rem;
  margin-bottom: 4px;
}

.error-state h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-error);
}

.error-state p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 280px;
  line-height: 1.6;
}

/* ===========================
   Buttons
   =========================== */
.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 28px;
  border: none;
  border-radius: var(--radius-lg);
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  opacity: 0;
  transition: opacity 0.2s;
}

.btn:hover::after { opacity: 1; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled::after { display: none; }

.btn-primary {
  background: linear-gradient(135deg, #1d4ed8 0%, #7c3aed 100%);
  color: white;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 28px rgba(99, 102, 241, 0.6);
  transform: translateY(-2px);
}

.btn-secondary {
  background: linear-gradient(135deg, #065f46 0%, #0f766e 100%);
  color: white;
  box-shadow: 0 4px 20px rgba(20, 184, 166, 0.3);
}

.btn-secondary:hover:not(:disabled) {
  box-shadow: 0 6px 28px rgba(20, 184, 166, 0.5);
  transform: translateY(-2px);
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-icon {
  font-size: 1.2rem;
}

/* ===========================
   Map Preview
   =========================== */
.map-preview {
  border-radius: var(--radius-xl);
  overflow: hidden;
  border: 1px solid var(--border);
  height: 320px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
  animation: slide-up 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.map-header {
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.map-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: var(--transition);
}

.map-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

/* ===========================
   History Section
   =========================== */
.history-section {
  margin-top: 12px;
  animation: fade-in 0.6s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 0 4px;
}

.history-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-title::before {
  content: '🕒';
  font-size: 1.2rem;
}

.btn-text-only {
  background: none;
  border: none;
  color: var(--accent-1);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.btn-text-only:hover {
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-1);
}

.history-empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
  animation: slide-in-left 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slide-in-left {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.history-item:hover {
  background: var(--surface-hover);
  border-color: var(--accent-1);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.history-item-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
}

.history-item-icon {
  font-size: 1.25rem;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.history-item-address {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.history-item-arrow {
  color: var(--text-muted);
  font-weight: 700;
  margin-left: auto;
  opacity: 0;
  transition: var(--transition);
  transform: translateX(-5px);
}

.history-item:hover .history-item-arrow {
  opacity: 1;
  transform: translateX(0);
  color: var(--accent-1);
}

.history-item-delete {
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
}

.history-item-delete:hover {
  background: rgba(248, 113, 113, 0.1);
  color: var(--accent-error);
}

/* ===========================
   Footer
   =========================== */
.footer {
  text-align: center;
  padding: 16px 0 8px;
}

.footer p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===========================
   Utilities
   =========================== */
.hidden {
  display: none !important;
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 360px) {
  .coords-grid {
    grid-template-columns: 1fr;
  }
  .coord-item:last-child {
    grid-column: 1;
  }
  .logo-text h1 {
    font-size: 1.4rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
