:root {
  --bg: #ffffff;
  --side-bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e5e7eb;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #ff4b4b;
  --primary-text: #ffffff;
  --up-bg: #dcfce7;
  --up: #15803d;
  --down-bg: #fee2e2;
  --down: #c62828;
  --flat-bg: #eef1f5;
  --flat: #64748b;
  --info-bg: #e8f1fd;
  --info: #1d4f91;
  --warn-bg: #fff4e5;
  --warn: #8a4b00;
  --err-bg: #fdecec;
  --err: #a12020;
  --ok-bg: #e7f6ec;
  --ok: #1b6b3a;
  --chip-on: #ff4b4b;
  --chip-on-text: #ffffff;
  --dot-blue: #3b82f6;
  --dot-pink: #ec4899;
  --dot-green: #22c55e;
  --seg-row: #f3f6fb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --side-bg: #161a23;
    --panel: #1a1f2b;
    --panel-2: #202636;
    --line: #2d3445;
    --text: #e6e8ee;
    --muted: #9aa3b5;
    --up-bg: #12351f;
    --up: #5fd48a;
    --down-bg: #3d1717;
    --down: #ff8a8a;
    --flat-bg: #262c3a;
    --flat: #a3acbd;
    --info-bg: #15263f;
    --info: #9cc3f5;
    --warn-bg: #3a2a12;
    --warn: #f3c27a;
    --err-bg: #3d1717;
    --err: #ff9a9a;
    --ok-bg: #12351f;
    --ok: #7fe0a4;
    --seg-row: #1f2637;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.5;
}
button { font: inherit; color: inherit; }

.app { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side-bg); border-right: 1px solid var(--line); padding: 24px 18px; display: flex; flex-direction: column; gap: 10px; }
.side-title { margin: 0 0 6px; font-size: 18px; }
.main { padding: 28px 40px 60px; min-width: 0; }
.title { margin: 0 0 18px; font-size: 30px; letter-spacing: -0.5px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover:not(:disabled) { color: var(--primary-text); filter: brightness(1.05); }
.btn.on { border-color: var(--primary); color: var(--primary); font-weight: 600; }
.btn.wide { width: 100%; }
.link { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 12px; text-decoration: underline; }
.or { text-align: center; color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; }
.field-label { font-size: 13px; font-weight: 600; margin-top: 10px; }
.media-head { display: flex; justify-content: space-between; align-items: baseline; }

.upload { display: flex; flex-direction: column; gap: 4px; border: 1px dashed var(--line); border-radius: 8px; padding: 10px; background: var(--panel); }
.upload-label { font-size: 13px; font-weight: 600; }
.upload input { font-size: 12px; max-width: 100%; }

.rd-status { border-radius: 8px; padding: 9px 11px; font-size: 13px; background: var(--ok-bg); color: var(--ok); word-break: break-all; }
.rd-status.err { background: var(--err-bg); color: var(--err); }
.rd-status .sub { display: block; font-size: 11px; opacity: .85; margin-top: 2px; }

.seg3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.custom-range { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }
.custom-range input { width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
.custom-range .btn { grid-column: 1 / -1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 260px; overflow: auto; padding: 2px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.chip.on { background: var(--chip-on); border-color: var(--chip-on); color: var(--chip-on-text); }

.alert { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; background: var(--warn-bg); color: var(--warn); white-space: pre-line; }
.alert.err { background: var(--err-bg); color: var(--err); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 9px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; color: var(--muted); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.loading { color: var(--muted); padding: 30px 0; }
.tab-body.busy { opacity: .55; pointer-events: none; }
.header { font-size: 18px; font-weight: 700; margin: 2px 0 16px; }
.block-title { font-weight: 700; margin: 22px 0 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 28px; }
.card .label { color: var(--muted); font-size: 13px; }
.card .value { font-size: 30px; font-weight: 500; letter-spacing: -0.5px; line-height: 1.25; margin-top: 2px; }
.delta { display: inline-block; margin-top: 4px; border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 600; }
.delta.up { background: var(--up-bg); color: var(--up); }
.delta.down { background: var(--down-bg); color: var(--down); }

.details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.detail { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.detail .t { font-weight: 700; margin-bottom: 6px; }
.detail .l { font-size: 12px; color: var(--muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--panel-2); text-align: right; padding: 9px 14px; border-bottom: 1px solid var(--line); font-weight: 600; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td { padding: 8px 14px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.segment td { background: var(--seg-row); font-weight: 700; }
tr.detail-row td:first-child { padding-left: 32px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.dot.blue { background: var(--dot-blue); } .dot.pink { background: var(--dot-pink); } .dot.green { background: var(--dot-green); }
.badge { display: inline-block; border-radius: 8px; padding: 1px 8px; font-size: 11px; font-weight: 700; }
.badge.good { background: var(--up-bg); color: var(--up); }
.badge.bad { background: var(--down-bg); color: var(--down); }
.badge.flat { background: var(--flat-bg); color: var(--flat); }

.info { border-radius: 8px; padding: 12px 14px; background: var(--info-bg); color: var(--info); }

.comment-title { font-weight: 700; margin-bottom: 2px; }
.caption { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.comment-actions { display: grid; grid-template-columns: 2fr 1fr auto; gap: 8px; }
textarea {
  width: 100%; min-height: 300px; margin-top: 12px; padding: 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Malgun Gothic", monospace; font-size: 13px; line-height: 1.55; resize: vertical;
}
.comment-msg { margin-top: 8px; font-size: 13px; }
.comment-msg.ok { color: var(--ok); }
.comment-msg.err { color: var(--err); }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); padding: 18px 16px; }
  .main { padding: 20px 16px 48px; }
  .cards, .details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .title { font-size: 24px; }
}
@media (max-width: 520px) {
  .cards, .details { grid-template-columns: 1fr; }
  .comment-actions { grid-template-columns: 1fr 1fr; }
  .comment-actions .btn.primary { grid-column: 1 / -1; }
}
