/* DSG Energy Report Portal – light theme, colours from dsgenergy.com.pk */
:root {
  --green-900: #172b15;
  --green-800: #185310;
  --green-700: #245311;
  --green-600: #2f6b1c;
  --teal: #4aa485;
  --teal-dark: #2f7d63;
  --teal-soft: #e8f5ef;
  --lime: #7afc20;
  --lime-soft: #f1fde6;
  --ink: #16211a;
  --text: #3b4740;
  --muted: #74817a;
  --bg: #f6f8f6;
  --card: #ffffff;
  --border: #e4eae5;
  --border-strong: #d3ddd5;
  --danger: #c93b3b;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(22, 33, 26, .05);
  --shadow: 0 1px 2px rgba(22, 33, 26, .04), 0 6px 20px rgba(22, 33, 26, .05);
  --shadow-lg: 0 2px 4px rgba(22, 33, 26, .04), 0 16px 40px rgba(22, 33, 26, .10);
  --font: "Hind", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-head: "Merriweather", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, .h2, .h3 { font-family: var(--font-head); color: var(--ink); line-height: 1.25; margin: 0 0 .35em; letter-spacing: -.2px; }
h1 { font-size: 1.65rem; }
h2, .h2 { font-size: 1.3rem; }
h3, .h3 { font-size: 1.08rem; }
p { margin: 0 0 .8em; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .86em; background: #eff4f0; padding: .1em .4em; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pad { padding: 20px 24px; margin: 0; }
.inline { display: inline; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 .93rem/1 var(--font);
  padding: 11px 18px 9px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none !important;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-sm { font-size: .84rem; padding: 7px 12px 5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--green-800); color: #fff; box-shadow: 0 1px 2px rgba(24,83,16,.25); }
.btn-primary:hover { background: var(--green-600); }
.btn-light { background: #fff; color: var(--green-800); border-color: var(--border-strong); }
.btn-light:hover { border-color: var(--teal); background: #fafdfb; }
.btn-danger { background: #fff; color: var(--danger); border-color: #f0d4d4; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #000; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: #f0f4f1; color: var(--green-800); border-color: var(--border); text-decoration: none; }

/* ---------- Top bar (light) ---------- */
.topbar {
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar::before { content: ""; display: block; height: 3px; background: linear-gradient(90deg, var(--green-800), var(--teal) 55%, var(--lime)); }
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  height: 66px; padding: 0 20px;
  display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none !important; flex: none; }
.brand img { height: 46px; width: auto; display: block; }
.brand-text {
  font-size: .72rem; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--teal-dark); padding: 4px 0 2px 14px; border-left: 1px solid var(--border-strong);
}
.nav { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 100%; }
.nav-links { display: flex; align-items: center; gap: 4px; height: 100%; }
.nav-links a {
  position: relative; display: flex; align-items: center; height: 100%;
  padding: 3px 14px 0; color: var(--muted); font-weight: 500; font-size: .95rem; text-decoration: none;
  transition: color .15s;
}
.nav-links a:hover { color: var(--ink); }
.nav-links a.active { color: var(--green-800); font-weight: 600; }
.nav-links a.active::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--green-800); }
.nav-user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; letter-spacing: .5px;
  color: var(--green-800); background: var(--teal-soft); border: 1px solid #cfe8dc;
}
.nav-user-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.nav-user-text strong { color: var(--ink); font-size: .9rem; font-weight: 600; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user-text a { font-size: .78rem; color: var(--muted); }
.nav-user-text a:hover, .nav-user-text a.active { color: var(--teal-dark); }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; padding: 8px; cursor: pointer; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: var(--ink); margin: 4px 0; border-radius: 2px; }

/* "Viewing as" bar for admins */
.imp-bar {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 7px 16px; font-size: .9rem; color: #5a4a12;
  background: #fff7dc; border-bottom: 1px solid #f1e2a8;
}
.imp-bar form { margin: 0; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 32px 20px 44px; flex: 1; }
.footer { text-align: center; padding: 18px; font-size: .84rem; color: var(--muted); border-top: 1px solid var(--border); background: #fff; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { margin-bottom: 2px; }
.page-head p { margin: 0; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.back-link { display: inline-block; font-size: .9rem; margin-bottom: 6px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 440px; width: 100%; }
.card.narrow-left { max-width: 680px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.card-logo { text-align: center; margin-bottom: 14px; }
.card-logo img { height: 90px; }
.center-page { flex: 1; display: flex; align-items: center; justify-content: center; padding: 30px 16px; }

/* ---------- Alerts & badges ---------- */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; font-size: .94rem; }
.alert-success { background: #f0fbe8; border-color: #cdebb6; color: #24520f; }
.alert-error { background: #fdf2f2; border-color: #f2d3d3; color: #8a2424; }
.alert-info { background: #eef7f3; border-color: #cbe6da; color: #235a47; }
.badge { display: inline-block; font-size: .76rem; font-weight: 600; padding: 3px 9px 1px; border-radius: 99px; background: #eef2ef; color: var(--muted); white-space: nowrap; }
.badge-ok, .badge-login { background: #e9f8df; color: #2c6a12; }
.badge-off, .badge-login_failed { background: #fbeaea; color: #9b2c2c; }
.badge-warn { background: #fdf3e1; color: #8a5a12; }
.badge-view_site { background: var(--teal-soft); color: #25705a; }
.badge-password_change { background: #eef0fb; color: #3a4a9b; }
.badge-login_as { background: #fff4d6; color: #7a5b0c; }

/* ---------- Forms ---------- */
.form label { display: block; font-weight: 600; font-size: .9rem; color: var(--ink); margin-bottom: 16px; }
.form label .muted { font-weight: 400; }
.form label small { display: block; font-weight: 400; margin-top: 4px; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=date], input:not([type]), select {
  display: block; width: 100%; margin-top: 6px;
  font: 400 1rem var(--font); color: var(--ink);
  padding: 10px 12px 8px;
  border: 1px solid var(--border-strong); border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 4px rgba(74,164,133,.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form .check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.form .check input { width: 18px; height: 18px; accent-color: var(--green-800); margin: 0; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.pw-field { position: relative; display: block; }
.pw-field input { padding-right: 64px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); margin-top: 3px; background: none; border: 0; color: var(--teal-dark); font: 600 .85rem var(--font); cursor: pointer; padding: 6px 8px; }
.search { display: flex; gap: 8px; }
.search input, .search select { margin: 0; min-width: 200px; padding: 8px 12px 6px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 600; background: #fafbfa; padding: 12px 16px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 16px; border-bottom: 1px solid #eff3f0; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfcfb; }
.table .btn + .btn, .table .btn + form, .table form + form, .table form + .btn { margin-left: 4px; }
.card:not(.flush) .table th:first-child, .card:not(.flush) .table td:first-child { padding-left: 0; }
.url-cell { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.ua { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  display: flex; align-items: center; gap: 14px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow-sm); text-decoration: none !important; transition: transform .15s, box-shadow .15s, border-color .15s;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #d5e4da; }
.stat-icon { width: 48px; height: 48px; flex: none; border-radius: 14px; display: grid; place-items: center; color: var(--tone); background: var(--tone-bg); }
.stat-body { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.stat-body strong { font-family: var(--font-head); font-size: 1.7rem; color: var(--ink); }
.stat-body span { font-size: .84rem; color: var(--muted); margin-top: 2px; }
.tone-green { --tone: #185310; --tone-bg: #e8f4e3; }
.tone-teal { --tone: #2f7d63; --tone-bg: #e4f4ed; }
.tone-blue { --tone: #2f5fb3; --tone-bg: #e8effb; }
.tone-lime { --tone: #4c8a0e; --tone-bg: #eefbe0; }
.tone-red { --tone: #c93b3b; --tone-bg: #fbeaea; }
.tone-red strong { color: var(--danger); }
.tone-gray { --tone: #74817a; --tone-bg: #f0f3f1; }
.filters { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 12px; align-items: end; padding: 16px 20px; }
.filters label { font-weight: 600; font-size: .85rem; margin: 0; }
.filters-actions { display: flex; gap: 8px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 10px 0 20px; }
.purge { display: flex; align-items: center; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.purge select { width: auto; margin: 0; padding: 6px 10px 4px; }

/* Admin overview site list */
.site-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 10px; }
.site-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: #fcfdfc; }
.site-row.is-hidden { opacity: .6; }
.site-row-icon { width: 36px; height: 36px; flex: none; border-radius: 10px; display: grid; place-items: center; color: var(--green-800); background: var(--teal-soft); }
.site-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.site-row-text strong { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-row-actions { display: flex; gap: 6px; flex: none; }

/* ---------- Customer site tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px; }
.tile {
  display: flex; flex-direction: column; gap: 10px; min-height: 210px;
  background: #fff; border: 1px solid var(--border); border-radius: 18px;
  padding: 22px; box-shadow: var(--shadow-sm); color: var(--text);
  text-decoration: none !important; position: relative; overflow: hidden;
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.tile::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 160px; height: 160px; border-radius: 50%;
  background: radial-gradient(circle, rgba(122,252,32,.16), transparent 70%); transition: transform .3s;
}
.tile:hover { transform: translateY(-4px); border-color: #cfe3d6; box-shadow: var(--shadow-lg); }
.tile:hover::after { transform: scale(1.25); }
.tile-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.tile-icon {
  width: 50px; height: 50px; border-radius: 14px; display: grid; place-items: center;
  color: var(--green-800); background: linear-gradient(135deg, var(--teal-soft), var(--lime-soft));
  border: 1px solid #d8eee2;
}
.tile-status { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; color: var(--teal-dark); background: var(--teal-soft); padding: 4px 10px 2px; border-radius: 99px; position: relative; z-index: 1; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #37c26a; box-shadow: 0 0 0 3px rgba(55,194,106,.2); margin-top: -2px; }
.tile-name { font-size: 1.15rem; font-weight: 600; color: var(--ink); line-height: 1.3; }
.tile-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .88rem; color: var(--muted); }
.meta-item { display: inline-flex; align-items: center; gap: 5px; }
.meta-item svg { margin-top: -2px; color: var(--teal); }
.tile-foot {
  margin-top: auto; padding-top: 14px; border-top: 1px solid #eef2ef;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; font-size: .9rem; color: var(--green-800);
}
.tile-arrow { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #f1f5f2; transition: background .18s, color .18s, transform .18s; }
.tile:hover .tile-arrow { background: var(--green-800); color: #fff; transform: translateX(3px); }
.empty { text-align: center; padding: 56px 24px; }
.empty-icon { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; color: var(--teal-dark); background: var(--teal-soft); }

/* ---------- Login (light) ---------- */
.auth { flex: 1; display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.auth-brand {
  background:
    radial-gradient(circle at 85% 12%, rgba(122,252,32,.20), transparent 42%),
    radial-gradient(circle at 8% 92%, rgba(74,164,133,.20), transparent 48%),
    linear-gradient(160deg, #f7fbf6, #e9f5ee);
  border-right: 1px solid var(--border);
  display: flex; align-items: center; padding: 60px;
}
.auth-brand-inner { max-width: 460px; }
.auth-logo { display: inline-flex; margin-bottom: 30px; }
.auth-logo img { height: 110px; display: block; mix-blend-mode: multiply; }
.auth-brand h1 { font-size: 2.3rem; font-weight: 900; color: var(--ink); }
.auth-brand h1 span { color: var(--green-800); background: linear-gradient(transparent 62%, rgba(122,252,32,.45) 62%); padding: 0 2px; }
.auth-brand p { color: var(--text); font-size: 1.08rem; }
.auth-points { list-style: none; padding: 0; margin: 24px 0 34px; }
.auth-points li { padding: 6px 0 6px 32px; position: relative; color: var(--text); }
.auth-points li::before { content: "✓"; position: absolute; left: 0; top: 7px; width: 21px; height: 21px; border-radius: 50%; background: var(--green-800); color: #fff; font-size: 12px; font-weight: 700; line-height: 22px; text-align: center; }
.auth-site { font-weight: 600; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: #fff; }
.auth-card { width: 100%; max-width: 380px; padding: 8px 0; margin: 0; border: 0; box-shadow: none; background: transparent; }
.auth-card h2 { font-size: 1.6rem; }
.auth-card .btn-block { margin-top: 6px; padding: 14px 18px 12px; font-size: 1rem; }
.auth-card .small { margin: 18px 0 0; }
.auth-logo-mobile { display: none; }

/* ---------- Report viewer (light) ---------- */
.area-viewer { height: 100vh; overflow: hidden; }
.viewer { display: flex; flex-direction: column; height: 100vh; background: #fff; }
.viewer-bar {
  flex: none; display: flex; align-items: center; gap: 10px;
  height: 60px; padding: 0 14px; background: #fff;
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
  position: relative;
}
.viewer-bar::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: linear-gradient(90deg, var(--green-800), var(--teal) 55%, var(--lime)); }
.viewer-logo { display: flex; flex: none; }
.viewer-logo img { height: 42px; }
.viewer-divider { width: 1px; height: 28px; background: var(--border-strong); margin: 0 4px; flex: none; }
.viewer-title { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.viewer-title strong { color: var(--ink); font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-title small { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-switch { margin: 0; padding: 2px 28px 0 0; border: 0; background-color: transparent; font-weight: 600; color: var(--ink); font-size: 1rem; cursor: pointer; width: auto; max-width: 100%; box-shadow: none !important; }
.viewer-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: none; }
.viewer-frame { flex: 1; position: relative; background: #fff; }
.viewer-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--muted); }
.spinner { width: 40px; height: 40px; border: 3px solid #e6eee8; border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; margin-bottom: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.viewer .center-page { background: var(--bg); }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-logo-mobile { display: flex; justify-content: center; margin-bottom: 18px; }
  .auth-logo-mobile img { height: 90px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters-actions { grid-column: 1 / -1; }
}
@media (max-width: 800px) {
  .nav-toggle { display: block; }
  .topbar-inner { position: relative; height: 60px; padding: 0 16px; }
  .brand img { height: 40px; }
  .nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%; height: auto;
    flex-direction: column; align-items: stretch; gap: 6px;
    background: #fff; padding: 8px 16px 16px; border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .nav-open .nav { display: flex; }
  .nav-links { flex-direction: column; align-items: stretch; height: auto; }
  .nav-links a { height: auto; padding: 11px 12px 9px; border-radius: 10px; }
  .nav-links a.active { background: var(--teal-soft); }
  .nav-links a.active::after { display: none; }
  .nav-user { padding-top: 12px; border-top: 1px solid var(--border); }
  .nav-user form { margin-left: auto; }
  .container { padding: 22px 16px 32px; }
  h1 { font-size: 1.4rem; }
  .form-row { grid-template-columns: 1fr; }
  .search { flex-wrap: wrap; width: 100%; }
  .search input, .search select { min-width: 0; flex: 1; }
  .page-actions { width: 100%; }
  .tiles { grid-template-columns: 1fr; }
  .site-list { grid-template-columns: 1fr; }
  .tile { min-height: 0; }
  .viewer-bar { height: 54px; padding: 0 8px; gap: 6px; }
  .viewer-logo img { height: 34px; }
  .viewer-divider, .hide-sm { display: none; }
  .card { padding: 18px; }
}
