:root {
  --light-body: rgb(226,234,249);
  --dark-body: #1a1a2e;
  --light-bg: #f5f5f5;
  --light-card: rgb(204,218,246);
  --light-text: #222;
  --dark-bg: #16213e;
  --dark-card: #0f3460;
  --dark-text: #f5f5f5;
  --header-height: 60px;
  --card-width: 315px;
  --card-height: 195px;
  --menu-width: 280px;
  --gap: 8px;
}

body.light {
  background: var(--light-body);
  color: var(--light-text);
}
body.dark {
  background: var(--dark-body);
  color: var(--dark-text);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden;
}

/* Wrapper keeps header/footer same width as grid */
.wrapper {
  display: grid;
  justify-content: center;
  grid-template-columns: repeat(5, var(--card-width));
  gap: var(--gap);
  margin: 10px auto;
  max-width: calc(var(--card-width) * 5 + var(--gap) * 4);
  padding: 0 10px;
  transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  z-index: 1;
}

/* Header + Footer - will span full width of grid */
header, footer {
  grid-column: 1 / -1;
  width: 100%;
  background: var(--dark-bg);
  border-radius: 8px;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  transition: background 0.3s;
  height: var(--header-height);
  z-index: 100;
  position: relative;
  color: white;
}
body.dark header, body.dark footer {
  background: var(--dark-card);
}

/* Header controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

/* Unit selector */
.unit-selector {
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}
body.dark .unit-selector {
  background: rgba(0,0,0,0.3);
  color: var(--dark-text);
}
.unit-selector option {
  background: var(--dark-bg);
  color: white;
}
body.dark .unit-selector option {
  background: var(--dark-card);
}

/* 4 cards */
@media screen and (max-width: 1720px) {
  .wrapper {
    grid-template-columns: repeat(4, var(--card-width));
    max-width: calc(var(--card-width) * 4 + var(--gap) * 3);
  }
}

/* 3 cards */
@media screen and (max-width: 1380px) {
  .wrapper {
    grid-template-columns: repeat(3, var(--card-width));
    max-width: calc(var(--card-width) * 3 + var(--gap) * 2);
  }
}

/* 2 cards */
@media screen and (max-width: 1040px) {
  .wrapper {
    grid-template-columns: repeat(2, var(--card-width));
    max-width: calc(var(--card-width) * 2 + var(--gap) * 1);
  }
}

/* 1 card - header and footer match card width */
@media screen and (max-width: 700px) {
  .wrapper {
    grid-template-columns: var(--card-width);
    max-width: var(--card-width);
    justify-content: center;
  }
}

/* Very small screens - maintain card width */
@media screen and (max-width: 400px) {
  .wrapper {
    grid-template-columns: minmax(280px, var(--card-width));
    max-width: 100%;
    padding: 0 10px;
  }
  
  .card {
    width: 100%;
    max-width: var(--card-width);
    margin: 0 auto;
  }
  
  .header-controls {
    gap: 5px;
  }
  
  .unit-selector {
    max-width: 80px;
    font-size: 10px;
    padding: 4px;
  }
}

/* Cards container */
.cards-container {
  display: contents;
}

/* Cards */
.card {
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 8px;
  background: var(--light-card);
  border: 2px solid var(--dark-bg);
  transition: background 0.3s, border-color 0.3s, transform 0.2s, opacity 0.2s;
  user-select: none;
  padding: 6px 8px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  cursor: grab;
  overflow-y: auto;
  overflow-x: hidden;
}
body.dark .card {
  background: var(--dark-card);
  border-color: var(--light-bg);
}

/* Custom scrollbar for cards */
.card::-webkit-scrollbar {
  width: 4px;
}

.card::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.05);
  border-radius: 4px;
}

.card::-webkit-scrollbar-thumb {
  background: #ff6b6b;
  border-radius: 4px;
}

.card:active {
  cursor: grabbing;
}

