/* ============================================================
   CSS Variables
   ============================================================ */
:root {
  --bg:          #f0f4f8;
  --bg-card:     #ffffff;
  --header-bg:   #3584e4;
  --header-text: #ffffff;
  --text:        #1a1a2e;
  --text-sub:    #5c6680;
  --text-muted:  #9aa3b2;
  --accent:      #3584e4;
  --border:      #e2e8f0;
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:   0 4px 18px rgba(0,0,0,0.13);
  --radius:      14px;
  --radius-sm:   8px;
  --panel-w:     320px;
}

/* Auto dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0f0f1a;
    --bg-card:     #1e1e2e;
    --header-bg:   #1a2744;
    --header-text: #e2e8f0;
    --text:        #e2e8f0;
    --text-sub:    #94a3b8;
    --text-muted:  #64748b;
    --accent:      #89b4fa;
    --border:      #2a2a3e;
    --shadow-sm:   0 1px 4px rgba(0,0,0,0.35);
    --shadow-md:   0 4px 18px rgba(0,0,0,0.5);
  }
}

/* Forced dark */
[data-theme="dark"] {
  --bg:          #0f0f1a;
  --bg-card:     #1e1e2e;
  --header-bg:   #1a2744;
  --header-text: #e2e8f0;
  --text:        #e2e8f0;
  --text-sub:    #94a3b8;
  --text-muted:  #64748b;
  --accent:      #89b4fa;
  --border:      #2a2a3e;
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.35);
  --shadow-md:   0 4px 18px rgba(0,0,0,0.5);
}

/* Forced light */
[data-theme="light"] {
  --bg:          #f0f4f8;
  --bg-card:     #ffffff;
  --header-bg:   #3584e4;
  --header-text: #ffffff;
  --text:        #1a1a2e;
  --text-sub:    #5c6680;
  --text-muted:  #9aa3b2;
  --accent:      #3584e4;
  --border:      #e2e8f0;
  --shadow-sm:   0 1px 4px rgba(0,0,0,0.08);
  --shadow-md:   0 4px 18px rgba(0,0,0,0.13);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

.hidden { display: none !important; }
.muted  { color: var(--text-muted); }

/* ============================================================
   Header
   ============================================================ */
.app-header {
  background: var(--header-bg);
  color: var(--header-text);
  height: 56px;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.app-title {
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0.95;
  flex-shrink: 0;
}

.search-wrapper {
  flex: 1;
  max-width: 460px;
  position: relative;
}

.search-container { position: relative; display: flex; align-items: center; }

.search-icon {
  position: absolute;
  left: 10px;
  font-size: 0.8rem;
  pointer-events: none;
  opacity: 0.65;
}

#search-input {
  width: 100%;
  height: 34px;
  padding: 0 1rem 0 2.2rem;
  border: none;
  border-radius: 17px;
  background: rgba(255,255,255,0.22);
  color: var(--header-text);
  font-size: 0.88rem;
  outline: none;
  transition: background 0.2s;
}

#search-input::placeholder { color: rgba(255,255,255,0.6); }
#search-input:focus        { background: rgba(255,255,255,0.32); }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 200;
  max-height: 300px;
  overflow-y: auto;
}

.search-item {
  padding: 0.6rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--text);
  transition: background 0.12s;
  gap: 0.5rem;
}

.search-item:hover { background: var(--bg); }

.search-sub { font-size: 0.77rem; color: var(--text-muted); white-space: nowrap; }

.search-no-results {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  margin-left: auto;
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 5px 7px;
  border-radius: 7px;
  color: var(--header-text);
  opacity: 0.85;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1;
}

.btn-icon:hover { opacity: 1; background: rgba(255,255,255,0.18); }

/* ============================================================
   Main
   ============================================================ */
main {
  flex: 1;
  padding: 1.5rem 1rem 2.5rem;
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
}

/* ============================================================
   Placeholder
   ============================================================ */
