/* Operator web UI — themed to match the invoice PDF (Montserrat, the
   invoice's blue/green palette). Fonts are served from /static/fonts. */

@font-face {
  font-family: "Montserrat";
  src: url("fonts/Montserrat-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Montserrat";
  src: url("fonts/Montserrat-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Montserrat";
  src: url("fonts/Montserrat-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #333333;          /* invoice body text */
  --strong: #222222;       /* invoice value text */
  --muted: #6b7a8c;
  --line: #d5dfec;
  --bg: #f4f7fb;
  --card: #ffffff;
  --accent: #1f5c99;       /* invoice title / tariff-header blue */
  --accent-dark: #2a4c7f;  /* invoice footer-strip navy */
  --accent-ink: #ffffff;
  --band: #cfdff2;         /* invoice header band */
  --band-header: #ccdcf0;  /* invoice tariff-strip header */
  --green: #7bae40;        /* invoice footer green */
  --flash-bg: #eaf1fa;
  --flash-line: #c3d7ee;
  --shell-gap: clamp(1rem, 2.5vw, 2.5rem);  /* side gap for the full-width shell */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

header {
  background: var(--band);
  border-bottom: 3px solid var(--green);
}

/* Navy footer strip echoing the invoice's bottom band. */
.site-footer {
  margin-top: auto;
  background: var(--accent-dark);
  color: #dbe6f5;
  border-top: 3px solid var(--green);
}

.footer-inner {
  margin: 0 auto;
  padding: 0.7rem var(--shell-gap);
  font-size: 0.85rem;
  display: flex;
  gap: 0.5rem;
}

.footer-sep { opacity: 0.6; }

.header-inner {
  margin: 0 auto;
  padding: 0.6rem var(--shell-gap);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--accent);
  letter-spacing: 0.2px;
}

.brand-logo {
  height: 2rem;
  width: auto;
  display: block;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Header pills: nav items and the Home button read as outlined pills on
   the light-blue band; they fill with accent on hover, staying distinct
   from the solid primary action buttons used inside pages. */
nav a,
.nav-btn {
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
}

nav a:hover,
.nav-btn:hover {
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  filter: none;
}

nav form { margin: 0; }

/* Full-width shell: header, main, and footer span the window with a
   small side gap (--shell-gap), so wide tables use the available width
   instead of scrolling inside a narrow centered column. Components that
   should stay narrow (login card, settings forms) set their own
   max-width and remain centered. */
main {
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem var(--shell-gap) 3rem;
  flex: 1;
}

h1 { font-size: 1.35rem; margin: 0.5rem 0 1rem; color: var(--accent); }
h2 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; color: var(--accent-dark); }
h1 .muted, h2 .muted { font-weight: 400; font-size: 0.85em; }

.muted { color: var(--muted); }

a { color: var(--accent); }

code {
  background: #e9eff8;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

pre {
  background: #22344f;
  color: #e6edf3;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
}

.flash {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.flash li {
  background: var(--flash-bg);
  border: 1px solid var(--flash-line);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.5rem;
}

/* Alerts flashed with a message (e.g. Generate's warnings), collapsed
   by default under one "Alerts (N)" box. */
.flash-alerts {
  background: var(--flash-bg);
  border: 1px solid var(--flash-line);
  border-radius: 8px;
  padding: 0 0.9rem;
  margin: 0 0 1rem;
}
.flash-alerts > summary {
  cursor: pointer;
  padding: 0.6rem 0;
  font-weight: 600;
}
.flash-alerts ul { margin: 0 0 0.6rem; padding-left: 1.25rem; font-size: 0.9rem; }
.flash-alerts li { margin: 0.3rem 0; }

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f2f6fc; }
th {
  background: var(--band-header);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}
.num { text-align: right; }

/* Click-to-sort headers (src/web/static/sortable.js). The active column
   shows ⌄ (descending) or ⌃ (ascending) via aria-sort; unsorted columns
   hint the affordance with a faint ⌄ on hover. */
table.sortable th[data-sort-type] { cursor: pointer; user-select: none; }
table.sortable th[data-sort-type]::after {
  content: "⌄";
  display: inline-block;
  width: 1em;
  margin-left: 0.25em;
  opacity: 0;
  font-weight: 700;
}
table.sortable th[data-sort-type]:hover::after { opacity: 0.35; }
table.sortable th[aria-sort="descending"]::after { content: "⌄"; opacity: 1; }
table.sortable th[aria-sort="ascending"]::after { content: "⌃"; opacity: 1; }

/* Drag-to-resize columns (src/web/static/resizable.js). Grips sit on the
   right edge of each header cell; once dragged the table freezes to fixed
   layout and shrunken cells ellipsize. Double-click a grip resets. */
thead th { position: relative; }
.col-grip {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
}
.col-grip:hover, .col-grip:active {
  background: linear-gradient(to right,
    transparent 40%, var(--accent) 40%, var(--accent) 60%, transparent 60%);
  opacity: 0.45;
}
table.is-resized th, table.is-resized td { overflow: hidden; text-overflow: ellipsis; }

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  margin: 0 0 1rem;
}

.facts dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.facts dd { margin: 0; }

.action-card, .login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

.action-card h2 { margin-top: 0; }
.action-card form { display: flex; align-items: end; gap: 0.75rem; flex-wrap: wrap; }
.action-card label { display: block; font-size: 0.8rem; color: var(--muted); }

/* Collapsible card (native <details>, e.g. the plant page's Devices
   section): same dress as .action-card, summary styled like an h2. */
.collapse-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 1.25rem;
  margin: 1rem 0;
}
.collapse-card > summary {
  cursor: pointer;
  padding: 0.75rem 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent-dark);
}
.collapse-card > summary .muted { font-weight: 400; }
.collapse-card[open] { padding-bottom: 1rem; }

.login-card {
  max-width: 22rem;
  margin: 12vh auto 0;
}

.login-card h1 { margin-top: 0; }
.login-card form { display: flex; flex-direction: column; gap: 0.35rem; }
.login-card label { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; }
.login-card button { margin-top: 1rem; }

input {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}

input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* Number field locked to an existing invoice's number (regeneration reuses it). */
input.locked { background: #f1f4f8; color: var(--muted); cursor: not-allowed; }

button {
  padding: 0.45rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }

button.linklike {
  background: none;
  color: var(--ink);
  font-weight: 400;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

select, textarea {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  width: 100%;
}

select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
textarea { resize: vertical; }
textarea.code-edit { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; white-space: pre; }

/* Centered content column for text/card pages, so they don't spread
   edge-to-edge or pin to the left inside the full-width shell. Matches
   the settings form width for a consistent feel. */
.content-narrow { max-width: 60rem; margin-inline: auto; }

/* Settings hub cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.nav-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--ink);
}

.nav-card:hover { border-color: var(--accent); }
.nav-card h2 { margin: 0 0 0.35rem; font-size: 1.05rem; }
.nav-card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.button-link {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.button-link:hover { filter: brightness(1.08); }

/* Settings forms */
.settings-form { max-width: 60rem; margin-inline: auto; }
.settings-form h2 { border-bottom: 1px solid var(--line); padding-bottom: 0.3rem; }

.field { margin: 0.6rem 0; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.2rem; }
.field input, .field select, .field textarea { width: 100%; }

.field-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.field-row .field { flex: 1 1 12rem; }

.help { margin: 0.25rem 0 0; font-size: 0.8rem; color: var(--muted); }

/* Leaflet coordinate picker on the plant form */
#plant-map {
  height: 340px;
  margin-top: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  z-index: 0; /* keep Leaflet panes below the sticky header/nav */
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

input:disabled {
  background: #eef1f5;
  color: var(--muted);
}

/* Invisible wrapper that lets one fieldset[disabled] grey a whole form
   for view-only roles (native HTML: disables every control inside). */
fieldset.role-scope { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.role-scope:disabled select,
fieldset.role-scope:disabled textarea {
  background: #eef1f5;
  color: var(--muted);
}

button.danger { background: #b42318; }
.danger-link { color: #b42318; }
form.inline { display: inline; margin: 0; }
.nowrap { white-space: nowrap; }
tr.is-archived td { background: #f6f8fb; color: var(--muted); }
tr.is-archived td:nth-child(2) { font-style: italic; }
tr.is-voided td { background: #fbf7f7; color: var(--muted); }
tr.is-voided td:nth-child(2) { text-decoration: line-through; }

.badge-archived {
  display: inline-block;
  vertical-align: middle;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a5a00;
  background: #fdf0d5;
  border: 1px solid #f0d79a;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
}

.badge-void {
  display: inline-block;
  vertical-align: middle;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #b42318;
  background: #fdeceb;
  border: 1px solid #f3c3bf;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
}

/* Helper text under the action-card form (the form itself is a flex row, so
   this sits on its own line below it). */
.action-card .hint { margin: 0.4rem 0 0; font-size: 0.8rem; }

/* Month calendar picker (src/web/static/monthpicker.js) */
.month-picker { position: relative; display: inline-block; }

.mp-display {
  cursor: pointer;
  min-width: 11rem;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%231f5c99' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='4' width='18' height='18' rx='2'/><line x1='3' y1='10' x2='21' y2='10'/><line x1='8' y1='2' x2='8' y2='6'/><line x1='16' y1='2' x2='16' y2='6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}

.mp-popup {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  width: 15rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(31, 92, 153, 0.18);
  padding: 0.6rem;
}

.mp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.mp-year { font-weight: 700; color: var(--accent-dark); }

.mp-nav {
  background: none;
  color: var(--accent);
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
}
.mp-nav:hover { background: var(--band); filter: none; }

.mp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}

.mp-month {
  background: #f2f6fc;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.5rem 0;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}
.mp-month:hover { background: var(--band); filter: none; }
.mp-month.selected {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* The plant page's Check panel and the result page (step 18): a finding
   that blocks Generate in red, a warning in plain text. */
.findings { margin: 0.5rem 0; padding-left: 1.25rem; }
.findings li { margin: 0.25rem 0; }
.finding-block { color: #b42318; }
button.secondary { background: var(--card); color: var(--accent); border: 1px solid var(--accent); }
