:root {
  --ink: #17201d;
  --muted: #69736f;
  --line: #dfe4e1;
  --paper: #ffffff;
  --canvas: #f4f6f4;
  --green: #1e6b4f;
  --green-soft: #e2f0e8;
  --lime: #b7db47;
  --amber: #b86b16;
  --amber-soft: #fff0dc;
  --red: #bd3e43;
  --red-soft: #fae8e8;
  --blue: #2f64a3;
  --shadow: 0 14px 38px rgba(23, 32, 29, .08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 14px; letter-spacing: 0; }
body:has(dialog[open]) { overflow: hidden; }
button, input, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }
.is-hidden { display: none !important; }
.sr-only { position: absolute; left: 0; top: 0; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.eyebrow, .section-kicker { color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: 1.4px; }

.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, .82fr) 1.18fr; background: #f7f8f6; }
.login-panel { display: flex; flex-direction: column; padding: clamp(34px, 6vw, 78px); min-height: 100vh; background: var(--paper); position: relative; z-index: 1; }
.login-brand, .brand { display: flex; align-items: center; gap: 12px; font-size: 12px; font-weight: 800; letter-spacing: 1.3px; }
.brand-mark { width: 38px; height: 38px; display: inline-grid; place-items: center; background: var(--ink); color: var(--lime); border-radius: 6px; }
.brand-mark svg { width: 21px; height: 21px; }
.login-heading { margin: auto 0 46px; max-width: 540px; }
.login-heading h1 { margin: 14px 0 18px; font-size: clamp(38px, 4.4vw, 66px); line-height: 1.08; font-weight: 650; letter-spacing: 0; }
.login-heading p { color: var(--muted); font-size: 16px; line-height: 1.7; margin: 0; }
.login-form { max-width: 440px; display: grid; gap: 17px; }
.field { display: grid; gap: 8px; min-width: 0; }
.field > span:first-child { color: #4d5854; font-size: 13px; font-weight: 700; }
.field input, .field select { width: 100%; height: 43px; border: 1px solid #cfd6d2; border-radius: 6px; padding: 0 13px; color: var(--ink); background: #fff; outline: none; transition: border-color .18s, box-shadow .18s; }
.field input:focus, .field select:focus, .search-box input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(30, 107, 79, .12); }
.input-wrap { height: 46px; display: flex; align-items: center; border: 1px solid #cfd6d2; border-radius: 6px; background: #fff; color: #89938e; padding-left: 13px; }
.input-wrap:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(30, 107, 79, .12); }
.input-wrap svg { width: 17px; }
.input-wrap input { border: 0; height: 100%; box-shadow: none !important; }
.button { height: 41px; border: 1px solid transparent; border-radius: 6px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font-weight: 750; white-space: nowrap; transition: transform .15s, background .15s, border-color .15s; }
.button:hover { transform: translateY(-1px); }
.button svg { width: 17px; height: 17px; }
.button.primary { background: var(--ink); color: #fff; }
.button.primary:hover { background: #26322e; }
.button.secondary { background: var(--green-soft); border-color: #c9dfd3; color: #16563f; }
.button.ghost { background: #fff; border-color: var(--line); }
.button.danger { background: var(--red); color: #fff; }
.button:disabled, .icon-button:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.button.compact { height: 38px; padding: 0 12px; font-size: 12px; }
.login-button { height: 49px; justify-content: space-between; margin-top: 3px; padding: 0 18px; }
.register-link { width: 100%; height: 43px; }
.form-error { color: var(--red); min-height: 18px; margin: -5px 0 0; font-size: 13px; }
.login-foot { margin-top: auto; padding-top: 34px; display: flex; align-items: center; gap: 8px; color: #84908a; font-size: 12px; }
.login-foot svg { width: 16px; }
.login-visual { min-height: 100vh; display: grid; place-items: center; padding: 7vw; overflow: hidden; background: #1b2421; position: relative; }
.login-visual::before { content: ""; position: absolute; inset: 0; opacity: .26; background-image: linear-gradient(rgba(255,255,255,.09) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.09) 1px, transparent 1px); background-size: 44px 44px; }
.signal-board { width: min(600px, 100%); padding: clamp(28px, 5vw, 62px); border: 1px solid rgba(255,255,255,.14); color: white; position: relative; background: rgba(14, 22, 19, .68); backdrop-filter: blur(8px); }
.signal-head { display: flex; justify-content: space-between; color: #aebbb5; font-size: 11px; font-weight: 800; letter-spacing: 1.6px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 7px rgba(183,219,71,.12); }
.signal-value { margin-top: 56px; color: #9cad9f; font-size: 24px; }
.signal-value span { color: white; font-size: clamp(58px, 8vw, 104px); font-weight: 600; }
.signal-bars { height: 180px; display: flex; gap: clamp(8px, 1.5vw, 18px); align-items: end; margin-top: 48px; border-bottom: 1px solid rgba(255,255,255,.16); }
.signal-bars span { height: var(--h); flex: 1; background: var(--lime); opacity: .86; }
.signal-meta { display: grid; grid-template-columns: 1fr auto; gap: 14px; padding-top: 28px; border-top: 1px solid rgba(255,255,255,.1); color: #91a099; }
.signal-meta strong { color: #fff; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 236px; padding: 25px 17px 18px; display: flex; flex-direction: column; background: var(--ink); color: #fff; z-index: 20; }
.brand { padding: 0 8px 28px; }
.brand-mark { flex: 0 0 38px; }
.brand-copy { display: grid; line-height: 1.05; }
.brand-copy strong { font-size: 17px; }
.brand-copy small { color: #89988f; font-size: 9px; letter-spacing: 2px; margin-top: 5px; }
.main-nav { display: grid; gap: 5px; }
.nav-item { width: 100%; min-height: 44px; padding: 0 12px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: 6px; background: transparent; color: #a9b4ae; cursor: pointer; font-weight: 650; text-align: left; }
.nav-item:hover { background: rgba(255,255,255,.05); color: white; }
.nav-item.active { background: #2b3833; color: #fff; }
.nav-item.active svg { color: var(--lime); }
.nav-item svg { width: 18px; }
.nav-item b { margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px; display: inline-grid; place-items: center; border-radius: 10px; background: rgba(255,255,255,.1); font-size: 11px; }
.sidebar-status { margin: auto 5px 16px; padding: 13px 10px; display: flex; align-items: center; gap: 11px; border-top: 1px solid #33413c; border-bottom: 1px solid #33413c; }
.pulse-ring { width: 32px; height: 32px; display: grid; place-items: center; color: var(--lime); border: 1px solid #42524b; border-radius: 50%; }
.pulse-ring svg { width: 15px; }
.sidebar-status div { display: grid; gap: 3px; min-width: 0; }
.sidebar-status strong { font-size: 11px; }
.sidebar-status small { color: #82918a; font-size: 10px; }
.account-button { display: grid; grid-template-columns: 34px 1fr 18px; align-items: center; gap: 9px; width: 100%; padding: 8px; border: 0; border-radius: 6px; background: transparent; color: white; cursor: pointer; text-align: left; }
.account-button:hover { background: #26332e; }
.account-button > span:nth-child(2) { display: grid; gap: 2px; }
.account-button small { color: #819087; font-size: 10px; }
.account-button > svg { width: 16px; color: #74847c; }
.avatar { width: 34px; height: 34px; display: grid; place-items: center; background: var(--lime); color: var(--ink); border-radius: 5px; font-weight: 800; }
.sidebar-scrim { display: none; }
.main-content { min-width: 0; grid-column: 2; }
.topbar { height: 88px; display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 0 clamp(20px, 3vw, 42px); background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(14px); }
.topbar-title { display: flex; align-items: center; gap: 13px; }
.topbar-title h1 { margin: 4px 0 0; font-size: 24px; line-height: 1; letter-spacing: 0; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.last-sync { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; margin-right: 7px; }
.last-sync svg { width: 15px; }
.icon-button { width: 40px; height: 40px; padding: 0; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.icon-button:hover { background: #f3f6f4; }
.icon-button svg { width: 18px; }
.icon-button.loading svg { animation: spin .8s linear infinite; }
.menu-button { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.content-wrap { padding: clamp(22px, 3vw, 38px); max-width: 1680px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; animation: page-in .22s ease; }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { min-height: 142px; padding: 19px 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); display: flex; flex-direction: column; }
.stat-card.dark { background: var(--ink); color: white; border-color: var(--ink); }
.stat-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 650; }
.stat-card.dark .stat-top { color: #a7b3ad; }
.stat-top svg { width: 19px; height: 19px; color: var(--green); }
.stat-card.dark .stat-top svg { color: var(--lime); }
.stat-card > strong { margin-top: auto; font-size: clamp(25px, 2vw, 34px); line-height: 1.15; font-weight: 650; }
.stat-card > small { color: var(--muted); margin-top: 6px; }
.stat-card.dark > small { color: #98a59f; }
.alert-card.has-alert { border-color: #e7bc82; background: #fffaf2; }
.alert-card.has-alert .stat-top svg { color: var(--amber); }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, .8fr); gap: 14px; margin-top: 14px; }
.panel { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.profit-panel, .attention-panel, .channel-snapshot { padding: 22px; }
.section-head { min-height: 43px; display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.section-head h2 { margin: 4px 0 0; font-size: 18px; letter-spacing: 0; }
.chart-legend { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 11px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 8px; height: 8px; display: block; border-radius: 2px; }
.legend-profit { background: var(--green); }
.legend-cost { background: #b9c3be; }
.chart-wrap { height: 244px; margin-top: 12px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.text-button { padding: 4px 0; border: 0; background: none; color: var(--green); display: flex; align-items: center; gap: 5px; cursor: pointer; font-weight: 750; font-size: 12px; }
.text-button svg { width: 15px; }
.attention-list { display: grid; gap: 3px; margin-top: 12px; }
.attention-item { min-height: 58px; display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid #edf0ee; }
.attention-item { width: 100%; border-top: 0; border-right: 0; border-left: 0; background: transparent; text-align: left; cursor: pointer; }
.attention-item:last-child { border: 0; }
.attention-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; background: var(--amber-soft); color: var(--amber); }
.attention-item.error .attention-icon { background: var(--red-soft); color: var(--red); }
.attention-icon svg { width: 17px; }
.attention-copy { display: grid; gap: 3px; min-width: 0; }
.attention-copy strong, .attention-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention-copy small { color: var(--muted); font-size: 11px; }
.attention-item > strong { font-size: 12px; color: var(--amber); }
.all-clear { min-height: 178px; display: grid; place-items: center; align-content: center; gap: 8px; color: var(--muted); text-align: center; }
.all-clear span { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--green); background: var(--green-soft); }
.all-clear strong { color: var(--ink); }
.channel-snapshot { margin-top: 14px; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 6px; background: #f5f7f5; }
.segmented button { min-height: 29px; padding: 0 11px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; cursor: pointer; font-size: 12px; font-weight: 650; }
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.channel-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); margin-top: 18px; }
.channel-card { min-width: 0; padding: 17px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; transition: background .15s; }
.channel-card:hover { background: #f8faf8; }
.channel-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.channel-identity { display: grid; grid-template-columns: 36px 1fr; align-items: center; gap: 10px; min-width: 0; }
.channel-logo { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; background: #edf2ef; color: var(--green); font-weight: 850; text-transform: uppercase; }
.channel-identity > span { display: grid; gap: 3px; min-width: 0; }
.channel-identity strong, .channel-identity small { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.channel-identity small { color: var(--muted); }
.status-pill { height: 25px; padding: 0 8px; display: inline-flex; align-items: center; gap: 5px; border-radius: 13px; background: var(--green-soft); color: var(--green); font-size: 10px; font-weight: 800; white-space: nowrap; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.low { background: var(--amber-soft); color: var(--amber); }
.status-pill.empty, .status-pill.error { background: var(--red-soft); color: var(--red); }
.status-pill.pending, .status-pill.disabled { background: #ecefed; color: #69736f; }
.status-pill.pricing { background: #fff5df; color: #a56718; }
.channel-balance { display: flex; justify-content: space-between; align-items: end; margin-top: 18px; }
.channel-balance > span { display: grid; gap: 3px; color: var(--muted); font-size: 11px; }
.channel-balance strong { color: var(--ink); font-size: 23px; }
.channel-balance > small { color: var(--muted); }
.usage-caption { display: flex; align-items: center; gap: 5px; margin-top: 10px; color: var(--muted); font-size: 10px; }
.usage-caption svg { color: var(--green); }
.pricing-warning { display: flex; align-items: center; gap: 5px; margin-top: 12px; color: #a56718; font-size: 10px; font-weight: 700; }
.pricing-warning svg { flex: 0 0 auto; }
.pricing-warning-inline { display: flex; align-items: center; gap: 4px; color: #a56718; font-size: 10px; font-style: normal; }
.progress { height: 5px; margin-top: 12px; background: #e8ece9; overflow: hidden; }
.progress i { height: 100%; display: block; background: var(--green); }
.progress.low i { background: #d28a2f; }
.progress.empty i, .progress.error i { background: var(--red); }

.table-panel { overflow: hidden; }
.table-toolbar { min-height: 70px; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); }
.search-box { width: min(360px, 100%); height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; background: #f8faf8; color: var(--muted); }
.search-box svg { width: 16px; }
.search-box input { min-width: 0; width: 100%; height: 100%; border: 0; outline: 0; background: transparent; box-shadow: none; }
.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 990px; }
.data-table th { height: 45px; padding: 0 15px; border-bottom: 1px solid var(--line); color: #78837e; background: #fafbfa; font-size: 10px; font-weight: 800; text-align: left; text-transform: uppercase; }
.data-table td { height: 72px; padding: 10px 15px; border-bottom: 1px solid #ecefed; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fafcfb; }
.table-identity { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.table-identity > span { display: grid; gap: 4px; }
.table-identity small { color: var(--muted); }
.balance-cell { display: grid; gap: 4px; }
.balance-cell strong { font-size: 16px; }
.balance-cell small { color: var(--muted); font-size: 10px; }
.water-cell { width: 120px; }
.water-cell small { color: var(--muted); font-size: 10px; }
.water-cell .progress { margin-top: 6px; width: 106px; }
.price-cell { display: grid; gap: 4px; }
.price-cell small { color: var(--muted); }
.usage-inline { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 10px; font-style: normal; }
.profit-cell { font-weight: 800; color: var(--green); }
.profit-cell.negative { color: var(--red); }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.row-actions button { width: 31px; height: 31px; display: grid; place-items: center; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; }
.row-actions button:hover { background: #eaf0ec; color: var(--ink); }
.row-actions svg { width: 16px; }
.empty-state { min-height: 320px; display: grid; place-items: center; align-content: center; gap: 10px; color: var(--muted); text-align: center; }
.empty-state > span { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 8px; background: #edf1ee; color: var(--green); }
.empty-state h3, .empty-state p { margin: 0; }
.empty-state p { font-size: 12px; }
.ledger-summary { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 8px; background: var(--paper); margin-bottom: 14px; }
.ledger-summary > div { padding: 19px 22px; display: grid; gap: 8px; border-right: 1px solid var(--line); }
.ledger-summary > div:last-child { border: 0; }
.ledger-summary span { color: var(--muted); font-size: 12px; }
.ledger-summary strong { font-size: 24px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.ledger-panel .section-head { padding: 20px 20px 16px; border-bottom: 1px solid var(--line); }
.data-caption { color: var(--muted); font-size: 11px; }
.event-pill { display: inline-flex; min-width: 48px; height: 24px; align-items: center; justify-content: center; border-radius: 12px; font-size: 10px; font-weight: 800; background: #edf1ee; color: var(--muted); }
.event-pill.usage { background: #e4efff; color: var(--blue); }
.event-pill.recharge { background: var(--green-soft); color: var(--green); }
.event-pill.error { background: var(--red-soft); color: var(--red); }

.downstream-page-head { margin-bottom: 14px; align-items: flex-end; }
.downstream-page-head h2 { margin: 4px 0 6px; font-size: 20px; }
.downstream-page-head .data-caption { margin: 0; line-height: 1.5; }
.downstream-summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.downstream-summary-card { min-height: 126px; padding: 17px 18px; display: flex; flex-direction: column; gap: 7px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.downstream-summary-card > span { color: var(--muted); font-size: 11px; font-weight: 700; }
.downstream-summary-card > strong { margin-top: auto; font-size: 22px; line-height: 1.2; font-weight: 700; }
.downstream-summary-card > small { color: var(--muted); font-size: 10px; }
.downstream-summary-card.added { border-top: 3px solid var(--green); }
.downstream-summary-card.unadded { border-top: 3px solid var(--amber); }
.downstream-groups { display: grid; gap: 14px; }
.downstream-group { overflow: hidden; }
.downstream-group-head { min-width: 0; padding: 19px 21px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); }
.downstream-group-head h3 { margin: 5px 0 4px; font-size: 17px; }
.downstream-group-head small { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.downstream-group-count { flex: 0 0 auto; padding: 6px 9px; border: 1px solid #c9dfd3; border-radius: 5px; background: var(--green-soft); color: var(--green-dark, #16563f); font-size: 11px; font-weight: 750; }
.downstream-items { display: grid; }
.downstream-item { border-bottom: 1px solid var(--line); }
.downstream-item:last-child { border-bottom: 0; }
.downstream-item summary { min-width: 0; min-height: 63px; padding: 12px 21px; display: flex; align-items: center; justify-content: space-between; gap: 14px; list-style: none; cursor: pointer; }
.downstream-item summary::-webkit-details-marker { display: none; }
.downstream-item summary:hover { background: #fafcfb; }
.downstream-channel-title { min-width: 0; display: grid; gap: 4px; }
.downstream-channel-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.downstream-channel-title small { color: var(--muted); font-size: 10px; }
.downstream-channel-meta { display: flex; align-items: center; justify-content: flex-end; gap: 12px; flex: 0 0 auto; color: var(--muted); font-size: 10px; }
.downstream-channel-meta svg { width: 16px; transition: transform .18s; }
.downstream-item[open] .downstream-channel-meta svg { transform: rotate(180deg); }
.downstream-detail { padding: 0 21px 20px; }
.downstream-channel-info { display: grid; grid-template-columns: minmax(0, 2fr) repeat(2, minmax(130px, 1fr)); gap: 1px; border: 1px solid var(--line); background: var(--line); }
.downstream-channel-info > span { min-width: 0; padding: 11px 13px; display: grid; gap: 5px; background: #fff; }
.downstream-channel-info b, .downstream-stat-grid span { color: var(--muted); font-size: 10px; font-weight: 650; }
.downstream-channel-info strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.downstream-stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-top: 12px; border: 1px solid var(--line); background: var(--line); }
.downstream-stat-grid > div { min-width: 0; padding: 12px 13px; display: grid; gap: 6px; background: #f8faf8; }
.downstream-stat-grid strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.downstream-model-table-wrap { margin-top: 12px; overflow-x: auto; border: 1px solid var(--line); }
.downstream-model-table { width: 100%; min-width: 680px; border-collapse: collapse; font-size: 11px; }
.downstream-model-table th { padding: 10px 12px; background: #f4f7f5; color: var(--muted); font-size: 10px; font-weight: 750; text-align: left; white-space: nowrap; }
.downstream-model-table td { padding: 11px 12px; border-top: 1px solid var(--line); vertical-align: top; }
.downstream-model-table td:first-child { min-width: 170px; }
.downstream-model-table td:first-child strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.downstream-model-table td small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; line-height: 1.4; }
.downstream-model-table td.missing { color: var(--amber); }
.downstream-source { color: var(--muted); }
.downstream-badge { display: inline-flex; min-width: 54px; justify-content: center; padding: 4px 7px; border-radius: 4px; font-size: 10px; font-weight: 750; }
.downstream-badge.added { background: var(--green-soft); color: var(--green); }
.downstream-badge.unadded { background: var(--amber-soft); color: var(--amber); }
.downstream-table-empty, .downstream-no-items { padding: 24px !important; color: var(--muted); text-align: center; }
.downstream-no-items { padding: 25px 21px; font-size: 11px; }

.settings-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-block { border-top: 3px solid var(--ink); padding: 24px; background: var(--paper); }
.account-info { min-height: 130px; margin-top: 24px; padding: 18px; display: flex; align-items: flex-start; gap: 13px; border: 1px solid var(--line); background: #f8faf8; }
.account-info-icon { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); }
.account-info-icon svg { width: 19px; }
.account-info strong { font-size: 13px; }
.account-info p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.settings-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 14px; margin-top: 24px; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 18px; }
.input-suffix, .input-prefix { height: 43px; display: flex; align-items: center; border: 1px solid #cfd6d2; border-radius: 6px; background: #fff; overflow: hidden; }
.input-suffix input, .input-prefix input { min-width: 0; flex: 1; height: 100%; border: 0; box-shadow: none !important; }
.input-suffix b, .input-prefix b { padding: 0 12px; color: var(--muted); font-size: 12px; }
.input-suffix b, .input-prefix b { white-space: nowrap; }
.input-suffix b { border-left: 1px solid var(--line); }
.input-prefix b { border-right: 1px solid var(--line); }
.formula-band { margin-top: 14px; padding: 19px 22px; display: flex; align-items: center; gap: 15px; background: #e8efe8; border-left: 3px solid var(--green); }
.formula-band > svg { flex: 0 0 auto; color: var(--green); }
.formula-band div { display: grid; gap: 4px; }
.formula-band p { margin: 0; color: var(--muted); line-height: 1.5; }

.modal { border: 0; padding: 0; background: transparent; width: min(960px, calc(100vw - 30px)); max-width: none; max-height: calc(100vh - 24px); overflow: visible; }
.modal::backdrop, .confirm-dialog::backdrop { background: rgba(10, 17, 14, .68); backdrop-filter: blur(3px); }
.modal-shell { margin: 0; width: 100%; max-height: calc(100vh - 24px); display: flex; flex-direction: column; border-radius: 8px; background: var(--paper); box-shadow: 0 24px 80px rgba(0,0,0,.28); overflow: hidden; }
.modal-head { min-height: 77px; padding: 17px 20px 15px 24px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 4px 0 0; font-size: 20px; }
.modal-body { overflow-y: auto; padding: 0 24px 24px; }
.form-section { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 22px; padding: 24px 0; border-bottom: 1px solid var(--line); }
.form-section:last-child { border: 0; }
.form-section-title { display: flex; gap: 10px; align-items: flex-start; }
.form-section-title > span { width: 26px; height: 26px; display: grid; place-items: center; border: 1px solid #b9c3be; border-radius: 50%; color: var(--green); font-size: 10px; font-weight: 800; }
.form-section-title div { display: grid; gap: 4px; }
.form-section-title small { color: var(--muted); font-size: 10px; }
.form-grid { display: grid; gap: 15px 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.model-config { min-width: 0; display: grid; gap: 14px; }
.balance-query-result { min-height: 44px; padding: 9px 12px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 6px; background: #f8faf8; color: var(--muted); font-size: 11px; }
.balance-query-result > svg { width: 17px; flex: 0 0 auto; color: #829089; }
.balance-query-result > span { min-width: 0; display: grid; gap: 2px; }
.balance-query-result strong { color: var(--ink); font-size: 12px; }
.balance-query-result small { color: var(--muted); }
.balance-query-result.success { border-color: #c6ddd1; background: var(--green-soft); }
.balance-query-result.success > svg { color: var(--green); }
.model-toolbar { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; gap: 8px; }
.model-toolbar .search-box { width: 100%; height: 41px; }
.model-picker-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.model-picker-head button { padding: 3px 0; border: 0; background: transparent; color: var(--green); cursor: pointer; font-weight: 750; }
.model-list { min-height: 126px; max-height: 240px; padding: 8px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: 5px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; background: #f8faf8; }
.model-option { min-width: 0; height: 36px; padding: 0 9px; display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 5px; background: #fff; cursor: pointer; }
.model-option:hover { border-color: #c8d9cf; }
.model-option input { position: absolute; opacity: 0; pointer-events: none; }
.model-option > i { width: 18px; height: 18px; display: grid; place-items: center; border: 1px solid #bfc8c3; border-radius: 4px; color: transparent; background: #fff; }
.model-option input:checked + i { border-color: var(--green); background: var(--green); color: #fff; }
.model-option span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.model-list-empty { grid-column: 1 / -1; min-height: 108px; display: grid; place-items: center; align-content: center; gap: 8px; color: var(--muted); font-size: 11px; }
.model-list-empty svg { width: 22px; color: #8d9993; }
.pricing-config { min-width: 0; display: grid; gap: 14px; }
.fixed-ratio-note { grid-column: 1 / -1; min-height: 42px; padding: 0 12px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 6px; background: #f2f7f3; color: var(--green-dark); }
.fixed-ratio-note svg { width: 17px; flex: 0 0 17px; }
.fixed-ratio-note span { display: grid; gap: 2px; }
.fixed-ratio-note strong { font-size: 11px; }
.fixed-ratio-note small { color: var(--muted); font-size: 10px; }
.pricing-preset-toolbar { min-width: 0; padding: 12px; display: grid; grid-template-columns: minmax(180px, 1fr) auto; align-items: end; gap: 10px; border: 1px solid var(--line); border-radius: 6px; background: #f8faf8; }
.pricing-preset-toolbar .field { gap: 5px; }
.pricing-preset-toolbar .field > span:first-child { font-size: 10px; }
.pricing-preset-toolbar select { height: 38px; }
.pricing-preset-actions { display: flex; align-items: center; gap: 7px; }
.pricing-preset-actions .icon-button.compact { width: 38px; height: 38px; flex: 0 0 38px; }
.model-pricing-list { max-height: 410px; display: grid; gap: 8px; overflow-y: auto; }
.pricing-empty { min-height: 92px; display: grid; place-items: center; padding: 16px; border: 1px dashed #cbd3cf; border-radius: 6px; color: var(--muted); background: #fafbfa; font-size: 11px; text-align: center; }
.model-pricing-row { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 6px; background: #f8faf8; }
.model-pricing-head { display: grid; grid-template-columns: minmax(0, 1fr) 180px; align-items: end; gap: 12px; }
.model-pricing-head > strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-bottom: 9px; font-size: 12px; }
.model-pricing-head label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; }
.model-pricing-head select { width: 100%; height: 36px; padding: 0 10px; border: 1px solid #cfd6d2; border-radius: 6px; background: #fff; color: var(--ink); }
.model-access-field { display: grid; gap: 5px; color: var(--muted); font-size: 10px; }
.model-access-field select { height: 36px; }
.model-pricing-head .model-access-field { grid-column: 1 / -1; }
.shared-price-note { grid-column: 1 / -1; color: var(--blue); font-size: 10px; }
.model-price-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--line); }
.model-price-fields .field { gap: 5px; }
.model-price-fields .field > span:first-child { font-size: 10px; }
.model-price-fields .input-suffix { height: 38px; }
.model-price-fields .input-suffix b { padding: 0 9px; font-size: 10px; }
.model-price-fields input[readonly] { color: #66756e; background: #eef2ef; cursor: not-allowed; }
.pricing-controls { display: grid; grid-template-columns: minmax(210px, .7fr) minmax(300px, 1.3fr); gap: 10px; }
.preset-modal { width: min(760px, calc(100vw - 30px)); }
.preset-modal-body { padding-top: 22px; display: grid; gap: 14px; }
.preset-rule-help { display: grid; gap: 4px; padding: 11px 13px; border-left: 3px solid var(--green); background: #f2f7f3; }
.preset-rule-help strong { font-size: 12px; }
.preset-rule-help small { color: var(--muted); font-size: 10px; line-height: 1.5; }
.preset-price-fields { display: grid; gap: 10px; padding-top: 2px; }
.preset-rule { min-width: 0; padding: 12px; display: grid; gap: 10px; border: 1px solid var(--line); border-radius: 6px; background: #f8faf8; }
.preset-rule-head { display: grid; grid-template-columns: minmax(0, 1fr) 155px auto; align-items: end; gap: 10px; }
.preset-rule-head .field { gap: 5px; }
.preset-rule-head .field > span:first-child, .preset-rule-prices .field > span:first-child { font-size: 10px; }
.preset-rule-head select { height: 38px; }
.preset-rule-title { display: flex; align-items: center; gap: 7px; min-height: 38px; padding-bottom: 1px; color: var(--muted); font-size: 10px; font-weight: 700; }
.preset-rule-title b { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 4px; background: #e4eee7; color: var(--green-dark); font-size: 10px; }
.preset-rule-actions { display: flex; gap: 5px; }
.preset-rule-actions .icon-button { width: 34px; height: 34px; }
.preset-rule-prices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.preset-rule-prices .field { gap: 5px; }
.preset-rule-prices .input-suffix { height: 38px; }
.preset-rule-prices .input-suffix b { padding: 0 8px; font-size: 10px; }
.preset-add-rule { justify-self: start; }
.switch-field { min-height: 59px; padding: 9px 11px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.switch-field > span { display: grid; gap: 3px; }
.switch-field small { color: var(--muted); font-size: 10px; }
.switch-field input { position: absolute; opacity: 0; pointer-events: none; }
.switch-field > i { width: 36px; height: 20px; padding: 2px; border-radius: 10px; background: #cbd2ce; transition: background .2s; }
.switch-field > i::after { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: white; transition: transform .2s; }
.switch-field input:checked + i { background: var(--green); }
.switch-field input:checked + i::after { transform: translateX(16px); }
.profit-preview { min-height: 70px; padding: 13px 16px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 16px; background: var(--ink); color: #fff; border-radius: 6px; }
.profit-preview span { color: #aab6b0; font-size: 11px; }
.profit-preview strong { grid-row: span 2; font-size: 24px; color: var(--lime); }
.profit-preview small { color: #82928a; }
.modal-foot { min-height: 71px; padding: 14px 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--line); background: #fafbfa; }
.modal-foot-right { display: flex; gap: 8px; }
.detail-modal { width: min(720px, calc(100vw - 30px)); }
.detail-content { padding: 24px; overflow-y: auto; }
.detail-hero { display: flex; align-items: center; gap: 14px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.detail-hero .channel-logo { width: 48px; height: 48px; font-size: 18px; }
.detail-hero > div { display: grid; gap: 5px; }
.detail-hero h3 { margin: 0; font-size: 20px; }
.detail-hero small { color: var(--muted); }
.detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 20px 0; border: 1px solid var(--line); }
.detail-stats > div { padding: 15px; display: grid; gap: 5px; border-right: 1px solid var(--line); }
.detail-stats > div:last-child { border: 0; }
.detail-stats span { color: var(--muted); font-size: 10px; }
.detail-stats strong { font-size: 17px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.detail-grid > div { padding: 13px 15px; display: grid; gap: 5px; background: #fff; min-width: 0; }
.detail-grid span { color: var(--muted); font-size: 10px; }
.detail-grid strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.detail-models { margin-top: 16px; display: grid; gap: 9px; }
.detail-models > span { color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.detail-models > div { max-height: 130px; display: flex; flex-wrap: wrap; gap: 6px; overflow-y: auto; }
.detail-models b { padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: #f7f9f7; font-size: 10px; font-weight: 650; }
.detail-model-prices { margin-top: 16px; display: grid; gap: 9px; }
.detail-model-prices > span { color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.detail-model-prices > div { max-height: 220px; display: grid; gap: 6px; overflow-y: auto; }
.detail-model-price { min-width: 0; padding: 10px 11px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; border: 1px solid var(--line); background: #f8faf8; }
.detail-model-price.accounting { border-left: 3px solid var(--green); background: var(--green-soft); }
.detail-model-price > span:first-child { min-width: 0; display: grid; gap: 3px; }
.detail-model-price > span:first-child strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.detail-model-price > span:first-child small { color: var(--muted); font-size: 9px; }
.detail-log-status { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; padding: 11px 13px; border: 1px solid var(--line); background: #f8faf8; color: var(--muted); font-size: 10px; }
.detail-log-status span { display: inline-flex; align-items: center; gap: 6px; }
.detail-log-status svg { color: var(--green); }
.detail-log-status strong { color: var(--ink); font-size: 10px; font-weight: 650; }
.formula-band.pricing-missing { background: #fff5df; border-left-color: #c4862f; }
.formula-band.pricing-missing > svg { color: #a56718; }
.detail-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.confirm-dialog { width: min(410px, calc(100vw - 30px)); border: 0; padding: 0; border-radius: 8px; box-shadow: var(--shadow); }
.confirm-dialog form { padding: 28px; text-align: center; }
.confirm-icon { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto; border-radius: 50%; background: var(--red-soft); color: var(--red); }
.confirm-dialog h2 { margin: 16px 0 7px; }
.confirm-dialog p { color: var(--muted); line-height: 1.6; }
.confirm-dialog form > div { display: flex; justify-content: center; gap: 8px; margin-top: 21px; }
.auth-dialog { width: min(440px, calc(100vw - 30px)); border: 0; padding: 0; border-radius: 8px; box-shadow: var(--shadow); }
.auth-dialog::backdrop { background: rgba(10, 17, 14, .68); backdrop-filter: blur(3px); }
.auth-dialog form { margin: 0; background: var(--paper); }
.auth-body { display: grid; gap: 16px; padding: 21px 24px 24px; }
.auth-caption { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.auth-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); background: #fafbfa; }
.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 100; display: grid; gap: 9px; }
.toast { min-width: 280px; max-width: 420px; min-height: 48px; padding: 11px 13px; display: grid; grid-template-columns: 22px 1fr; align-items: center; gap: 9px; border: 1px solid #cbd8d0; border-left: 4px solid var(--green); border-radius: 6px; background: #fff; box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { border-left-color: var(--red); }
.toast svg { width: 18px; color: var(--green); }
.toast.error svg { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 1180px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .channel-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .downstream-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-layout { grid-template-columns: 1fr; }
}

@media (max-width: 920px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-panel { min-height: 100vh; }
  .login-visual { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 15; width: 100%; height: 100%; border: 0; background: rgba(10,17,14,.55); }
  .sidebar.open + .sidebar-scrim { display: block; }
  .main-content { grid-column: 1; }
  .menu-button { display: inline-grid; }
  .overview-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 20px; }
  .last-sync { display: none; }
}

@media (max-width: 680px) {
  .login-panel { padding: 30px 22px; }
  .login-heading { margin-bottom: 34px; }
  .login-heading h1 { font-size: 38px; }
  .topbar { height: 76px; }
  .topbar-title h1 { font-size: 19px; }
  .topbar-title .eyebrow { display: none; }
  .topbar-actions .button span { display: none; }
  .topbar-actions .button { width: 40px; padding: 0; }
  .content-wrap { padding: 14px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .stat-card { min-height: 123px; padding: 15px; }
  .stat-card > strong { font-size: 23px; }
  .profit-panel, .attention-panel, .channel-snapshot { padding: 17px; }
  .chart-wrap { height: 210px; }
  .channel-cards { grid-template-columns: 1fr; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .segmented { max-width: 100%; overflow-x: auto; }
  .ledger-summary { grid-template-columns: 1fr; }
  .ledger-summary > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .settings-block { padding: 19px; }
  .account-info { margin-top: 19px; padding: 15px; }
  .settings-form { grid-template-columns: 1fr; }
  .downstream-page-head { align-items: stretch; flex-direction: column; }
  .downstream-summary-grid { grid-template-columns: 1fr; }
  .downstream-group-head, .downstream-item summary { padding-left: 15px; padding-right: 15px; }
  .downstream-channel-meta > span:not(.status-pill) { display: none; }
  .downstream-detail { padding-left: 15px; padding-right: 15px; }
  .downstream-channel-info, .downstream-stat-grid { grid-template-columns: 1fr 1fr; }
  .downstream-channel-info > span:first-child { grid-column: 1 / -1; }
  .form-section { grid-template-columns: 1fr; gap: 15px; }
  .model-config, .profit-preview { grid-column: 1; }
  .model-toolbar { grid-template-columns: 1fr 1fr; }
  .model-toolbar .search-box { grid-column: 1 / -1; }
  .model-list { grid-template-columns: 1fr; }
  .model-pricing-head { grid-template-columns: 1fr; align-items: stretch; }
  .model-pricing-head > strong { padding-bottom: 0; }
  .model-pricing-list { max-height: none; overflow: visible; }
  .model-price-fields, .pricing-controls, .pricing-preset-toolbar, .preset-rule-head, .preset-rule-prices { grid-template-columns: 1fr; }
  .pricing-preset-actions { flex-wrap: wrap; }
  .pricing-preset-actions .button { flex: 1 1 190px; }
  .preset-rule-actions { justify-content: flex-end; }
  .form-grid.two, .form-grid.four { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: 1; }
  .modal-body { padding: 0 17px 18px; }
  .modal-head, .modal-foot { padding-left: 17px; padding-right: 17px; }
  .modal-foot { align-items: stretch; flex-direction: column; }
  .modal-foot .button { flex: 1; }
  .modal-foot-right { display: flex; }
  .detail-stats { grid-template-columns: 1fr; }
  .detail-stats > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-model-price { grid-template-columns: 1fr; }
  .toast-region { right: 12px; left: 12px; bottom: 12px; }
  .toast { min-width: 0; }
  .auth-body { padding-left: 17px; padding-right: 17px; }
  .auth-foot { padding-left: 17px; padding-right: 17px; }
}

@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { min-height: 112px; }
  .chart-legend { display: none; }
}
