﻿*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    :root {
      --bg: #f6faf9; --bg2: #eef6f4; --panel: #ffffff; --panel-soft: #eef6f4;
      --ink: #102027; --ink2: #1e3a44; --muted: #5b7370; --dim: #5f726e;
      --line: #d9e7e4; --teal: #0f9f8f; --teal-dark: #08766c; --teal-light: #e0f5f3;
      --amber: #b7791f; --rose: #b42336; --success: #0c7a5f; --warn: #b7791f; --danger: #b42336;
      --shadow-sm: 0 2px 8px rgba(16,32,39,0.07);
      --shadow: 0 8px 32px rgba(16,32,39,0.10);
      --radius: 10px; --radius-sm: 6px; --tr: 0.16s ease;
    }
    html, body {
      height: 100%;
      background: linear-gradient(160deg, #fbfdfc 0%, var(--bg) 60%, var(--bg2) 100%);
      color: var(--ink);
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      font-size: 13px; line-height: 1.5; -webkit-font-smoothing: antialiased;
    }
    body { padding: 20px; min-height: 100%; overflow: hidden; }
    button, input, select { font: inherit; }

    .app { width: min(1500px,100%); height: calc(100vh - 40px); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; min-height: 0; }

    .topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
    .brand { display: flex; align-items: center; gap: 12px; }
    .brand-mark { width: 38px; height: 38px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center; flex-shrink: 0; box-shadow: var(--shadow-sm); }
    .brand-mark svg { width: 24px; height: 24px; }
    .brand-name { font-size: 17px; font-weight: 800; letter-spacing: -0.3px; }
    .brand-tag { font-size: 12px; color: var(--muted); margin-top: 1px; }
    .status-pills { display: flex; flex-wrap: wrap; gap: 7px; }
    .pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 11.5px; font-weight: 500; box-shadow: var(--shadow-sm); }
    .pill strong { color: var(--ink); font-weight: 700; }
    .pill-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); display: inline-block; }
    .home-pill { text-decoration: none; color: #fff; background: var(--teal-dark); border-color: var(--teal-dark); font-weight: 800; font-size: 12.5px; padding: 7px 14px; cursor: pointer; transition: background .15s ease, box-shadow .15s ease; }
    .home-pill svg { width: 15px; height: 15px; }
    .home-pill strong { color: #fff; }
    .home-pill:hover { background: var(--teal); box-shadow: 0 2px 8px rgba(15,159,143,0.35); }
    .account-menu { position: relative; }
    .account-menu[hidden] { display: none; }
    .account-btn { display: inline-flex; align-items: center; gap: 7px; padding: 4px 9px 4px 4px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; box-shadow: var(--shadow-sm); font: inherit; transition: border-color .15s ease; }
    .account-btn:hover { border-color: var(--teal); }
    .account-avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--teal); color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; text-transform: uppercase; }
    .account-email { font-size: 12px; font-weight: 600; color: var(--ink); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .account-btn svg { width: 12px; height: 12px; color: var(--muted); }
    .account-dropdown { position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; min-width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 12px 30px rgba(15,42,38,0.16); padding: 12px; }
    .account-dropdown[hidden] { display: none; }
    .account-dd-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
    .account-dd-email { font-size: 12.5px; font-weight: 700; color: var(--ink); word-break: break-all; margin-top: 3px; }
    .account-dd-status { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
    .account-dd-divider { height: 1px; background: var(--line); margin: 10px 0; }
    .account-dd-item { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 8px 9px; border-radius: 8px; border: none; background: transparent; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--ink); text-decoration: none; cursor: pointer; }
    .account-dd-item svg { width: 15px; height: 15px; flex: none; }
    .account-dd-item:hover { background: #eef3f1; }
    .account-dd-item.danger { color: #c0433d; }
    .account-dd-item.danger:hover { background: #fdecec; }

    .demo-banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid #cfe4df; border-radius: var(--radius-sm); background: #f5fbfa; color: var(--muted); box-shadow: var(--shadow-sm); }
    .demo-banner[hidden] { display: none; }
    .demo-banner strong { color: var(--ink); font-size: 12px; font-weight: 850; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
    .demo-banner span { min-width: 0; font-size: 12px; font-weight: 600; }
    .demo-banner a { margin-left: auto; color: var(--teal-dark); font-size: 12px; font-weight: 800; text-decoration: none; white-space: nowrap; }
    .demo-banner a:hover { text-decoration: underline; }

    .layout { display: grid; grid-template-columns: 340px minmax(0,1fr); gap: 16px; align-items: start; flex: 1; min-height: 0; overflow: hidden; }

    .sidebar { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-y: auto; overflow-x: hidden; max-height: 100%; overscroll-behavior: contain; scrollbar-gutter: stable; }
    .sidebar-inner { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
    .section { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); overflow: hidden; }
    .section[hidden] { display: none; }
    .section-title { width: 100%; min-height: 38px; padding: 10px 12px; border: 0; background: var(--panel-soft); font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: 0.8px; color: var(--dim); display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; user-select: none; }
    .section-title:hover { color: var(--teal-dark); background: var(--teal-light); }
    .section-title:focus-visible { outline: 3px solid rgba(15,159,143,0.16); outline-offset: -3px; }
    .section-title-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .section-chevron { width: 16px; height: 16px; flex-shrink: 0; display: grid; place-items: center; color: var(--muted); transition: transform var(--tr); }
    .section-chevron svg { width: 14px; height: 14px; }
    .section.collapsed .section-chevron { transform: rotate(-90deg); }
    .section-content { padding: 12px; }
    .section.collapsed .section-content { display: none; }
    .subpanel { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fbfdfc; overflow: hidden; }
    .subpanel + .subpanel { margin-top: 8px; }
    .subpanel-title { width: 100%; min-height: 34px; padding: 8px 10px; border: 0; background: #f4faf8; color: var(--muted); font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .07em; display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; }
    .subpanel-title:hover { color: var(--teal-dark); background: var(--teal-light); }
    .subpanel-title:focus-visible { outline: 3px solid rgba(15,159,143,0.16); outline-offset: -3px; }
    .subpanel-content { padding: 10px; }
    .subpanel.collapsed .subpanel-content { display: none; }
    .subpanel .section-chevron { width: 14px; height: 14px; }
    .subpanel.collapsed .section-chevron { transform: rotate(-90deg); }
    label { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
    select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); color: var(--ink); appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235b7370' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
    select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,159,143,0.12); }
    .control { margin-top: 11px; }
    .range-row { display: grid; grid-template-columns: 1fr 72px; gap: 8px; align-items: center; }
    input[type="range"] { width: 100%; accent-color: var(--teal); cursor: pointer; }
    .value-input { width: 100%; min-height: 28px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-soft); font-size: 11.5px; font-weight: 700; color: var(--ink); text-align: center; padding: 4px 6px; }
    .value-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,159,143,0.12); background: var(--panel); }
    .check-row { display: flex; align-items: center; gap: 8px; min-height: 30px; color: var(--ink); font-size: 12px; font-weight: 650; cursor: pointer; }
    .check-row input { width: 15px; height: 15px; accent-color: var(--teal); }
    .check-hint { margin-left: 23px; margin-top: -2px; color: var(--dim); font-size: 10.5px; line-height: 1.35; }
    .inline-warning { margin-top: 7px; padding: 8px 9px; border: 1px solid #f4c56d; border-radius: var(--radius-sm); background: #fff8e6; color: #7a4b00; font-size: 11px; font-weight: 650; line-height: 1.35; }
    .inline-warning[hidden] { display: none; }
    .label-help { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
    .label-help label { margin-bottom: 0; }
    .help-dot { width: 18px; height: 18px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--muted); font-size: 11px; font-weight: 800; line-height: 1; display: grid; place-items: center; cursor: help; position: relative; }
    .help-dot:hover, .help-dot:focus { border-color: var(--teal); color: var(--teal-dark); background: var(--teal-light); outline: none; }
    .help-dot::after { content: attr(data-tip); position: absolute; right: 0; top: 24px; width: 230px; padding: 8px 9px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--ink); color: white; font-size: 10.5px; font-weight: 600; line-height: 1.35; box-shadow: var(--shadow-sm); opacity: 0; pointer-events: none; transform: translateY(-3px); transition: opacity var(--tr), transform var(--tr); z-index: 20; }
    .help-dot:hover::after, .help-dot:focus::after { opacity: 1; transform: translateY(0); }
    .delayed-tooltip { position: fixed; max-width: 260px; padding: 8px 9px; border: 1px solid rgba(10,31,36,0.18); border-radius: var(--radius-sm); background: var(--ink); color: white; font-size: 11px; font-weight: 650; line-height: 1.35; box-shadow: var(--shadow); z-index: 9999; pointer-events: none; opacity: 0; transform: translateY(-3px); transition: opacity var(--tr), transform var(--tr); }
    .delayed-tooltip.visible { opacity: 1; transform: translateY(0); }

    .preset-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 5px; }
    .preset-btn { padding: 6px 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); color: var(--muted); font-size: 11px; font-weight: 700; line-height: 1.15; cursor: pointer; transition: all var(--tr); text-align: center; min-height: 42px; }
    .preset-btn small { display: block; font-size: 10px; font-weight: 650; opacity: 0.9; }
    .preset-btn:hover { border-color: var(--teal); color: var(--teal-dark); background: var(--teal-light); }
    .preset-btn.active { border-color: var(--teal); background: var(--teal); color: white; }

    .mode-row { display: grid; grid-template-columns: repeat(2,1fr); gap: 5px; margin-bottom: 11px; }
    .group-select-row { display: grid; grid-template-columns: 1fr 36px; gap: 6px; align-items: center; }

    .view-toggle { display: grid; grid-template-columns: repeat(2,1fr); gap: 5px; }
    .view-toggle.manual-toggle { grid-template-columns: repeat(2,1fr); }
    .view-toggle.manual-toggle .wide { grid-column: 1 / -1; }
    .view-btn { padding: 7px 4px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; transition: all var(--tr); text-align: center; }
    .view-btn.active { border-color: rgba(15,159,143,0.5); background: var(--teal); color: white; }
    .icon-btn.danger { color: #9f1239; border-color: #f3c4cf; background: #fff5f7; }
    .icon-btn.danger:hover { color: white; border-color: #be123c; background: #be123c; }

    .style-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
    .style-row select { min-height: 34px; }

    .action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 12px; }
    .btn { min-height: 36px; padding: 7px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; transition: all var(--tr); display: flex; align-items: center; justify-content: center; gap: 5px; }
    .btn:hover { border-color: var(--teal); color: var(--teal-dark); background: var(--teal-light); }
    .btn.primary { background: var(--ink); color: white; border-color: var(--ink); }
    .btn.primary:hover { background: var(--ink2); border-color: var(--ink2); }
    .btn:disabled { opacity: 0.4; cursor: not-allowed; }

    .meta-grid { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
    .meta-row { display: grid; grid-template-columns: 110px 1fr; gap: 6px; font-size: 11.5px; }
    .meta-key { color: var(--dim); }
    .meta-val { color: var(--ink); font-weight: 600; word-break: break-word; }

    .metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .metric-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; background: var(--panel); }
    .metric-card.good { border-color: rgba(8,118,108,0.35); background: rgba(8,118,108,0.04); }
    .metric-card.warn { border-color: rgba(183,121,31,0.35); background: rgba(183,121,31,0.04); }
    .metric-card.bad  { border-color: rgba(180,35,54,0.35);  background: rgba(180,35,54,0.04); }
    .metric-label { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--dim); }
    .metric-number { font-size: 18px; font-weight: 800; color: var(--ink); margin: 4px 0 2px; overflow-wrap: anywhere; line-height: 1.1; }
    .metric-card.good .metric-number { color: var(--teal-dark); }
    .metric-card.warn .metric-number { color: var(--amber); }
    .metric-card.bad  .metric-number { color: var(--rose); }
    .metric-hint { font-size: 10.5px; color: var(--muted); }

    .export-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }

    .workspace { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-y: auto; overflow-x: hidden; max-height: 100%; overscroll-behavior: contain; scrollbar-gutter: stable; }
    .canvas-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: rgba(238,246,244,0.5); }
    .canvas-title { font-size: 12.5px; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
    .canvas-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
    .canvas-actions { display: flex; gap: 7px; flex-shrink: 0; }
    .icon-btn { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); color: var(--muted); cursor: pointer; display: grid; place-items: center; transition: all var(--tr); }
    .icon-btn:hover { border-color: var(--teal); color: var(--teal-dark); background: var(--teal-light); }
    .icon-btn svg { width: 15px; height: 15px; }
    .angle-chip { min-width: 46px; height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-soft); color: var(--ink); display: grid; place-items: center; font-size: 11px; font-weight: 750; }
    .file-picker-label { position: relative; overflow: hidden; }
    .file-input-native { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; opacity: 0; cursor: pointer; }

    .drop-zone { position: relative; min-height: 580px; display: grid; place-items: center; background: linear-gradient(45deg,rgba(16,32,39,.028) 25%,transparent 25%), linear-gradient(-45deg,rgba(16,32,39,.028) 25%,transparent 25%), linear-gradient(45deg,transparent 75%,rgba(16,32,39,.028) 75%), linear-gradient(-45deg,transparent 75%,rgba(16,32,39,.028) 75%); background-size: 24px 24px; background-position: 0 0,0 12px,12px -12px,-12px 0; overflow: hidden; transition: background-color .2s; }
    .drop-zone[hidden], .group-view[hidden] { display: none; }
    .drop-zone.dragging { background-color: rgba(15,159,143,0.06); }
    .drop-zone.dragging::after { content: 'Drop image to analyze'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; font-weight: 700; color: var(--teal); border: 2px dashed var(--teal); border-radius: 6px; background: rgba(15,159,143,0.05); pointer-events: none; }
    canvas { max-width: 100%; max-height: 75vh; border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 8px 32px rgba(16,32,39,0.12); cursor: grab; display: block; transform-origin: center center; user-select: none; }
    canvas.grabbing { cursor: grabbing; }
    .group-nav-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 38px; height: 54px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: rgba(255,255,255,.92); color: var(--ink); box-shadow: var(--shadow-sm); display: grid; place-items: center; cursor: pointer; transition: all var(--tr); z-index: 5; }
    .group-nav-btn:hover { border-color: var(--teal); background: var(--teal-light); color: var(--teal-dark); box-shadow: var(--shadow); }
    .group-nav-btn:disabled { opacity: 0; pointer-events: none; }
    .group-nav-btn.prev { left: 12px; }
    .group-nav-btn.next { right: 12px; }
    .group-nav-btn svg { width: 18px; height: 18px; }

    .empty-state { width: min(480px,90%); text-align: center; border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 40px 32px; background: rgba(255,255,255,0.7); }
    .empty-icon { font-size: 40px; margin-bottom: 12px; }
    .empty-title { font-size: 16px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
    .empty-text { color: var(--muted); font-size: 12.5px; line-height: 1.6; }

    .group-view { min-height: 580px; padding: 16px; background: linear-gradient(45deg,rgba(16,32,39,.025) 25%,transparent 25%), linear-gradient(-45deg,rgba(16,32,39,.025) 25%,transparent 25%), linear-gradient(45deg,transparent 75%,rgba(16,32,39,.025) 75%), linear-gradient(-45deg,transparent 75%,rgba(16,32,39,.025) 75%); background-size: 24px 24px; background-position: 0 0,0 12px,12px -12px,-12px 0; }
    .group-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; align-items: start; }
    .group-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); overflow: hidden; cursor: pointer; transition: border-color var(--tr), box-shadow var(--tr), transform var(--tr); }
    .group-card:hover { border-color: rgba(15,159,143,0.55); box-shadow: var(--shadow); transform: translateY(-1px); }
    .group-card-head { padding: 10px 11px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
    .group-card-title { min-width: 0; }
    .group-card-name { font-size: 12px; font-weight: 800; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .group-card-sub { font-size: 10.5px; color: var(--muted); margin-top: 1px; }
    .group-chip { flex-shrink: 0; border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; font-size: 10px; font-weight: 800; color: var(--teal-dark); background: var(--teal-light); }
    .group-image-wrap { background: #f8fbfa; display: grid; place-items: center; min-height: 220px; }
    .group-canvas { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; display: block; background: #f8fbfa; border: 0; box-shadow: none; cursor: pointer; }
    .group-card-body { padding: 10px 11px 12px; display: grid; gap: 7px; }
    .group-metric { display: grid; grid-template-columns: 82px 1fr; gap: 7px; font-size: 11px; }
    .group-metric span:first-child { color: var(--dim); }
    .group-metric span:last-child { color: var(--ink); font-weight: 700; overflow-wrap: anywhere; }
    .series-summary { margin-bottom: 14px; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 10px; }
    .series-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; box-shadow: var(--shadow-sm); }
    .series-card.good { border-color: rgba(22,163,74,.35); background: rgba(22,163,74,.055); }
    .series-card.warn { border-color: rgba(217,119,6,.38); background: rgba(217,119,6,.06); }
    .series-card.bad { border-color: rgba(180,35,54,.35); background: rgba(180,35,54,.055); }
    .series-card.danger { border-color: rgba(190,18,60,.58); background: #fff1f2; }
    .series-card.danger .series-number { color: #be123c; }
    .series-label { font-size: 10.5px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
    .series-number { margin-top: 6px; font-size: 18px; line-height: 1.05; font-weight: 850; color: var(--teal-dark); overflow-wrap: anywhere; }
    .series-hint { margin-top: 5px; font-size: 11px; line-height: 1.35; color: var(--muted); }
    .calibration-report { margin-bottom: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); overflow: hidden; }
    .calibration-report[hidden] { display: none; }
    .calibration-head { padding: 11px 12px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
    .calibration-title { font-size: 11px; font-weight: 850; color: var(--ink); text-transform: uppercase; letter-spacing: .08em; }
    .calibration-summary { font-size: 11px; color: var(--muted); text-align: right; }
    .calibration-table { width: 100%; border-collapse: collapse; font-size: 11px; }
    .calibration-table th, .calibration-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
    .calibration-table th:first-child, .calibration-table td:first-child { text-align: left; }
    .calibration-table tr:last-child td { border-bottom: 0; }
    .calibration-table th { color: var(--dim); font-weight: 800; background: var(--panel-soft); }
    .error-good { color: #15803d; font-weight: 800; }
    .error-warn { color: #b45309; font-weight: 800; }
    .error-bad { color: #b42336; font-weight: 800; }

    .log-bar { padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; min-height: 40px; }
    .log-bar strong { color: var(--ink); }
    .timer { margin-left: auto; font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }

    .spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin .7s linear infinite; flex-shrink: 0; display: none; }
    .spinner.active { display: block; }
    @keyframes spin { to { transform: rotate(360deg); } }

    .zoom-badge { position: absolute; bottom: 12px; right: 12px; background: rgba(16,32,39,0.72); color: white; border-radius: 6px; padding: 3px 8px; font-size: 11px; font-weight: 700; pointer-events: none; opacity: 0; transition: opacity .3s; }
    .zoom-badge.visible { opacity: 1; }
    .plot-panel { position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center; padding: 22px; background: rgba(10,31,36,0.42); }
    .plot-panel[hidden] { display: none !important; }
    .plot-dialog { width: min(1120px,96vw); max-height: 92vh; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
    .plot-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--panel-soft); }
    .plot-title { font-size: 14px; font-weight: 800; color: var(--ink); }
    .plot-body { overflow: auto; padding: 14px; display: grid; place-items: center; }
    .plot-body canvas { max-width: 100%; max-height: 75vh; box-shadow: none; cursor: default; }

    @media (max-width: 1050px) { body { padding: 14px; overflow: auto; } .app { height: auto; min-height: 100vh; } .layout { grid-template-columns: 1fr; overflow: visible; } .sidebar, .workspace { max-height: none; overflow: visible; } .drop-zone, .group-view { min-height: 420px; } .group-grid, .series-summary { grid-template-columns: 1fr; } }
    @media (max-width: 600px) { .topbar { flex-direction: column; align-items: flex-start; } .demo-banner { align-items: flex-start; flex-direction: column; } .demo-banner a { margin-left: 0; } .metrics { grid-template-columns: 1fr; } .action-row, .export-row { grid-template-columns: 1fr; } .view-toggle { grid-template-columns: repeat(2,1fr); } }

    /* "edited" dot on collapsed sections the user has touched */
    .section.section-modified.collapsed > .section-title .section-title-text::after {
      content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
      background: var(--teal); margin-left: 7px; vertical-align: middle;
    }

    /* empty-state open button spacing */
    .empty-actions { margin: 16px 0 4px; display: flex; justify-content: center; }
    .empty-formats { color: var(--dim); font-size: 11px; margin-top: 10px; }

    /* ---------------- Dark mode (auto, follows OS preference) ---------------- */
    @media (prefers-color-scheme: dark) {
      :root {
        --bg: #0e1714; --bg2: #13201c; --panel: #15211d; --panel-soft: #1b2a25;
        --ink: #e7f0ec; --ink2: #cdddd6; --muted: #a6b9b3; --dim: #8ea29b;
        --line: #27362f; --teal: #1bb3a1; --teal-dark: #46d4c1; --teal-light: #16302b;
        --shadow-sm: 0 2px 8px rgba(0,0,0,0.4); --shadow: 0 10px 32px rgba(0,0,0,0.5);
      }
      body { background: var(--bg); }
      .subpanel { background: #16231f; }
      .subpanel-title { background: #1b2a25; }
      .canvas-head { background: rgba(27,42,37,0.55); }
      .group-image-wrap, .group-canvas { background: #0f1a16; }
      .empty-state { background: rgba(21,33,29,0.7); }
      .demo-banner { background: #16302b; border-color: #27362f; }
      .inline-warning { background: #2a2410; border-color: #5a4a1e; color: #ecd690; }
      /* tooltips must stay dark with light text (ink is now light) */
      .help-dot::after, .delayed-tooltip { background: #05100d; color: #e7f0ec; border-color: #27362f; }
      .zoom-badge { background: rgba(0,0,0,0.7); }
      /* primary button: ink is light now, so use teal with dark text */
      .btn.primary { background: var(--teal); border-color: var(--teal); color: #06120f; }
      .btn.primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
      .account-dd-item:hover { background: #1b2a25; }
      .account-dd-item.danger:hover { background: #2a1416; }
      .metric-card.good { background: rgba(70,212,193,0.08); }
      .metric-card.warn { background: rgba(183,121,31,0.14); }
      .metric-card.bad  { background: rgba(180,35,54,0.16); }
      canvas { box-shadow: 0 8px 32px rgba(0,0,0,0.55); }
      /* checkerboard: light dots so the transparency cue shows on dark */
      .drop-zone, .group-view {
        background-image:
          linear-gradient(45deg, rgba(255,255,255,.03) 25%, transparent 25%),
          linear-gradient(-45deg, rgba(255,255,255,.03) 25%, transparent 25%),
          linear-gradient(45deg, transparent 75%, rgba(255,255,255,.03) 75%),
          linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.03) 75%);
      }
    }

