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

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--tx);
  background:
    radial-gradient(1200px 700px at 80% -10%, #13202f 0%, transparent 60%),
    radial-gradient(900px 600px at 0% 100%, #101a16 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  overflow: hidden;            /* tek ekran — scroll yok (masaüstü) */
}

.page {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  height: 100dvh;              /* tüm içerik bir ekrana sığar */
  margin: 0 auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* HERO — sabit oranlı (kompakt), kalan alanı grid'e bırakır */
#hero { flex: 0 0 auto; }
#hero.hero-intro { min-height: 0; height: clamp(200px, 30vh, 330px); border-radius: var(--radius); }  /* kartlara daha çok yükseklik → ikonlar büyür */
/* dashboard içindeyken marka bloğu küçültülür (önizleme dosyası etkilenmez) */
#hero.hero-intro .hi-badge { width: 78px; height: 78px; border-radius: 19px; margin-bottom: 14px; }
#hero.hero-intro .hi-badge svg { width: 46px; height: 46px; }
#hero.hero-intro .hi-name { font-size: clamp(28px, 4vw, 42px) !important; }
#hero.hero-intro .hi-greet { margin-top: 12px; }
#hero.hero-intro .hi-greet .hi-hi { font-size: clamp(15px, 1.8vw, 20px); }
#hero.hero-intro .hi-greet .hi-tag { font-size: clamp(13px, 1.4vw, 17px); margin-top: 7px; }
#hero.hero-intro .hi-live .clock { font-size: clamp(16px, 2vw, 22px); }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 19px; color: #0a0f17;
  background: linear-gradient(135deg, #ffb020, #ff7a00);
  box-shadow: 0 8px 22px rgba(255, 140, 0, 0.32);
}
.brand-name { font-size: 16px; font-weight: 600; }
.brand-sub { font-size: 12px; color: var(--tx-mut); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.clock { font-variant-numeric: tabular-nums; color: var(--tx-dim); font-size: 14px; }
.alarms-link {
  display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--tx-dim);
  background: var(--card); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  transition: border-color .2s, color .2s;
}
.alarms-link:hover { border-color: var(--line-2); color: var(--tx); }
.alarms-link .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.alarms-link.has-active .dot { background: var(--red); box-shadow: 0 0 10px var(--red); }
.badge {
  background: rgba(248, 113, 113, 0.18); color: var(--red);
  border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600;
}

/* ---- Cards ---- */
.card {
  position: relative;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hero { min-height: 340px; }
.hero-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
}
.hero-title { font-size: 24px; font-weight: 700; letter-spacing: -0.3px; }
.hero-greet { color: var(--tx-dim); font-size: 14px; margin-top: 4px; }
.hero-stats { display: flex; gap: 26px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-l { font-size: 11px; color: var(--tx-mut); text-transform: uppercase; letter-spacing: .08em; }
.stat-v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-v small { font-size: 13px; color: var(--tx-mut); margin-left: 3px; font-weight: 500; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  flex: 1 1 auto;             /* hero'dan kalan tüm yüksekliği doldurur */
  min-height: 0;             /* grid'in taşmadan küçülebilmesi için */
}
.grid .card { min-height: 0; }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { display: flex; flex-direction: column; }
.card-title .ttl { font-size: 18px; font-weight: 700; display: inline-flex; align-items: center; gap: 9px; color: var(--card-accent, var(--tx)); }
.card-title .sub { font-size: 12px; color: var(--tx-mut); margin-top: 3px; padding-left: 18px; }

/* Başlık aksan noktası — her kart kendi tema rengini taşır (--card-accent) */
.card-title .ttl::before, .bat .ttl::before {
  content: ""; flex: 0 0 auto; width: 9px; height: 9px; border-radius: 3px;
  background: var(--card-accent, var(--teal));
  box-shadow: 0 0 10px var(--card-accent, var(--teal));
}
/* Tüm kart başlıkları EPİAŞ amber'ı (dot + metin) */
#card-roof, #card-field, #card-battery, #card-ptf { --card-accent: #fbbf24; }
.card-metric { font-size: clamp(26px, 3vw, 34px); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1; }
.card-metric small { font-size: 16px; color: var(--tx-mut); margin-left: 4px; font-weight: 500; }
.card-metric .metric-dir { font-size: 12px; letter-spacing: .02em; }
/* net akış: çekiş = nötr, veriş (negatif) = yeşil (üretim fazlası şebekeye) */
.card-metric.is-export { color: var(--green); }
.card-metric.is-export small { color: var(--green); opacity: .8; }

.weather-chip, .chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 11px; font-size: 12px; color: var(--tx-dim);
  white-space: nowrap;
}
.weather-chip .wx-ico { font-size: 14px; display: inline-flex; }
.weather-chip .wx-ico img { width: 18px; height: 18px; display: block; }

.ptf-stats { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--tx-mut); }
.ptf-stats b { color: var(--tx-dim); font-weight: 600; }
.ptf-stats .yekdem { color: var(--amber); }
.ptf-stats .yekdem b { color: var(--amber); }

/* PTF — renkli animasyonlu SVG bar grafiği (3D yerine) */
.ptf-chart { flex: 1 1 auto; min-height: 0; margin-top: 10px; }
.ptf-chart svg { width: 100%; height: 100%; display: block; }
@keyframes rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* The 3D draw area inside each card. Transparent — the canvas (on top) draws here. */
.scene-slot { flex: 1 1 auto; margin-top: 8px; min-height: 0; }

/* Düz ikon görünümü (3D yerine sade ikon kartları) */
.card-icon { flex: 1 1 auto; margin-top: 8px; min-height: 0; display: grid; place-items: center; }
.card-icon img {
  width: min(100%, 168px); height: auto; opacity: 0.92;
  transform: translateY(-16px);
  filter: invert(1) drop-shadow(0 6px 18px rgba(126, 240, 200, 0.22));
}

/* Inline (renkli, kendi stilini taşıyan) SVG ikon — invert YOK */
.card-art { flex: 1 1 auto; margin-top: 8px; min-height: 0; display: grid; place-items: center; }
.card-art svg {
  width: 100%; max-width: 340px; height: auto;   /* kart genişliğine göre ölçekle (vw değil → daralınca küçülür, binmez) */
  max-height: 100%;            /* hücreye sığdır — alt çizgi kırpılmasın (gömülme fix) */
  filter: drop-shadow(0 6px 18px rgba(74, 168, 255, 0.18));
}
/* Saha Üretim kartı: farm ikonu türbinleri döner + biraz daha büyük */
.card-art svg.farm-art { max-width: 400px; }
@keyframes farmSpin { to { transform: rotate(360deg); } }
.farm-art .wind-a { transform-box: view-box; transform-origin: 74px 50px; animation: farmSpin 3.4s linear infinite; }
.farm-art .wind-b { transform-box: view-box; transform-origin: 128px 42px; animation: farmSpin 4.2s linear infinite; }

/* Tesis Tüketim kartı: yenilenebilir "eco" ikonu (akış diyagramıyla aynı) — türbinler döner */
.card-art svg.eco-art { max-width: 420px; }
.eco-art .turb1 { transform-box: view-box; transform-origin: 72px 50px; animation: farmSpin 3.6s linear infinite; }
.eco-art .turb2 { transform-box: view-box; transform-origin: 108px 42px; animation: farmSpin 4.4s linear infinite; }
.eco-art .turb3 { transform-box: view-box; transform-origin: 278.5px 62px; animation: farmSpin 3.2s linear infinite; }

/* ---- Batarya kartı (su dolumlu pil + yatırım fırsatı modu) ---- */
.bat .ttl { font-size: 18px; font-weight: 700; display: inline-flex; align-items: center; gap: 9px; color: var(--card-accent, var(--tx)); }
.bat .chip { position: absolute; top: 14px; right: 16px; }
.bat .loc { display: inline-flex; align-items: center; gap: 7px; margin-top: 7px;
  background: rgba(126,240,200,.1); border: 1px solid rgba(126,240,200,.25);
  border-radius: 999px; padding: 4px 11px; font-size: 12.5px; color: #aee9d3;
  font-family: ui-monospace, 'JetBrains Mono', monospace; align-self: flex-start; }
.bat .loc svg { width: 13px; height: 13px; }
.bat .val { margin-top: 16px; font-size: clamp(34px, 4vw, 44px); font-weight: 300; letter-spacing: -.02em; line-height: 1; }
.bat .val b { font-weight: 600; }
/* düşük şarj (SoC < %20): rakam kırmızı + hafif nabız */
#card-battery.bat-low .val b { color: #ff6b6b; animation: batLowPulse 1.6s ease-in-out infinite; }
#card-battery.bat-low .loc { background: rgba(229,72,77,.12); border-color: rgba(229,72,77,.35); color: #ffb3b5; }
@keyframes batLowPulse { 50% { opacity: .55; } }
.bat .val .u { font-size: .42em; color: #9fb4c8; margin-left: 5px; }
.bat .pbox { position: absolute; bottom: 26px; left: 18px; }
.bat .lab { font-size: 12.5px; color: #8fa3b8; }
.bat .big { font-size: clamp(22px, 2.6vw, 30px); font-weight: 600; color: #37e0a6; margin-top: 4px; letter-spacing: -.01em; }
.bat .ico { position: absolute; bottom: 0; right: 12px; width: clamp(66px, 26%, 146px); height: auto; }
.bat .op { display: none; position: absolute; left: 18px; bottom: 24px; max-width: 56%; }
.bat .op-tag { display: inline-flex; align-items: center; gap: 6px; background: rgba(126,240,200,.12);
  border: 1px solid rgba(126,240,200,.32); color: #7ef0c8; border-radius: 999px; padding: 5px 12px;
  font-size: 11px; font-family: ui-monospace, 'JetBrains Mono', monospace; letter-spacing: .14em; margin-bottom: 14px; }
.bat .op-tag svg { width: 12px; height: 12px; }
.bat .op-lab { font-size: 13px; color: #9fb4c8; }
.bat .op-val { font-size: clamp(28px, 3.2vw, 36px); font-weight: 600; color: #37e0a6; margin-top: 4px; letter-spacing: -.02em; }
.bat .op-sub { font-size: 12.5px; color: #7c8ba0; margin-top: 7px; line-height: 1.5; max-width: 30ch; }
.bat .ico-op { display: none; position: absolute; bottom: 4px; right: 16px; width: clamp(64px, 25%, 142px); height: auto; }
.bat[data-batt="1"] .op, .bat[data-batt="1"] .ico-op { display: none; }
.bat[data-batt="0"] .loc, .bat[data-batt="0"] .chip, .bat[data-batt="0"] .val,
.bat[data-batt="0"] .pbox, .bat[data-batt="0"] .ico { display: none; }
.bat[data-batt="0"] .op { display: block; }
.bat[data-batt="0"] .ico-op { display: block; }

/* 2D fallback shown only when WebGL is unavailable */
.fallback {
  display: none;
  position: absolute; left: 0; right: 0; bottom: 0; top: auto;
  height: 60%;
  align-items: center; justify-content: center;
  color: var(--tx-mut); font-size: 13px;
  background:
    radial-gradient(120px 80px at 50% 60%, rgba(34,211,165,.12), transparent 70%);
}
body.no-webgl #scene-canvas { display: none; }
body.no-webgl .fallback { display: flex; }

/* ---- Responsive ---- */
/* Mobilde 5 blok tek ekrana sığmaz → dikey yığın + scroll serbest */
@media (max-width: 820px) {
  body { overflow: auto; }
  .page { height: auto; min-height: 100dvh; }
  #hero.hero-intro { height: auto; min-height: 280px; }
  .grid { grid-template-columns: 1fr; grid-template-rows: none; }
  .grid .card { min-height: 240px; }
}

/* Kısa/ölçekli masaüstü ekranlar (örn. HiDPI laptop, %150 ölçek): tek ekrana
   sığdırmaya zorlama — kartlar ezilip içerikleri üst üste biniyordu. Kartlara
   sabit minimum yükseklik ver, gerekiyorsa dikey kaydırmaya izin ver. */
@media (min-width: 821px) and (max-height: 820px) {
  body { overflow-y: auto; }
  .page { height: auto; min-height: 100dvh; padding-bottom: 16px; }
  #hero { flex: 0 0 auto; }
  #hero.hero-intro { height: clamp(220px, 32vh, 300px); }
  .grid {
    flex: 0 0 auto;
    grid-template-rows: none;
    grid-auto-rows: 246px;       /* her kart yeterli yükseklik → içerik binmesin */
  }
  .grid .card { min-height: 246px; }
}

/* Tesis Tüketim kartı — 3 satırlı değer bloğu (yük / üretim / şebeke) */
.tesis-vals { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.tv-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.tv-l { font-size: 12.5px; color: var(--tx-dim); letter-spacing: .02em; }
.tv-v { font-size: 13px; color: var(--tx-mut); font-family: var(--font); white-space: nowrap; }
.tv-v b { font-size: 22px; font-weight: 700; color: var(--tx); font-variant-numeric: tabular-nums; margin-right: 3px; }
.tv-prod b { color: var(--green); }                 /* GES üretim daima yeşil */
.tv-grid.is-import b, .tv-grid.is-import .tv-l { color: var(--red); }    /* şebekeden çekiş → kırmızı */
.tv-grid.is-export b, .tv-grid.is-export .tv-l { color: var(--green); }  /* şebekeye veriş → yeşil */
