/* Emma logbook: "Nautical" design (mockup C). Tokens match the Emma app. No inline styles anywhere (strict CSP). */
:root {
  --bg: #0b0f14; --card: #141b24; --card2: #0f151d; --line: #222c38;
  --txt: #e6edf3; --muted: #8b98a5; --faint: #5d6b79;
  --ok: #2ee6a8; --solar: #4aa3ff; --warn: #f5a623; --danger: #ff5c5c; --dis: #d98a8a; --violet: #a78bfa;
  --grid-major: rgba(120, 160, 200, 0.055); --grid-minor: rgba(120, 160, 200, 0.022);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
/* light theme: opt-in through the header toggle (the logbook is dark by default, like the app) */
:root[data-theme="light"] {
    --bg: #f3f5f8; --card: #ffffff; --card2: #eef1f5; --line: #dde3ea;
    --txt: #1a222c; --muted: #637282; --faint: #93a0ad;
    --ok: #0fa877; --solar: #2f7fed; --warn: #d9820a; --danger: #e5484d; --dis: #c56f6f; --violet: #7c5cf0;
    --grid-major: rgba(40, 80, 130, 0.07); --grid-minor: rgba(40, 80, 130, 0.03);
    --shadow: 0 1px 2px rgba(20, 30, 45, 0.06), 0 6px 18px rgba(20, 30, 45, 0.06);
    color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--txt); font: 14px/1.45 var(--sans);
  background-color: var(--bg);
  /* chart-paper grid: major every 96px, minor every 24px */
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
  background-size: 96px 96px, 96px 96px, 24px 24px, 24px 24px;
  background-attachment: fixed;
}
.serif, h1, h2, .wordmark { font-family: var(--serif); font-weight: 400; letter-spacing: 0.01em; }
h1, h2 { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--solar); outline-offset: 2px; border-radius: 6px; }
code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.num, .big, .tile b, .devval, td { font-variant-numeric: tabular-nums; }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--txt); text-decoration: none; }
.compass { width: 28px; height: 28px; }
.wordmark { font-size: 30px; line-height: 1; }
.brand-big .compass { width: 44px; height: 44px; }
.brand-big .wordmark { font-size: 46px; }

/* ---------- controls ---------- */
.primary {
  border: 0; border-radius: 10px; padding: 11px 16px; background: var(--solar); color: #fff; font-weight: 600;
}
.primary:disabled { opacity: 0.55; cursor: default; }
.primary.small { padding: 6px 12px; font-size: 13px; }
.link { border: 0; background: none; padding: 4px 2px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--txt); }
.icon {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--card2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px; line-height: 1; color: var(--muted);
}
.icon:hover { color: var(--txt); border-color: var(--faint); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--card2); }
.seg button { border: 0; background: none; padding: 5px 11px; color: var(--muted); font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--card); color: var(--txt); font-weight: 600; }
.chip {
  display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: var(--card2);
}
.msg { min-height: 1.2em; margin: 6px 0 0; font-size: 13px; color: var(--danger); }
.fine { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
input[type=password], input[type=text], input:not([type]), input[type=date] {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card2); color: var(--txt);
}
input[type=date] { width: auto; padding: 5px 8px; font-size: 13px; }

