:root { --graphite: var(--ink); --sheet: var(--card); --ink-tint: var(--blue-tint); --rule: var(--line); --highlight: var(--gold); }
.staff .logo { color: var(--ink); }
body.staff { background: var(--paper); font-size: 15px; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 6px; padding: 32px; width: min(400px, 100%); }
.login-card h1 { font-size: 1.6rem; margin: 20px 0; }

.admin-top { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--sheet); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.admin-top .logo { font-size: 1.05rem; }
.admin-top .logo-mark { height: 34px; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button, .filters button { font: 600 .92rem var(--body); background: none; border: 1.5px solid transparent; border-radius: 999px; padding: .45em .95em; cursor: pointer; color: var(--graphite); white-space: nowrap; }
.tabs button[aria-selected=true], .filters button[aria-pressed=true] { border-color: var(--graphite); background: var(--sheet); }
.count { background: var(--highlight); border-radius: 999px; padding: 0 7px; font-size: .78rem; margin-left: 4px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding: 16px 20px 0; }
.stat { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; padding: 12px 16px; }
.stat b { display: block; font: 800 1.5rem var(--display); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
@media (max-width: 700px) { .stats { grid-template-columns: 1fr 1fr; } }

.tab { padding: 16px 20px 40px; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between; margin-bottom: 12px; }
.filters { display: flex; gap: 4px; flex-wrap: wrap; }
.toolbar input { max-width: 320px; min-height: 40px; }

.split { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.list { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; max-height: calc(100dvh - 230px); overflow-y: auto; }
.list button { display: grid; gap: 2px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px dashed var(--rule); padding: 12px 14px; cursor: pointer; font: inherit; color: inherit; }
.list button:hover { background: #fbfdf9; }
.list button[aria-current=true] { background: var(--ink-tint); }
.list .row1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.list .row2 { color: var(--muted); font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .unread { background: var(--highlight); border-radius: 999px; padding: 0 7px; font-size: .78rem; }
.empty { color: var(--muted); padding: 24px; }

.detail { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; padding: 20px; min-width: 0; }
.detail h2 { font-size: 1.35rem; margin-bottom: 4px; }
.detail h3 { font-size: 1rem; margin: 22px 0 8px; padding-top: 14px; border-top: 1px solid var(--rule); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; }
@media (max-width: 1200px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: .92rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions select, .actions input { width: auto; min-height: 40px; }
.actions .btn { padding: .55em .9em; font-size: .9rem; }
.thread { background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.thread .msg-customer { align-self: flex-start; background: var(--sheet); color: var(--graphite); border: 1px solid var(--rule); border-radius: 14px 14px 14px 4px; }
.thread .msg-agent { align-self: flex-end; background: var(--graphite); color: #fff; border: 0; border-radius: 14px 14px 4px 14px; }
.reply { display: grid; gap: 8px; margin-top: 10px; }
.reply textarea { min-height: 80px; }
.events { font-size: .85rem; color: var(--muted); list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--graphite); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; }

.table-wrap { overflow-x: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.grid { border-collapse: collapse; width: 100%; font-size: .92rem; }
.grid th, .grid td { padding: 10px 12px; border-bottom: 1px dashed var(--rule); text-align: left; white-space: nowrap; }
.grid th { color: var(--ink); font-size: .82rem; }
.promo-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.promo-form .field { margin: 0; }

/* ---------- Team dashboard additions ---------- */
body.staff { background: var(--paper); font-size: 15px; }
.staff .logo { color: var(--ink); }
.login-card form[hidden] { display: none; }
.login-card h1 { margin: 18px 0 4px; }
.login-alt { margin: 14px 0 0; }
.code-input { font: 700 1.5rem var(--display); letter-spacing: .4em; text-align: center; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue-deep); text-decoration: underline; cursor: pointer; font: inherit; }
.who { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.role-badge { font: 700 .72rem var(--display); text-transform: uppercase; letter-spacing: .06em; padding: 3px 9px; border-radius: 999px; background: var(--ink); color: #fff; }
.role-badge.r-admin { background: #b42318; }
.role-badge.r-editor { background: var(--blue-deep); }
.role-badge.r-writer { background: #0e6b40; }
.banner { margin: 12px 20px 0; padding: 12px 16px; border-radius: 10px; background: #fff4c2; color: #6b5300; font-size: .92rem; }
.banner code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }
#view > section { padding: 16px 20px 48px; }
.overview-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.ov-card { background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 16px; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.ov-card:hover { border-color: var(--ink); }
.ov-card b { display: block; font: 800 1.7rem var(--display); }
.ov-card span { color: var(--muted); font-size: .86rem; }
.ov-card.alert b { color: #b42318; }
.guide { background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 16px 20px; max-width: 820px; }
.guide h2 { font-size: 1.1rem; }
.guide ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.list .tag { font-size: .74rem; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.tag-unpaid { background: #fff4c2; color: #6b5300; }
.tag-paid { background: #dcf7e9; color: #0e6b40; }
.tag-review { background: #fde2e1; color: #b42318; }
.tag-proposal { background: var(--blue-tint); color: var(--blue-deep); }
.pill-in_progress, .pill-in_review { background: var(--blue-tint); color: var(--blue-deep); }
.card-block { border: 1px solid var(--rule); border-radius: 10px; padding: 14px 16px; margin-top: 14px; background: #fcfdff; }
.card-block h3 { margin-top: 0 !important; padding-top: 0 !important; border-top: 0 !important; }
.files-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.files-table td { padding: 8px 6px; border-bottom: 1px dashed var(--rule); vertical-align: top; }
.review-st { font-size: .75rem; font-weight: 700; border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.rs-pending { background: #fde2e1; color: #b42318; }
.rs-approved { background: #dcf7e9; color: #0e6b40; }
.rs-rejected { background: #eee; color: #555; }
.rs-internal { background: var(--blue-tint); color: var(--blue-deep); }
.thread .msg-system { align-self: center; background: var(--gold-tint); color: #6b5300; font-size: .82rem; border-radius: 10px; }
.thread .msg-internal { align-self: stretch; background: #fff8dd; color: #4a3b00; border: 1px dashed #e0b500; border-radius: 10px; }
.thread .msg-agent.mine { background: var(--blue-deep); }
.thread .msg-author { display: block; font: 600 .74rem var(--display); opacity: .85; margin-bottom: 3px; color: inherit; }
.thread time { display: block; font-size: .72rem; opacity: .7; margin-top: 4px; }
.reply-opts { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: .9rem; }
.reply-opts label { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.approval { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; }
.approval p { margin: 0; }
.team-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.team-form .field { margin: 0; }
.redacted { color: var(--muted); font-style: italic; }
.hint-box { font-size: .86rem; color: var(--muted); background: var(--paper); border-radius: 8px; padding: 8px 12px; margin: 8px 0 0; }
.card-block .lines td:first-child, .card-block .lines th { text-align: left; }
.card-block .lines { width: 100%; }

/* ---------- Revenue (admin) ---------- */
.rev-custom { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .88rem; }
.rev-custom label { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.rev-custom input { width: auto; min-height: 38px; }
.rev-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.rev-tile { background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 14px 16px; display: grid; gap: 2px; }
.rev-tile span { color: var(--muted); font-size: .84rem; }
.rev-tile b { font: 800 1.55rem var(--display); color: var(--ink); font-variant-numeric: tabular-nums; }
.rev-tile small { color: var(--muted); font-size: .8rem; }
.rev-hero { border-color: var(--ink); }
.rev-hero b { font-size: 2rem; }
.rev-panel { background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; min-width: 0; }
.rev-panel h2 { font-size: 1.1rem; margin: 0 0 4px; }
.rev-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.rev-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .rev-split { grid-template-columns: minmax(0, 1fr); } }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid tr.refunded td { color: var(--muted); text-decoration: line-through; }
.share-bar { display: inline-block; width: 60px; height: 6px; background: var(--paper); border-radius: 3px; margin-right: 8px; vertical-align: middle; overflow: hidden; }
.share-bar span { display: block; height: 100%; background: #3b6ff5; border-radius: 3px; }

.rev-chart { margin: 12px 0 0; }
.rev-plot { position: relative; height: 260px; padding: 0 0 26px 64px; }
.rev-grid { position: absolute; inset: 0 0 26px 64px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.rev-grid div { border-top: 1px solid #e8ebf2; position: relative; height: 0; }
.rev-grid div:last-child { border-top-color: #b9c0d0; }
.rev-grid span { position: absolute; right: calc(100% + 8px); top: -8px; font-size: .74rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rev-bars { position: relative; height: 100%; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 2px; align-items: end; }
.rev-col { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; cursor: default; }
.rev-col:hover, .rev-col:focus-visible { background: rgba(59, 111, 245, .06); border-radius: 4px; }
.rev-bar { width: min(36px, 70%); background: #3b6ff5; border-radius: 4px 4px 0 0; min-height: 0; }
.rev-x { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: .72rem; color: var(--muted); white-space: nowrap; }
.rev-tip { display: none; position: absolute; bottom: calc(100% - 8px); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 10px; border-radius: 8px; font-size: .84rem; white-space: nowrap; z-index: 3; box-shadow: var(--shadow-lg); text-align: center; }
.rev-tip strong { display: block; font-size: .76rem; opacity: .8; }
.rev-tip span { display: block; font-size: .76rem; opacity: .8; }
.rev-col:hover .rev-tip, .rev-col:focus-visible .rev-tip { display: block; }
.rev-table { margin-top: 10px; font-size: .9rem; }
.rev-table summary { cursor: pointer; color: var(--blue-deep); }
@media (max-width: 640px) { .rev-x { font-size: .62rem; transform: translateX(-50%) rotate(-45deg); transform-origin: top; } .rev-plot { padding-left: 52px; } .rev-grid { left: 52px; } }

/* ---------- Clients (admin) ---------- */
.list-count { margin: 0; padding: 10px 14px; font-size: .8rem; color: var(--muted); border-bottom: 1px dashed var(--rule); }
.client-tiles { margin: 12px 0 4px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .client-tiles { grid-template-columns: minmax(0, 1fr); } }
#clientDetail .grid td, #clientDetail .grid th { white-space: normal; }
#clientDetail .grid td.num { white-space: nowrap; }
