/* RSME Cargo dashboard. One stylesheet, light and dark. */
:root {
  --bg: #f3f4f2; --panel: #ffffff; --fg: #1b2420; --muted: #5d6a64; --line: #d9ddd9;
  --accent: #0b6e62; --accent-soft: #e1f0ec; --ok: #2f8a4b; --warn: #b7791f; --crit: #c0392b; --idle: #8a948f;
  --c26: #0b6e62; --c29: #b7791f; --cw: #3b5ba9;
  --display: "Barlow Condensed", "Arial Narrow", Arial, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121816; --panel: #1a2220; --fg: #e4ebe8; --muted: #97a6a0; --line: #2c3734;
    --accent: #4fc1ae; --accent-soft: #1d3531; --ok: #5cc07a; --warn: #e0a548; --crit: #ec6b5e; --idle: #6f7c77;
    --c26: #4fc1ae; --c29: #e0a548; --cw: #8aa6ef;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--body); min-height: 100vh; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.1; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 15px; font-family: var(--body); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  font-weight: 500; font-size: 13px; padding: 7px 12px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--bg);
}
button.ghost { background: transparent; color: var(--accent); }
button.small { padding: 4px 9px; font-size: 12px; }
button.danger { border-color: var(--crit); background: transparent; color: var(--crit); }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 7px 9px; width: 100%; min-width: 0;
}
textarea { font: 13px/1.5 var(--mono); resize: vertical; min-height: 140px; }
label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--fg); }
label.check input { width: auto; }

/* Top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--fg); color: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { font: 700 13px var(--display); letter-spacing: .06em; padding: 3px 7px; border: 1px solid currentColor; border-radius: 3px; }
.logo.alt { background: var(--bg); color: var(--fg); }
.product { font: 700 20px var(--display); letter-spacing: .04em; }
.product small { font: 500 11px var(--mono); padding: 1px 6px; border-radius: 3px; background: var(--accent); color: var(--bg); vertical-align: 3px; }
.top-right { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.topbar button.ghost { color: var(--bg); border-color: var(--bg); }
.conn { font: 500 11px var(--mono); padding: 2px 8px; border-radius: 10px; border: 1px solid currentColor; }
.conn.demo { color: #f0c46b; } .conn.online { color: #7fdc98; } .conn.off { color: #ff8a7d; }

/* Login */
.login { max-width: 400px; margin: 48px auto; padding: 0 16px; }
.login .card { display: grid; gap: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel); color: var(--fg); }
.seg button.on { background: var(--fg); color: var(--bg); }

/* Shell */
.tabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs button {
  background: transparent; color: var(--muted); border: 0; border-bottom: 3px solid transparent; border-radius: 0;
  padding: 11px 12px 8px; white-space: nowrap; font: 600 15px var(--display); letter-spacing: .02em;
}
.tabs button.on { color: var(--fg); border-bottom-color: var(--accent); }
.subbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px 6px; max-width: 1280px; margin: 0 auto; }
.subbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fleet-switch { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.fleet-switch button { border: 0; border-radius: 0; background: var(--panel); color: var(--fg); }
.fleet-switch button.on { background: var(--fg); color: var(--bg); }
button.wa { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.view { max-width: 1280px; margin: 0 auto; padding: 6px 16px 32px; display: grid; gap: 16px; }
.foot { max-width: 1280px; margin: 0 auto; padding: 0 16px 24px; color: var(--muted); font-size: 12px; }
#banner { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.note-bar { background: var(--accent-soft); border-radius: 4px; padding: 8px 12px; font-size: 13px; margin-top: 6px; }
.note-bar.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); }

/* Panels and grids */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px; display: grid; gap: 10px; align-content: start; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.panel-head .sub { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .g2, .g3, .g21 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.form .wide { grid-column: 1 / -1; }

/* KPI tiles */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--idle); border-radius: 5px; padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.kpi .l { font: 500 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.kpi .v { font: 600 30px var(--display); font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .v small { font-size: 16px; color: var(--muted); }
.kpi .t { font-size: 12px; color: var(--muted); }
.kpi.ok { border-top-color: var(--ok); } .kpi.warn { border-top-color: var(--warn); } .kpi.crit { border-top-color: var(--crit); }

/* Loco status board */
.board { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.unit { border: 1px solid var(--line); border-left: 5px solid var(--idle); border-radius: 4px; padding: 7px 8px; background: var(--panel); display: grid; gap: 1px; cursor: pointer; text-align: left; color: var(--fg); font-weight: 400; }
.unit b { font: 600 18px var(--display); }
.unit span { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit.s-available { border-left-color: var(--ok); } .unit.s-standby { border-left-color: #7fb98e; }
.unit.s-corrective { border-left-color: var(--crit); } .unit.s-pe, .unit.s-waiting { border-left-color: var(--warn); }
.unit.s-stopped { border-left-color: var(--fg); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* Tables */
.tbl { overflow-x: auto; border: 1px solid var(--line); border-radius: 4px; }
.tbl table { border-collapse: collapse; width: 100%; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .clip { max-width: 420px; }
.tbl.scroll { max-height: 460px; overflow-y: auto; }
.pill { font: 500 11px var(--mono); padding: 1px 7px; border-radius: 10px; border: 1px solid currentColor; white-space: nowrap; display: inline-block; }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.crit { color: var(--crit); } .pill.idle { color: var(--muted); }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.bar i.warn { background: var(--warn); } .bar i.crit { background: var(--crit); }

/* Charts */
.chart { position: relative; height: 260px; }
.chart.short { height: 200px; }

/* WhatsApp boxes */
.paste { display: grid; gap: 8px; }
.paste details summary { cursor: pointer; color: var(--accent); font-size: 12px; }
.paste pre { margin: 0; font: 12px/1.5 var(--mono); background: var(--bg); border-radius: 4px; padding: 8px; white-space: pre-wrap; }
pre.wa-out { margin: 0; font: 13px/1.5 var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 10px; white-space: pre-wrap; word-break: break-word; max-height: 55vh; overflow: auto; }

/* Modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border-radius: 8px; padding: 16px; width: min(720px, 100%); max-height: 92vh; overflow: auto; display: grid; gap: 12px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 6px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 30; }
.toast.show { opacity: 1; }
[hidden] { display: none !important; }
.panel-head select, .panel-head input, .subbar select { width: auto; max-width: 100%; }
.row select { width: auto; max-width: 100%; }
