:root {
  --ink: #212529;
  --muted: #61666d;
  --surface: #fff;
  --bg: #f8f9fa;
  --border: #d3d7dc;
  --brand: #f29559;
  --blue: #2563eb;
  --green: #16875d;
  --red: #b42318;
  --soft-blue: #edf4ff;
  --soft-green: #eaf7f1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body.portal-body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  margin: 0;
  overflow: hidden;
}
.portal-navbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  left: 0;
  min-height: 60px;
  padding: 10px 20px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 1030;
}
.portal-brand { color: var(--ink); font-size: 1.2rem; font-weight: 700; }
.portal-brand span, .login-brand span { color: var(--brand); }
.portal-brand em, .login-brand em { color: #4b4b4b; font-style: normal; font-weight: 600; }
.portal-navbar .nav-link { color: #4b4b4b; padding-bottom: 4px; padding-top: 4px; }
.portal-navbar .nav-link:hover { color: var(--blue); }
.portal-userbox { align-items: center; display: flex; gap: 12px; }
.portal-userbox form { margin: 0; }
.portal-main {
  bottom: 36px;
  left: 0;
  overflow: auto;
  padding: 20px;
  position: absolute;
  right: 0;
  top: 60px;
}
.portal-main.is-login { bottom: 0; display: grid; place-items: center; top: 0; }
.portal-footer {
  background: #f0f0f0;
  border-top: 1px solid var(--border);
  bottom: 0;
  color: var(--muted);
  font-size: .72rem;
  height: 36px;
  left: 0;
  padding: 9px 20px;
  position: fixed;
  right: 0;
}
h1 { font-size: clamp(1.55rem, 3vw, 2.15rem); font-weight: 700; margin: 2px 0 4px; }
h2 { font-size: 1rem; font-weight: 700; margin: 0; }
p { color: var(--muted); }
.eyebrow { color: var(--brand); font-size: .7rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.page-heading { align-items: end; display: flex; gap: 24px; justify-content: space-between; margin-bottom: 16px; }
.page-heading p { margin: 0; }
.page-heading.compact { align-items: center; }
.generate-bar { align-items: end; display: grid; gap: 8px; grid-template-columns: minmax(210px, auto) minmax(190px, 1fr) auto; }
.generate-period { background: #fff; border: 1px solid var(--border); border-radius: 4px; min-height: 38px; padding: 7px 9px; }
.generate-period label { color: var(--muted); display: block; font-size: .62rem; line-height: 1; margin: 0; }
.generate-period strong { font-size: .8rem; }
.generate-status { color: var(--muted); font-size: .72rem; grid-column: 1 / -1; text-align: right; }
.generate-bar label, .portal-form label { display: block; font-size: .73rem; font-weight: 700; margin-bottom: 4px; }
input, select, textarea {
  background: #fff;
  border: 1px solid #bfc5cc;
  border-radius: 4px;
  min-height: 38px;
  padding: 7px 9px;
  width: 100%;
}
input[type="checkbox"] { min-height: auto; width: auto; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 7px rgb(15 23 42 / 5%);
  margin-bottom: 16px;
  padding: 16px;
}
.panel-heading { align-items: center; display: flex; justify-content: space-between; margin-bottom: 10px; }
.metric-grid { display: grid; gap: 10px; grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; }
.metric-card { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: 5px; display: grid; padding: 12px 14px; }
.metric-card span { color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.metric-card strong { font-size: 1.35rem; }
.metric-card small { color: var(--muted); }
.production-chart-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
.production-chart-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  padding: 14px 16px 10px;
  text-align: left;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
.production-chart-card:first-child { grid-column: span 2; }
.production-chart-card:hover, .production-chart-card:focus-visible { border-color: #9eb9ee; box-shadow: 0 7px 22px rgb(37 99 235 / 12%); outline: 0; transform: translateY(-1px); }
.chart-card-heading, .chart-card-footer { align-items: flex-start; display: flex; gap: 12px; justify-content: space-between; }
.chart-card-heading > span:first-child { display: grid; }
.chart-card-heading > span:first-child > strong { font-size: 1rem; margin-top: 2px; }
.chart-current { text-align: right; }
.chart-current strong { display: block; font-size: 1.12rem; }
.chart-current small, .chart-card-footer { color: var(--muted); font-size: .68rem; }
.chart-current .chart-secondary-current { color: #b45309; margin-top: 2px; }
.chart-current .chart-plan-current { color: #6d28d9; margin-top: 2px; }
.production-mini-chart { display: block; height: 145px; margin: 5px 0 2px; width: 100%; }
.chart-card-footer { border-top: 1px solid #edf0f2; padding-top: 7px; }
.chart-card-footer span:last-child { color: var(--blue); font-weight: 700; }
.production-modal .modal-dialog { max-width: min(1320px, 96vw); }
.production-modal .modal-content { border: 0; box-shadow: 0 22px 80px rgb(15 23 42 / 25%); }
.production-modal .modal-header { align-items: flex-start; }
.production-modal .modal-header p { font-size: .78rem; margin-top: 4px; }
.chart-range-toolbar { align-items: end; display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chart-range-toolbar label { color: var(--muted); font-size: .7rem; font-weight: 700; }
.chart-range-toolbar input { display: block; min-height: 32px; padding: 4px 7px; width: 145px; }
.production-large-chart-wrap { background: #fbfcfe; border: 1px solid var(--border); border-radius: 6px; min-height: 450px; overflow: hidden; position: relative; }
#productionLargeChart { display: block; height: 430px; width: 100%; }
.chart-legend { align-items: center; display: flex; flex-wrap: wrap; gap: 8px 16px; min-height: 30px; padding: 8px 12px 0; }
.chart-legend span { align-items: center; color: var(--muted); display: inline-flex; font-size: .7rem; font-weight: 700; gap: 6px; }
.chart-legend i { background: #2563eb; border-radius: 2px; display: inline-block; height: 3px; width: 20px; }
.chart-legend i.is-secondary { background: #f59e0b; }
.chart-legend i.is-plan { background: #7c3aed; }
.chart-tooltip .is-secondary-value { color: #fbbf24; }
.chart-tooltip .is-plan-value { color: #c4b5fd; }
.chart-tooltip { background: rgb(24 30 39 / 94%); border-radius: 5px; color: #fff; font-size: .72rem; padding: 7px 9px; pointer-events: none; position: absolute; z-index: 2; }
.chart-tooltip strong, .chart-tooltip span { display: block; }
.chart-tooltip span { color: #d8dde5; }
.chart-loading { align-items: center; background: rgb(255 255 255 / 78%); bottom: 0; color: var(--muted); display: flex; font-size: .8rem; justify-content: center; left: 0; position: absolute; right: 0; top: 0; z-index: 3; }
.chart-loading[hidden] { display: none; }
.dashboard-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .75fr); }
.portal-table { font-size: .79rem; margin: 0; }
.portal-table thead th { background: #f4f6f8; border-bottom-color: var(--border); color: #50555b; font-size: .67rem; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.portal-table td { vertical-align: middle; }
.portal-table td small { color: var(--muted); display: block; font-size: .68rem; }
.portal-table code { color: #465569; font-size: .72rem; }
.type-badge, .status { border-radius: 999px; display: inline-block; font-size: .67rem; font-weight: 700; padding: 3px 7px; white-space: nowrap; }
.type-badge.is-hydro { background: #e8f2ff; color: #175ca8; }
.type-badge.is-wind { background: #e9f7ef; color: #24734d; }
.status.success { background: var(--soft-green); color: var(--green); }
.status.danger { background: #fff0ef; color: var(--red); }
.status.muted { background: #eef0f2; color: #687078; }
.status.warning { background: #fff4ce; color: #815b00; }
.run-list > a { align-items: center; border-bottom: 1px solid var(--border); color: var(--ink); display: flex; justify-content: space-between; padding: 11px 4px; text-decoration: none; }
.run-list > a:hover { background: #fafbfc; }
.run-list small { color: var(--muted); display: block; font-size: .7rem; }
.split-grid { display: grid; gap: 16px; grid-template-columns: minmax(320px, .8fr) minmax(0, 1.4fr); }
.portal-form > div { margin-bottom: 12px; }
.portal-form .errorlist { color: var(--red); font-size: .75rem; margin: 4px 0; }
.portal-form .helptext { color: var(--muted); display: block; font-size: .7rem; margin-top: 3px; }
.wide-form { max-width: 1100px; }
.form-section + .form-section { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 18px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 12px; }
.check-field { align-items: center; display: flex; gap: 8px; }
.check-field label { margin: 0; }
.form-actions { margin-top: 18px; }
.section-note { color: var(--muted); font-size: .78rem; margin: 6px 0; }
.item-list > div { align-items: center; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; padding: 12px 0; }
.item-list > div:last-child { border-bottom: 0; }
.item-list span, .item-list small { color: var(--muted); display: block; font-size: .75rem; }
.empty-state { color: var(--muted); font-size: .82rem; padding: 20px 4px !important; }
.integration-note code { background: #f3f5f7; border-radius: 4px; display: block; margin: 6px 0; overflow-wrap: anywhere; padding: 8px; }
.integration-note p { font-size: .78rem; margin: 8px 0 0; }
.integration-note p code { display: inline; padding: 2px 4px; }
.action-bar { display: flex; gap: 8px; }
.reading-filter { align-items: end; display: flex; gap: 8px; margin-bottom: 12px; }
.reading-filter > div { flex: 1 1 360px; max-width: 620px; }
.reading-filter.wind-filter > div { flex-basis: 180px; max-width: 420px; }
.wind-export-actions { margin: 4px 0 12px; }
.reading-filter label { display: block; font-size: .73rem; font-weight: 700; margin-bottom: 4px; }
.reading-pagination { align-items: center; color: var(--muted); display: flex; font-size: .75rem; justify-content: space-between; padding-top: 12px; }
.plan-preview { max-height: 520px; overflow: auto; }
.plan-preview thead { position: sticky; top: 0; z-index: 1; }
.login-shell { width: min(420px, 94vw); }
.login-brand { font-size: 1.6rem; font-weight: 700; margin-bottom: 12px; text-align: center; }
.login-panel { padding: 28px; }
.login-panel h1 { font-size: 1.5rem; }

@media (max-width: 980px) {
  body.portal-body { overflow: auto; }
  .portal-main { bottom: auto; min-height: calc(100vh - 60px); position: relative; top: 60px; }
  .portal-footer { display: none; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .generate-bar, .dashboard-grid, .split-grid { grid-template-columns: 1fr; }
  .production-chart-grid { grid-template-columns: 1fr; }
  .production-chart-card:first-child { grid-column: auto; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .reading-pagination { align-items: stretch; flex-direction: column; gap: 8px; }
}
@media (max-width: 560px) {
  .portal-main { padding: 12px; }
  .metric-grid, .form-grid { grid-template-columns: 1fr; }
  .action-bar { flex-direction: column; width: 100%; }
  .reading-filter { align-items: stretch; flex-direction: column; }
  .reading-filter > div { flex-basis: auto; max-width: none; }
  .reading-pagination .pagination { flex-wrap: wrap; }
  .chart-card-heading { align-items: flex-start; }
  .chart-range-toolbar { align-items: stretch; flex-direction: column; }
  .chart-range-toolbar .btn-group, .chart-range-toolbar label, .chart-range-toolbar input, .chart-range-toolbar > .btn { width: 100%; }
  .production-modal .modal-dialog { margin: 6px; max-width: none; width: calc(100% - 12px); }
  .production-modal .modal-header, .production-modal .modal-body { padding: 12px; }
  .production-modal .modal-header > div { min-width: 0; }
  .production-modal .modal-title { font-size: 1.15rem; overflow-wrap: anywhere; }
  .production-large-chart-wrap { min-height: 340px; width: 100%; }
  .chart-range-toolbar .btn-group { display: grid; grid-template-columns: repeat(2, 1fr); }
  .chart-range-toolbar .btn-group > .btn { border-radius: 4px !important; }
  .chart-legend { gap: 5px 10px; padding-inline: 8px; }
}
