/* Pipelet Load Management — Momentum-aligned operator UI */

/* Self-hosted serif font — no external requests */
@font-face { font-family:'Source Serif 4'; font-style:italic; font-weight:400; font-display:swap; src:url('/static/fonts/source-serif-4-400-italic.ttf') format('truetype'); }
@font-face { font-family:'Source Serif 4'; font-style:italic; font-weight:700; font-display:swap; src:url('/static/fonts/source-serif-4-700-italic.ttf') format('truetype'); }
@font-face { font-family:'Source Serif 4'; font-style:normal; font-weight:300; font-display:swap; src:url('/static/fonts/source-serif-4-300.ttf') format('truetype'); }
@font-face { font-family:'Source Serif 4'; font-style:normal; font-weight:400; font-display:swap; src:url('/static/fonts/source-serif-4-400.ttf') format('truetype'); }
@font-face { font-family:'Source Serif 4'; font-style:normal; font-weight:500; font-display:swap; src:url('/static/fonts/source-serif-4-500.ttf') format('truetype'); }
@font-face { font-family:'Source Serif 4'; font-style:normal; font-weight:700; font-display:swap; src:url('/static/fonts/source-serif-4-700.ttf') format('truetype'); }


*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(180deg, #f5efe4 0%, #ffffff 100%);
  background-attachment: fixed;
  color: #181D27;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: '';
  position: fixed; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, #c49a6c, #1170cf 50%, #c49a6c);
  z-index: 10;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(160%) blur(10px);
  position: sticky; top: 0; z-index: 5;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: 'GT Alpina', 'Source Serif 4', Georgia, 'Times New Roman', serif;
  font-size: 15px; font-weight: 500; letter-spacing: -0.01em;
  color: #181D27;
}

