:root {
  --ink: #10221a;
  --muted: #68776f;
  --paper: #f1f4ef;
  --surface: #ffffff;
  --line: #dce4dc;
  --deep: #0b1712;
  --deep-soft: #15271f;
  --green: #28c984;
  --green-dark: #087347;
  --green-pale: #e5f8ef;
  --amber: #d99525;
  --red: #c74444;
  --red-pale: #fff0ee;
  --shadow: 0 18px 48px rgba(12, 30, 22, 0.09);
}

* { box-sizing: border-box; }
html {
  background: var(--paper);
  color-scheme: light;
  min-width: 320px;
  scroll-behavior: smooth;
}
body {
  background:
    radial-gradient(circle at 6% 0%, rgba(40, 201, 132, 0.12), transparent 25rem),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  min-height: 100vh;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible {
  outline: 3px solid rgba(40, 201, 132, 0.3);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.sr-only {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}
.app-shell {
  margin: 0 auto;
  max-width: 1420px;
  min-height: 100vh;
  padding: 24px clamp(17px, 4vw, 54px) 34px;
}
.topbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: 5px 0 24px;
}
.brand {
  align-items: center;
  color: inherit;
  display: flex;
  gap: 13px;
  text-decoration: none;
}
.brand-mark {
  align-items: center;
  background: var(--deep);
  border-radius: 13px;
  color: #fff;
  display: flex;
  height: 48px;
  justify-content: center;
  overflow: hidden;
  position: relative;
  width: 48px;
}
.brand-mark b { font-size: 13px; letter-spacing: -0.04em; position: relative; z-index: 1; }
.brand-mark i { background: var(--green); bottom: 0; height: 5px; left: 0; position: absolute; width: 100%; }
.brand > span:last-child { display: grid; gap: 4px; }
.brand small, .eyebrow {
  color: #76837d;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  margin: 0;
}
.brand strong { font-size: clamp(18px, 2vw, 23px); letter-spacing: -0.035em; }
.top-actions { align-items: center; display: flex; gap: 9px; }
.button, .icon-button, .modal-close {
  align-items: center;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
}
.button {
  border-radius: 10px;
  font-size: 13px;
  font-weight: 750;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}
.button:hover:not(:disabled), .icon-button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.52; }
.button-primary { background: var(--deep); color: white; }
.button-primary:hover { background: #183328; }
.button-ghost { background: white; border: 1px solid var(--line); color: var(--ink); }
.button-danger { background: var(--red); color: white; }
.button-danger-soft { background: var(--red-pale); color: var(--red); }
.icon-button {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 22px;
  height: 42px;
  transition: transform 150ms ease;
  width: 42px;
}
.icon-button.is-spinning span { animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.connection-panel {
  align-items: stretch;
  background: var(--deep);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 19px;
  box-shadow: 0 22px 60px rgba(8, 25, 18, 0.19);
  color: white;
  display: flex;
  justify-content: space-between;
  overflow: hidden;
}
.connection-lead {
  align-items: center;
  display: flex;
  flex: 1;
  gap: 14px;
  min-width: 330px;
  padding: 21px 23px;
}
.connection-lead .eyebrow { color: #758a80; margin-bottom: 4px; }
.connection-lead h1 { font-size: 15px; letter-spacing: -0.02em; margin: 0; }
.connection-lead p:last-child {
  color: #91a39b;
  font-size: 11px;
  margin: 4px 0 0;
}
.status-orb {
  background: #4c5e55;
  border: 4px solid rgba(255, 255, 255, 0.06);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.11);
  flex: 0 0 auto;
  height: 17px;
  width: 17px;
}
.status-orb.is-live {
  background: var(--green);
  box-shadow: 0 0 0 1px rgba(40, 201, 132, 0.52), 0 0 19px rgba(40, 201, 132, 0.7);
}
.connection-facts { display: grid; grid-template-columns: repeat(3, minmax(155px, 1fr)); }
.connection-facts > div {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 17px 22px;
}
.connection-facts > div > span {
  color: #81958b;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.1em;
  margin-bottom: 7px;
  text-transform: uppercase;
}
.connection-facts strong {
  font-size: 12px;
  font-weight: 750;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.signal-value { align-items: center; display: flex; gap: 9px; }
.signal-bars { align-items: end; display: inline-flex; gap: 2px; height: 14px; }
.signal-bars i { background: #3e5249; border-radius: 2px 2px 0 0; display: block; width: 3px; }
.signal-bars i:nth-child(1) { height: 4px; }
.signal-bars i:nth-child(2) { height: 7px; }
.signal-bars i:nth-child(3) { height: 10px; }
.signal-bars i:nth-child(4) { height: 14px; }
.signal-bars[data-level="1"] i:nth-child(-n+1),
.signal-bars[data-level="2"] i:nth-child(-n+2),
.signal-bars[data-level="3"] i:nth-child(-n+3),
.signal-bars[data-level="4"] i:nth-child(-n+4) { background: var(--green); }
.signal-bars[data-level="1"] i:nth-child(1) { background: #ef6b5b; }

.offline-banner {
  align-items: center;
  background: #fff4dd;
  border: 1px solid #ebd29b;
  border-radius: 13px;
  color: #6e5321;
  display: flex;
  font-size: 12px;
  gap: 8px;
  margin-top: 14px;
  padding: 12px 15px;
}
main { display: grid; gap: 27px; padding-top: 30px; }
.section-heading {
  align-items: flex-end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}
.section-heading .eyebrow { margin-bottom: 6px; }
.section-heading h2 { font-size: clamp(20px, 2vw, 27px); letter-spacing: -0.04em; margin: 0; }
.section-heading p:not(.eyebrow) { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.summary-pills { align-items: center; display: flex; gap: 8px; }
.summary-pills span {
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--muted);
  display: inline-flex;
  font-size: 11px;
  gap: 6px;
  padding: 7px 11px;
}
.summary-pills b { color: var(--ink); }
.summary-dot { background: #b0bbb5; border-radius: 50%; height: 7px; width: 7px; }
.summary-dot.is-on { background: var(--green); box-shadow: 0 0 8px rgba(40, 201, 132, 0.6); }

.channel-grid { display: grid; gap: 14px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.channel-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 17px;
  box-shadow: 0 12px 36px rgba(12, 30, 22, 0.055);
  min-width: 0;
  overflow: hidden;
  padding: 18px;
  position: relative;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}
.channel-card:hover { transform: translateY(-2px); }
.channel-card.is-running {
  border-color: rgba(40, 201, 132, 0.48);
  box-shadow: 0 16px 42px rgba(13, 116, 72, 0.12);
}
.channel-card::before {
  background: #c5cec9;
  content: "";
  height: 4px;
  left: 0;
  position: absolute;
  top: 0;
  width: 100%;
}
.channel-card.is-running::before { background: var(--green); }
.channel-topline { align-items: flex-start; display: flex; justify-content: space-between; gap: 10px; }
.channel-index { color: #8a9790; font-size: 10px; font-weight: 800; letter-spacing: 0.1em; margin: 0 0 5px; }
.channel-name-row { align-items: center; display: flex; gap: 6px; min-width: 0; }
.channel-name {
  font-size: 16px;
  letter-spacing: -0.03em;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.edit-name {
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: #839088;
  cursor: pointer;
  font-size: 16px;
  height: 28px;
  padding: 0;
  width: 28px;
}
.edit-name:hover { background: var(--paper); color: var(--green-dark); }
.state-badge {
  align-items: center;
  background: #eef1ef;
  border-radius: 99px;
  color: #69766f;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 850;
  gap: 5px;
  padding: 6px 8px;
}
.state-badge i { background: currentColor; border-radius: 50%; height: 6px; width: 6px; }
.state-badge.is-on { background: var(--green-pale); color: var(--green-dark); }
.runtime-label { color: var(--muted); font-size: 10px; font-weight: 700; margin: 24px 0 8px; text-transform: uppercase; }
.runtime {
  color: var(--deep);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(24px, 2.4vw, 34px);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: -0.07em;
  line-height: 1;
  white-space: nowrap;
}
.runtime-unit { color: #8b9791; display: flex; font-size: 9px; justify-content: space-between; margin-top: 7px; padding: 0 2px; }
.session-row {
  align-items: center;
  border-top: 1px solid #edf0ed;
  color: var(--muted);
  display: flex;
  font-size: 10px;
  justify-content: space-between;
  margin-top: 17px;
  padding-top: 13px;
}
.session-row strong { color: var(--ink); font-family: monospace; font-size: 11px; }
.reset-hourmeter {
  background: transparent;
  border: 1px solid #ead3d3;
  border-radius: 9px;
  color: var(--red);
  cursor: pointer;
  font-size: 10px;
  font-weight: 800;
  margin-top: 11px;
  min-height: 34px;
  width: 100%;
}
.reset-hourmeter:hover { background: var(--red-pale); }

.history-section {
  background: white;
  border: 1px solid var(--line);
  border-radius: 19px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 2.5vw, 27px);
}
.history-heading { align-items: center; }
.history-toolbar {
  align-items: center;
  border-bottom: 1px solid #e8ece8;
  border-top: 1px solid #e8ece8;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin-top: 20px;
  padding: 13px 0;
}
.filter-group, .period-group { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.filter-group::-webkit-scrollbar, .period-group::-webkit-scrollbar { display: none; }
.filter-group button, .period-group button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #64726a;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 750;
  min-height: 34px;
  padding: 0 11px;
}
.filter-group button:hover, .period-group button:hover { background: var(--paper); }
.filter-group button.is-active {
  background: var(--deep);
  color: white;
}
.period-group { background: var(--paper); border-radius: 9px; padding: 3px; }
.period-group button.is-active { background: white; box-shadow: 0 2px 8px rgba(20, 40, 31, 0.1); color: var(--ink); }
.history-summary { color: #819087; display: flex; font-size: 10px; justify-content: space-between; padding: 14px 1px 8px; }
.history-table-wrap { min-height: 160px; overflow-x: auto; position: relative; }
.history-table { border-collapse: collapse; min-width: 750px; width: 100%; }
.history-table th {
  border-bottom: 1px solid #e8ece8;
  color: #89968f;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.09em;
  padding: 11px 9px;
  text-align: left;
  text-transform: uppercase;
}
.history-table td { border-bottom: 1px solid #edf0ed; font-size: 12px; padding: 13px 9px; vertical-align: middle; }
.history-table tbody tr:hover { background: #fafcf9; }
.history-line { font-weight: 750; }
.history-date, .history-total { color: #647269; font-variant-numeric: tabular-nums; }
.history-time { font-family: monospace; font-weight: 700; }
.event-badge {
  border-radius: 99px;
  display: inline-flex;
  font-size: 9px;
  font-weight: 850;
  min-width: 42px;
  padding: 5px 8px;
  justify-content: center;
}
.event-badge.is-on { background: var(--green-pale); color: var(--green-dark); }
.event-badge.is-off { background: #eef1ef; color: #647169; }
.row-delete {
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: #a0aaa4;
  cursor: pointer;
  font-size: 17px;
  height: 30px;
  width: 30px;
}
.row-delete:hover { background: var(--red-pale); color: var(--red); }
.empty-state { align-items: center; color: var(--muted); display: flex; flex-direction: column; min-height: 190px; justify-content: center; text-align: center; }
.empty-state > span { color: #9eaaa3; font-size: 31px; margin-bottom: 7px; }
.empty-state strong { color: var(--ink); font-size: 13px; }
.empty-state p { font-size: 11px; margin: 5px 0 0; }

footer { color: #87938c; display: flex; font-size: 10px; justify-content: space-between; padding: 22px 2px 0; }
.toast-stack { bottom: 18px; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); position: fixed; right: 18px; z-index: 50; }
.toast {
  animation: toast-in 200ms ease both;
  background: var(--deep);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 11px;
  box-shadow: 0 15px 42px rgba(5, 20, 13, .24);
  color: white;
  font-size: 12px;
  line-height: 1.45;
  padding: 12px 14px;
}
.toast.is-error { background: #7c2929; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.modal {
  background: transparent;
  border: 0;
  color: var(--ink);
  margin: auto;
  max-width: min(450px, calc(100vw - 28px));
  padding: 0;
  width: 100%;
}
.modal::backdrop { background: rgba(4, 17, 11, 0.62); backdrop-filter: blur(4px); }
.modal form { background: white; border-radius: 18px; box-shadow: 0 25px 80px rgba(0, 15, 8, .32); padding: 23px; }
.modal-heading { align-items: flex-start; display: flex; justify-content: space-between; margin-bottom: 20px; }
.modal-heading .eyebrow { margin-bottom: 5px; }
.modal-heading h2 { font-size: 22px; letter-spacing: -0.04em; margin: 0; }
.eyebrow-danger { color: var(--red); }
.modal-close { background: var(--paper); border-radius: 9px; color: #637169; font-size: 23px; height: 34px; width: 34px; }
.modal label { color: #4d5d54; display: grid; font-size: 11px; font-weight: 700; gap: 7px; margin-top: 13px; }
.modal input {
  background: #fafcf9;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  min-height: 44px;
  padding: 0 12px;
  width: 100%;
}
.modal-copy { color: var(--muted); font-size: 12px; line-height: 1.55; margin: -5px 0 14px; }
.form-error { color: var(--red); font-size: 11px; min-height: 16px; margin: 10px 0 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 13px; }

@media (max-width: 1100px) {
  .connection-panel { display: block; }
  .connection-facts { border-top: 1px solid rgba(255,255,255,.08); }
  .connection-facts > div:first-child { border-left: 0; }
  .channel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .app-shell { padding-left: 14px; padding-right: 14px; }
  .topbar { padding-bottom: 18px; }
  .brand > span:last-child small { display: none; }
  .brand strong { font-size: 17px; }
  .brand-mark { border-radius: 11px; height: 42px; width: 42px; }
  #installButton { font-size: 0; gap: 0; padding: 0; width: 42px; }
  #installButton span { font-size: 20px; }
  .connection-lead { min-width: 0; padding: 18px; }
  .connection-facts { grid-template-columns: 1fr 1fr; }
  .connection-facts > div { min-width: 0; padding: 14px 16px; }
  .connection-facts > div:last-child { border-left: 0; border-top: 1px solid rgba(255,255,255,.08); grid-column: 1 / -1; }
  .section-heading { align-items: flex-start; gap: 12px; }
  .summary-pills span { padding: 6px 9px; }
  .channel-grid { grid-template-columns: 1fr; }
  .channel-card { padding: 17px; }
  .runtime { font-size: 34px; }
  .history-section { border-radius: 16px; padding: 17px 14px; }
  .history-heading { align-items: flex-start; }
  .history-heading .button { font-size: 0; min-width: 42px; padding: 0; }
  .history-heading .button::after { content: "⌫"; font-size: 19px; }
  .history-toolbar { align-items: stretch; flex-direction: column; }
  .period-group { align-self: flex-start; }
  footer { flex-direction: column; gap: 5px; }
  .modal-actions .button { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
}
