:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #1d2939;
    --muted: #667085;
    --line: #e4e7ec;
    --blue: #2f7df6;
    --blue-2: #155eef;
    --green: #21bf63;
    --red: #f04438;
    --orange: #f59e0b;
    --purple: #8b5cf6;
    --sidebar: #0e2138;
    --sidebar-2: #07182d;
    --shadow: 0 10px 30px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
a { color: var(--blue); text-decoration: none; }
button, input, select { font: inherit; }
code { color: #344054; background: #f2f4f7; padding: 2px 6px; border-radius: 4px; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar {
    width: 260px;
    flex: 0 0 260px;
    color: #dbe7ff;
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
    min-height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
}
.brand {
    height: 68px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    font-size: 18px;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
    width: 30px;
    height: 30px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, #377dff, #0ecb81);
    font-size: 14px;
    flex: 0 0 auto;
}
.nav { padding: 14px 12px 28px; }
.nav-section {
    color: #7f93b4;
    font-size: 13px;
    padding: 16px 10px 8px;
    display: flex;
    justify-content: space-between;
}
.nav-link {
    color: #d7e4f7;
    height: 44px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 7px;
    margin-bottom: 5px;
}
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-link.active { background: linear-gradient(90deg, #1e66ff, #2f7df6); color: #fff; }
.nav-icon {
    width: 20px;
    height: 20px;
    display: inline-grid;
    place-items: center;
    opacity: .92;
    flex: 0 0 auto;
}
.nav-icon svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.main-shell { min-width: 0; flex: 1; }
.topbar {
    height: 68px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 18px;
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar-spacer { flex: 1; }
.task-time { color: #12b76a; font-size: 14px; }
.topbar-divider { height: 24px; width: 1px; background: var(--line); }
.icon-button {
    width: 36px;
    height: 36px;
    border: 0;
    display: inline-grid;
    place-items: center;
    border-radius: 6px;
    background: transparent;
    color: #475467;
    cursor: pointer;
}
.badge-dot { position: relative; }
.badge-dot::after {
    content: "12";
    position: absolute;
    top: 2px;
    right: 0;
    min-width: 18px;
    height: 16px;
    border-radius: 8px;
    font-size: 10px;
    color: #fff;
    background: #f04438;
}
.user-menu { display: flex; align-items: center; gap: 10px; color: #475467; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; background: #d1f1ff; color: #175cd3; font-weight: 700; }
.page-content { padding: 26px 28px 38px; }
.page-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}
.page-heading h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
.page-heading p { margin: 8px 0 0; color: var(--muted); }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-actions form { margin: 0; }
.inline-filter { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
input, select {
    height: 38px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    padding: 0 12px;
    color: #344054;
    background: #fff;
}
.primary-button, .outline-button {
    min-height: 38px;
    border-radius: 6px;
    border: 1px solid transparent;
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    white-space: nowrap;
}
.primary-button { background: var(--blue); color: #fff; box-shadow: 0 6px 14px rgba(47, 125, 246, .22); }
.primary-button:hover { background: var(--blue-2); color: #fff; }
.outline-button { background: #f7fbff; border-color: #b8d4ff; color: var(--blue); }
.full { width: 100%; }
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
.metric-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 116px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 17px;
    box-shadow: var(--shadow);
    min-width: 0;
}
.metric-icon {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    font-size: 18px;
    font-weight: 700;
    flex: 0 0 auto;
}
.metric-card.green .metric-icon { background: #dcfae6; color: var(--green); }
.metric-card.blue .metric-icon { background: #eaf2ff; color: var(--blue); }
.metric-card.purple .metric-icon { background: #f1e9ff; color: var(--purple); }
.metric-card.red .metric-icon { background: #fee4e2; color: var(--red); }
.metric-card.orange .metric-icon { background: #fef0c7; color: var(--orange); }
.metric-card div { min-width: 0; }
.metric-card p { margin: 0 0 8px; color: #344054; }
.metric-card strong { display: block; font-size: 22px; margin-bottom: 8px; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-card small { color: var(--muted); line-height: 1.4; }
.dashboard-layout {
    display: grid;
    gap: 12px;
}
.analytics-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(320px, .78fr);
    gap: 12px;
    align-items: stretch;
}
.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(290px, .82fr);
    gap: 12px;
    align-items: start;
}
.trend-panel,
.share-panel,
.logs-panel {
    min-width: 0;
}
.logs-panel { grid-column: span 2; }
.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 1.2fr .95fr;
    gap: 10px;
    align-items: start;
}
.dashboard-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: var(--shadow);
    padding: 18px;
    min-width: 0;
}
.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.trend-panel .panel-title {
    position: relative;
    z-index: 2;
}
.panel-title h2 { margin: 0; font-size: 16px; letter-spacing: 0; }
.segmented {
    display: flex;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    overflow: hidden;
    color: #475467;
    font-size: 13px;
}
.trend-panel .segmented {
    position: relative;
    z-index: 3;
    pointer-events: auto;
}
.segmented span,
.segmented a {
    padding: 7px 14px;
    border-right: 1px solid #d0d5dd;
    background: #fff;
    color: #475467;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
}
.segmented span:last-child,
.segmented a:last-child { border-right: 0; }
.segmented a:hover { background: #f8fbff; color: var(--blue); }
.segmented .active { background: #eff6ff; color: var(--blue); }
.chart { width: 100%; height: 292px; display: block; cursor: crosshair; position: relative; z-index: 1; }
.chart.tall { height: 360px; }
.donut-wrap {
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
    justify-content: center;
    justify-items: center;
    gap: 14px;
    min-height: 0;
    min-width: 0;
    overflow: visible;
}
.donut { width: 100%; max-width: 190px; height: 190px; display: block; justify-self: center; }
.legend { display: grid; gap: 10px; min-width: 0; width: 100%; overflow: visible; }
.legend > div {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    min-width: 0;
    width: 100%;
    padding: 9px 10px;
    border: 1px solid #edf1f5;
    border-radius: 6px;
    background: #fafbfc;
}
.legend span { width: 12px; height: 12px; border-radius: 3px; background: var(--blue); }
.legend div:nth-child(2) span { background: #50d47c; }
.legend div:nth-child(3) span { background: #ffca2c; }
.legend > div > span {
    grid-column: 1;
    grid-row: 1;
}
.legend > div > strong {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
}
.legend strong { color: #101828; min-width: 0; }
.legend-text {
    display: grid;
    gap: 3px;
    min-width: 0;
}
.legend-label {
    color: #344054;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.legend-percent {
    justify-self: end;
    white-space: nowrap;
    font-size: 14px;
}
.legend em {
    grid-column: 2 / -1;
    grid-row: 2;
    color: var(--muted);
    font-style: normal;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    overflow-wrap: normal;
    font-size: 12px;
}
.platform-legend .legend-item {
    grid-template-columns: 12px minmax(0, 1fr) auto;
}
.platform-legend .legend-text {
    grid-column: 2;
    grid-row: 1;
}
.platform-legend .legend-percent {
    grid-column: 3;
    grid-row: 1;
}
.side-stack { display: grid; gap: 10px; }
.status-list { display: grid; gap: 0; margin-bottom: 14px; }
.status-list div {
    min-height: 36px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--line);
    gap: 12px;
}
.status-list.large div { min-height: 58px; }
.status-list span { color: var(--muted); }
.channel-list { display: grid; }
.channel-list a {
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    color: #344054;
}
.channel-list strong { color: #12b76a; font-size: 13px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #f8fafc; color: #475467; font-weight: 600; font-size: 13px; }
td { color: #344054; }
.compact th, .compact td { padding: 10px 12px; font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.sub-row td { color: var(--red); background: #fff8f7; }
.rank {
    width: 21px;
    height: 21px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    background: #eef2f6;
    font-size: 12px;
}
.rank-1 { background: #fdb022; color: #fff; }
.rank-2 { background: #98a2b3; color: #fff; }
.rank-3 { background: #fb7a32; color: #fff; }
.tag {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 8px;
    border-radius: 5px;
    font-size: 12px;
    color: #344054;
    background: #eef2f6;
}
.tag.success { color: #079455; background: #dcfae6; }
.tag.failed { color: #d92d20; background: #fee4e2; }
.tag.running { color: #175cd3; background: #d1e9ff; }
.tag.muted { color: #667085; background: #f2f4f7; margin-right: 4px; }
.actions { display: flex; align-items: center; gap: 10px; }
.actions form { display: inline; }
.actions button { border: 0; background: transparent; color: #d92d20; cursor: pointer; padding: 0; }
.form { display: grid; gap: 16px; }
.grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form label { display: grid; gap: 7px; color: #344054; }
.form input, .form select { width: 100%; }
.field-hint { color: var(--muted); line-height: 1.6; }
.form-panel { max-width: 980px; }
.settings-form {
    gap: 18px;
}
.settings-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 18px;
}
.settings-fields label {
    align-content: start;
}
.check-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 18px; }
.check-row label, .switch-line { display: flex; align-items: center; gap: 8px; }
.check-row input, .switch-line input { width: auto; height: auto; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 12px; }
.channel-config {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 16px;
    display: grid;
    gap: 12px;
}
.channel-config .field-hint { margin: -2px 0 2px; }
.channel-config-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.channel-config-head > div {
    display: grid;
    gap: 4px;
}
.channel-config-head strong {
    color: #101828;
    font-size: 16px;
}
.channel-config-head span {
    color: var(--muted);
    font-size: 13px;
}
.channel-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 16px;
}
.channel-fields label {
    display: grid;
    align-content: start;
    gap: 7px;
}
.channel-fields .field-wide {
    grid-column: 1 / -1;
}
.code-box {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 16px;
}
.code-box code { display: block; overflow-x: auto; padding: 12px; }
.mt { margin-top: 10px; }
.flash-stack { display: grid; gap: 8px; margin-bottom: 14px; }
.flash {
    border-radius: 6px;
    padding: 12px 14px;
    border: 1px solid transparent;
}
.flash.success { background: #ecfdf3; border-color: #abefc6; color: #067647; }
.flash.error { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.flash.warning { background: #fffaeb; border-color: #fedf89; color: #b54708; }
.auth-page {
    background:
        radial-gradient(circle at 15% 20%, rgba(47, 125, 246, .16), transparent 32%),
        radial-gradient(circle at 90% 80%, rgba(18, 183, 106, .14), transparent 30%),
        #f4f7fb;
}
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: min(440px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(16, 24, 40, .12);
    padding: 30px;
}
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.login-brand h1 { margin: 0 0 5px; font-size: 22px; }
.login-brand p { margin: 0; color: var(--muted); }
.notice { padding: 12px; background: #fffaeb; border: 1px solid #fedf89; color: #b54708; border-radius: 6px; margin-bottom: 16px; }

@media (max-width: 1280px) {
    .analytics-grid, .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .share-panel, .side-stack { grid-column: auto; }
    .logs-panel { grid-column: span 2; }
    .metric-grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
    .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .side-stack { grid-column: span 2; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 1500px) {
    .donut { max-width: 180px; height: 180px; }
    .legend { max-width: 100%; }
}

@media (max-width: 860px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; left: -280px; top: 0; z-index: 20; transition: left .2s ease; }
    .sidebar.open { left: 0; }
    .topbar { padding: 0 14px; gap: 8px; }
    .task-time, .topbar-divider { display: none; }
    .page-content { padding: 18px 14px 28px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .metric-grid, .analytics-grid, .detail-grid, .dashboard-grid, .dashboard-grid.two, .side-stack, .grid-form, .settings-fields, .channel-fields { grid-template-columns: 1fr; }
    .span-2, .side-stack, .logs-panel { grid-column: auto; }
    .panel-title { align-items: flex-start; flex-direction: column; }
    .segmented { width: 100%; }
    .segmented a, .segmented span { flex: 1; text-align: center; padding-left: 8px; padding-right: 8px; }
    .metric-card { min-height: 112px; }
    .metric-card strong { font-size: 20px; }
    .inline-filter { width: 100%; }
    .inline-filter input, .inline-filter select, .inline-filter button { flex: 1 1 150px; }
}
