/* Energy platform UI. Light theme; logical properties so Arabic (RTL) mirrors correctly. */
:root {
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --border: #e3e2de;
  --border-strong: #cfcdc7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --brand: #2a78d6;
  --brand-dark: #1c5cab;
  --brand-tint: #e8f1fc;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Noto Sans", Tahoma, sans-serif;
  color: var(--text-primary);
  background: var(--surface-0);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.45; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; font-weight: 650; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; font-weight: 620; }
h3 { font-size: .95rem; margin: 0 0 .5rem; font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* ---- top bar ---- */
.topbar { background: #102a43; color: #fff; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem; flex-wrap: wrap; }
.topbar a { color: #dbe7f5; }
.topbar .brand { font-weight: 700; color: #fff; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.topbar .brand svg { flex: none; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { padding: .35rem .7rem; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; gap: .75rem; align-items: center; font-size: .9rem; }
.pill-count { background: var(--critical); color: #fff; border-radius: 999px; padding: 0 .45rem; font-size: .75rem;
  margin-inline-start: .3rem; }

main { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1rem; }
.crumbs { font-size: .85rem; color: var(--text-muted); margin-bottom: .2rem; }

/* ---- cards & grids ---- */
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.card + .card, .section + .section { margin-top: 1rem; }
.section { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.sites { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
@media (max-width: 520px) { .grid.two { grid-template-columns: 1fr; } main { padding: .75rem; } }

/* ---- KPI tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: .75rem; }
.tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem .9rem; box-shadow: var(--shadow); min-height: 112px; display: flex; flex-direction: column; }
.tile .label { font-size: .8rem; color: var(--text-secondary); display: flex; justify-content: space-between; gap: .4rem; }
.tile .value { font-size: 1.55rem; font-weight: 650; margin-top: .3rem; }
.tile .value .unit { font-size: .85rem; font-weight: 500; color: var(--text-secondary); margin-inline-start: .2rem; }
.tile .sub { font-size: .78rem; color: var(--text-muted); margin-top: auto; padding-top: .3rem; }
.tile.unavailable .value { color: var(--text-muted); font-weight: 500; font-size: 1.1rem; }

/* ---- value-type badges: measured / calculated / estimated / no data ---- */
.vt { font-size: .68rem; border-radius: 4px; padding: .05rem .35rem; white-space: nowrap; border: 1px solid; font-weight: 600;
  letter-spacing: .01em; height: fit-content; }
.vt.measured { color: #184f95; border-color: #9ec5f4; background: #eef5fd; }
.vt.calculated { color: #3e3d3a; border-color: var(--border-strong); background: #f4f4f2; }
.vt.estimated { color: #8a4a00; border-color: #f2c977; background: #fff7e6; border-style: dashed; }
.vt.nodata { color: var(--text-muted); border-color: var(--border); background: transparent; }

/* ---- status: always icon + label, never colour alone ---- */
.status { display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; flex: none; }
.status.online { color: var(--good-text); } .status.online::before { background: var(--good); }
.status.stale { color: #8a5a00; } .status.stale::before { background: var(--warning); border-radius: 2px; transform: rotate(45deg); }
.status.offline, .status.never { color: #a12b2b; } .status.offline::before, .status.never::before { background: var(--critical); border-radius: 1px; }
.status.active { color: #a12b2b; } .status.active::before { background: var(--critical); border-radius: 1px; transform: rotate(45deg); }
.status.closed { color: var(--text-muted); } .status.closed::before { background: var(--border-strong); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: start; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; color: var(--text-secondary); font-weight: 600; background: var(--surface-1); white-space: nowrap; }
td.r, th.r { text-align: end; }
tr:hover td { background: #fafaf8; }

/* ---- forms & buttons ---- */
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text-primary); padding: .45rem .85rem; border-radius: 7px;
  font: inherit; font-size: .9rem; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-1); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.small { padding: .2rem .55rem; font-size: .8rem; }
.btn.danger { color: #a12b2b; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-2); padding: .35rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; }
.seg button + button { border-inline-start: 1px solid var(--border-strong); }
.seg button[aria-pressed="true"] { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; }
form.stack { display: grid; gap: .85rem; max-width: 560px; }
label.f { display: grid; gap: .3rem; font-size: .88rem; font-weight: 550; color: var(--text-secondary); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid var(--border-strong); border-radius: 7px;
  background: #fff; color: var(--text-primary); width: 100%; }
textarea { min-height: 80px; }
.help { font-size: .78rem; color: var(--text-muted); font-weight: 400; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .9rem; }
.days { display: flex; flex-wrap: wrap; gap: .6rem; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }

/* ---- messages ---- */
.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .75rem; border: 1px solid; font-size: .9rem; }
.flash.error { background: #fdf0f0; border-color: #f0b6b6; color: #8b1f1f; }
.flash.ok { background: #effaf0; border-color: #a8dca9; color: #145c14; }
.notice { background: #fff7e6; border: 1px solid #f2c977; border-radius: 8px; padding: .6rem .8rem; font-size: .86rem; }
.keybox { font-family: ui-monospace, Menlo, Consolas, monospace; background: #102a43; color: #e8f1fc;
  padding: .8rem; border-radius: 8px; word-break: break-all; direction: ltr; }

/* ---- site cards ---- */
.site-card h3 { font-size: 1.05rem; margin-bottom: .1rem; }
.site-card .kv { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: .8rem 0; }
.site-card .kv .v { font-size: 1.25rem; font-weight: 650; }
.site-card .kv .k { font-size: .76rem; color: var(--text-secondary); display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; }
.site-card footer { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; font-size: .82rem;
  border-top: 1px solid var(--border); padding-top: .6rem; }

/* ---- charts ---- */
.chart-card .head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.chart { position: relative; width: 100%; min-height: 260px; direction: ltr; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--text-muted); font-size: 11px; }
.chart .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-size: .9rem; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--text-secondary); }
.legend .sw { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-inline-end: .35rem; vertical-align: -1px; }
.legend .sw.line { height: 3px; vertical-align: 3px; border-radius: 2px; }
.legend .sw.dash { background: repeating-linear-gradient(90deg, var(--series-2) 0 5px, transparent 5px 8px) !important; }
.legend .sw.hatch { background: repeating-linear-gradient(135deg, var(--series-1) 0 2px, #cde2fb 2px 5px); }
.tooltip { position: absolute; pointer-events: none; background: #fff; border: 1px solid var(--border-strong);
  border-radius: 8px; padding: .45rem .6rem; font-size: .8rem; box-shadow: 0 4px 14px rgba(0,0,0,.1); white-space: nowrap;
  z-index: 5; display: none; }
.tooltip .t { color: var(--text-muted); font-size: .75rem; margin-bottom: .15rem; }
.tooltip .row { display: flex; gap: .4rem; align-items: center; }
.tooltip .sw { width: 9px; height: 9px; border-radius: 2px; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #102a43, #1c5cab); padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { display: flex; gap: .5rem; align-items: center; font-weight: 700; font-size: 1.15rem; margin-bottom: 1rem; }

.foot { max-width: 1280px; margin: 1.5rem auto 2rem; padding: 0 1.25rem; font-size: .78rem; color: var(--text-muted);
  display: flex; gap: 1rem; flex-wrap: wrap; justify-content: space-between; }
.legend-vt { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
[dir="rtl"] .chart, [dir="rtl"] .keybox { direction: ltr; }
