/* Modern och stilren CSS-stilmall */
:root {
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  
  /* Ljust färgtema */
  --bg-base: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.95);
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border-focus: #4f46e5;
  
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-glow: rgba(79, 70, 229, 0.25);
  
  --success: #10b981;
  --success-bg: #ecfdf5;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-card: 0 12px 32px -4px rgba(15, 23, 42, 0.08), 0 4px 12px -2px rgba(15, 23, 42, 0.04);
  --shadow-button: 0 4px 14px rgba(79, 70, 229, 0.35);
  
  --transition-speed: 0.25s;
}

[data-theme="dark"] {
  --bg-base: #090d16;
  --bg-card: rgba(18, 24, 38, 0.92);
  --bg-subtle: #1e293b;
  --border-color: #273549;
  --border-focus: #6366f1;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: rgba(99, 102, 241, 0.15);
  --primary-glow: rgba(99, 102, 241, 0.35);
  
  --shadow-card: 0 16px 36px -4px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow-x: hidden;
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

/* Bakgrundsdekorationer */
.background-decorations {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.6;
  animation: float 14s infinite alternate ease-in-out;
}

.blob-1 {
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.28) 0%, rgba(168, 85, 247, 0.1) 70%);
  top: -100px;
  right: -50px;
}

.blob-2 {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.22) 0%, rgba(79, 70, 229, 0.08) 70%);
  bottom: -120px;
  left: -80px;
  animation-delay: -6s;
}

@keyframes float {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(35px) scale(1.08); }
}

/* Huvudbehållare */
.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  padding: 24px 16px;
  transition: max-width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-container:has(#welcome-view.active),
.app-container.dashboard-mode {
  max-width: 880px;
}

/* Card-komponent */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 40px 36px;
  transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
}

/* Vyer & Övergångar */
.view-panel {
  display: none;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.view-panel.active {
  display: block;
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Inloggningshuvud */
.card-header {
  text-align: center;
  margin-bottom: 28px;
}

.logo-badge {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.3);
}

.card-header h1 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.subtitle {
  font-size: 0.925rem;
  color: var(--text-secondary);
}

/* Formulär */
.form-group {
  margin-bottom: 20px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.link-forgot {
  font-size: 0.8rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-speed);
}

.link-forgot:hover {
  text-decoration: underline;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  pointer-events: none;
  transition: color var(--transition-speed);
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 12px 14px 12px 42px;
  font-size: 0.95rem;
  font-family: inherit;
  background-color: var(--bg-subtle);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition-speed), box-shadow var(--transition-speed), background-color var(--transition-speed);
}

input[type="password"] {
  padding-right: 44px;
}

input[type="text"]::placeholder,
input[type="password"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--border-focus);
  background-color: transparent;
  box-shadow: 0 0 0 4px var(--primary-glow);
}

input[type="text"]:focus + .input-icon,
.input-wrapper:focus-within .input-icon {
  color: var(--border-focus);
}

/* Ikonknapp (Visa lösenord) */
.btn-icon {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-speed), background-color var(--transition-speed);
}

.btn-icon:hover {
  color: var(--text-primary);
  background-color: var(--bg-subtle);
}

/* Checkbox */
.form-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.checkbox-container {
  display: inline-flex;
  align-items: center;
  position: relative;
  cursor: pointer;
  user-select: none;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  height: 18px;
  width: 18px;
  background-color: var(--bg-subtle);
  border: 1.5px solid var(--border-color);
  border-radius: 5px;
  margin-right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;
}

.checkbox-container:hover input ~ .checkmark {
  border-color: var(--border-focus);
}

.checkbox-container input:checked ~ .checkmark {
  background-color: var(--primary);
  border-color: var(--primary);
}

.checkmark::after {
  content: "";
  display: none;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.checkbox-container input:checked ~ .checkmark::after {
  display: block;
}

/* Varning / Felmeddelande */
.alert-message {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 20px;
  animation: shake 0.35s ease;
}

.alert-message.error {
  background-color: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--danger);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Knappar */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 20px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  position: relative;
  transition: all var(--transition-speed) cubic-bezier(0.16, 1, 0.3, 1);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-button);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 20px rgba(79, 70, 229, 0.45);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
  margin-top: 10px;
}

