:root{
  color-scheme: light dark;

  --bg: #0b0c10;
  --panel: #111318;
  --panel2: #0f1015;
  --text: #e9eef5;
  --muted: #a8b2c1;
  --border: #232734;
  --accent: #7aa2ff;
  --danger: #ff6b6b;
  --ok: #3ddc97;

  --radius: 16px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --gap: 14px;
  --pad: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial;
}

[data-theme="light"]{
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel2: #fbfcff;
  --text: #111827;
  --muted: #586377;
  --border: #e6e9f2;
  --accent: #245bff;
  --danger: #d92d20;
  --ok: #027a48;

  --shadow: 0 10px 26px rgba(16,24,40,.08);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

[hidden]{ display: none !important; }

  .app-header{
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: var(--gap);
    row-gap: 8px;
    padding: 10px calc(16px + 18px + 2px);
    border-bottom: 1px solid var(--border);
    background: color-mix(in oklab, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
  }

  .app-header img{ display: block; justify-self: start; }
  .imgLogo {  
    height: 66px;
    background-color: steelblue;
    mask-image: url(../img/logo.png);
    mask-repeat: no-repeat;
    mask-position: center;
    mask-size: contain;
  }
.imgLogo {
  color: #000;
}

@media (prefers-color-scheme: dark) {
  .imgLogo {
    color: #fff;
  }
}

  .brand{
    display:flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    justify-self: center;
    align-items: center;
    text-align: center;
  }
  .brand__title{ font-size: 32px; font-weight: 650; line-height: 1.1; }
  .brand__subtitle{ font-size: 18px; color: var(--muted); margin-top: 0; line-height: 1.2; }

  .toolbar{ display:flex; gap: 10px; align-items:center; justify-self: end; flex-wrap: wrap; }

.btn{
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--panel) 88%, transparent);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.btn:hover{ border-color: color-mix(in oklab, var(--border) 70%, var(--accent)); }
.btn:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--ghost{ box-shadow:none; background: transparent; }
a.btn{ text-decoration: none; display: inline-flex; align-items: center; }
.btn--icon{
  padding: 8px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn--theme .icon{
  width: 18px;
  height: 18px;
  display: none;
  fill: currentColor;
  stroke: currentColor;
}
html[data-theme="dark"] .btn--theme .icon--sun{ display: block; }
html[data-theme="light"] .btn--theme .icon--moon{ display: block; }

.app-main{
  padding: 16px;
  display:grid;
  gap: var(--gap);
  grid-template-columns: 1.2fr 1fr;
  align-items: start;
}

.app-main--channels{
  grid-template-columns: 1fr;
}

.app-main--sidebar{
  grid-template-columns: minmax(0, 1fr) 320px;
}

.sidebar-left{
  display:flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

.sidebar-right{
  display:grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--gap);
  width: 320px;
  max-width: 320px;
  height: calc(100vh - 140px);
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.app-main--sidebar .panel{
  display:flex;
  flex-direction: column;
  min-height: 0;
}

.app-main--sidebar .panel__body{
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
}

/* Responsive: collapse to single column on small screens */
@media (max-width: 980px){
  .app-main{ grid-template-columns: 1fr; }
  .app-main--sidebar{ grid-template-columns: 1fr; }
  .sidebar-right{
    display:flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    height: auto;
    min-height: auto;
    overflow: visible;
    padding-right: 0;
  }
}

.panel{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel__header{
  display:flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}
.panel__header { display: flex; align-items: center; gap: 12px; }
.panel__actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.panel__actions .btn{ display: inline-flex; align-items: center; line-height: 1; }

.panel__title{ margin:0; font-size: 14px; font-weight: 650; }
.panel__meta{ font-size: 12px; color: var(--muted); }

.panel__body{ padding: var(--pad); }

.dropzone{
  grid-column: 1 / -1;
}
.dropzone__inner{
  padding: 18px;
  border: 1px dashed color-mix(in oklab, var(--border) 55%, var(--accent));
  border-radius: calc(var(--radius) - 6px);
  background: color-mix(in oklab, var(--panel) 92%, transparent);
}
  .dropzone__title{ font-size: 14px; font-weight: 650; }
  .dropzone__hint{ font-size: 12px; color: var(--muted); margin-top: 6px; }
  .dropzone__status{ margin-top: 10px; font-size: 12px; color: var(--muted); }
.dropzone.is-over .dropzone__inner{
  border-color: var(--accent);
  background: color-mix(in oklab, var(--panel) 85%, var(--accent) 15%);
}

.kv{
  display:grid;
  grid-template-columns: 160px 1fr;
  gap: 10px 12px;
  font-size: 12px;
}
.kv__k{ color: var(--muted); }
.kv__v{ color: var(--text); overflow-wrap: anywhere; }

.channels{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

/* Phone: horizontal cards to maximize per-channel scanability */
@media (max-width: 520px){
  .channels{
    display:grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(240px, 1fr);
    grid-template-columns: unset;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
  }
  .channel-card{ scroll-snap-align: start; }
}

.channel-card{
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: color-mix(in oklab, var(--panel) 92%, transparent);
}
.channel-card__name{ font-size: 13px; font-weight: 650; }
.channel-card__meta{ margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.4; }
.badge{
  display:inline-flex;
  align-items:center;
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  margin-right: 6px;
}
.badge--ok{ border-color: color-mix(in oklab, var(--ok) 40%, var(--border)); color: var(--ok); }
.badge--warn{ border-color: color-mix(in oklab, var(--danger) 40%, var(--border)); color: var(--danger); }

.diagnostics{
  display:flex;
  flex-direction: column;
  gap: 10px;
}
.diag-item{
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: color-mix(in oklab, var(--panel) 92%, transparent);
}
.diag-item__title{ font-size: 13px; font-weight: 650; }
.diag-item__body{ margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.5; }

.plot-placeholder{
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 16px;
  font-size: 12px;
  color: var(--muted);
}

.plot-controls{
  display:flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.field{
  display:flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
  font-size: 12px;
  color: var(--muted);
}
.field select{
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--panel) 88%, transparent);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 10px;
}
.field--check{
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: unset;
}
.field--inline{
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: unset;
}
.field--inline select{
  min-width: 120px;
}
#stackRender{
  width: 120px;
}
.field--check input{
  width: 16px;
  height: 16px;
}

.plot-readout{
  margin-left: auto;
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46%;
}

#stackReadout{
  margin-left: 0;
  text-align: left;
  margin-bottom: 3px;
}

#stackReadout:hover{
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  max-width: 100%;
}

.plot-wrap{
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: color-mix(in oklab, var(--panel2) 96%, transparent);
}

.plot-hint{
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.plot-stack{
  display:flex;
  flex-direction: column;
  gap: 12px;
}

.plot-pane{
  display:flex;
  flex-direction: column;
  gap: 8px;
}

.plot-pane__label{
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.plot-canvas{
  display:block;
  width: 100%;
  height: auto;
  touch-action: none;
}

.plot-tooltip{
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: color-mix(in oklab, var(--panel) 92%, #000 8%);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 11px;
  max-width: 360px;
  box-shadow: var(--shadow);
  white-space: normal;
  word-break: break-word;
}

@media (max-width: 520px){
  .plot-readout{ max-width: 100%; margin-left: 0; }
  .field{ min-width: 140px; }
}
