:root {
  --bg: #F3F4F6;
  --card: #FFFFFF;
  --line: #E3E6EA;
  --line-soft: #EDEFF2;
  --ink: #111418;
  --text: #1F252B;
  --muted: #4F5862;
  --faint: #5F6873;
  --amber: #F2A93B;
  --amber-ink: #9A5B00;
  --amber-bg: #FFF3DD;
  --green: #1E7F4F;
  --green-bg: rgba(63,185,122,0.14);
  --blue: #1F62B0;
  --blue-bg: rgba(106,174,240,0.16);
  --red: #C2362C;
  --red-bg: rgba(240,112,103,0.14);
  --gray-bg: #EEF0F2;
  --dark: #111418;
  --dark-2: #1D2228;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; }
a { color: var(--amber-ink); }
a:hover { color: #6E4100; }
button { font: inherit; }
h1, h2, h3 { margin: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--faint); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- layout */
.shell { min-height: 100vh; display: flex; flex-wrap: wrap; }
.side {
  flex: 1 1 232px; max-width: 100%; background: var(--card); border-right: 1px solid var(--line);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: .06em; color: var(--ink); line-height: 1; }
.brand-sub { font-family: var(--mono); font-size: 11px; color: var(--faint); margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a .n { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.nav a.active { background: var(--amber-bg); color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--amber); }
.nav a.active .n { color: var(--amber-ink); }
.nav a.soon { opacity: .55; }
.nav a .tag { margin-left: auto; font-family: var(--mono); font-size: 10px; padding: 2px 6px; border-radius: 4px; background: var(--gray-bg); color: var(--faint); }
.sysbox {
  margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px;
  border: 1px solid var(--line); border-radius: 10px; font-family: var(--mono); font-size: 12px; color: var(--muted);
}
.sysbox div { display: flex; justify-content: space-between; gap: 8px; }
.side-foot { display: flex; gap: 8px; }
.side-foot button { flex: 1; }

.main { flex: 999 1 560px; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.crumb { font-family: var(--mono); font-size: 12px; color: var(--faint); letter-spacing: .08em; text-transform: uppercase; }
.crumb a { color: var(--faint); }
.title { margin-top: 6px; font-family: var(--display); font-weight: 700; font-size: 38px; letter-spacing: .03em; text-transform: uppercase; color: var(--ink); line-height: 1; }
.head-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

/* ---------- elements */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-title { font-family: var(--display); font-weight: 700; font-size: 20px; letter-spacing: .05em; color: var(--ink); text-transform: uppercase; }
.card-body { padding: 16px 18px; }
.label { font-family: var(--mono); font-size: 11px; color: var(--faint); letter-spacing: .06em; text-transform: uppercase; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.kpi .v { font-family: var(--display); font-weight: 600; font-size: 42px; color: var(--ink); line-height: 1; }
.kpi .v small { font-size: 20px; color: var(--faint); font-weight: 500; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kpi.alert { border-color: #F0A39C; }
.kpi.alert .label, .kpi.alert .v { color: var(--red); }
.slots { display: flex; gap: 3px; height: 6px; }
.slots span { flex: 1 1 0; border-radius: 2px; }

.live-pill { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border-radius: 16px; font-family: var(--mono); font-size: 12px; font-weight: 600; }
.live-pill.on { background: var(--green-bg); color: var(--green); }
.live-pill.off { background: var(--red-bg); color: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 4px; background: currentColor; display: inline-block; }
.live-pill.on .dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 4px; font-family: var(--mono); font-size: 11px; font-weight: 600; white-space: nowrap; }
.chip.round { border-radius: 13px; height: 26px; padding: 0 11px; }
.st-Available { background: var(--green-bg); color: var(--green); }
.st-Charging { background: var(--blue-bg); color: var(--blue); }
.st-Preparing, .st-Finishing, .st-SuspendedEV, .st-SuspendedEVSE, .st-Reserved { background: rgba(242,176,69,.16); color: var(--amber-ink); }
.st-Faulted { background: var(--red-bg); color: var(--red); }
.st-Unavailable, .st-Offline, .st-Unknown { background: var(--gray-bg); color: var(--muted); }
.st-completed { background: var(--green-bg); color: var(--green); }
.st-active { background: var(--blue-bg); color: var(--blue); }
.bar-Available { background: #3FB97A; } .bar-Charging { background: #3C7FD0; }
.bar-Preparing, .bar-Finishing, .bar-SuspendedEV, .bar-SuspendedEVSE, .bar-Reserved { background: var(--amber); }
.bar-Faulted { background: #E0574C; } .bar-Unavailable, .bar-Offline, .bar-Unknown { background: #C3CAD1; }

.btn {
  min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid #D3D8DE; background: var(--card);
  color: var(--text); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
.btn:hover { background: #F7F8F9; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { border: 0; background: var(--amber); color: #1A1206; font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: .06em; text-transform: uppercase; }
.btn.primary:hover { background: #E89A26; }
.btn.dark { border: 0; background: var(--dark); color: #fff; font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: .06em; text-transform: uppercase; }
.btn.danger { border-color: #E0574C; color: var(--red); }
.btn.danger:hover { background: #FFF5F4; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.lg { min-height: 48px; }

.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { min-height: 34px; padding: 0 12px; border-radius: 17px; cursor: pointer; font-family: var(--mono); font-size: 12px; font-weight: 600; border: 1px solid #D3D8DE; background: var(--card); color: var(--muted); }
.pill.on { border-color: var(--ink); background: var(--ink); color: #fff; }

.field { display: flex; flex-direction: column; gap: 6px; }
.input, select.input {
  height: 40px; padding: 0 12px; border: 1px solid #D3D8DE; border-radius: 8px; background: #fff; color: var(--text);
  font: 14px var(--sans); min-width: 0;
}
.input.mono { font-family: var(--mono); font-size: 13px; }
.input:focus { outline: 2px solid var(--amber); outline-offset: -1px; border-color: transparent; }
.search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; border: 1px solid #D3D8DE; border-radius: 8px; background: #fff; color: var(--faint); }
.search input { border: 0; outline: none; background: transparent; color: var(--text); font: 13px var(--mono); width: 200px; }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { background: #F7F8F9; text-align: left; font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .06em; font-weight: 600; padding: 11px 12px; white-space: nowrap; text-transform: uppercase; }
.tbl td { border-top: 1px solid var(--line-soft); padding: 11px 12px; vertical-align: middle; }
.tbl th:first-child, .tbl td:first-child { padding-left: 18px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 18px; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #FAFBFB; }
.tbl .num { text-align: right; font-family: var(--mono); }
.empty { padding: 36px 18px; text-align: center; color: var(--faint); }
.id-link { font-family: var(--display); font-weight: 700; font-size: 19px; letter-spacing: .04em; color: var(--ink); text-decoration: none; }

/* ---------- dashboard connector cards */
.grid-2 { display: flex; flex-wrap: wrap; gap: 16px; align-items: stretch; }
.grid-2 > .wide { flex: 3 1 560px; min-width: 0; }
.grid-2 > .narrow { flex: 2 1 360px; min-width: 0; }
.st-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.st-card { display: flex; flex-direction: column; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; color: inherit; text-decoration: none; }
.st-card:hover { border-color: #C9CFD6; }
.st-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.st-card .name { font-family: var(--display); font-weight: 700; font-size: 20px; letter-spacing: .04em; color: var(--ink); }
.st-card .sub { font-size: 12px; color: var(--muted); }
.con-mini { border-radius: 8px; padding: 9px 11px; display: flex; flex-direction: column; gap: 2px; }
.con-mini .h { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.con-mini .s { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: .05em; }
.con-mini .d { font-family: var(--mono); font-size: 12px; color: var(--text); }
.st-card .foot { font-family: var(--mono); font-size: 11px; color: var(--faint); border-top: 1px solid var(--line-soft); padding-top: 8px; }

.feed-row { display: grid; grid-template-columns: 64px minmax(0,1fr) auto; gap: 10px; align-items: center; padding: 9px 18px; border-bottom: 1px solid var(--line-soft); }
.feed-row .t { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.feed-row .a { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-row .cp { font-family: var(--mono); font-weight: 600; font-size: 13px; color: var(--ink); }
.dir-in { color: var(--blue); } .dir-out { color: var(--amber-ink); }

.alert-row { display: flex; gap: 12px; padding: 12px; border-radius: 8px; }
.alert-row.bad { background: rgba(240,112,103,.10); }
.alert-row.warn { background: rgba(242,176,69,.12); }
.alert-row.info { background: rgba(106,174,240,.12); }
.alert-row .i { font-family: var(--mono); font-weight: 700; }
.alert-row.bad .i { color: var(--red); } .alert-row.warn .i { color: var(--amber-ink); } .alert-row.info .i { color: var(--blue); }
.alert-row .x { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- station page */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.info-grid > div { background: var(--card); padding: 12px 16px; }
.info-grid .v { font-family: var(--mono); font-size: 13px; color: var(--ink); margin-top: 4px; word-break: break-all; }
.con-card { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; gap: 14px; padding: 18px; }
.con-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.con-name { font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: .05em; color: var(--ink); }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.metric { background: #F7F8F9; border-radius: 8px; padding: 10px 12px; }
.metric .v { font-family: var(--display); font-weight: 600; font-size: 30px; color: var(--ink); line-height: 1.1; }
.metric .u { font-size: 11px; color: var(--faint); }
.metric.blue .v { color: var(--blue); } .metric.green .v { color: var(--green); }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; font-size: 13px; }
.kv > div { display: flex; justify-content: space-between; gap: 8px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-family: var(--mono); }
.idle-box { padding: 18px; border: 1.5px dashed #D3D8DE; border-radius: 8px; text-align: center; display: flex; flex-direction: column; gap: 4px; }
.idle-box .big { font-family: var(--display); font-weight: 600; font-size: 22px; color: var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .grow { flex: 1 1 140px; }
.cmd-list { display: flex; flex-direction: column; gap: 10px; }
.cmd-group { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft); }
.cmd-group:last-child { border-bottom: 0; padding-bottom: 0; }

.term { background: var(--dark); border-radius: 10px; overflow: hidden; color: #C8CED5; }
.term-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid #262C33; }
.term-head .card-title { color: #fff; }
.term-body { max-height: 460px; overflow: auto; padding: 8px 0; }
.term-row { display: grid; grid-template-columns: 82px 18px 210px minmax(380px, 1fr); gap: 10px; padding: 4px 18px; font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.term-row.new { background: rgba(242,169,59,.10); }
.term-row .t { color: #8A939D; }
.term-row .act { color: #F2C26B; overflow: hidden; text-overflow: ellipsis; }
.term-row .p { color: #C8CED5; overflow: hidden; text-overflow: ellipsis; }
.term-row .din { color: #6AAEF0; } .term-row .dout { color: var(--amber); }
.term .pill { background: transparent; border-color: #343B43; color: #C3CAD1; }
.term .pill.on { background: var(--amber); border-color: var(--amber); color: #1A1206; }

.cfg-row td input { width: 100%; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--dark); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.login-brand { display: flex; align-items: center; gap: 12px; }
.err { color: var(--red); font-size: 13px; }

/* ---------- toast + modal */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--dark); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 8px 24px rgba(17,20,24,.25); max-width: 420px; border-left: 0; }
.toast.ok b { color: #7FE0AE; } .toast.bad b { color: #FF9C93; }
.modal-bg { position: fixed; inset: 0; background: rgba(17,20,24,.45); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 760px; max-height: calc(100vh - 32px); overflow: auto; }
.modal.small { max-width: 420px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }
.chart { width: 100%; height: 180px; display: block; }

@media (max-width: 820px) {
  .main { padding: 20px 16px 40px; }
  .side { padding: 14px 16px; gap: 14px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .sysbox, .side-foot { display: none; }
  .title { font-size: 30px; }
  .search input { width: 140px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
