/* Prosperity Energy back office */
:root {
  --red: #c8102e; --red-dark: #9d0c24; --navy: #0b1826; --navy-2: #13273b; --ink: #0f1c2a; --muted: #55606c;
  --line: #dcd9d2; --paper: #f5f3ee; --white: #fff; --green: #1c6b3a; --amber: #8a5a00; --radius: 4px;
  --sans: "Anuphan", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15.5px/1.6 var(--sans); color: var(--ink); background: var(--paper); }
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
h1 { font-size: 26px; font-weight: 600; line-height: 1.3; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15.5px; font-weight: 600; }
a { color: var(--red-dark); text-underline-offset: 3px; }
small { font-size: 13px; font-weight: 400; color: var(--muted); }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
.late { color: var(--red-dark); font-weight: 600; }
.center { text-align: center; }

/* Layout */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--navy); color: #fff; padding: 22px 14px 18px; overflow-y: auto; }
.side-brand { display: block; padding: 4px 10px 22px; color: #fff; text-decoration: none; font-size: 19px; font-weight: 600; }
.side-brand b { color: #ff8a96; font-weight: 600; }
.side-brand span { display: block; font-size: 13px; font-weight: 400; color: rgba(255,255,255,.7); }
.side nav { display: grid; gap: 2px; }
.side nav a { display: block; padding: 10px 12px; border-radius: var(--radius); color: rgba(255,255,255,.84); text-decoration: none; font-weight: 500; }
.side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side nav a[aria-current="page"] { background: var(--red); color: #fff; }
.side-user { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid rgba(255,255,255,.16); font-size: 14px; }
.side-user strong { display: block; font-weight: 600; }
.side-user span { color: rgba(255,255,255,.7); }
.side-links { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; }
.side-links a, .side-links button { padding: 6px 0; border: 0; background: none; font: inherit; color: rgba(255,255,255,.84); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.main { padding: 30px 36px 64px; min-width: 0; }
.menu-toggle { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 24px; margin-bottom: 22px; }
.page-head .muted { margin-top: 4px; }
.crumb { font-size: 14px; margin-bottom: 2px; }
.crumb a { color: var(--muted); }
.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 9px 16px; border: 1px solid #bdb9b0; border-radius: var(--radius); background: #fff; font: 500 15px/1.2 var(--sans); color: var(--ink); text-decoration: none; cursor: pointer; transition: background-color .15s, border-color .15s; }
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn-danger { background: var(--red-dark); border-color: var(--red-dark); color: #fff; }
.btn-danger-ghost { color: var(--red-dark); border-color: #e1b5bc; }
.btn-danger-ghost:hover { border-color: var(--red-dark); }
.link { padding: 0; border: 0; background: none; font: inherit; color: var(--red-dark); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.inline-form { display: inline-flex; gap: 8px; margin: 0; }

/* Messages */
.flash { display: grid; gap: 8px; margin-bottom: 18px; }
.flash p, .flash-error, .notice { padding: 11px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.flash-success { border-color: #b9d8c4; background: #eef7f1; color: var(--green); }
.flash-error { border-color: #e1b5bc; background: #fbeef0; color: var(--red-dark); }
.notice { border-color: #e6d3a8; background: #fbf5e6; color: #5c3d00; margin-bottom: 18px; }

/* Tabs and toolbar */
.tabs { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--muted); text-decoration: none; font-weight: 500; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--red); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.toolbar input, .toolbar select { min-height: 40px; padding: 8px 12px; border: 1px solid #bdb9b0; border-radius: var(--radius); background: #fff; font: 15px var(--sans); color: var(--ink); }
.toolbar input[type="search"] { flex: 1 1 240px; max-width: 360px; }

/* Panels */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.panel.table-wrap { padding: 0; }
.table-wrap { overflow-x: auto; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.two-col .panel { margin-bottom: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }
.cards .panel { margin-bottom: 0; }
.dept.is-off { opacity: .6; }
.note { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); }
.empty { padding: 18px 0; color: var(--muted); }
td.empty { padding: 28px 16px; text-align: center; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 16px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table thead th { font-size: 14px; font-weight: 600; color: var(--muted); white-space: nowrap; background: #faf9f6; }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: 0; }
.table tbody tr:hover td { background: #faf9f6; }
.table tfoot th, .table tfoot td { border-top: 1px solid var(--ink); border-bottom: 0; font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions a, .table .actions .link { margin-left: 14px; }
.table .danger, .link.danger { color: var(--red-dark); }
.table .grand th { font-size: 17px; }
.table .grow { width: 50%; }
.table td input, .table td select { min-height: 38px; padding: 7px 10px; border: 1px solid #bdb9b0; border-radius: var(--radius); font: 15px var(--sans); width: 100%; min-width: 80px; }
.table td input[type="checkbox"] { width: 20px; min-width: 0; min-height: 20px; }
.table.sums th { font-weight: 500; }
.matrix thead th small { display: block; }
.matrix tbody th { font-weight: 400; }
.matrix .group th { background: var(--paper); font-weight: 600; }
.matrix input { width: 20px; height: 20px; accent-color: var(--red); }
.pager { display: flex; align-items: center; gap: 16px; margin-top: -4px; }

/* Forms */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; max-width: 980px; }
.form.narrow { grid-template-columns: 1fr; max-width: 520px; }
.field { display: grid; gap: 5px; align-content: start; }
.field label { font-size: 14.5px; font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid #bdb9b0; border-radius: var(--radius); background: #fff; font: 15.5px/1.5 var(--sans); color: var(--ink); }
.field textarea { grid-column: 1 / -1; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--navy); outline-offset: 0; border-color: var(--navy); }
.field-check { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.field-check input { width: 20px; min-height: 20px; height: 20px; order: -1; accent-color: var(--red); }
.field ul, .field > div[id] { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; }
.field ul label, .field > div[id] label { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.field ul input, .field > div[id] input { width: 18px; min-height: 18px; height: 18px; accent-color: var(--red); }
.req { color: var(--red); }
.help { font-size: 13.5px; color: var(--muted); }
.error { font-size: 14px; color: var(--red-dark); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--red); }
.form-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.panel > .form-actions, form > .form-actions { margin-top: 16px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.action-row select { flex: 1 1 220px; min-height: 40px; padding: 8px 12px; border: 1px solid #bdb9b0; border-radius: var(--radius); background: #fff; font: 15px var(--sans); max-width: 340px; }
.action-row input { flex: 1 1 260px; min-height: 40px; padding: 8px 12px; border: 1px solid #bdb9b0; border-radius: var(--radius); font: 15px var(--sans); }

/* Figures */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.tile { display: grid; gap: 2px; padding: 18px 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; transition: border-color .15s; }
.tile:hover { border-color: var(--ink); }
.tile-label { font-size: 14px; color: var(--muted); }
.tile strong { font-size: 30px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile-note { font-size: 13.5px; color: var(--muted); }
.tile-alert strong { color: var(--red-dark); }
.figures { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px 28px; }
.figures.two { grid-template-columns: repeat(2, 1fr); }
.figures dt { font-size: 27px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.figures dt small { font-size: 14px; }
.figures dd { margin-top: 2px; font-size: 14px; color: var(--muted); }
.kv > div { display: grid; grid-template-columns: 160px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); }
.bars li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.bars li:last-child { border-bottom: 0; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.log span { color: var(--muted); font-variant-numeric: tabular-nums; }
.steps { display: grid; gap: 0; }
.steps li { display: grid; gap: 0; padding: 9px 0 9px 26px; position: relative; color: var(--muted); }
.steps li::before { content: ""; position: absolute; left: 4px; top: 15px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #bdb9b0; background: #fff; }
.steps li.done { color: var(--ink); }
.steps li.done::before { background: var(--green); border-color: var(--green); }
.steps span { font-size: 14px; color: var(--muted); }
.meter { display: flex; height: 14px; margin-top: 18px; background: #e6e2d9; border-radius: 2px; overflow: hidden; }
.meter-a { background: var(--green); }
.meter-b { background: #d99a1e; }
.legend { margin-top: 8px; font-size: 14px; color: var(--muted); }
.key { display: inline-block; width: 12px; height: 12px; margin: 0 4px 0 12px; border-radius: 2px; vertical-align: -1px; background: #e6e2d9; }
.key:first-child { margin-left: 0; }
.key-a { background: var(--green); }
.key-b { background: #d99a1e; }

/* Badges */
.badge, .tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; line-height: 1.5; background: #ebe8e1; color: var(--ink); vertical-align: middle; white-space: nowrap; }
.tag { border-radius: var(--radius); margin-right: 6px; }
.badge-install, .badge-commission, .badge-po-requested, .badge-inv-billed, .badge-chq-deposited, .tag-high, .badge-alarm-warning, .badge-plant-idle { background: #fbf0d6; color: #5c3d00; }
.badge-handover, .badge-om, .badge-po-approved, .badge-po-received, .badge-inv-paid, .badge-chq-cleared, .badge-plant-online { background: #e3f1e8; color: var(--green); }
.badge-po-rejected, .badge-po-cancelled, .badge-inv-cancelled, .badge-chq-bounced, .tag-urgent, .badge-alarm-critical, .badge-plant-offline, .badge-plant-error { background: #fbe3e7; color: var(--red-dark); }
.badge-procure, .badge-survey, .badge-po-ordered, .badge-inv-cheque, .badge-inv-issued, .badge-chq-received { background: #e3ebf5; color: #1d3f66; }

/* Kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.lane { background: #ebe8e1; border-radius: var(--radius); padding: 12px; min-height: 140px; }
.lane.is-over, .lane.is-full-target { background: #fbe3e7; }
.lane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.lane-head h2, .lane-head h3 { font-size: 15px; font-weight: 600; }
.lane-count { font-size: 13.5px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.lane.is-over .lane-count { color: var(--red-dark); }
.lane-note { font-size: 13.5px; color: var(--muted); margin-bottom: 8px; }
.lane-body { display: grid; gap: 8px; min-height: 60px; padding-top: 6px; align-content: start; }
.lane-body.is-target { outline: 2px dashed var(--navy); outline-offset: 2px; border-radius: var(--radius); }
.lane-empty { padding: 10px 2px; font-size: 14px; color: var(--muted); }
.lane-add { display: block; margin-top: 10px; padding: 9px 10px; border-radius: var(--radius); font-size: 14.5px; color: var(--muted); text-decoration: none; }
.lane-add:hover { background: rgba(11,24,38,.06); color: var(--ink); }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 13px; box-shadow: 0 1px 2px rgba(11,24,38,.06); }
.card[draggable="true"] { cursor: grab; }
.card.is-dragging { opacity: .45; }
.card-title { display: block; font-weight: 600; line-height: 1.4; color: var(--ink); text-decoration: none; }
a.card-title:hover { color: var(--red-dark); text-decoration: underline; }
.card-meta { margin-top: 4px; font-size: 13.5px; color: var(--muted); }
.board-msg { min-height: 0; margin-bottom: 0; }
.board-msg:not(:empty) { padding: 11px 16px; margin-bottom: 14px; border: 1px solid #e1b5bc; border-radius: var(--radius); background: #fbeef0; color: var(--red-dark); }
.board-static { grid-auto-columns: minmax(230px, 1fr); }

/* Charts */
.chart { min-height: 220px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font: 12.5px var(--sans); fill: var(--muted); }
.chart .val { fill: var(--ink); font-weight: 600; }
.chart-empty { padding: 60px 0; text-align: center; color: var(--muted); }
.chart-legend { display: flex; gap: 18px; margin-top: 6px; font-size: 14px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 2px; vertical-align: -1px; }

/* Monitoring */
.plants { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.plant { display: grid; gap: 3px; padding: 16px 18px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; transition: border-color .15s; }
.plant:hover { border-color: var(--ink); }
.plant-state { justify-self: start; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; background: #ebe8e1; }
.state-online .plant-state { background: #e3f1e8; color: var(--green); }
.state-idle .plant-state { background: #fbf0d6; color: #5c3d00; }
.state-offline .plant-state, .state-error .plant-state { background: #fbe3e7; color: var(--red-dark); }
.plant-name { margin-top: 6px; font-weight: 600; line-height: 1.4; }
.plant-meta { font-size: 13.5px; color: var(--muted); }
.plant-power { margin-top: 8px; font-size: 28px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.plant-bar { display: block; height: 6px; margin: 4px 0 6px; background: #e6e2d9; border-radius: 3px; overflow: hidden; }
.plant-bar span { display: block; height: 100%; max-width: 100%; background: var(--green); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--navy); }
.login-card { display: grid; gap: 10px; width: 100%; max-width: 400px; padding: 36px; background: #fff; border-radius: var(--radius); }
.login-card h1 b { color: var(--red); font-weight: 600; }
.login-card label { margin-top: 8px; font-size: 14.5px; font-weight: 500; }
.login-card input { min-height: 46px; padding: 10px 12px; border: 1px solid #bdb9b0; border-radius: var(--radius); font: 16px var(--sans); }
.login-card .btn { margin-top: 14px; min-height: 46px; }

@media (max-width: 1000px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(11,24,38,.5); }
  .menu-toggle { display: inline-flex; align-items: center; min-height: 40px; padding: 9px 16px; margin-bottom: 16px; border: 1px solid #bdb9b0; border-radius: var(--radius); background: #fff; font: 500 15px var(--sans); cursor: pointer; }
  .main { padding: 20px 18px 48px; }
  .two-col, .form { grid-template-columns: 1fr; }
  .figures { grid-template-columns: repeat(2, 1fr); }
  .kv > div { grid-template-columns: 1fr; gap: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }
