* { box-sizing: border-box; }
body.rp { margin: 0; background: var(--rp-white); }
h1, h2, h3 { font-family: var(--rp-font-heading); font-weight: 700; margin: 0 0 .4em; }
h2 { font-size: 1.6rem; line-height: 1.05; }
h3 { font-size: 1.15rem; line-height: 1.1; }
.muted { color: var(--rp-grey-700); }
.small { font-size: .85rem; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 24px; padding: 14px 24px; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; }
.brand .rp-eyebrow { color: var(--rp-bg-red); font-size: .68rem; }
.brand .title { font-family: var(--rp-font-heading); font-weight: 700; font-size: 1.5rem; line-height: 1; color: #fff; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { font-family: var(--rp-font-body); font-weight: 700; background: transparent; color: #fff;
  border: 2px solid transparent; border-radius: var(--rp-radius-button); padding: .5em 1.2em; cursor: pointer;
  letter-spacing: .05em; }
.tabs button:hover { border-color: #fff; }
.tabs button.active { background: #fff; color: var(--rp-charcoal); }
.logout { margin-left: auto; color: var(--rp-grey-300); font-size: .9rem; }

/* Controls */
.controls { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; padding: 14px 24px;
  border-bottom: 1px solid var(--rp-grey-300); position: sticky; top: 0; z-index: 5; }
.controls label { display: flex; flex-direction: column; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: var(--rp-tracking-eyebrow); color: var(--rp-grey-700); gap: 4px; }
.controls .rp-input { font-size: .95rem; min-width: 150px; text-transform: none; letter-spacing: 0; }
.controls .rp-btn { padding: .6em 1.3em; }
.banner { background: var(--rp-pale-cyan); padding: 10px 24px; font-size: .92rem; }

main { padding: 24px; max-width: 1500px; margin: 0 auto; }
.loading { padding: 60px; text-align: center; color: var(--rp-grey-700); }
.loading::after { content: ""; display: block; width: 32px; height: 32px; margin: 16px auto 0;
  border: 4px solid var(--rp-beige); border-top-color: var(--rp-bg-red); border-radius: 50%;
  animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .meta { color: var(--rp-grey-700); }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em;
  padding: 3px 8px; background: var(--rp-beige); color: var(--rp-charcoal); margin-right: 6px; }
.pill.meta { background: var(--rp-beige); }
.pill.google { background: var(--rp-pale-cyan); }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.tile { border: 1px solid var(--rp-grey-300); padding: 14px 16px; background: #fff; }
.tile .lbl { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: var(--rp-tracking-eyebrow); color: var(--rp-grey-700); }
.tile .val { font-family: var(--rp-font-heading); font-weight: 700; font-size: 1.75rem; line-height: 1.1; margin: 4px 0; }
.tile .sub { font-size: .82rem; color: var(--rp-grey-700); }
.tile.red { border-left: 6px solid var(--rp-danger); }
.tile.amber { border-left: 6px solid var(--rp-warning); }
.delta { font-weight: 700; font-size: .82rem; }
.delta.good { color: #3f8a0f; }
.delta.bad { color: var(--rp-danger); }
.delta.flat { color: var(--rp-grey-500); }

/* Flags */
.flag-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 26px; }
@media (max-width: 1000px) { .flag-cols { grid-template-columns: 1fr; } }
.flag-col { border: 1px solid var(--rp-grey-300); background: #fff; }
.flag-col > h3 { padding: 12px 14px; margin: 0; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--rp-grey-300); }
.flag-col.urgent > h3 { border-top: 5px solid var(--rp-danger); }
.flag-col.medium > h3 { border-top: 5px solid var(--rp-warning); }
.flag-col.opt > h3 { border-top: 5px solid var(--rp-success); }
.flag-col .count { font-family: var(--rp-font-body); font-size: .9rem; background: var(--rp-charcoal); color: #fff; padding: 2px 9px; }
.flag-list { max-height: 520px; overflow: auto; }
.flag { padding: 10px 14px; border-bottom: 1px solid var(--rp-grey-100); }
.flag:last-child { border-bottom: 0; }
.flag .t { font-weight: 700; }
.flag .d { font-size: .86rem; color: var(--rp-grey-700); margin-top: 2px; }
.flag .c { font-size: .78rem; font-weight: 700; color: var(--rp-bg-red); cursor: pointer; text-transform: uppercase; letter-spacing: .1em; }
.empty { padding: 14px; color: var(--rp-grey-500); font-size: .9rem; }

/* Tables */
.tbl-wrap { overflow-x: auto; margin-bottom: 26px; border: 1px solid var(--rp-grey-300); }
.rp-table { font-size: .92rem; }
.rp-table th { white-space: nowrap; font-size: .8rem; }
.rp-table td.num, .rp-table th.num { text-align: right; white-space: nowrap; }
.rp-table tbody tr.click { cursor: pointer; }
.rp-table tbody tr.click:hover { background: var(--rp-pale-cyan); }
.badges span { display: inline-block; min-width: 24px; text-align: center; font-weight: 700; font-size: .8rem; padding: 2px 6px; margin-right: 3px; }
.b-urgent { background: var(--rp-danger); color: #fff; }
.b-medium { background: var(--rp-warning); color: var(--rp-charcoal); }
.b-opt { background: var(--rp-success); color: #fff; }
.b-zero { background: var(--rp-grey-100); color: var(--rp-grey-500); }
.err { color: var(--rp-danger); font-size: .85rem; }

/* Chart + split */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 26px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }
.panel { border: 1px solid var(--rp-grey-300); padding: 16px; background: #fff; }
.chart-box { position: relative; height: 300px; }

/* Settings */
.settings-section { margin-bottom: 34px; }
.settings-section .rp-input { padding: .4em .5em; font-size: .9rem; width: 100%; min-width: 80px; }
.settings-section td { vertical-align: middle; }
.settings-section .rp-btn { padding: .45em 1em; font-size: .85rem; }
.row-actions { display: flex; gap: 6px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin: 10px 0; }
.inline-form .rp-input { width: auto; }
.saved { color: #3f8a0f; font-weight: 700; font-size: .85rem; }

/* Login */
body.rp.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--rp-charcoal); padding: 16px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login-card label { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: var(--rp-tracking-eyebrow); }
.login-err { color: var(--rp-danger); margin: 0; }

@media (max-width: 640px) {
  .topbar, .controls { padding: 12px 16px; }
  main { padding: 16px; }
  .controls .rp-input { min-width: 0; width: 100%; }
  .controls label { flex: 1 1 45%; }
}
