:root {
  --bg: #0b0f14;
  --card: #141b24;
  --card2: #1a2330;
  --text: #eef3f8;
  --muted: #8fa0b3;
  --accent: #ffcc00;
  --accent2: #4da3ff;
  --good: #3ecf8e;
  --warn: #ffb020;
  --bad: #ff6b6b;
  --line: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

body {
  padding: 0 0 calc(72px + env(safe-area-inset-bottom));
}

a { color: var(--accent2); text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
  background: rgba(11, 15, 20, 0.85);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.topbar .sub {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.actions {
  display: flex;
  gap: 8px;
}

button, .btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card2);
  color: var(--text);
}

button.primary {
  background: linear-gradient(135deg, #ffcc00, #e6a800);
  color: #111;
}

button:active { transform: scale(0.98); }

.container {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

.section {
  margin-bottom: 20px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  font-size: 0.92rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.balance-card {
  background: linear-gradient(145deg, #1a2330, #101820);
}

.balance-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.balance-value .cur {
  font-size: 1rem;
  color: var(--muted);
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.direct-cost-row .metric-highlight {
  background: rgba(255, 204, 0, 0.1);
  border: 1px solid rgba(255, 204, 0, 0.22);
}

.direct-cost-row .metric-highlight .val {
  color: var(--accent);
}

.metric {
  background: var(--card2);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.metric .val {
  font-size: 1.1rem;
  font-weight: 700;
}

.metric .lbl {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
}

.delta-row {
  min-height: 1.35rem;
  margin-top: 4px;
}

.delta-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  border-radius: 999px;
  padding: 3px 9px;
  line-height: 1.2;
}

.delta-arrow {
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
}

.delta-chip.up {
  color: #2ecc71 !important;
  background: rgba(62, 207, 142, 0.22) !important;
  border: 1px solid rgba(62, 207, 142, 0.45) !important;
}

.delta-chip.down {
  color: #ff5252 !important;
  background: rgba(255, 82, 82, 0.18) !important;
  border: 1px solid rgba(255, 82, 82, 0.45) !important;
}

.delta-chip.up .delta-arrow,
.delta-chip.down .delta-arrow {
  color: inherit !important;
}

.delta-chip.neutral {
  color: var(--muted);
  font-weight: 500;
  background: rgba(255, 255, 255, 0.04);
  padding: 3px 8px;
}

.id-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent2);
  background: rgba(77, 163, 255, 0.12);
  border-radius: 8px;
  padding: 2px 7px;
  margin-left: 4px;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

.counter-site .id-badge {
  margin-left: 0;
}

.goal-chip .delta {
  margin-left: 4px;
  font-size: 0.68rem;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(77, 163, 255, 0.15);
  color: var(--accent2);
  white-space: nowrap;
}

.pill.on {
  background: rgba(62, 207, 142, 0.22);
  color: var(--good);
  border-color: rgba(62, 207, 142, 0.45);
}

.pill.off {
  background: rgba(255, 107, 107, 0.18);
  color: var(--bad);
  border-color: rgba(255, 107, 107, 0.45);
}

.pill.warn {
  background: rgba(255, 176, 32, 0.22);
  color: var(--warn);
  border-color: rgba(255, 176, 32, 0.45);
}

.pill.manual {
  background: rgba(255, 176, 32, 0.15);
  color: var(--warn);
}

.card-has-issue {
  border-color: rgba(255, 176, 32, 0.45);
  box-shadow: 0 0 0 1px rgba(255, 176, 32, 0.15), var(--shadow);
}

.api-notice {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 176, 32, 0.1);
  border: 1px solid rgba(255, 176, 32, 0.28);
  color: var(--warn);
  font-size: 0.78rem;
  line-height: 1.35;
}

.health-banner {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 176, 32, 0.1);
  border: 1px solid rgba(255, 176, 32, 0.35);
  font-size: 0.8rem;
  color: var(--warn);
}

.health-banner ul {
  margin: 0;
  padding-left: 1.1rem;
}

.health-banner li {
  margin: 4px 0;
  line-height: 1.35;
  color: var(--text);
}

.status-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.sub-status {
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: right;
  max-width: 9rem;
}

.sub-status.warn { color: var(--warn); }

.status-line {
  margin: 8px 0 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-line.warn { color: var(--warn); }
.status-line.bad { color: var(--bad); }

.group-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.group-chip {
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 176, 32, 0.12);
  color: var(--warn);
  line-height: 1.3;
}

.campaign-name {
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.3;
}

.counter-site {
  color: var(--muted);
  font-size: 0.82rem;
}

.goals {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.goal-chip {
  background: rgba(255, 204, 0, 0.12);
  color: var(--accent);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.78rem;
}

.loading, .error-box, .login-box {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.error-box { color: var(--bad); }

.login-box {
  max-width: 360px;
  margin: 12vh auto;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 28px 20px;
}

.login-box h2 {
  margin: 0 0 8px;
  color: var(--text);
}

.login-box input {
  width: 100%;
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--text);
  font-size: 1rem;
}

.login-box .btn { width: 100%; }

.stale-banner {
  background: rgba(255, 176, 32, 0.12);
  color: var(--warn);
  border: 1px solid rgba(255, 176, 32, 0.25);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

.hidden { display: none !important; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(11, 15, 20, 0.95);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
}

.nav-btn .nav-icon { font-size: 1.1rem; line-height: 1; }

.nav-btn.active {
  color: var(--accent);
  background: rgba(255, 204, 0, 0.1);
}

.bids-hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(77, 163, 255, 0.08);
  border: 1px solid rgba(77, 163, 255, 0.2);
}

.bid-card { margin-bottom: 10px; }

.bid-card .bid-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.bid-head-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.bid-status-note {
  margin: -4px 0 10px;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--muted);
}

.bid-status-note.warn,
.bid-status-note.bad {
  color: var(--warn);
}

.bid-status-note.bad {
  color: var(--bad);
}

.bid-kind {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
}

.bid-kind.cpa { background: rgba(77, 163, 255, 0.18); color: var(--accent2); }
.bid-kind.bids { background: rgba(62, 207, 142, 0.15); color: var(--good); }
.bid-kind.frozen { background: rgba(143, 160, 179, 0.15); color: var(--muted); }

.strategy-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.strategy-toggle button {
  padding: 12px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.strategy-toggle button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 204, 0, 0.12);
}

.bid-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.bid-field label {
  color: var(--muted);
  font-size: 0.85rem;
}

.bid-field input {
  width: 88px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--text);
  font-size: 1rem;
  text-align: right;
}

.bid-markup-hint {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.3;
  margin-bottom: 8px;
}

.bid-save {
  width: 100%;
  margin-top: 8px;
  background: linear-gradient(135deg, #ffcc00, #e6a800);
  color: #111;
}

.bid-save:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.bid-frozen-note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.bid-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 30;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--card2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: fadeIn 0.2s ease;
}

.bid-toast.ok { border-color: rgba(62, 207, 142, 0.45); color: var(--good); }
.bid-toast.err { border-color: rgba(255, 107, 107, 0.45); color: var(--bad); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 640px) {
  .balance-value { font-size: 2.4rem; }
}