.btn-ghost:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.btn-sm {
  width: auto;
  padding: 8px 14px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

/* Spinner för laddning */
.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn.loading .btn-text {
  visibility: hidden;
}

.btn.loading .spinner {
  display: block;
  position: absolute;
}

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

/* ==========================================================================
   VÄLKOMSTVY (SINGLE PAGE)
   ========================================================================== */
.welcome-card {
  max-width: 100%;
  margin: 0 auto;
}

.welcome-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.user-greeting-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5 0%, #ec4899 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-bottom: 4px;
}

.badge.online {
  background-color: var(--success-bg);
  color: var(--success);
}

.badge.online::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--success);
  margin-right: 6px;
}

.welcome-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

/* Snabbval / Action buttons */
.quick-actions h3 {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.actions-list {
  display: flex;
  gap: 12px;
}

.action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.action-btn:hover {
  background-color: var(--border-color);
  transform: translateY(-1px);
}

/* Toast Notis */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-primary);
  color: var(--bg-base);
  padding: 12px 20px;
  border-radius: var(--radius-full);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 600;
}

/* ==========================================================================
   SMHI TEMPERATURSEKTION
   ========================================================================== */
.smhi-section {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.smhi-logo-pill {
  background: #004b87;
  color: white;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 6px;
}

.section-title-wrap h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.btn-icon-refresh {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed);
}

.btn-icon-refresh:hover {
  color: var(--primary);
  background: var(--border-color);
}

.btn-icon-refresh.spinning svg {
  animation: spin 0.8s linear infinite;
}

/* Hero kort för väder */
.weather-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-speed) ease;
}

.weather-hero-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.weather-icon-badge {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25);
  transition: background 0.3s ease;
}

.weather-icon-badge.warm {
  background: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.weather-icon-badge.mild {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
}

.weather-icon-badge.cold {
  background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.weather-meta {
  display: flex;
  flex-direction: column;
}

.weather-station-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.weather-obs-time {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.weather-hero-right {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.temperature-value {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
}

.temperature-unit {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Snabbval av städer */
.city-chips-wrap {
  margin-bottom: 14px;
}

.chips-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.city-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.825rem;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.chip-btn:hover {
  border-color: var(--primary);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.chip-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* Stationsväljare */
.station-search-box {
  margin-top: 14px;
}

.station-search-box label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.search-select-wrapper {
  position: relative;
}

.station-dropdown {
  width: 100%;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.875rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-speed);
}

.station-dropdown:focus {
  border-color: var(--border-focus);
}

/* ==========================================================================
   3-MÅNADERS TEMPERATURDIAGRAM & STATISTIK
   ========================================================================== */
.history-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 22px;
  margin-top: 18px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-speed) ease;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.chart-title-meta h4 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.chart-subtitle {
  font-size: 0.825rem;
  color: var(--text-secondary);
}

.chart-view-toggle {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  gap: 4px;
}

.toggle-btn {
  background: transparent;
  border: none;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn:hover {
  color: var(--text-primary);
}

.toggle-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 6px var(--primary-glow);
}

/* Statistikbrickor */
.history-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.h-stat-tile {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-speed), border-color var(--transition-speed);
}

.h-stat-tile:hover {
  border-color: var(--border-focus);
  transform: translateY(-2px);
}

.h-stat-label {
  font-size: 0.725rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.h-stat-val-row {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.h-stat-value {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.h-stat-unit {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.h-stat-sub {
  font-size: 0.725rem;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-warm .h-stat-value {
  color: #ea580c;
}

.stat-cool .h-stat-value {
  color: #0284c7;
}

.stat-avg .h-stat-value {
  color: #10b981;
}

.stat-count .h-stat-value {
  color: #8b5cf6;
}

/* Diagramduk och laddningsruta */
.chart-container-wrap {
  position: relative;
  width: 100%;
  min-height: 290px;
}

.chart-canvas-box {
  width: 100%;
  height: 340px;
  position: relative;
}

.chart-loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-card);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: opacity 0.2s ease;
}

.chart-loading-overlay[hidden] {
  display: none !important;
}

.chart-spinner {
  display: block;
  width: 26px;
  height: 26px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Responsiv anpassning */
@media (max-width: 720px) {
  .history-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 540px) {
  .card {
    padding: 28px 20px;
  }
  
  .history-stats-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .chart-header {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-view-toggle {
    width: 100%;
  }

  .chart-view-toggle .toggle-btn {
    flex: 1;
    text-align: center;
  }
  
  .actions-list {
    flex-direction: column;
  }

  .welcome-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .welcome-header .btn-logout {
    width: 100%;
  }
}