.auth-hint { font-size: 12px; color: #A4A7AE; cursor: pointer; }
.auth-hint:hover { color: #1170cf; }

.content { max-width: 1200px; margin: 32px auto; padding: 0 32px; }

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px;
}

h2 {
  font-family: 'GT Alpina', 'Source Serif 4', Georgia, 'Times New Roman', serif;
  font-size: 22px; font-weight: 500; letter-spacing: -0.3px;
}
h3 {
  font-family: 'GT Alpina', 'Source Serif 4', Georgia, 'Times New Roman', serif;
  font-size: 20px; font-weight: 500; margin-bottom: 18px;
}
h4 {
  font-size: 11px; font-weight: 600; color: #535862;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin: 16px 0 8px;
}

.muted { color: #535862; font-size: 14px; line-height: 1.5; }

button {
  padding: 8px 16px; font-size: 14px; font-weight: 600;
  border-radius: 9999px; border: 1px solid transparent;
  cursor: pointer; font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
button.primary { background: #1170cf; color: #fff; }
button.primary:hover { background: #0353a8; }
button.ghost { background: #fff; color: #181D27; border-color: #D5D7DA; }
button.ghost:hover { border-color: #1170cf; color: #1170cf; }
button.danger { background: #fff; color: #ab0a15; border-color: #FECDCA; }
button.danger:hover { background: #ffe8ea; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.card {
  background: #fff; border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px; padding: 18px 20px;
  display: flex; flex-direction: column; gap: 10px;
  cursor: pointer; transition: box-shadow 0.15s, border-color 0.15s;
}
.card:hover { border-color: rgba(17, 112, 207, 0.4); box-shadow: 0 4px 12px rgba(0,0,0,0.04); }

.card-title { font-size: 15px; font-weight: 600; color: #181D27; }
.card-meta { font-size: 12px; color: #A4A7AE; font-family: 'JetBrains Mono', monospace; }

.metric-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  font-size: 12px; color: #535862;
}
.metric-grid span { font-family: 'JetBrains Mono', monospace; color: #181D27; }

.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 6px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.badge.active    { background: #cef5eb; color: #185e46; }
.badge.inactive  { background: #eef1f4; color: #4b5563; }
.badge.pv        { background: #f5efe4; color: #6b4f2a; }
.badge.battery   { background: #eef4fd; color: #1170cf; }

.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.08); border-radius: 12px;
  overflow: hidden;
}
.data-table th, .data-table td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid #f0f0f0;
}
.data-table th {
  background: #f8f9fa; font-size: 11px; font-weight: 600;
  text-transform: uppercase; color: #535862; letter-spacing: 0.04em;
}
.data-table td.mono, .data-table th.mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #535862; }
.data-table td.r, .data-table th.r { text-align: right; }
.data-table td.c, .data-table th.c { text-align: center; }

.state-pill {
  display: inline-block; padding: 2px 10px;
  border-radius: 4px; font-size: 11px; font-weight: 600;
}
.state-pill.accepted  { background: #cef5eb; color: #185e46; }
.state-pill.rejected  { background: #ffe8ea; color: #ab0a15; }
.state-pill.notsupported { background: #fff4d6; color: #8a5a00; }
.state-pill.networkerror { background: #eef1f4; color: #4b5563; }
.state-pill.stationnotconnected { background: #ffe8ea; color: #ab0a15; }

.modal {
  position: fixed; inset: 0;
  background: rgba(24, 29, 39, 0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 32px; z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: #fff; border-radius: 16px;
  max-width: 560px; width: 100%;
  max-height: 90vh; overflow: auto;
  padding: 28px 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-card.large { max-width: 920px; }
.modal-card form { display: flex; flex-direction: column; gap: 12px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #414651; font-weight: 500; }
.modal-card input, .modal-card select {
  padding: 8px 12px; font-size: 14px;
  border: 1px solid #D5D7DA; border-radius: 8px;
  background: #fff; color: #181D27; font-family: inherit;
}
.modal-card input:focus, .modal-card select:focus {
  outline: none; border-color: #1170cf;
  box-shadow: 0 0 0 3px rgba(17,112,207,0.12);
}
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }

.detail-section { margin: 16px 0; }
.detail-kv {
  display: grid; grid-template-columns: 180px 1fr; gap: 8px;
  font-size: 13px; margin: 4px 0;
}
.detail-kv .k { color: #535862; font-weight: 500; }
.detail-kv .v { color: #181D27; font-family: 'JetBrains Mono', monospace; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 18px; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  z-index: 200;
  max-width: 420px;
}
.toast.ok  { background: #cef5eb; color: #185e46; border: 1px solid #A6F4C5; }
.toast.err { background: #ffe8ea; color: #ab0a15; border: 1px solid #FECDCA; }

.tick-pre {
  background: #f8f9fa; border: 1px solid #D5D7DA; border-radius: 8px;
  padding: 16px; font-family: 'JetBrains Mono', monospace; font-size: 11px;
  white-space: pre-wrap; max-height: 400px; overflow: auto;
}

/* ========================================================== M9 — top nav */

.topnav {
  display: flex; gap: 4px; flex: 1;
  margin-left: 24px;
}
.topnav .navlink {
  padding: 8px 14px; border-radius: 6px;
  color: #535862; text-decoration: none; font-weight: 500; font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.topnav .navlink:hover { background: #f1f3f5; color: #181D27; }
.topnav .navlink.active {
  background: #181D27; color: #fff;
}

.route-page.hidden { display: none; }


/* =========================================================== M9 — meters */

.layout-split {
  display: grid; grid-template-columns: 320px 1fr; gap: 16px;
  align-items: start;
}
.meter-source-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 70vh; overflow-y: auto;
}
.meter-source-item {
  background: #fff; border: 1px solid #E9EAEB;
  border-radius: 8px; padding: 12px 14px;
  cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s;
}
.meter-source-item:hover {
  border-color: #181D27;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.meter-source-item.active {
  border-color: #181D27; background: #f8f9fa;
}
.meter-source-item .meter-name {
  font-weight: 600; font-size: 14px; color: #181D27;
}
.meter-source-item .meter-meta {
  font-size: 12px; color: #717680; margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
}
.meter-source-item .quality-pill {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  font-size: 10px; font-weight: 600; margin-left: 6px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.quality-pill.ok        { background: #dcfae6; color: #067647; }
.quality-pill.stale     { background: #fef0c7; color: #b54708; }
.quality-pill.error     { background: #fee4e2; color: #b42318; }
.quality-pill.synthetic { background: #e0eaff; color: #2342a3; }

.meter-chart-card {
  padding: 18px;
}
.meter-chart-card canvas {
  width: 100% !important; height: 220px !important;
}


/* ============================================================ M9 — BESS */

.bess-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.bess-grid .full-row { grid-column: 1 / -1; }
.bess-form .form-group {
  margin-bottom: 12px;
  display: grid; grid-template-columns: 180px 1fr; gap: 8px;
  align-items: center;
}
.bess-form .form-group label {
  font-size: 13px; color: #535862; font-weight: 500;
}
.bess-form .form-group input,
.bess-form .form-group select {
  padding: 6px 10px; border: 1px solid #D5D7DA; border-radius: 6px;
  font-size: 13px; font-family: inherit;
}
.bess-mode-pill {
  display: inline-block; padding: 2px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.bess-mode-pill.idle             { background: #f1f3f5; color: #535862; }
.bess-mode-pill.self_consumption { background: #dcfae6; color: #067647; }
.bess-mode-pill.peak_shaving     { background: #fef0c7; color: #b54708; }
.bess-mode-pill.price_arbitrage  { background: #e0eaff; color: #2342a3; }


/* =========================================================== M9 — Edges */

.edge-table {
  width: 100%; border-collapse: collapse;
  background: #fff; border: 1px solid #E9EAEB; border-radius: 8px;
  overflow: hidden;
}
.edge-table th, .edge-table td {
  padding: 12px 14px; text-align: left; font-size: 13px;
  border-bottom: 1px solid #E9EAEB;
}
.edge-table th {
  background: #fafafa; font-weight: 600; color: #535862;
}
.edge-table tr:last-child td { border-bottom: none; }
.edge-table tr:hover { background: #fafafa; }

.health-pill {
  display: inline-block; padding: 2px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.health-pill.ok    { background: #dcfae6; color: #067647; }
.health-pill.stale { background: #fef0c7; color: #b54708; }
.health-pill.down  { background: #fee4e2; color: #b42318; }


/* ====================================================== M9 — Phase gauge */

.phase-gauge {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: #fff; border: 1px solid #E9EAEB;
  border-radius: 8px;
}
.phase-gauge-bars {
  display: flex; align-items: end; gap: 4px; height: 40px;
}
.phase-gauge-bars .bar {
  width: 14px; background: #181D27; border-radius: 2px 2px 0 0;
  transition: height 0.3s, background 0.15s;
  min-height: 2px;
}
.phase-gauge-bars .bar.hot { background: #c11574; }
.phase-gauge-label {
  font-size: 11px; color: #717680;
  font-family: 'JetBrains Mono', monospace;
}
.phase-gauge-pct {
  font-weight: 700; font-size: 16px; color: #181D27;
  font-family: 'JetBrains Mono', monospace;
}
.phase-gauge-pct.warn     { color: #b54708; }
.phase-gauge-pct.critical { color: #b42318; }


/* ===================================================== M9 — day-ahead UI */

fieldset.day-ahead-fields {
  margin-top: 12px; padding: 12px; border: 1px dashed #D5D7DA;
  border-radius: 8px;
}
fieldset.day-ahead-fields legend {
  font-size: 12px; color: #717680; padding: 0 6px;
}
