:root {
  --bg: #0f1115;
  --card: #181b22;
  --card-2: #20242d;
  --line: #2a2f3a;
  --text: #eef1f6;
  --muted: #8b93a3;
  --accent: #6ea8fe;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 28px;
  --gap: 24px;
  --touch: 72px;
  font-size: clamp(14px, 1.15vw, 22px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: var(--gap);
  gap: var(--gap);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input { -webkit-user-select: text; user-select: text; }

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
}
.time { font-size: 4.2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.date { font-size: 1.4rem; color: var(--muted); margin-top: 6px; }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.weather { display: flex; align-items: center; gap: 12px; font-size: 2.2rem; }
.weather-temp { font-weight: 600; }
.icon-btn {
  width: var(--touch); height: var(--touch);
  border-radius: 50%;
  background: var(--card);
  font-size: 1.8rem;
}
.icon-btn:active { background: var(--card-2); }

/* Grid */
.grid {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: var(--gap);
  grid-template-columns: 1.6fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "cal meals shop"
    "cal home  home";
}
.card-calendar { grid-area: cal; }
.card-meals { grid-area: meals; }
.card-shopping { grid-area: shop; }
.card-home { grid-area: home; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 18px;
}
.card-head { min-height: 68px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card-head h2 { margin: 0; font-size: 1.6rem; font-weight: 650; }
.card-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.card-body::-webkit-scrollbar { display: none; }
.placeholder-note { font-size: 0.85rem; color: var(--muted); opacity: 0.7; }

/* Segmented */
.seg { display: flex; background: var(--card-2); border-radius: 999px; padding: 6px; }
.seg-btn { min-height: 56px; padding: 0 26px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.seg-btn.active { background: var(--accent); color: #0b1220; }
.pill-btn { min-height: 56px; padding: 0 24px; border-radius: 999px; background: var(--card-2); color: var(--muted); font-weight: 600; }
.pill-btn:active { background: var(--line); }

/* Calendar */
.cal-day { padding: 14px 0; border-bottom: 1px solid var(--line); }
.cal-day:last-child { border-bottom: 0; }
.cal-day-name { font-size: 1.1rem; font-weight: 650; color: var(--muted); margin-bottom: 10px; }
.cal-day.today .cal-day-name { color: var(--accent); }
.cal-empty { color: var(--muted); opacity: 0.6; font-size: 1rem; }
.event {
  display: flex; align-items: center; gap: 16px;
  min-height: var(--touch);
  padding: 12px 18px; margin-bottom: 10px;
  background: var(--card-2); border-radius: 18px;
  border-left: 8px solid var(--c, var(--accent));
}
.event-time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 5.5em; font-size: 1.05rem; }
.event-title { font-size: 1.2rem; font-weight: 550; flex: 1; }
.event-who { font-size: 0.95rem; color: var(--muted); }

/* Meals */
.meal {
  display: flex; align-items: center; gap: 18px;
  min-height: 60px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
}
.meal:last-child { border-bottom: 0; }
.meal-day { width: 4.2em; color: var(--muted); font-weight: 650; text-transform: capitalize; }
.meal-dish { font-size: 1.2rem; }
.meal.today { background: var(--card-2); border-radius: 16px; padding-left: 16px; border-bottom-color: transparent; }
.meal.today .meal-day { color: var(--accent); }

/* Shopping */
.add-row { display: flex; gap: 12px; }
.add-row input {
  flex: 1; min-height: var(--touch);
  padding: 0 22px; border-radius: 18px;
  border: 2px solid var(--line); background: var(--card-2);
  font-size: 1.2rem; outline: none;
}
.add-row input:focus { border-color: var(--accent); }
.add-btn { width: var(--touch); min-height: var(--touch); border-radius: 18px; background: var(--accent); color: #0b1220; font-size: 2rem; font-weight: 700; }
.shop-list { list-style: none; margin: 0; padding: 0; }
.shop-item {
  display: flex; align-items: center; gap: 18px;
  min-height: var(--touch);
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 1.2rem;
}
.shop-item .check {
  width: 48px; height: 48px; flex: none;
  border-radius: 14px; border: 3px solid var(--line);
  display: grid; place-items: center; font-size: 1.5rem; color: #0b1220;
}
.shop-item.done { color: var(--muted); text-decoration: line-through; }
.shop-item.done .check { background: var(--green); border-color: var(--green); }
.shop-empty { color: var(--muted); opacity: 0.6; padding: 12px 4px; }

/* Smart home */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 16px;
  align-content: start;
}
.device {
  min-height: 9rem;
  border-radius: 22px;
  background: var(--card-2);
  padding: 20px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start;
  text-align: left;
  transition: background .15s, transform .1s;
}
.device:active { transform: scale(0.97); }
.device-icon { font-size: 2.2rem; }
.device-name { font-size: 1.1rem; font-weight: 600; }
.device-state { font-size: 0.95rem; color: var(--muted); }
.device.on { background: #3a3320; }
.device.on .device-state { color: var(--amber); }
.device.sensor { cursor: default; }
.status-dot { font-size: 0.95rem; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.status-dot::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--red); }
.status-dot.ok::before { background: var(--green); }

/* Stående skærm som fallback */
@media (orientation: portrait) {
  .grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1.3fr 1fr 1fr;
    grid-template-areas: "cal cal" "meals shop" "home home";
  }
}