/* ---------- sign in ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; padding: 30px 26px 24px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.tagline { margin: 10px 0 22px; color: var(--muted); font-family: var(--serif); font-size: 17px; font-style: italic; }
.login-form label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.login-form .check { display: flex; gap: 8px; align-items: center; margin: 12px 0 16px; font-size: 13px; color: var(--muted); }
.login-form .primary { width: 100%; }

/* ---------- app frame ---------- */
.app { max-width: 1320px; margin: 0 auto; padding: 0 20px 24px; }
.top { display: flex; align-items: center; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
/* main menu */
.menu { display: flex; gap: 4px; padding-left: 16px; margin-left: 4px; border-left: 1px solid var(--line); }
.menu a {
  font-family: var(--serif); font-size: 19px; color: var(--muted); text-decoration: none;
  padding: 5px 12px; border-radius: 9px; border: 1px solid transparent;
}
.menu a:hover { color: var(--txt); }
.menu a.on { color: var(--txt); background: var(--card); border-color: var(--line); box-shadow: inset 0 -2px 0 var(--solar); }
.grow { flex: 1; }
.sync { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(46, 230, 168, 0.15); }
.sync.stale .dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.15); }
.layout { display: block; }
/* an object page keeps the other devices and phones in a column on the left */
.layout.split { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.main { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.devpage { display: flex; flex-direction: column; gap: 14px; }
.devpage .group { font-size: 22px; margin: 6px 0 -4px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.empty { color: var(--muted); font-size: 15px; }
.foot { text-align: center; color: var(--faint); font-size: 12px; margin-top: 26px; font-family: var(--serif); font-style: italic; }

/* ---------- left panel on an object page ---------- */
.side { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 14px; }
.sgroup { font-family: var(--serif); font-size: 13px; color: var(--muted); padding: 10px 10px 4px; }
.sgroup:first-child { padding-top: 0; }
.sdev {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 9px; text-decoration: none;
  color: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid transparent;
}
.sdev:hover { background: var(--card2); }
.sdev.on { background: var(--card); border-color: var(--line); box-shadow: inset 2px 0 0 var(--solar); }
.sdev .devicon { width: 26px; height: 21px; }
.sdev .sname { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sdev .sval { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sdev .sval small { font-size: 10px; margin-left: 2px; }

/* ---------- device and phone cards ---------- */
.devgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; align-items: start; }
.dev {
  display: grid; grid-template-columns: 56px 1fr; gap: 4px 12px; align-items: center; text-decoration: none; color: inherit;
  padding: 16px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.dev:hover { border-color: var(--faint); }
.dev .devicon { grid-row: span 3; width: 56px; height: 44px; }
.dev .devname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev .devval { font-size: 24px; line-height: 1.1; }
.dev .devval small { font-size: 12px; color: var(--muted); margin-left: 4px; }
.dev .devsub { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.dev .devsub code { font-size: 11px; }
/* the controller's three blocks: PV, battery, load — one row each, V / A / W */
.dev .cc { grid-column: 1 / -1; display: grid; grid-template-columns: auto repeat(3, 1fr); gap: 2px 8px; margin-top: 2px; }
.dev .cc .rl { font-size: 12px; color: var(--muted); }
.dev .cc .rv { font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; }
.dev .cc .rv small { font-size: 10px; color: var(--muted); margin-left: 2px; }
.dev .cc .cc-batt { color: var(--warn); }
.dev .cc .cc-load { color: var(--dis); }
/* component of a solar block in the data table */
.comp { display: inline-block; margin-left: 6px; font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--ok); }
.comp.cc-batt { color: var(--warn); } .comp.cc-load { color: var(--dis); } .comp.cc-other { color: var(--muted); }
.dev .devdata {
  grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--line); font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums;
}
.neg { color: var(--danger); }
.pos { color: var(--ok); }
.solarval { color: var(--ok); }

/* ---------- device page ---------- */
.devhead { display: flex; flex-direction: column; gap: 8px; }
.back { color: var(--muted); text-decoration: none; font-size: 13px; }
.back:hover { color: var(--txt); }
.devtitle { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.devtitle h1 { font-size: 34px; line-height: 1.1; }
.rename { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rename input { width: 260px; max-width: 100%; }
.devmeta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.latest { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.daynav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.day { font-size: 26px; min-width: 0; }
.toggles { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- line chart ---------- */
.chartwrap { position: relative; }
.chartbox { position: relative; height: 340px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; }
.chartinner { position: relative; width: 100%; height: 100%; }
/* the value scale pinned over a scrolled chart; the fade keeps passing lines from colliding with it */
.cax { position: absolute; top: 0; bottom: 0; width: 38px; pointer-events: none; }
.cax.l { left: 0; background: linear-gradient(90deg, var(--card) 65%, transparent); }
.cax.r { right: 0; background: linear-gradient(270deg, var(--card) 65%, transparent); }
.cax span { position: absolute; font: 11px var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.cax.l span { left: 4px; } .cax.r span { right: 4px; }
.seg.zoom { align-items: center; }
.seg.zoom button { font-size: 16px; line-height: 1; padding: 4px 11px; }
.seg.zoom button:disabled { opacity: 0.35; cursor: default; }
.seg.zoom .zl { min-width: 34px; text-align: center; font-size: 13px; color: var(--txt); font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--line); border-right: 1px solid var(--line); padding: 5px 4px; }
.chart, .overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.overlay { pointer-events: none; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ylab, .chart .xlab { fill: var(--muted); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.overlay .cross { stroke: var(--muted); stroke-width: 1; }
.overlay .mark { stroke: var(--bg); stroke-width: 1.5; }
.hover {
  position: absolute; top: 8px; z-index: 2; pointer-events: none; min-width: 170px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  box-shadow: var(--shadow); font-size: 12px;
}
.hover .ht { color: var(--muted); margin-bottom: 4px; }
.hover .hr { display: flex; justify-content: space-between; gap: 12px; }
.hover .hr b { font-weight: 600; font-variant-numeric: tabular-nums; }
.hover .lgdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.fine-u { color: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.lg {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--line); background: var(--card2); color: var(--txt);
}
.lg i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.lg.off { color: var(--faint); }
.lg.off i { opacity: 0.3; }

/* ---------- energy bars (shared markup from chart.js) ---------- */
.echart { display: flex; align-items: stretch; gap: 2px; height: 260px; }
.ebars { flex: 1; display: flex; align-items: flex-end; gap: 6px; overflow-x: auto; min-width: 0; padding-bottom: 6px; }
.ebars .nodata { margin: auto; color: var(--muted); }
.ebar { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1 0 26px; min-width: 26px; height: 100%; cursor: pointer; border-radius: 6px; padding: 2px 1px 0; }
.ebar.sel { background: var(--card2); }
.ebar.sel .elbl { color: var(--txt); font-weight: 700; }
.ecol { flex: 1; min-height: 0; width: 72%; max-width: 34px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 4px; }
.estub { height: 6%; width: 100%; background: var(--muted); opacity: 0.4; border-radius: 3px; }
.ecap { position: relative; width: 100%; background: rgba(46, 230, 168, 0.35); border-radius: 3px 3px 0 0; }
.ered { position: relative; width: 100%; background: var(--danger); border-radius: 3px 3px 0 0; display: flex; flex-direction: column; justify-content: flex-end; }
.egrn { position: relative; width: 100%; background: var(--ok); border-radius: 3px 3px 0 0; }
.epct { position: absolute; left: 0; right: 0; text-align: center; font-size: 8px; font-weight: 700; color: #fff; }
.ecap .epct, .egrn .epct { top: 50%; transform: translateY(-50%); }
.ered > .epct { top: 2px; }
.egrn .epct { color: #08241b; }
.ecap .epct { color: var(--ok); }
.elbl { font-size: 10px; color: var(--muted); white-space: nowrap; }
.eax { flex: none; display: flex; flex-direction: column; padding-bottom: 20px; }
.eaxcol { flex: 1; display: flex; flex-direction: column; justify-content: space-between; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.eax:first-child .eaxcol { text-align: right; padding-right: 4px; }
.eax:last-child .eaxcol { padding-left: 4px; }
/* the line between the bars and the tiles: a quiet hint for the average, a marked strip for a chosen bar */
.esel {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 14px; flex-wrap: wrap;
  margin-top: 10px; padding: 8px 12px; min-height: 46px; border-radius: 10px; border: 1px solid transparent;
}
.esel p { margin: 0; font-size: 13px; color: var(--muted); }
.esel.on { background: var(--card2); border-color: var(--line); box-shadow: inset 3px 0 0 var(--solar); }
.esel.on p { color: var(--txt); font-size: 14px; }
.esel-acts { display: flex; align-items: center; gap: 10px; }
.legend-energy { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.sw-grn { background: var(--ok); } .sw-red { background: var(--danger); } .sw-cap { background: rgba(46, 230, 168, 0.35); }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-align: center;
  box-shadow: var(--shadow); min-width: 0;
}
.tile > span { display: block; font-family: var(--serif); font-size: 16px; color: var(--muted); }
.tile b { display: block; font-size: 24px; font-weight: 500; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile b span { display: inline; }
.tile b small { font-size: 13px; color: var(--muted); margin-left: 3px; }
.tile .arrow { font-size: 16px; margin-left: 4px; }

/* ---------- data on the server ---------- */
.stats h2 { font-size: 22px; }
.tablewrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.badge.warn { color: var(--warn); border: 1px solid rgba(245, 166, 35, 0.4); }
.badge.ok { color: var(--muted); border: 1px solid var(--line); }
.stats + .stats { margin-top: 0; }
td a { color: var(--txt); text-decoration: none; border-bottom: 1px solid var(--line); }
td a:hover { border-bottom-color: var(--solar); }
td.none { color: var(--muted); text-align: center; padding: 16px 8px; }
.kind { color: var(--muted); font-size: 11px; margin-left: 8px; }
td.act { text-align: right; width: 1%; }
td.act .del { opacity: 0.55; font-size: 15px; }
td.act .del:hover { opacity: 1; color: var(--danger); }
td.confirm { white-space: nowrap; }
.danger, .danger-link { color: var(--danger); }
.danger {
  border: 1px solid var(--danger); background: none; border-radius: 9px; padding: 5px 11px; font-size: 13px;
  margin-right: 8px;
}
.danger:hover { background: var(--danger); color: var(--bg); }
.delall { margin-top: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* no room for a column beside the page: the list becomes a strip above it */
  .layout.split { display: flex; flex-direction: column; gap: 14px; }
  .side { position: static; flex-direction: row; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
  .side .sgroup { display: none; }
  .sdev { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); }
}
@media (max-width: 560px) {
  .app { padding: 0 12px 20px; }
  .top { gap: 10px; }
  .top { flex-wrap: wrap; row-gap: 8px; }
  .menu { order: 5; flex-basis: 100%; padding-left: 0; margin-left: 0; border-left: 0; justify-content: space-between; }
  .menu a { flex: 1; text-align: center; font-size: 17px; padding: 6px 4px; }
  .top > * { flex-shrink: 0; }
  #syncText { display: none; }
  .top .grow { flex: 1 1 0; min-width: 0; }
  .wordmark { font-size: 26px; }
  .day { font-size: 21px; }
  .chartbox { height: 260px; }
  .echart { height: 220px; }
  .devtitle h1 { font-size: 26px; }
  .tile b { font-size: 19px; }
  .panel { padding: 12px; }
}
