/* Transfo theme — modern variant.
   Palette from https://transfo.energy/ (orange #ff712a, green #59b73f),
   restyled into a soft, airy, glassy dashboard look. */
:root {
    --orange: #ff712a;
    --green: #59b73f;
    --green-soft: #8fd07a;
    --blue: #5bb3e6;
    --dark: #1c2530;
    --slate: #7b8794;
    --slate-light: #9aa5b1;
    --line: #e8ecf0;
    --card: rgba(255, 255, 255, 0.72);
    --card-solid: #ffffff;
    --radius: 20px;
    --radius-sm: 14px;
    --shadow: 0 6px 28px rgba(28, 52, 38, 0.07);
    --shadow-sm: 0 2px 10px rgba(28, 52, 38, 0.05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: 'Poppins', 'Segoe UI', Helvetica, Arial, sans-serif;
    color: var(--dark);
    /* soft green-to-white ambient gradient, echoing the reference */
    background:
        radial-gradient(1200px 480px at 18% -8%, rgba(89, 183, 63, 0.18), transparent 60%),
        radial-gradient(1000px 420px at 92% -12%, rgba(91, 179, 230, 0.14), transparent 55%),
        linear-gradient(180deg, #f3f7f4 0%, #f7f9f8 38%, #f6f8fa 100%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

/* The Dash app renders inside an iframe with a transparent body so the
   parent gradient shows through. */
.dash-root { background: transparent; padding: 6px 16px 12px; overflow-x: hidden; }

/* ============================ Top bar ============================ */
.topbar {
    position: relative;
    z-index: 200;                 /* keep nav dropdowns above the dashboard iframe */
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 68px;
    padding: 0 30px;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.6);
}
.topbar-left { display: flex; align-items: center; gap: 11px; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; display: block; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -0.4px; color: var(--dark); }
.brand-dot { color: var(--green); }

/* centre pill nav (decorative, echoes the reference) */
.nav-pill {
    display: flex; align-items: center; gap: 4px;
    background: var(--dark); border-radius: 999px; padding: 6px;
    box-shadow: 0 6px 18px rgba(28, 37, 48, 0.28);
}
.nav-pill .nav-item {
    color: #aeb6c2; font-size: 13px; font-weight: 500;
    padding: 7px 16px; border-radius: 999px; cursor: default; white-space: nowrap;
}
.nav-pill .nav-item.active { background: #fff; color: var(--dark); font-weight: 600; }

/* centered grouped pill nav with dropdown submenus */
.topnav {
    position: absolute; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 4px;
    background: rgba(255, 255, 255, 0.65); backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.7); border-radius: 999px;
    padding: 5px; box-shadow: var(--shadow-sm);
}
.topnav-group { position: relative; }
.topnav-pill {
    display: flex; align-items: center; gap: 7px;
    background: transparent; border: none; cursor: pointer;
    color: var(--dark); font-family: inherit; font-size: 13px; font-weight: 500;
    padding: 8px 16px; border-radius: 999px; white-space: nowrap; transition: background .12s ease;
}
.topnav-pill:hover { background: rgba(89, 183, 63, 0.1); }
.topnav-group.active .topnav-pill { background: var(--dark); color: #fff; font-weight: 600; }
.topnav-icon { display: inline-flex; align-items: center; }
.topnav-caret { font-size: 9px; opacity: .6; margin-left: -2px; }
.topnav-menu {
    position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%);
    display: none; flex-direction: column; min-width: 210px;
    background: #fff; border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 12px 34px rgba(28, 52, 38, 0.14); padding: 6px; z-index: 50;
}
/* transparent bridge filling the gap so hover doesn't drop between pill & menu */
.topnav-menu::before {
    content: ""; position: absolute; left: 0; right: 0; top: -10px; height: 10px;
}
@media (hover: hover) { .topnav-group:hover .topnav-menu { display: flex; } }
.topnav-group.open .topnav-menu { display: flex; }
.topnav-link {
    text-decoration: none; color: var(--dark); font-size: 13px; font-weight: 500;
    padding: 9px 12px; border-radius: 9px; white-space: nowrap; transition: all .1s ease;
}
.topnav-link:hover { background: rgba(89, 183, 63, 0.1); }
.topnav-link.active { background: var(--dark); color: #fff; font-weight: 600; }

.icon-btn {
    width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.6); color: var(--slate); cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: all .12s ease;
}
.icon-btn:hover { background: #fff; color: var(--dark); border-color: var(--green); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--green), var(--green-soft));
    color: #fff; font-weight: 600; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-name { font-size: 13px; font-weight: 600; color: var(--dark); }
.user-role { font-size: 11px; color: var(--slate-light); }
.logout-form { margin: 0; }
.btn-logout {
    color: #fff; background: var(--dark); border: none;
    padding: 9px 18px; border-radius: 999px; font-size: 13px; font-weight: 500;
    cursor: pointer; font-family: inherit;
    box-shadow: 0 4px 14px rgba(28, 37, 48, 0.22); transition: transform .12s ease;
}
.btn-logout:hover { transform: translateY(-1px); background: #2a3744; }

.content { padding: 22px 30px 44px; }
.dash-wrap { max-width: 1480px; margin: 0 auto; }

/* ============================ Title strip ============================ */
.title-strip { display: flex; align-items: center; gap: 14px; margin: 2px 0 18px; }
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -0.6px; color: var(--dark); }
.client-badge {
    font-size: 12px; font-weight: 600; color: var(--green);
    background: rgba(89, 183, 63, 0.14); padding: 5px 14px; border-radius: 999px;
}
.data-badge { font-size: 11px; font-weight: 600; color: var(--slate-light); padding: 4px 10px; }
.data-badge:empty { display: none; }

/* ============================ Cards / panels ============================ */
.panel, .kpi-card {
    background: var(--card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel { padding: 20px; height: 100%; }
.kpi-card { transition: transform .15s ease, box-shadow .15s ease; }
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 12px 34px rgba(28, 52, 38, 0.1); }
.kpi-card .card-body { padding: 20px; }

.panel-head {
    font-size: 15px; font-weight: 600; color: var(--dark);
    margin-bottom: 16px;
}

/* ---- Filter rail ---- */
.filter-panel .filter-label { font-size: 12px; color: var(--slate); margin: 4px 0 2px; }
.ref-date-big { font-size: 30px; font-weight: 700; color: var(--dark); margin-bottom: 12px; letter-spacing: -0.5px; }
.filter-item { margin-top: 10px; }
.filter-panel hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.filter-dd .Select-control {
    border-radius: 10px !important; border-color: var(--line) !important; font-size: 13px;
}
/* Open dropdown menus must float above the panels/charts that follow them in
   the DOM (Gains & Losses, the chart cards). The filter rail gets its own
   stacking context above those siblings, and the react-select menu sits on top. */
.filter-panel { position: relative; z-index: 60; }
.filter-dd { position: relative; }
.filter-dd .Select-menu-outer,
.filter-dd .Select-menu,
.filter-panel .Select.is-open { z-index: 1000 !important; }
.filter-dd .Select-menu-outer {
    border-radius: 10px; box-shadow: 0 12px 34px rgba(28, 52, 38, 0.18);
    border-color: var(--line);
}

/* ---- KPI cards (middle) ---- */
.card-kpi-title { font-size: 14px; font-weight: 600; color: var(--slate); margin-bottom: 4px; }
.card-kpi-value {
    font-size: 44px; font-weight: 700; color: var(--dark);
    line-height: 1.05; margin: 2px 0 14px; letter-spacing: -1px;
}
.card-chart-title { font-size: 12px; color: var(--slate-light); margin-bottom: 2px; font-weight: 500; }

/* ---- Snapshot analysis panel (right) ---- */
.snap-metric {
    margin-bottom: 14px; padding: 14px 16px;
    background: rgba(255, 255, 255, 0.55); border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.7);
}
.snap-metric:last-child { margin-bottom: 0; }
.snap-label { font-size: 12px; color: var(--slate); margin-bottom: 4px; }
.snap-value-row { display: flex; align-items: baseline; gap: 8px; }
.snap-value { font-size: 30px; font-weight: 700; color: var(--dark); letter-spacing: -0.5px; }
.kpi-delta {
    font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
}
.kpi-delta.up { color: var(--orange); background: rgba(255, 113, 42, 0.12); }
.kpi-delta.down { color: var(--green); background: rgba(89, 183, 63, 0.14); }
.kpi-delta.flat { color: var(--slate-light); background: rgba(123, 135, 148, 0.1); }

/* ---- Gains & Losses ---- */
.gainloss-panel { margin-top: 18px; }
.main-row { align-items: stretch; }

/* ============================ Login ============================ */
.login-wrap { min-height: calc(100vh - 68px); display: flex; align-items: center; justify-content: center; }
.login-card {
    background: rgba(255, 255, 255, 0.75); backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.8); border-radius: 24px;
    padding: 40px 38px; width: 380px; box-shadow: 0 20px 60px rgba(28, 52, 38, 0.12);
}
.login-logo { width: 56px; height: 56px; object-fit: contain; display: block; margin: 0 auto 16px; }
.login-title { margin: 0 0 4px; font-size: 24px; font-weight: 700; color: var(--dark); letter-spacing: -0.5px; text-align: center; }
.login-sub { text-align: center; }
.login-sub { margin: 0 0 24px; font-size: 13px; color: var(--slate); }
.login-card label { display: block; font-size: 12px; color: var(--slate); margin: 12px 0 5px; }
.login-card input[type=text], .login-card input[type=password] {
    width: 100%; padding: 12px 14px; border: 1px solid var(--line);
    border-radius: 12px; font-size: 14px; background: rgba(255, 255, 255, 0.8); font-family: inherit;
}
.login-card input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(89, 183, 63, 0.15); }
.btn-primary {
    width: 100%; margin-top: 22px; padding: 13px; border: none; border-radius: 12px;
    background: linear-gradient(135deg, var(--orange), #ff8a4d); color: #fff;
    font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
    box-shadow: 0 8px 20px rgba(255, 113, 42, 0.3); transition: transform .12s ease;
}
.btn-primary:hover { transform: translateY(-1px); }
.login-error { background: #fdecea; color: #d6452f; font-size: 12px; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }
.login-hint { margin-top: 20px; font-size: 11px; color: var(--slate-light); text-align: center; }
.login-hint code { background: rgba(89, 183, 63, 0.12); color: var(--green); padding: 2px 6px; border-radius: 6px; }

.no-client { text-align: center; padding: 90px 20px; color: var(--slate); }

/* ============================ Dashboard switcher ============================ */
.dash-switcher {
    display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.55); backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.7); border-radius: 999px;
    padding: 6px; box-shadow: var(--shadow-sm); width: fit-content; max-width: 100%;
}
.switch-item {
    text-decoration: none; color: var(--slate); font-size: 13px; font-weight: 500;
    padding: 8px 16px; border-radius: 999px; white-space: nowrap; transition: all .12s ease;
}
.switch-item:hover { color: var(--dark); background: rgba(89, 183, 63, 0.1); }
.switch-item.active { background: var(--dark); color: #fff; font-weight: 600; }

/* utility */
.mt { margin-top: 16px; }
.card-chart-title.mt { margin-top: 14px; }

/* ============================ KPI table ============================ */
.kpi-sections { display: flex; flex-direction: column; gap: 18px; }
.kpi-table {
    width: 100%; border-collapse: separate; border-spacing: 0;
    background: var(--card); border: 1px solid rgba(255,255,255,0.7);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
.kpi-section-th {
    text-align: left; font-size: 14px; font-weight: 700; color: var(--dark);
    padding: 14px 18px; background: rgba(89,183,63,0.08);
}
.kpi-col-th {
    text-align: right; font-size: 12px; font-weight: 600; color: var(--slate);
    padding: 14px 18px; background: rgba(89,183,63,0.08); white-space: nowrap;
}
.kpi-row-label { font-size: 13px; font-weight: 600; color: var(--dark); padding: 12px 18px;
    border-top: 1px solid var(--line); }
.kpi-cell { text-align: right; padding: 12px 18px; border-top: 1px solid var(--line);
    white-space: nowrap; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--dark); letter-spacing: -0.5px; }
.kpi-budget { color: var(--slate); font-size: 14px; }
.kpi-sup { font-size: 9px; margin-left: 3px; font-weight: 600; }
.kpi-sup.good { color: var(--green); }
.kpi-sup.bad { color: var(--orange); }

/* ============================ Energy Balance table ============================ */
.eb-table-wrap { overflow-x: auto; max-height: 560px; overflow-y: auto; }
.eb-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.eb-th {
    position: sticky; top: 0; background: #fff; text-align: right; color: var(--slate);
    font-weight: 600; padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap;
}
.eb-th-period { text-align: left; }
.eb-period { text-align: right; color: var(--slate); padding: 8px 12px; border-bottom: 1px solid var(--line); }
.eb-cell { text-align: right; padding: 8px 12px; border-bottom: 1px solid var(--line);
    color: var(--dark); white-space: nowrap; }
.eb-cell:nth-child(2), .eb-cell:nth-child(6) {
    background: rgba(89,183,63,0.10); font-weight: 600;
}
.eb-totals { font-weight: 700; color: var(--dark); background: rgba(89,183,63,0.08); }

/* ============================ Variance cards ============================ */
.var-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.var-card {
    background: rgba(255,255,255,0.6); border: 1px solid rgba(255,255,255,0.7);
    border-radius: var(--radius-sm); padding: 16px 18px;
}
.var-label { font-size: 13px; color: var(--slate); margin-bottom: 6px; }
.var-value-row { display: flex; align-items: baseline; gap: 8px; }
.var-value { font-size: 26px; font-weight: 700; color: var(--dark); letter-spacing: -0.5px; }
.var-sub { font-size: 10px; color: var(--slate-light); }

/* ============================ Manage area ============================ */
.btn-ghost {
    color: var(--dark); background: rgba(255,255,255,0.6); border: 1px solid var(--line);
    padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
    text-decoration: none; transition: all .12s ease;
}
.btn-ghost:hover { background: #fff; border-color: var(--green); }

.manage-wrap { max-width: 1200px; margin: 0 auto; }
.manage-head { margin-bottom: 16px; }
.manage-head .page-title { display: block; margin-bottom: 12px; }
.manage-grid { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }

.manage-form { display: flex; flex-direction: column; gap: 4px; }
.manage-form label { font-size: 12px; color: var(--slate); margin-top: 10px; }
.manage-form label.check { flex-direction: row; display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.manage-form input[type=text], .manage-form input[type=email], .manage-form input[type=password],
.manage-form select, .manage-form input[type=file] {
    padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
    font-size: 14px; font-family: inherit; background: rgba(255,255,255,0.8);
}
.manage-form input:focus, .manage-form select:focus { outline: none; border-color: var(--green); }
.manage-form .btn-primary { margin-top: 16px; width: auto; }
.form-hint { font-size: 11px; color: var(--slate-light); margin: 10px 0 0; }
.form-hint code { background: var(--grey-bg); padding: 1px 5px; border-radius: 4px; }

.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data-table th { text-align: left; color: var(--slate); font-weight: 600; padding: 9px 10px;
    border-bottom: 2px solid var(--line); }
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); color: var(--dark); vertical-align: middle; }
.data-table .muted { color: var(--slate-light); }
.pill-ok { background: rgba(89,183,63,0.14); color: var(--green); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-pending { background: rgba(255,113,42,0.12); color: var(--orange); padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.btn-link-danger { background: none; border: none; color: var(--orange); cursor: pointer; font-size: 13px; font-family: inherit; padding: 0; }
.btn-link-danger:hover { text-decoration: underline; }

/* messages */
.msg-list { max-width: 1480px; margin: 0 auto 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 11px 16px; border-radius: 12px; font-size: 13px; border: 1px solid; }
.msg-success { background: rgba(89,183,63,0.1); border-color: rgba(89,183,63,0.3); color: #2f7a1d; }
.msg-error { background: #fdecea; border-color: #f5c6c0; color: #c0341d; }
.msg-info, .msg-warning { background: rgba(91,179,230,0.1); border-color: rgba(91,179,230,0.3); color: #1a6a96; }

/* source-data dashboard controls */
.sd-controls { margin-bottom: 12px; }
.sd-radio label { margin-right: 18px; font-size: 13px; color: var(--dark); }
.sd-notice { padding: 24px; color: var(--slate); font-size: 14px; }

/* ============================ Responsive ============================ */
@media (max-width: 1024px) {
    /* nav no longer fits centered between logo and actions -> wrap to its own row */
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; }
    .topnav {
        position: static; transform: none; order: 3;
        width: 100%; margin-top: 8px; justify-content: center; flex-wrap: wrap;
    }
}
@media (max-width: 820px) {
    .content { padding: 16px 14px 32px; }
    .page-title { font-size: 22px; }
    .var-grid { grid-template-columns: 1fr; }
    .manage-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .user-meta { display: none; }       /* keep avatar + logout, drop name/role */
    .brand { font-size: 16px; }
    .dash-switcher { width: 100%; justify-content: flex-start; }
    .topnav-menu { left: 0; transform: none; min-width: 180px; }
    .topnav-pill { padding: 7px 12px; }
}