.card-header {
  font-size: 12px;
  font-weight: 700;
  color: #ff6b6b;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid rgba(255,107,107,0.3);
  padding-bottom: 2px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.card-main-value {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
  flex-shrink: 0;
}

.card-sub-value {
  font-size: 11px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  line-height: 1.3;
  margin-bottom: 2px;
}
body.dark .card-sub-value {
  color: #aaa;
}

.card-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.3;
}
body.dark .card-row {
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

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

.card-label {
  color: #666;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
  font-size: 10px;
}
body.dark .card-label {
  color: #aaa;
}

.card-value {
  font-weight: 600;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
  text-align: right;
  font-size: 10px;
}
body.dark .card-value {
  color: #fff;
}

/* For cards with many rows, allow them to be scrollable */
.card.has-many-rows {
  overflow-y: auto;
}

/* Fixed card (first one) - different styling */
.card.fixed {
  background: linear-gradient(135deg, var(--light-card) 0%, #e0e8f5 100%);
  border-color: #ff6b6b;
  cursor: default;
}
body.dark .card.fixed {
  background: linear-gradient(135deg, var(--dark-card) 0%, #1a2a4a 100%);
  border-color: #ff6b6b;
}
.card.fixed:active {
  cursor: default;
}

/* Dragging */
.dragging {
  opacity: 0.5;
  transform: scale(0.98);
  cursor: grabbing;
}

/* Drag over indicator */
.drag-over {
  border-top: 3px solid #ff6b6b;
  transform: translateY(-1px);
}

/* Hamburger / Close Button */
.menu-btn {
  width: 30px;
  height: 22px;
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 200;
}
.menu-btn span {
  height: 3px;
  width: 100%;
  background: orange;
  border-radius: 2px;
  transition: 0.4s ease;
  transform-origin: center;
}
body.menu-open .menu-btn span:nth-child(1) {
  transform: rotate(45deg) translateY(9px);
}
body.menu-open .menu-btn span:nth-child(2) {
  opacity: 0;
}
body.menu-open .menu-btn span:nth-child(3) {
  transform: rotate(-45deg) translateY(-9px);
}

/* Theme Toggle */
#themeToggle {
  font-size: 22px;
  background: none;
  border: none;
  cursor: pointer;
  color: orange;
  z-index: 200;
}

/* Slide-in menu - FIXED POSITIONING */
.menu {
  position: fixed;
  top: 0;
  left: calc(-1 * var(--menu-width));
  width: var(--menu-width);
  height: 100vh;
  background: white;
  padding: 20px;
  padding-top: calc(var(--header-height) + 20px);
  box-shadow: 2px 0 10px rgba(0,0,0,0.2);
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  overflow-y: auto;
  box-sizing: border-box;
}
body.dark .menu {
  background: var(--dark-card);
  color: var(--dark-text);
}
body.menu-open .menu {
  left: 0;
}

/* Overlay for outside click - FIXED */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  z-index: 900;
  pointer-events: none;
}
body.menu-open .overlay {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Station info in menu */
.station-info {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #ff6b6b;
}

.station-info h3 {
  margin: 0 0 15px 0;
  color: #ff6b6b;
  font-size: 18px;
}

.station-info p {
  margin: 8px 0;
  font-size: 14px;
}

/* Menu section headers */
.menu-section {
  color: #ff6b6b;
  font-size: 16px;
  font-weight: 600;
  margin: 20px 0 10px 0;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(255,107,107,0.3);
}

/* Loading state */
.loading {
  text-align: center;
  padding: 40px;
  font-size: 18px;
  color: #ff6b6b;
  grid-column: 1 / -1;
}

/* Location header */
.location-header {
  font-size: 18px;
  font-weight: 600;
  color: orange;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Error state */
.error {
  color: #ff6b6b;
  text-align: center;
  padding: 20px;
  font-size: 16px;
  grid-column: 1 / -1;
}

/* Menu item */
.menu-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
body.dark .menu-item {
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.menu-item-label {
  color: #666;
  font-weight: 500;
}
body.dark .menu-item-label {
  color: #aaa;
}

.menu-item-value {
  font-weight: 600;
  color: #333;
}
body.dark .menu-item-value {
  color: #fff;
}

/* Connection status */
.connection-status {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
}

.connected {
  background-color: #4caf50;
  box-shadow: 0 0 5px #4caf50;
}

.disconnected {
  background-color: #f44336;
  box-shadow: 0 0 5px #f44336;
}

/* Forecast card styles */
.forecast-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  margin-top: 2px;
}

.forecast-hour {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
body.dark .forecast-hour {
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.forecast-hour:last-child {
  border-bottom: none;
}

.forecast-time {
  font-weight: 600;
  color: #ff6b6b;
  min-width: 45px;
}

.forecast-temp {
  font-weight: 600;
  color: #333;
}
body.dark .forecast-temp {
  color: #fff;
}

.forecast-condition {
  flex: 1;
  text-align: left;
  padding-left: 8px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.dark .forecast-condition {
  color: #aaa;
}

.forecast-icon {
  font-size: 14px;
  margin-right: 4px;
}

.forecast-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font-size: 10px;
  font-weight: 600;
  color: #ff6b6b;
  padding: 2px 0;
  margin-top: 2px;
  border-bottom: 1px solid rgba(255,107,107,0.3);
}

.forecast-summary {
  font-size: 10px;
  color: #666;
  padding: 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.dark .forecast-summary {
  color: #aaa;
}
/* Enhanced forecast card styles */
.forecast-detailed {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  margin-top: 4px;
}

.forecast-hour-detailed {
  background: rgba(0,0,0,0.03);
  border-radius: 4px;
  padding: 4px;
  margin-bottom: 4px;
}
body.dark .forecast-hour-detailed {
  background: rgba(255,255,255,0.05);
}

.forecast-hour-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: #ff6b6b;
  padding-bottom: 2px;
  margin-bottom: 2px;
  border-bottom: 1px solid rgba(255,107,107,0.2);
}

.forecast-time-large {
  font-size: 11px;
}

.forecast-temp-large {
  font-size: 12px;
}

.forecast-details-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px 8px;
  font-size: 9px;
}

.forecast-detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.forecast-detail-label {
  color: #666;
  font-weight: 500;
}
body.dark .forecast-detail-label {
  color: #aaa;
}

.forecast-detail-value {
  font-weight: 600;
  color: #333;
}
body.dark .forecast-detail-value {
  color: #fff;
}

.forecast-condition-large {
  grid-column: span 2;
  text-align: center;
  padding: 2px 0;
  color: #666;
  font-style: italic;
  border-top: 1px dashed rgba(0,0,0,0.05);
  margin-top: 2px;
  padding-top: 2px;
}
body.dark .forecast-condition-large {
  border-top-color: rgba(255,255,255,0.05);
  color: #aaa;
}