:root {
  color-scheme: dark;
  --bg: #041823;
  --side: #051e2b;
  --panel: #092736;
  --panel2: #0c3040;
  --line: #24414c;
  --text: #eef3f3;
  --muted: #a3b6bc;
  --gold: #dfc394;
  --gold-strong: #f0d29a;
  --gradient: linear-gradient(115deg, #9d7440, #e8d3ac 45%, #bd955e 75%, #f4e2be);
  --ok: #6fcf97;
  --warn: #e8b85c;
  --bad: #ef8a80;
  --info: #7fb8d8;
  --radius: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.65 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; color: #d6e4ea; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }
h1 { font-size: clamp(22px, 3vw, 30px); font-weight: 600; margin: 4px 0 6px; letter-spacing: -.3px; overflow-wrap: anywhere; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 14px; color: var(--gold-strong); }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 3px; color: var(--gold); font-size: 11px; font-weight: 700; }

/* buttons */
button { cursor: pointer; border-radius: 3px; border: 1px solid transparent; padding: 9px 18px; font-weight: 600; background: transparent; }
button:disabled { opacity: .55; cursor: progress; }
.primary { background: var(--gradient); color: #17242b; border: 0; }
.ghost { border-color: #4e6872; }
.ghost:hover { border-color: var(--gold); }
.danger.primary, button.danger:not(.ghost) { background: #b54e44; color: #fff; }
.ghost.danger { color: var(--bad); border-color: #7a3d38; }
.small { padding: 4px 10px; font-size: 12px; }
.block { width: 100%; }
.linkBtn { padding: 0; border: 0; color: var(--gold); font-weight: 500; }
.linkBtn:hover { text-decoration: underline; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(ellipse at 70% 20%, #16495955, transparent 60%), var(--bg); }
.loginCard { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 32px 28px; display: grid; gap: 14px; }
.loginCard h1 { margin: 6px 0 0; }
.loginCard .linkBtn { justify-self: center; }
.loginBrand, .brand { display: flex; align-items: center; gap: 12px; color: var(--text); }
.loginBrand img, .brand img { width: 38px; height: 38px; object-fit: contain; }
.loginBrand strong, .brand strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 22px; font-weight: 500; letter-spacing: .3px; background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.loginBrand span, .brand span { display: block; font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.brand:hover { text-decoration: none; }

/* layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--side); border-right: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 26px; position: sticky; top: 0; height: 100vh; }
.side nav { display: grid; gap: 2px; }
.side nav a { color: #b8c7cb; padding: 9px 12px; border-radius: var(--radius); }
.side nav a:hover { background: #0b2a39; text-decoration: none; color: var(--text); }
.side nav a.active { background: #0f3446; color: var(--gold-strong); box-shadow: inset 3px 0 0 var(--gold); }
.me { margin-top: auto; border-top: 1px solid var(--line); padding-top: 16px; display: grid; gap: 2px; }
.me small { color: var(--muted); overflow-wrap: anywhere; }
.me .badge { justify-self: start; margin-top: 6px; }
.meActions { display: flex; gap: 16px; margin-top: 10px; }
.content { padding: 32px clamp(16px, 3vw, 48px) 64px; min-width: 0; }
/* Keep pages at a readable width on large screens instead of stretching edge to edge. */
.content > * { max-width: 1180px; margin-inline: auto; }
.content:focus { outline: none; }
.loading { color: var(--muted); padding: 40px 0; }
.pageHead { margin-bottom: 22px; }
.pageHead.split { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-end; }
.pageHead p { margin: 4px 0 0; }
.actionsRow { display: flex; flex-wrap: wrap; gap: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 22px 24px; margin-bottom: 20px; min-width: 0; }
.panelHead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.twoCol { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.twoCol > .panel { margin-bottom: 0; }

.stack { display: grid; gap: 12px; margin-bottom: 16px; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; }
.kpi span { font-size: 13px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi strong { display: block; font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi strong.small { font-size: 20px; line-height: 1.4; }

.serviceStatus { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.serviceStatus h2 { margin-bottom: 4px; }
.serviceStatus p { margin: 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; background: var(--muted); }
.serviceStatus.ok .dot { background: var(--ok); box-shadow: 0 0 0 4px #6fcf9722; }
.serviceStatus.bad .dot { background: var(--bad); }
.serviceStatus.warn .dot { background: var(--warn); }

/* tables */
.tableWrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
td { white-space: nowrap; }
td .detail { white-space: normal; display: inline-block; min-width: 220px; max-width: 420px; color: var(--muted); }
th.num, td.num { text-align: right; }
tbody tr:hover { background: #0b2c3b; }
.empty { color: var(--muted); padding: 22px 4px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px 22px; margin: 0; }
.fields dt { font-size: 13px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 2px 0 0; overflow-wrap: anywhere; }

.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.activity li { display: grid; grid-template-columns: 130px 1fr; gap: 2px 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.activity li span { color: var(--muted); font-size: 12px; grid-row: span 2; }
.activity li small { color: var(--muted); overflow-wrap: anywhere; }
.activity li.failed b { color: var(--bad); }

/* badges */
.badge { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 999px; border: 1px solid currentColor; line-height: 1.6; white-space: nowrap; }
.st-paid, .ls-active, .ms-active, .badge.ok { color: var(--ok); }
.st-pending { color: var(--warn); }
.st-refunded, .st-chargeback, .ls-revoked, .badge.bad { color: var(--bad); }
.st-cancelled, .ms-disabled { color: var(--muted); }
.ls-suspended { color: var(--warn); }
.badge.role, .badge.premium { color: var(--gold); }
.pre-new { color: var(--info); }
.pre-contacted { color: var(--warn); }
.pre-converted { color: var(--ok); }
.pre-withdrawn { color: var(--muted); }

/* toolbar & forms */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.toolbar input, .toolbar select { flex: 1 1 200px; }
input, select, textarea { background: #062232; border: 1px solid #36525e; border-radius: 4px; padding: 9px 11px; width: 100%; min-width: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: none; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 12px; color: var(--muted); }
.field small { color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input, .radios input { width: auto; }
.radios { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: grid; gap: 6px; margin: 0; }
.radios legend { color: var(--muted); font-size: 12px; padding: 0 6px; }
.formError { color: var(--bad); margin: 0; }
.notice { border: 1px solid #2f5a6b; background: #0b2e3e; border-radius: var(--radius); padding: 10px 14px; margin: 0 0 12px; }
.notice.warn { border-color: #7a6331; background: #2a2413; color: #f3dca6; }
.notice.bad { border-color: #7a3d38; background: #2c1614; color: #f6c3bd; }

/* dialog */
dialog { background: var(--panel); color: var(--text); border: 1px solid #36525e; border-radius: 10px; padding: 0; width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: #01080cc0; }
.dialogForm { padding: 22px 24px; display: grid; gap: 14px; }
.dialogForm h2 { font-size: 17px; margin: 0; overflow-wrap: anywhere; }
.dialogBody { display: grid; gap: 12px; }
.dialogBody p { margin: 0; }
.dialogActions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.keyBox { display: grid; gap: 6px; background: #041823; border: 1px solid var(--gold); border-radius: var(--radius); padding: 12px 14px; }
.keyBox span { color: var(--gold); font-size: 12px; }
.keyBox code { font-size: 16px; overflow-wrap: anywhere; user-select: all; }
.keyBox code.wrap { font-size: 12px; }
.keyBox button { justify-self: start; }

/* toast */
#toast { position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); max-width: min(420px, calc(100vw - 40px)); padding: 11px 16px; border-radius: var(--radius); background: #0f3446; border: 1px solid var(--line); opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; transform: none; }
#toast.ok { border-color: #2f6b4b; }
#toast.bad { border-color: #7a3d38; color: #f6c3bd; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: column; gap: 14px; padding: 14px 16px; }
  .side nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .side nav a { padding: 6px 10px; }
  .side nav a.active { box-shadow: inset 0 -2px 0 var(--gold); }
  .me { margin-top: 0; }
  .twoCol { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}

/* analytics */
.segmented { display: inline-flex; border: 1px solid #4e6872; border-radius: 4px; overflow: hidden; }
.segmented a { padding: 7px 14px; color: var(--muted); }
.segmented a.active { background: #0f3446; color: var(--gold-strong); }
.segmented a:hover { text-decoration: none; color: var(--text); }
.barCell { display: inline-flex; align-items: center; gap: 8px; min-width: 150px; }
.barCell b { font-weight: 500; font-variant-numeric: tabular-nums; min-width: 44px; }
progress { appearance: none; -webkit-appearance: none; width: 110px; height: 8px; border: 0; border-radius: 4px; background: #16394a; overflow: hidden; }
progress::-webkit-progress-bar { background: #16394a; border-radius: 4px; }
progress::-webkit-progress-value { background: var(--gold); border-radius: 4px; }
progress::-moz-progress-bar { background: var(--gold); border-radius: 4px; }
.funnel { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.funnel li { display: grid; grid-template-columns: minmax(120px, 190px) auto 1fr; align-items: center; gap: 14px; }
.funnel progress { width: min(420px, 45vw); height: 12px; }
.funnel small { color: var(--muted); }
.chartWrap svg { width: 100%; height: auto; display: block; }
.barVisits { fill: #2f6a82; }
.barReg { fill: var(--gold); }
.chartAxis { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 4px 0 10px; vertical-align: -1px; }
.legend .lv { background: #2f6a82; }
.legend .lr { background: var(--gold); }
.journeys { list-style: none; margin: 0; padding: 0; display: grid; }
.journeys li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.journeys li span { color: var(--muted); font-size: 12px; }
.journeys li b { font-weight: 500; overflow-wrap: anywhere; }
.journeys li em { font-style: normal; color: var(--ok); margin-left: 6px; }
@media (max-width: 700px) { .funnel li { grid-template-columns: 1fr; gap: 4px; } .funnel progress { width: 100%; } }

/* tabs: page-level (analytics) and inside a panel (license records) */
.subTabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.subTabs a, .subTabs button { padding: 10px 16px; color: var(--muted); border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 0; font-weight: 500; }
.subTabs a:hover, .subTabs button:hover { color: var(--text); text-decoration: none; }
.subTabs a.active, .subTabs button[aria-selected="true"] { color: var(--gold-strong); border-bottom-color: var(--gold); }
.subTabs.inPanel { margin: -6px -4px 16px; }
.pane[hidden] { display: none; }

/* 推廣夥伴 */
.ps-active { color: var(--ok); }
.ps-stopped { color: var(--muted); }
.rangeBar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 0 16px; }
.dateRange { display: inline-flex; align-items: center; gap: 6px; }
.dateRange input { width: auto; }
.kpi small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

/* 搜尋與文章 (H92) */
.connRow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px; padding: 14px 20px; }
.conn { display: inline-flex; align-items: center; gap: 6px; }
.conn b { font-weight: 600; }
.conn small { color: var(--warn); }
.conn.ok .dot { background: var(--ok); }
.conn.warn .dot { background: var(--warn); }
.conn.off .dot { background: #4e6872; }
.connRow > small { margin-left: auto; }
.dailyGrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 8px; }
.panel h3 { font-size: 14px; font-weight: 600; margin: 6px 0 8px; }
ul.plain { margin: 0; padding-left: 18px; }
ul.plain li { margin: 2px 0; overflow-wrap: anywhere; }
.chartWrap .hit { fill: transparent; }
.chartWrap .hit:hover { fill: #ffffff0d; }
.chartWrap polyline { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.lnGold { stroke: var(--gold); fill: var(--gold); }
.lnBlue { stroke: var(--info); fill: var(--info); }
polyline.lnGold, polyline.lnBlue { fill: none; }
.legend .lnGold { background: var(--gold); }
.legend .lnBlue { background: var(--info); }
.legend .barVisits { background: #2f6a82; }
.legend .barReg { background: var(--gold); }
.idx { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--line); margin-right: 2px; }
.idx.yes { color: var(--ok); border-color: #2f6b4b; }
.idx.no { color: var(--bad); border-color: #7a3d38; }
.idx.unk { color: var(--muted); }
.artTitle { display: inline-block; white-space: normal; min-width: 200px; max-width: 340px; }
.stickyFirst td:first-child, .stickyFirst th:first-child { position: sticky; left: 0; background: var(--panel); z-index: 1; }
.stickyFirst tbody tr:hover td:first-child { background: #0b2c3b; }
.setupGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.setupCard { border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; }
.setupCard.done { border-color: #2f6b4b; }
.setupCard ol { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.bad { color: var(--bad); }
@media (max-width: 900px) {
  .dailyGrid, .setupGrid { grid-template-columns: 1fr; }
  .connRow > small { margin-left: 0; }
  .artTitle { min-width: 150px; max-width: 200px; }
  .kpi strong { font-size: 22px; }
}
.why { color: var(--muted); font-size: 13px; margin: -6px 0 14px; padding-left: 10px; border-left: 2px solid #4e6872; }
.rate.good { color: var(--ok); }
.rate.needs { color: var(--warn); }
.rate.poor { color: var(--bad); }
.threeCol { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.threeCol > .panel { margin-bottom: 0; }
@media (max-width: 900px) { .threeCol { grid-template-columns: 1fr; } }