.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  text-align: center;
  opacity: 0.45;
}

.placeholder-icon { font-size: 4.5rem; margin-bottom: 1rem; }
.placeholder-text { font-size: 1rem; color: var(--text-sub); }

/* ============================================================
   Current conditions card
   ============================================================ */
.current-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 2rem 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  text-align: center;
}

.location-name {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.25rem;
}

.current-body { margin-bottom: 1rem; }

.current-icon-temp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.current-icon { font-size: 4rem; line-height: 1; }
.current-temp { font-size: 4rem; font-weight: 300; line-height: 1; color: var(--text); }

.current-desc {
  font-size: 1.1rem;
  color: var(--text-sub);
  margin-top: 0.4rem;
}

.current-meta {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.meta-item { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }

.meta-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.meta-value { font-size: 1rem; font-weight: 600; color: var(--text); }

/* ============================================================
   Forecast
   ============================================================ */
.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.forecast-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.forecast-scroll::-webkit-scrollbar        { height: 5px; }
.forecast-scroll::-webkit-scrollbar-track  { background: var(--border); border-radius: 3px; }
.forecast-scroll::-webkit-scrollbar-thumb  { background: var(--text-muted); border-radius: 3px; }

.forecast-card {
  flex: 1 0 0;
  min-width: 108px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.55rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  scroll-snap-align: start;
  transition: box-shadow 0.15s;
}

.forecast-card:hover { box-shadow: var(--shadow-md); }

.forecast-card:first-child {
  border-color: var(--accent);
  box-shadow: 0 0 0 1.5px var(--accent), var(--shadow-sm);
}

.fc-day {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.fc-icon { font-size: 1.75rem; line-height: 1; margin: 0.15rem 0; }

.fc-temps {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.83rem;
}

.fc-tmax { font-weight: 700; color: var(--text); }
.fc-tmin { color: var(--text-muted); }

.fc-divider { height: 1px; background: var(--border); margin: 0.25rem 0; }

.fc-details { display: flex; flex-direction: column; gap: 0.22rem; }

.fc-detail {
  font-size: 0.73rem;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Loading
   ============================================================ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

/* ============================================================
   Error banner
   ============================================================ */
.error-banner {
  margin-top: 1rem;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

[data-theme="dark"] .error-banner {
  background: #3b1f1f;
  color: #f87171;
  border-color: #7f1d1d;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .error-banner {
    background: #3b1f1f;
    color: #f87171;
    border-color: #7f1d1d;
  }
}

/* ============================================================
   Overlay
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.42);
  backdrop-filter: blur(2px);
  z-index: 150;
}

/* ============================================================
   Panels
   ============================================================ */
.panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h3 { font-size: 0.95rem; font-weight: 600; color: var(--text); }

.btn-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px 7px;
  border-radius: 5px;
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s;
}

.btn-close:hover { color: var(--text); background: var(--border); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

.panel-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 2.5rem 1rem;
  line-height: 1.9;
}

/* ============================================================
   Favorites list
   ============================================================ */
.fav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}

.fav-item:hover { background: var(--bg); }

.fav-info { flex: 1; min-width: 0; }

.fav-name {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-actions { display: flex; gap: 0.2rem; flex-shrink: 0; }

.fav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 4px 6px;
  border-radius: 5px;
  color: var(--text-muted);
  transition: color 0.15s, background 0.15s;
}

.fav-btn:hover { color: var(--text); background: var(--border); }

/* ============================================================
   Settings
   ============================================================ */
.setting-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }

.setting-row label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sub);
}

.setting-row select {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  outline: none;
}

.setting-row select:focus { border-color: var(--accent); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 480px) {
  .app-title { display: none; }
  .search-wrapper { max-width: none; }
  .current-card { padding: 1.25rem 1rem; }
  .current-icon, .current-temp { font-size: 3rem; }
  .current-meta { gap: 1.5rem; }
  .panel { width: 100%; }
}
