:root {
    color-scheme: dark;
    --bg: #080a0f;
    --surface: #0d1118;
    --surface-2: #121722;
    --line: #252b36;
    --line-soft: #1b202a;
    --text: #f4f1e9;
    --muted: #8f98a8;
    --gold: #e7b85f;
    --gold-soft: #f5d99f;
    --mint: #35d4a5;
    --coral: #ff756e;
    --blue: #69a7ff;
    --shadow: 0 18px 60px rgb(0 0 0 / 24%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
    letter-spacing: 0;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.app-shell { min-height: 100vh; background-image: linear-gradient(rgb(255 255 255 / 1%) 1px, transparent 1px), linear-gradient(90deg, rgb(255 255 255 / 1%) 1px, transparent 1px); background-size: 48px 48px; }

.topbar {
    height: 66px;
    padding: 0 24px;
    border-bottom: 1px solid var(--line);
    background: rgb(8 10 15 / 94%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(18px);
}

.brand { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 11px; min-width: 240px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid #8f6b2c; color: var(--gold-soft); font-weight: 900; background: #18150f; }
.brand-copy { display: grid; line-height: 1.15; }
.brand-copy strong { font-size: 16px; }
.brand-copy small { color: var(--muted); margin-top: 4px; font-size: 11px; }

.toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.live-pill { color: #aeb6c3; font-size: 12px; white-space: nowrap; margin-right: 6px; }
.live-pill span, .status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 12px var(--mint); margin-right: 7px; }
.live-pill span { animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.select-wrap {
    height: 36px;
    min-width: 210px;
    max-width: 280px;
    border: 1px solid var(--line);
    background: var(--surface);
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) 16px;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border-radius: 5px;
}
.select-wrap svg { width: 16px; color: var(--muted); }
.select-wrap select { border: 0; outline: 0; color: var(--text); background: transparent; min-width: 0; appearance: none; width: 100%; text-overflow: ellipsis; }

.segmented { height: 36px; display: inline-grid; grid-auto-flow: column; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; border-right: 1px solid var(--line); color: var(--muted); background: transparent; min-width: 46px; padding: 0 10px; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: #2b2417; color: var(--gold-soft); }

.icon-button, .button {
    height: 36px;
    border-radius: 5px;
    border: 1px solid #a57b31;
    background: var(--gold);
    color: #171208;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 14px;
    font-weight: 700;
}
.icon-button { width: 36px; padding: 0; border-color: var(--line); background: var(--surface); color: #c8ced8; }
.icon-button svg, .button svg { width: 17px; height: 17px; }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button.ghost { border-color: var(--line); background: transparent; color: var(--muted); }
.button.danger { margin-right: auto; border-color: #743c40; background: #241214; color: #ffaaa5; }
.button.small { height: 32px; padding: 0 10px; }
.icon-button:hover, .button.secondary:hover, .button.ghost:hover { border-color: #6e7581; color: #fff; }
.button:hover { filter: brightness(1.06); }

.dashboard { width: min(1760px, calc(100vw - 40px)); margin: 0 auto; padding: 24px 0 40px; }
.dashboard-title { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.eyebrow { color: var(--muted); margin: 0 0 7px; font-size: 11px; text-transform: uppercase; }
.dashboard-title h1 { margin: 0; font-size: clamp(22px, 2vw, 32px); line-height: 1.15; font-weight: 800; }
.timestamp { display: grid; text-align: right; gap: 4px; }
.timestamp span { color: var(--muted); font-size: 11px; }
.timestamp strong { font-size: 13px; font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.kpi { min-height: 112px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 18px; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 14px; box-shadow: var(--shadow); }
.kpi.primary { border-color: #66512d; background: #12110f; }
.kpi-icon { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid #765a25; color: var(--gold); background: #1c170f; border-radius: 5px; }
.kpi-icon.mint { border-color: #215f52; background: #0e1a18; color: var(--mint); }
.kpi-icon.coral { border-color: #713a3a; background: #1c1114; color: var(--coral); }
.kpi-icon.blue { border-color: #315781; background: #101824; color: var(--blue); }
.kpi-icon svg { width: 20px; }
.kpi > div:nth-child(2) { min-width: 0; display: grid; gap: 4px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi strong { font-size: clamp(21px, 1.65vw, 30px); line-height: 1.05; overflow-wrap: anywhere; }
.kpi small { color: #697180; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.delta { align-self: start; font-size: 11px; padding: 4px 6px; border-radius: 4px; background: #141820; color: var(--muted); }
.delta.positive { color: var(--mint); background: #0e211c; }
.delta.negative { color: var(--coral); background: #241214; }

.main-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 10px; }
.panel { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow); min-width: 0; overflow: hidden; }
.sales-panel { grid-column: span 8; min-height: 430px; }
.finance-panel { grid-column: span 4; min-height: 430px; }
.funnel-panel { grid-column: span 7; min-height: 330px; }
.ads-panel { grid-column: span 5; min-height: 330px; }
.panel-head { height: 70px; padding: 15px 18px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-head p { margin: 0 0 4px; color: var(--gold); font-size: 9px; font-weight: 800; }
.panel-head h2 { margin: 0; font-size: 16px; }
.tag { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; font-size: 10px; }
.chart-legend { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.chart-legend span { width: 14px; height: 2px; display: inline-block; }
.chart-legend .gold { background: var(--gold); }
.chart-legend .white { background: #dce2ea; margin-left: 5px; }

.sales-visual { height: 358px; position: relative; isolation: isolate; overflow: hidden; }
.sales-visual::before { content: ""; position: absolute; inset: 0; z-index: -2; background: radial-gradient(circle at 34% 40%, #263246 0, #111722 28%, transparent 57%); opacity: .85; }
.sales-visual::after { content: ""; position: absolute; inset: 0; z-index: -1; background-image: radial-gradient(circle, rgb(231 184 95 / 65%) 0 1px, transparent 1.5px); background-size: 42px 42px; mask-image: linear-gradient(90deg, #000, transparent 54%); opacity: .35; }
.orbit { position: absolute; left: 9%; top: 20px; width: min(38vw, 430px); aspect-ratio: 1; border: 1px solid rgb(231 184 95 / 20%); border-radius: 50%; box-shadow: inset 0 0 60px rgb(105 167 255 / 9%), 0 0 50px rgb(231 184 95 / 7%); }
.orbit span { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.orbit span:nth-child(1) { top: 14%; left: 17%; }
.orbit span:nth-child(2) { right: 8%; top: 44%; }
.orbit span:nth-child(3) { left: 39%; bottom: 3%; }
.hero-number { position: absolute; left: 0; top: 84px; width: 54%; text-align: center; display: grid; gap: 7px; z-index: 2; }
.hero-number span, .hero-number small { color: #9aa4b2; font-size: 11px; }
.hero-number strong { color: var(--gold-soft); font-size: clamp(30px, 3.4vw, 58px); line-height: 1; overflow-wrap: anywhere; }
.chart-box { position: absolute; right: 16px; bottom: 12px; top: 18px; width: 58%; min-width: 340px; }
.chart-box canvas { width: 100%; height: 100%; }

.finance-balance { padding: 30px 22px 22px; border-bottom: 1px solid var(--line-soft); display: grid; gap: 9px; }
.finance-balance span { color: var(--muted); font-size: 12px; }
.finance-balance strong { font-size: clamp(30px, 2.5vw, 44px); color: var(--gold-soft); line-height: 1.1; overflow-wrap: anywhere; }
.meter { height: 4px; background: #252a32; overflow: hidden; margin-top: 4px; }
.meter span { height: 100%; width: 60%; display: block; background: var(--gold); transition: width .5s ease; }
.finance-rows { display: grid; grid-template-columns: 1fr; padding: 0 22px; }
.finance-rows > div { min-height: 92px; border-bottom: 1px solid var(--line-soft); display: grid; grid-template-columns: 1fr auto; align-content: center; gap: 6px 14px; }
.finance-rows > div:last-child { border-bottom: 0; }
.finance-rows span { display: flex; gap: 7px; align-items: center; color: var(--muted); font-size: 11px; }
.finance-rows svg { width: 15px; color: var(--gold); }
.finance-rows strong { font-size: 18px; }
.finance-rows small { grid-column: 2; color: #6f7887; font-size: 10px; text-align: right; }

.funnel-steps { min-height: 160px; padding: 22px 18px 12px; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; gap: 8px; }
.funnel-step { min-width: 0; display: grid; gap: 8px; text-align: center; align-items: end; }
.funnel-step .bar { width: var(--bar-width); max-width: 100%; min-width: 46%; height: 48px; margin: 0 auto; position: relative; display: grid; place-items: center; background: #171b24; border: 1px solid var(--step-color); clip-path: polygon(7% 0, 93% 0, 100% 100%, 0 100%); }
.funnel-step strong { font-size: clamp(14px, 1.3vw, 21px); color: #fff; overflow-wrap: anywhere; }
.funnel-step span { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversion-row { border-top: 1px solid var(--line-soft); display: grid; grid-template-columns: repeat(4, 1fr); min-height: 76px; }
.conversion-row > div { padding: 14px; border-right: 1px solid var(--line-soft); display: grid; align-content: center; gap: 5px; }
.conversion-row > div:last-child { border-right: 0; }
.conversion-row span { color: var(--muted); font-size: 10px; }
.conversion-row strong { color: var(--mint); font-size: 17px; }

.ads-layout { min-height: 190px; display: grid; grid-template-columns: 42% 58%; align-items: center; padding: 12px 14px 8px; }
.donut-wrap { width: 180px; max-width: 100%; aspect-ratio: 1; margin: 0 auto; position: relative; display: grid; place-items: center; }
.donut-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.donut-wrap > div { text-align: center; display: grid; gap: 2px; z-index: 1; }
.donut-wrap span, .donut-wrap small { color: var(--muted); font-size: 9px; }
.donut-wrap strong { font-size: 25px; color: var(--gold-soft); }
.ad-stats { display: grid; grid-template-columns: 1fr 1fr; }
.ad-stats > div { min-height: 72px; padding: 11px 12px; border-bottom: 1px solid var(--line-soft); }
.ad-stats > div:nth-child(odd) { border-right: 1px solid var(--line-soft); }
.ad-stats > div:nth-last-child(-n+2) { border-bottom: 0; }
.ad-stats span { display: block; color: var(--muted); font-size: 10px; margin-bottom: 7px; }
.ad-stats strong { font-size: 16px; overflow-wrap: anywhere; }
.campaign-line { min-height: 66px; border-top: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 18px; }
.campaign-line > div { min-width: 0; display: grid; gap: 4px; }
.campaign-line span, .campaign-line small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; font-size: 10px; }
.campaign-line strong { color: var(--gold-soft); }

.account-dialog { width: min(900px, calc(100vw - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 7px; background: #0d1118; color: var(--text); box-shadow: 0 30px 100px #000; }
.account-dialog::backdrop { background: rgb(0 0 0 / 72%); backdrop-filter: blur(5px); }
.dialog-shell > header { height: 72px; padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.dialog-shell header p { margin: 0 0 4px; color: var(--gold); font-size: 9px; font-weight: 800; }
.dialog-shell header h2 { margin: 0; font-size: 18px; }
.dialog-body { display: grid; grid-template-columns: 40% 60%; min-height: 440px; max-height: calc(100vh - 114px); overflow: auto; }
.account-list-section { padding: 18px; border-right: 1px solid var(--line); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.section-title > span { color: var(--muted); font-size: 11px; }
.account-list { display: grid; gap: 7px; }
.account-item { width: 100%; min-height: 64px; border: 1px solid var(--line); background: #10141c; color: var(--text); border-radius: 5px; padding: 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; text-align: left; gap: 10px; }
.account-item:hover { border-color: #555e6d; }
.account-item strong, .account-item small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-item small { color: var(--muted); margin-top: 5px; }
.account-item .state { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.account-item .state.ok { background: var(--mint); }
.account-item .state.error { background: var(--coral); }
.account-editor { padding: 22px; display: grid; gap: 15px; align-content: start; }
.account-editor[hidden] { display: none; }
.account-editor label { display: grid; gap: 7px; color: var(--muted); font-size: 11px; }
.account-editor input, .account-editor textarea { width: 100%; border: 1px solid var(--line); border-radius: 5px; background: #080b10; color: var(--text); padding: 10px 11px; resize: vertical; }
.account-editor input { height: 40px; }
.account-editor textarea { min-height: 128px; max-height: 220px; font-family: Consolas, monospace; font-size: 11px; line-height: 1.5; }
.field-divider { margin: 2px 0 -3px; padding-top: 12px; border-top: 1px solid var(--line-soft); color: var(--gold); font-size: 10px; font-weight: 700; }
.security-note { margin: 0; color: #7c8797; font-size: 10px; line-height: 1.55; display: flex; gap: 8px; }
.security-note svg { width: 18px; min-width: 18px; color: var(--mint); }
.editor-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 50; max-width: min(400px, calc(100vw - 40px)); padding: 12px 15px; border: 1px solid #4e5a68; border-radius: 5px; background: #151b24; color: #fff; box-shadow: var(--shadow); transform: translateY(120px); opacity: 0; transition: .25s ease; pointer-events: none; }
.toast.show { transform: none; opacity: 1; }
.toast.error { border-color: #7b3d40; color: #ffb3ae; }
.loading-overlay { position: fixed; inset: 0; z-index: 40; background: rgb(8 10 15 / 72%); display: none; place-items: center; align-content: center; gap: 14px; color: #ccd2dc; backdrop-filter: blur(4px); }
.loading-overlay.show { display: grid; }
.loading-overlay .button { margin-top: 2px; }
.spinner { width: 32px; height: 32px; border: 2px solid #343b47; border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
    .live-pill { display: none; }
    .button.secondary span { display: none; }
    .button.secondary { width: 36px; padding: 0; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .sales-panel, .finance-panel, .funnel-panel, .ads-panel { grid-column: span 12; }
    .finance-panel { min-height: 330px; }
    .finance-rows { grid-template-columns: 1fr 1fr; }
    .finance-rows > div:first-child { border-right: 1px solid var(--line-soft); }
}

@media (max-width: 760px) {
    .topbar { height: auto; min-height: 64px; padding: 11px 14px; align-items: stretch; flex-direction: column; gap: 10px; }
    .brand { min-width: auto; }
    .brand-copy small { display: none; }
    .toolbar { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 36px 36px; gap: 7px; }
    .select-wrap { grid-column: 1; grid-row: 1; min-width: 0; max-width: none; width: 100%; }
    .segmented { grid-column: 1 / -1; grid-row: 2; grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .segmented button { width: 100%; }
    #refreshButton { grid-column: 2; grid-row: 1; }
    #manageButton { grid-column: 3; grid-row: 1; }
    #fullscreenButton { display: none; }
    .dashboard { width: calc(100vw - 24px); padding-top: 18px; }
    .dashboard-title { align-items: flex-start; }
    .dashboard-title h1 { font-size: 22px; }
    .timestamp { display: none; }
    .kpi-grid { grid-template-columns: 1fr; }
    .kpi { min-height: 94px; }
    .sales-panel { min-height: 520px; }
    .sales-visual { height: 448px; }
    .hero-number { width: 100%; top: 54px; }
    .orbit { left: 50%; transform: translateX(-50%); width: 310px; }
    .chart-box { left: 10px; right: 10px; top: 215px; width: auto; min-width: 0; height: 220px; }
    .finance-rows { grid-template-columns: 1fr; }
    .finance-rows > div:first-child { border-right: 0; }
    .funnel-steps { grid-template-columns: 1fr; align-items: stretch; }
    .funnel-step { grid-template-columns: 92px minmax(0, 1fr); text-align: left; align-items: center; }
    .funnel-step .bar { width: var(--bar-width); height: 42px; margin: 0; min-width: 55%; }
    .funnel-step span { grid-column: 1; grid-row: 1; }
    .funnel-step .bar { grid-column: 2; }
    .conversion-row { grid-template-columns: 1fr 1fr; }
    .conversion-row > div:nth-child(2) { border-right: 0; }
    .conversion-row > div:nth-child(-n+2) { border-bottom: 1px solid var(--line-soft); }
    .ads-layout { grid-template-columns: 1fr; }
    .ad-stats { width: 100%; }
    .dialog-body { grid-template-columns: 1fr; }
    .account-list-section { border-right: 0; border-bottom: 1px solid var(--line); }
    .account-dialog { max-height: calc(100vh - 20px); overflow: auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
