:root{--bg:#FFFFFF;--side:#FAFAFA;--card:#fff;--border:#E5E7EB;--ink:#111827;--ink-2:#374151;--muted:#6B7280;--primary:#111827;--accent:#F5B301;--active:#F3F1F1;
--solar:#F5B301;--battery:#16A34A;--grid:#2563EB;--home:#64748B;--export:#7C3AED;--heat:#EF4444;--ok:#16A34A;--warn:#D97706;--err:#DC2626;
--radius:10px;--shadow:none}
*{box-sizing:border-box}html,body{margin:0;padding:0}
body{font-family:Inter,system-ui,-apple-system,Segoe UI,sans-serif;background:var(--bg);color:var(--ink);font-size:15px;line-height:1.5;-webkit-font-smoothing:antialiased}
a{color:inherit;text-decoration:none}h1,h2,h3{margin:0;font-weight:600;letter-spacing:-.01em}h1{font-size:22px;font-weight:600}h2{font-size:15px;color:var(--ink);font-weight:600}h3{font-size:13px;color:var(--muted);font-weight:500}
.muted{color:var(--muted)}.small{font-size:12.5px}.mono{font-variant-numeric:tabular-nums}
.shell{display:grid;grid-template-columns:250px 1fr;min-height:100vh}
.sidebar{background:var(--side);border-right:1px solid var(--border);padding:16px 12px;display:flex;flex-direction:column;position:sticky;top:0;height:100vh}
.brand{display:flex;align-items:center;gap:10px;font-weight:600;font-size:16px;padding:8px 10px 22px}.brand-icon{width:30px;height:30px;border-radius:8px;background:var(--primary);display:grid;place-items:center;color:var(--accent)}.brand-icon svg{width:17px;height:17px}
.sidebar nav{display:flex;flex-direction:column;gap:2px}.sidebar nav a{display:flex;align-items:center;gap:11px;padding:9px 12px;border-radius:8px;color:var(--ink);font-weight:500;border-left:3px solid transparent}
.sidebar nav a svg{width:18px;height:18px;color:var(--ink-2)}.sidebar nav a:hover{background:#F3F4F6}.sidebar nav a.active{background:var(--active);color:var(--ink);border-left-color:var(--ink);border-radius:0 8px 8px 0}.sidebar nav a.active svg{color:var(--ink)}
.badge{margin-left:auto;background:var(--err);color:#fff;border-radius:999px;font-size:11px;padding:1px 7px;font-weight:600;display:none}.badge.show{display:inline-block}
.logout{margin-top:auto}.content{padding:28px 36px 48px;max-width:1400px;width:100%}
.topbar{display:flex;align-items:center;justify-content:space-between;margin-bottom:22px;padding-bottom:18px;border-bottom:1px solid var(--border)}.live{display:inline-flex;align-items:center;gap:8px;font-size:13px;color:var(--muted);background:#fff;border:1px solid var(--border);border-radius:8px;padding:6px 12px}
.dot{width:8px;height:8px;border-radius:50%;background:#CBD2DC}.live.ok .dot{background:var(--ok);box-shadow:0 0 0 3px rgba(22,163,74,.15)}.live.bad .dot{background:var(--err)}
.grid{display:grid;gap:16px}.g-4{grid-template-columns:repeat(4,1fr)}.g-3{grid-template-columns:repeat(3,1fr)}.g-2{grid-template-columns:repeat(2,1fr)}.g-32{grid-template-columns:2fr 1fr}
.card{background:var(--card);border:1px solid var(--border);border-radius:var(--radius);padding:20px 22px}
.card-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;gap:10px}.card-head h2{display:flex;align-items:center;gap:8px}.card-head h2 svg{width:16px;height:16px;color:var(--muted)}
.kpi{display:flex;flex-direction:column;gap:6px;position:relative;overflow:hidden}.kpi .lbl{font-size:12.5px;color:var(--muted);display:flex;align-items:center;gap:6px}.kpi .lbl svg{width:15px;height:15px}
.kpi .val{font-size:30px;font-weight:600;letter-spacing:-.02em;font-variant-numeric:tabular-nums;color:var(--ink)}.kpi .val small{font-size:14px;color:var(--muted);font-weight:500;margin-left:4px}.kpi .sub{font-size:12.5px;color:var(--muted)}
.kpi .lbl::before{content:"";width:8px;height:8px;border-radius:50%;background:var(--c,var(--border));display:inline-block}
.c-solar{--c:var(--solar)}.c-battery{--c:var(--battery)}.c-grid{--c:var(--grid)}.c-home{--c:var(--home)}.c-export{--c:var(--export)}.c-heat{--c:var(--heat)}
.chart{position:relative;height:300px}.chart.tall{height:360px}.chart.short{height:200px}
.chips{display:flex;flex-wrap:wrap;gap:8px}.chip{display:inline-flex;align-items:center;gap:6px;border:1px solid var(--border);border-radius:8px;padding:6px 11px;font-size:13px;background:#fff;color:var(--ink-2)}.chip svg{width:14px;height:14px;color:var(--muted)}
.chip.on{border-color:rgba(22,163,74,.35);background:rgba(22,163,74,.07);color:#166534}.chip.on svg{color:var(--ok)}.chip.warn{border-color:rgba(217,119,6,.35);background:rgba(217,119,6,.08);color:#92400E}.chip.warn svg{color:var(--warn)}.chip.bad{border-color:rgba(220,38,38,.35);background:rgba(220,38,38,.07);color:#991B1B}.chip.bad svg{color:var(--err)}
table{width:100%;border-collapse:collapse;font-size:13px}th{text-align:left;font-weight:500;color:var(--muted);font-size:12px;padding:8px 8px;border-bottom:1px solid var(--border)}td{padding:10px 8px;border-bottom:1px solid var(--border);font-variant-numeric:tabular-nums}tr:last-child td{border-bottom:0}td.r,th.r{text-align:right}
.btn{display:inline-flex;align-items:center;gap:6px;border:1px solid #D1D5DB;background:#fff;color:var(--ink);border-radius:8px;padding:8px 14px;font:inherit;font-weight:500;cursor:pointer;font-size:14px}.btn svg{width:15px;height:15px}.btn:hover{background:#F9FAFB}
.btn-primary{background:var(--primary);color:#fff;border-color:var(--primary)}.btn-primary:hover{background:#1F2937}.btn-ok{background:var(--ok);color:#fff;border-color:var(--ok)}.btn-danger{color:var(--err)}.btn-ghost{border-color:transparent;background:transparent;color:var(--muted);width:100%;justify-content:flex-start}.btn-block{width:100%;justify-content:center}.btn-sm{padding:5px 9px;font-size:12.5px}
.seg{display:inline-flex;border:1px solid #D1D5DB;border-radius:8px;overflow:hidden;background:#fff}.seg button{border:0;background:transparent;padding:6px 12px;font:inherit;font-size:13px;cursor:pointer;color:var(--muted)}.seg button.active{background:var(--primary);color:#fff}
input[type=text],input[type=password],input[type=date],textarea{width:100%;border:1px solid #D1D5DB;border-radius:8px;padding:10px 12px;font:inherit;background:#fff;color:var(--ink)}input:focus,textarea:focus{outline:2px solid rgba(37,99,235,.25);border-color:var(--grid)}label{display:block;font-size:12.5px;color:var(--muted);margin:10px 0 5px}
.alert{border-radius:10px;padding:10px 13px;font-size:13.5px}.alert-error{background:rgba(220,38,38,.08);color:#991B1B}.alert-warn{background:rgba(217,119,6,.1);color:#92400E}.alert-ok{background:rgba(22,163,74,.08);color:#166534}.alert-info{background:rgba(37,99,235,.08);color:#1E3A8A}
.list{display:flex;flex-direction:column}.list-item{display:flex;gap:12px;padding:12px 0;border-bottom:1px solid var(--border);align-items:flex-start}.list-item:last-child{border-bottom:0}.list-item .ic{width:30px;height:30px;border-radius:8px;display:grid;place-items:center;flex:none;background:#F3F4F6}.list-item .ic svg{width:15px;height:15px}
.lvl-error .ic{background:rgba(220,38,38,.1);color:var(--err)}.lvl-warn .ic{background:rgba(217,119,6,.12);color:var(--warn)}.lvl-info .ic{color:var(--muted)}

details.payload{margin-top:8px;font-size:12px}details.payload pre{background:#F6F8FA;border-radius:8px;padding:8px;overflow:auto;max-height:260px;margin:6px 0 0}
.compose{display:flex;gap:8px;margin-top:12px}.compose textarea{min-height:44px;resize:vertical}
.legend{display:flex;gap:14px;flex-wrap:wrap;font-size:12.5px;color:var(--muted)}.legend span::before{content:"";display:inline-block;width:10px;height:10px;border-radius:3px;background:var(--c);margin-right:6px;vertical-align:-1px}
.empty{color:var(--muted);text-align:center;padding:22px 0;font-size:13.5px}.mt{margin-top:14px}.row{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.login-body{display:grid;place-items:center;min-height:100vh;background:var(--side)}.login-card{background:#fff;border:1px solid var(--border);border-radius:12px;padding:36px 32px;width:min(380px,92vw);text-align:center}.login-logo{width:52px;height:52px;border-radius:14px;background:var(--primary);display:grid;place-items:center;margin:0 auto 14px;color:var(--accent)}.login-logo svg{width:26px;height:26px}.login-card h1{font-size:20px}.login-card form{text-align:left;margin-top:16px}.login-card .btn{margin-top:14px}
.flow{display:grid;grid-template-columns:repeat(4,1fr);gap:10px}.flow .node{border:1px solid var(--border);border-radius:12px;padding:12px;text-align:center}.flow .node .v{font-size:20px;font-weight:600;font-variant-numeric:tabular-nums}.flow .node .l{font-size:12px;color:var(--muted);display:flex;justify-content:center;gap:5px;align-items:center}.flow .node svg{width:14px;height:14px}
@media(max-width:1100px){.g-4{grid-template-columns:repeat(2,1fr)}.g-3{grid-template-columns:1fr 1fr}.g-32{grid-template-columns:1fr}}
@media(max-width:760px){.shell{grid-template-columns:1fr}.sidebar{position:static;height:auto;flex-direction:row;align-items:center;overflow-x:auto;padding:10px}.sidebar nav{flex-direction:row}.sidebar nav a.active{border-left:0;border-radius:8px}.sidebar nav a span:not(.badge){display:none}.brand span:last-child{display:none}.logout{margin:0 0 0 auto}.logout span{display:none}.content{padding:14px}.g-4,.g-3,.g-2{grid-template-columns:1fr}.msg{max-width:94%}.flow{grid-template-columns:1fr 1fr}}
.btn-ok:hover{background:#15803D;border-color:#15803D;color:#fff}.btn-primary:hover{color:#fff}.btn-danger:hover{background:rgba(220,38,38,.06);color:var(--err)}
.compose textarea{flex:1;width:auto;min-width:0}.compose .btn{flex:none;align-self:flex-start}
.card-head{flex-wrap:wrap}.card-head > span{flex:1 1 100%;min-width:0}

.thread{display:flex;flex-direction:column;max-height:62vh;overflow:auto}
.msg{display:grid;grid-template-columns:34px 1fr;gap:12px;padding:14px 0;border-bottom:1px solid var(--border);font-size:14.5px;white-space:pre-wrap}.msg:last-child{border-bottom:0}
.msg .av{width:32px;height:32px;border-radius:50%;display:grid;place-items:center;font-size:13px;font-weight:600;background:#F3F4F6;color:var(--ink-2)}.msg .av svg{width:16px;height:16px}
.msg.agent .av{background:#FFF7E0;color:#B45309}.msg.leon .av{background:var(--ink);color:#fff}.msg.system .av{background:#F3F4F6;color:var(--muted)}
.msg .meta{font-size:12.5px;color:var(--muted);margin-bottom:3px}.msg .meta b{color:var(--ink);font-weight:600}
.msg.proposal .body{border:1px solid var(--border);border-radius:10px;padding:12px 14px;background:#FAFAFA}
.msg.system{color:var(--muted);font-size:13px}
.msg .actions{display:flex;gap:8px;margin-top:10px;align-items:center;flex-wrap:wrap}
.status{font-size:12px;font-weight:600;padding:3px 9px;border-radius:6px;background:#F3F4F6;color:var(--muted)}.status.done,.status.approved{background:#ECFDF5;color:#166534}.status.rejected{background:#FEF2F2;color:#991B1B}.status.open{background:#FFF7E0;color:#92400E}
