/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:         #0f0f0f;
  --bg2:        #161616;
  --bg3:        #1e1e1e;
  --bg4:        #242424;
  --border:     rgba(255,255,255,0.07);
  --border2:    rgba(255,255,255,0.12);
  --text:       #f0f0ef;
  --text2:      #a0a09a;
  --text3:      #606060;
  --blue:       #4a90e2;
  --blue-bg:    rgba(74,144,226,0.12);
  --blue-text:  #7eb8f7;
  --green:      #4caf82;
  --green-bg:   rgba(76,175,130,0.12);
  --green-text: #6fd4a0;
  --red:        #e25555;
  --red-bg:     rgba(226,85,85,0.12);
  --red-text:   #f08080;
  --amber:      #e2a24a;
  --amber-bg:   rgba(226,162,74,0.12);
  --amber-text: #f0c070;
  --sidebar-w:  220px;
  --topbar-h:   56px;
  --radius:     10px;
  --radius-sm:  6px;
}

html, body { height: 100%; font-family: 'Inter', -apple-system, sans-serif; font-size: 14px; background: var(--bg); color: var(--text); line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen { display: none; height: 100vh; }
.screen.active { display: flex; }

/* ── Login ───────────────────────────────────────────────────────────────── */
#screen-login { align-items: center; justify-content: center; background: var(--bg); }
.login-wrap { width: 100%; max-width: 420px; padding: 20px; }
.login-card { background: var(--bg2); border: 1px solid var(--border2); border-radius: 16px; padding: 40px 36px; text-align: center; }
.login-logo { font-size: 32px; font-weight: 700; color: var(--text); letter-spacing: -1px; margin-bottom: 8px; }
.login-logo span { color: var(--blue); }
.login-tagline { font-size: 13px; color: var(--text2); margin-bottom: 32px; line-height: 1.6; }
.login-tagline span { color: var(--text3); font-size: 12px; }
.login-error { display: none; background: var(--red-bg); border: 1px solid var(--red); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; color: var(--red-text); margin-bottom: 16px; text-align: left; }
.login-google-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 12px; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius); color: var(--text); font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.login-google-btn:hover { background: var(--bg4); border-color: var(--border2); }
.login-note { font-size: 11px; color: var(--text3); margin-top: 20px; line-height: 1.6; }

/* ── ACCOUNTS OVERVIEW SCREEN ────────────────────────────────────────────── */
#screen-accounts { flex-direction: column; background: var(--bg); }
.accounts-shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.accounts-topbar { display: flex; align-items: center; justify-content: space-between; padding: 0 28px; height: 56px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.accounts-logo { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
.accounts-logo span { color: var(--blue); }
.accounts-topbar-right { display: flex; align-items: center; gap: 10px; }

.accounts-content { flex: 1; overflow-y: auto; padding: 28px; }

.accounts-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.accounts-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 4px; }
.accounts-header p { font-size: 13px; color: var(--text2); }
.accounts-header-right { display: flex; align-items: center; gap: 10px; }

/* KPI summary row */
.accounts-kpi-row { display: grid; grid-template-columns: repeat(10, 1fr); gap: 10px; margin-bottom: 20px; }
.accounts-kpi-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.accounts-kpi-card.skeleton { height: 70px; animation: pulse 1.5s ease-in-out infinite; }
.accounts-kpi-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin-bottom: 6px; }
.accounts-kpi-value { font-size: 22px; font-weight: 700; color: var(--text); }
.accounts-kpi-sub { font-size: 11px; color: var(--text3); margin-top: 3px; }

/* Accounts table */
.accounts-table tbody tr.account-row { cursor: pointer; transition: background 0.1s; }
.accounts-table tbody tr.account-row:hover td { background: var(--bg3); }
.acct-name-cell { min-width: 200px; }
.acct-name-cell strong { display: block; font-weight: 600; }
.acct-id { font-size: 11px; color: var(--text3); margin-top: 2px; }
.loading-cell { color: var(--text3); font-style: italic; font-size: 12px; }
.metric-loading { color: var(--text3); font-size: 12px; }

/* ── Dashboard shell ─────────────────────────────────────────────────────── */
#screen-dashboard { flex-direction: row; background: var(--bg); }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar { width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; height: 100vh; position: sticky; top: 0; overflow-y: auto; }
.sidebar-logo { font-size: 18px; font-weight: 700; color: var(--text); padding: 20px 18px 16px; letter-spacing: -0.5px; }
.sidebar-logo span { color: var(--blue); }
.sidebar-nav { flex: 1; padding: 0 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: none; background: transparent; color: var(--text2); font-size: 13px; font-weight: 500; cursor: pointer; text-align: left; position: relative; transition: background 0.12s, color 0.12s; margin-bottom: 2px; }
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--blue-bg); color: var(--blue-text); }
.nav-item svg { flex-shrink: 0; }
.nav-badge { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: var(--red); color: white; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 20px; min-width: 18px; text-align: center; }
.nav-badge:empty { display: none; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }
.sidebar-account { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 6px; }
.sidebar-account-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.sidebar-account-name { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.sidebar-account-user { font-size: 11px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.sidebar-back-btn { width: 100%; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--blue); background: var(--blue-bg); color: var(--blue-text); font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.12s; margin-bottom: 6px; text-align: left; }
.sidebar-back-btn:hover { background: var(--blue); color: white; }
.sidebar-logout { width: 100%; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: transparent; color: var(--text2); font-size: 12px; cursor: pointer; transition: background 0.12s; }
.sidebar-logout:hover { background: var(--bg3); color: var(--text); }

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar { height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; gap: 16px; }
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--text); }
.topbar-live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.topbar-live-txt { font-size: 11px; color: var(--green-text); font-weight: 600; }
.sidebar-toggle { background: transparent; border: none; color: var(--text2); cursor: pointer; padding: 6px; border-radius: var(--radius-sm); }
.sidebar-toggle:hover { background: var(--bg3); }
.date-range-select { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 12px; padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.refresh-btn { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; transition: all 0.12s; }
.refresh-btn:hover { border-color: var(--border2); color: var(--text); }
.refresh-btn.spinning svg { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tab content ─────────────────────────────────────────────────────────── */
.tab-content { display: none; flex: 1; overflow-y: auto; padding: 24px; }
.tab-content.active { display: block; }
.page-header { margin-bottom: 22px; }
.page-header h1 { font-size: 20px; font-weight: 600; margin-bottom: 3px; }
.page-header p { font-size: 13px; color: var(--text2); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 12px; }
.section-header h2 { font-size: 15px; font-weight: 600; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-loading { padding: 32px; text-align: center; color: var(--text2); font-size: 13px; }
.table-card { padding: 0; overflow: hidden; }
.optim-intro { font-size: 13px; color: var(--text2); margin-bottom: 16px; }

/* ── Metric grid ─────────────────────────────────────────────────────────── */
.metric-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 24px; }
.metric-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.metric-card.skeleton { height: 90px; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 0.8; } }
.metric-label { font-size: 11px; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.metric-value { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 5px; }
.metric-sub { font-size: 11px; color: var(--text3); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { font-size: 11px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 16px; text-align: left; background: var(--bg3); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 11px 16px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }
.data-table tr.selected td { background: var(--blue-bg); }
.col-name { font-weight: 500; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.badge-green  { background: var(--green-bg);  color: var(--green-text); }
.badge-red    { background: var(--red-bg);    color: var(--red-text); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber-text); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue-text); }
.badge-gray   { background: var(--bg4);        color: var(--text3); }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress-wrap { display: flex; align-items: center; gap: 8px; }
.progress-bar { flex: 1; height: 6px; background: var(--bg4); border-radius: 4px; overflow: hidden; min-width: 60px; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.progress-fill.good    { background: var(--green); }
.progress-fill.warning { background: var(--amber); }
.progress-fill.danger  { background: var(--red); }
.progress-label { font-size: 11px; color: var(--text2); min-width: 32px; text-align: right; }

/* ── Recommendations ─────────────────────────────────────────────────────── */
.reco-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.reco-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; gap: 13px; align-items: flex-start; }
.reco-card:hover { border-color: var(--border2); }
.reco-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; }
.reco-dot.critical    { background: var(--red); }
.reco-dot.warning     { background: var(--amber); }
.reco-dot.opportunity { background: var(--green); }
.reco-body { flex: 1; min-width: 0; }
.reco-title { font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.reco-desc { font-size: 12px; color: var(--text2); line-height: 1.55; }
.reco-impact { font-size: 11px; font-weight: 600; margin-top: 8px; color: var(--text3); }
.reco-ask-btn { font-size: 11px; color: var(--blue-text); background: none; border: none; cursor: pointer; margin-top: 8px; padding: 0; }
.reco-ask-btn:hover { text-decoration: underline; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alerts-grid { display: flex; flex-direction: column; gap: 10px; }
.alert-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; align-items: flex-start; gap: 14px; }
.alert-card.critical { border-left: 3px solid var(--red); }
.alert-card.warning  { border-left: 3px solid var(--amber); }
.alert-card.opportunity { border-left: 3px solid var(--green); }
.alert-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.alert-icon.critical    { background: var(--red-bg); }
.alert-icon.warning     { background: var(--amber-bg); }
.alert-icon.opportunity { background: var(--green-bg); }
.alert-body { flex: 1; }
.alert-campaign { font-size: 11px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; }
.alert-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.alert-message { font-size: 12px; color: var(--text2); line-height: 1.5; }
.alert-metric { font-size: 11px; font-weight: 700; margin-top: 6px; color: var(--text2); }
.alert-ask-btn { align-self: center; font-size: 11px; color: var(--blue-text); background: none; border: none; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.alert-ask-btn:hover { text-decoration: underline; }

/* ── Optimizations ───────────────────────────────────────────────────────── */
.optim-list { display: flex; flex-direction: column; gap: 10px; }
.optim-item { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; align-items: flex-start; gap: 16px; }
.optim-rank { font-size: 24px; font-weight: 700; color: var(--blue); min-width: 32px; line-height: 1; }
.optim-body { flex: 1; }
.optim-title { font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.optim-desc { font-size: 13px; color: var(--text2); line-height: 1.55; }
.optim-impact { display: inline-flex; align-items: center; margin-top: 8px; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.optim-impact.high   { background: var(--red-bg);   color: var(--red-text); }
.optim-impact.medium { background: var(--amber-bg); color: var(--amber-text); }
.optim-impact.low    { background: var(--green-bg); color: var(--green-text); }
.optim-ask-btn { align-self: center; font-size: 12px; color: var(--blue-text); background: var(--blue-bg); border: none; padding: 7px 14px; border-radius: var(--radius-sm); cursor: pointer; flex-shrink: 0; }
.optim-ask-btn:hover { filter: brightness(1.1); }

/* ── Budget section ──────────────────────────────────────────────────────── */
.budget-summary-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 22px; }
.budget-stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }

/* ── Close variant summary ───────────────────────────────────────────────── */
.close-variant-summary { background: var(--amber-bg); border: 1px solid var(--amber); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; font-size: 13px; color: var(--amber-text); }

/* ── Controls ────────────────────────────────────────────────────────────── */
.table-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.search-input { background: var(--bg2); border: 1px solid var(--border2); color: var(--text); font-size: 13px; padding: 7px 12px; border-radius: var(--radius-sm); outline: none; width: 220px; }
.search-input:focus { border-color: var(--blue); }
.filter-tabs { display: flex; gap: 4px; }
.filter-tab { background: transparent; border: 1px solid var(--border); color: var(--text2); font-size: 12px; padding: 5px 12px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; transition: all 0.12s; }
.filter-tab:hover { border-color: var(--border2); color: var(--text); }
.filter-tab.active { background: var(--blue-bg); border-color: var(--blue); color: var(--blue-text); }
.selected-count { font-size: 12px; color: var(--text2); }
.btn-primary { background: var(--blue); color: white; border: none; font-size: 12px; font-weight: 600; padding: 7px 14px; border-radius: var(--radius-sm); cursor: pointer; transition: opacity 0.12s; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary:not(:disabled):hover { opacity: 0.9; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text2); font-size: 12px; padding: 5px 12px; border-radius: var(--radius-sm); cursor: pointer; }
.btn-ghost:hover { border-color: var(--border2); color: var(--text); }

/* ── Checkbox ────────────────────────────────────────────────────────────── */
input[type="checkbox"] { accent-color: var(--blue); width: 14px; height: 14px; cursor: pointer; }

/* ── Ask AI ──────────────────────────────────────────────────────────────── */
#tab-ask-ai { display: none; flex-direction: column; }
#tab-ask-ai.active { display: flex; }
.ai-chat-wrap { display: flex; flex-direction: column; flex: 1; max-width: 760px; margin: 0 auto; width: 100%; }
.ai-messages { flex: 1; overflow-y: auto; padding-bottom: 16px; min-height: 300px; }
.ai-welcome { text-align: center; padding: 40px 20px 32px; }
.ai-welcome-icon { font-size: 32px; margin-bottom: 12px; }
.ai-welcome-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.ai-welcome-sub { font-size: 13px; color: var(--text2); margin-bottom: 24px; }
.ai-suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ai-suggestion { background: var(--bg3); border: 1px solid var(--border2); color: var(--text2); font-size: 12px; padding: 7px 14px; border-radius: 20px; cursor: pointer; transition: all 0.12s; }
.ai-suggestion:hover { background: var(--bg4); color: var(--text); border-color: var(--blue); }
.ai-msg { margin-bottom: 16px; display: flex; flex-direction: column; }
.ai-msg.user { align-items: flex-end; }
.ai-msg.assistant { align-items: flex-start; }
.ai-bubble { max-width: 85%; padding: 12px 16px; border-radius: 12px; font-size: 13px; line-height: 1.65; }
.ai-msg.user .ai-bubble { background: var(--blue); color: white; border-radius: 12px 12px 2px 12px; }
.ai-msg.assistant .ai-bubble { background: var(--bg3); color: var(--text); border-radius: 12px 12px 12px 2px; }
.ai-msg.loading .ai-bubble::after { content: '●●●'; animation: dots 1.2s infinite; letter-spacing: 3px; }
@keyframes dots { 0%,20% { color: transparent; text-shadow: 0.4em 0 0 transparent, 0.8em 0 0 transparent; } 40% { text-shadow: 0.4em 0 0 transparent, 0.8em 0 0 transparent; color: var(--text2); } 60% { text-shadow: 0.4em 0 0 var(--text2), 0.8em 0 0 transparent; } 80%,100% { text-shadow: 0.4em 0 0 var(--text2), 0.8em 0 0 var(--text2); } }
.ai-input-row { display: flex; gap: 10px; align-items: flex-end; padding-top: 12px; border-top: 1px solid var(--border); }
.ai-input { flex: 1; background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 13px; padding: 10px 14px; border-radius: var(--radius); outline: none; resize: none; font-family: inherit; line-height: 1.5; max-height: 120px; }
.ai-input:focus { border-color: var(--blue); }
.ai-send-btn { background: var(--blue); border: none; color: white; width: 38px; height: 38px; border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: opacity 0.12s; }
.ai-send-btn:hover { opacity: 0.85; }
.ai-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── ROAS color helpers ───────────────────────────────────────────────────── */
.roas-good { color: var(--green-text); font-weight: 600; }
.roas-mid  { color: var(--amber-text); font-weight: 600; }
.roas-bad  { color: var(--red-text);   font-weight: 600; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
/* ── Sidebar overlay (mobile) ────────────────────────────────────────────── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 99; }
.sidebar-overlay.active { display: block; }

/* ── Scrollable tables on all screens ───────────────────────────────────── */
.table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 1400px) {
  .accounts-kpi-row { grid-template-columns: repeat(5,1fr); }
}
@media (max-width: 1200px) {
  .metric-grid { grid-template-columns: repeat(3,1fr); }
  .accounts-kpi-row { grid-template-columns: repeat(5,1fr); }
}
@media (max-width: 900px) {
  /* Sidebar slides in */
  .sidebar { position: fixed; left: -240px; z-index: 100; transition: left 0.22s; box-shadow: none; }
  .sidebar.open { left: 0; box-shadow: 4px 0 24px rgba(0,0,0,0.5); }
  /* Hamburger always visible */
  .sidebar-toggle { display: flex; }
  /* Grid adjustments */
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .accounts-kpi-row { grid-template-columns: repeat(3,1fr); }
  .reco-grid { grid-template-columns: 1fr; }
  .budget-summary-grid { grid-template-columns: repeat(2,1fr); }
  /* Accounts topbar stack */
  .accounts-topbar { padding: 0 16px; gap: 8px; }
  .accounts-topbar-right { gap: 6px; }
  .accounts-header { flex-direction: column; gap: 10px; }
}
@media (max-width: 600px) {
  /* Grids */
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .accounts-kpi-row { grid-template-columns: repeat(2,1fr); }
  .budget-summary-grid { grid-template-columns: 1fr; }
  /* Padding */
  .topbar { padding: 0 12px; gap: 8px; }
  .tab-content { padding: 14px 12px; }
  .accounts-content { padding: 14px 12px; }
  .page-header { margin-bottom: 14px; }
  /* Topbar — hide account name text, show only essential controls */
  .topbar-breadcrumb span:first-child { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
  /* Accounts header stacks */
  .accounts-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .accounts-header input { width: 100%; }
  /* KPI cards smaller text */
  .accounts-kpi-value { font-size: 16px; }
  .accounts-kpi-label { font-size: 10px; }
  /* Modal full screen */
  .modal { max-height: 95vh; border-radius: 12px 12px 0 0; position: fixed; bottom: 0; left: 0; right: 0; max-width: 100%; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  /* Metric cards */
  .metric-value { font-size: 18px; }
  /* Alert cards stack */
  .alert-card { flex-wrap: wrap; }
  .alert-ask-btn { width: 100%; text-align: right; margin-top: 6px; }
  /* Settings */
  .settings-layout { max-width: 100%; }
  .settings-input-large { width: 160px; font-size: 20px; }
}

/* ── Import Accounts Button ───────────────────────────────────────────────── */
.btn-import { display: inline-flex; align-items: center; gap: 6px; background: var(--blue); color: white; border: none; font-size: 13px; font-weight: 600; padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; transition: opacity 0.12s; white-space: nowrap; }
.btn-import:hover { opacity: 0.88; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { background: var(--bg2); border: 1px solid var(--border2); border-radius: 14px; width: 100%; max-width: 560px; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; padding: 22px 22px 16px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 17px; font-weight: 700; margin-bottom: 3px; }
.modal-header p { font-size: 13px; color: var(--text2); }
.modal-close { background: transparent; border: none; color: var(--text2); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); line-height: 1; }
.modal-close:hover { background: var(--bg3); color: var(--text); }
.modal-search { padding: 14px 22px 10px; }
.modal-actions-top { display: flex; align-items: center; gap: 8px; padding: 0 22px 10px; border-bottom: 1px solid var(--border); }
.modal-count { margin-left: auto; font-size: 12px; color: var(--text2); font-weight: 600; }
.modal-list { flex: 1; overflow-y: auto; padding: 8px 12px; }
.modal-account-row { display: flex; align-items: center; gap: 12px; padding: 10px 10px; border-radius: var(--radius-sm); cursor: pointer; transition: background 0.1s; }
.modal-account-row:hover { background: var(--bg3); }
.modal-account-row.checked { background: var(--blue-bg); }
.modal-account-row input[type=checkbox] { flex-shrink: 0; }
.modal-account-info { flex: 1; min-width: 0; }
.modal-account-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-account-id { font-size: 11px; color: var(--text3); margin-top: 1px; }
.modal-footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ── Settings Tab ─────────────────────────────────────────────────────────── */
.settings-layout { display: flex; flex-direction: column; gap: 20px; max-width: 640px; }
.settings-main { flex: 1; }
.settings-save-bar { display: flex; justify-content: flex-start; }

.settings-single-account { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.settings-account-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); background: var(--bg3); }
.settings-account-name { font-size: 18px; font-weight: 700; margin-bottom: 3px; }
.settings-account-id { font-size: 12px; color: var(--text3); }

.settings-field-group { padding: 24px; }
.settings-label { font-size: 13px; font-weight: 700; color: var(--text); display: block; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.settings-hint { font-size: 13px; color: var(--text2); margin-bottom: 14px; line-height: 1.55; }
.settings-input-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.settings-dollar { font-size: 20px; color: var(--text2); font-weight: 600; }
.settings-input-large { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 24px; font-weight: 700; padding: 10px 16px; border-radius: var(--radius); width: 200px; outline: none; }
.settings-input-large:focus { border-color: var(--blue); }
.settings-input-large::placeholder { color: var(--text3); font-weight: 400; font-size: 18px; }
.settings-current { font-size: 12px; color: var(--text2); margin-top: 6px; }

.settings-preview-card { margin: 0 24px 24px; background: var(--blue-bg); border: 1px solid var(--blue); border-radius: var(--radius); padding: 14px 18px; }
.settings-preview-title { font-size: 12px; font-weight: 700; color: var(--blue-text); margin-bottom: 6px; }
.settings-preview-calc { font-size: 14px; color: var(--text); }

.job-value-input { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 13px; padding: 6px 10px; border-radius: var(--radius-sm); width: 130px; outline: none; }
.job-value-input:focus { border-color: var(--blue); }
.job-value-input::placeholder { color: var(--text3); }

/* ── Sortable column headers ──────────────────────────────────────────────── */
th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-sort]:hover { color: var(--text) !important; background: var(--bg4) !important; }

/* ── Keyword Opportunities Tab ───────────────────────────────────────────── */
.cv-stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-bottom: 4px; }
.cv-stat { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.cv-stat-val { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.cv-stat-val.green { color: var(--green-text); }
.cv-stat-val.red   { color: var(--red-text); }
.cv-stat-val.amber { color: var(--amber-text); }
.cv-stat-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; }
.cv-tabs { display: flex; gap: 4px; padding: 12px 16px 0; border-bottom: 1px solid var(--border); background: var(--bg3); }
.cv-tab { background: transparent; border: none; color: var(--text2); font-size: 13px; font-weight: 500; padding: 8px 16px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; cursor: pointer; border-bottom: 2px solid transparent; }
.cv-tab.active { color: var(--blue-text); border-bottom-color: var(--blue); background: var(--bg2); }
.cv-ai-section { margin-top: 20px; }
.cv-ai-card { background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--radius); padding: 20px; margin-top: 12px; }
.cv-ai-header { font-size: 13px; font-weight: 700; color: var(--blue-text); margin-bottom: 12px; }
.cv-ai-body { font-size: 13px; color: var(--text); line-height: 1.7; }
@media (max-width: 600px) { .cv-stats { grid-template-columns: repeat(2,1fr); } }

/* ── AI Suggestion Cards with Feedback ───────────────────────────────────── */
.ai-suggestions-wrap { display: flex; flex-direction: column; gap: 10px; margin: 8px 0; max-width: 760px; }
.ai-suggestion-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; transition: border-color 0.15s; }
.ai-suggestion-card.accepted { border-color: var(--green); background: var(--green-bg); }
.ai-suggestion-card.rejected  { border-color: var(--red);   opacity: 0.6; }
.ai-suggestion-card.critical  { border-left: 3px solid var(--red); }
.ai-suggestion-card.warning   { border-left: 3px solid var(--amber); }
.ai-suggestion-card.opportunity { border-left: 3px solid var(--green); }
.ai-sugg-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ai-sugg-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ai-sugg-dot.critical    { background: var(--red); }
.ai-sugg-dot.warning     { background: var(--amber); }
.ai-sugg-dot.opportunity { background: var(--green); }
.ai-sugg-title { font-size: 13px; font-weight: 600; }
.ai-sugg-body { font-size: 13px; color: var(--text2); line-height: 1.6; margin-bottom: 10px; }
.ai-sugg-actions { display: flex; gap: 8px; }
.ai-sugg-accept { background: var(--green-bg); border: 1px solid var(--green); color: var(--green-text); font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.12s; }
.ai-sugg-accept:hover { background: var(--green); color: white; }
.ai-sugg-reject { background: var(--red-bg); border: 1px solid var(--red); color: var(--red-text); font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.12s; }
.ai-sugg-reject:hover { background: var(--red); color: white; }
.ai-sugg-reject-form { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.ai-sugg-reason { flex: 1; background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 12px; padding: 6px 10px; border-radius: var(--radius-sm); outline: none; }
.ai-sugg-reason:focus { border-color: var(--blue); }
.ai-sugg-reason-save { background: var(--bg3); border: 1px solid var(--border2); color: var(--text2); font-size: 12px; padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; }
.ai-sugg-reason-save:hover { border-color: var(--border2); color: var(--text); }

/* ── Reco card feedback row ──────────────────────────────────────────────── */
.reco-feedback-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.reco-accept-btn { background: var(--green-bg); border: 1px solid var(--green); color: var(--green-text); font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.reco-accept-btn:hover { background: var(--green); color: white; }
.reco-reject-btn { background: var(--red-bg); border: 1px solid var(--red); color: var(--red-text); font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.reco-reject-btn:hover { background: var(--red); color: white; }
.reco-reject-form { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.reco-reason-input { flex: 1; background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 12px; padding: 5px 10px; border-radius: var(--radius-sm); outline: none; min-width: 0; }
.reco-reason-input:focus { border-color: var(--blue); }
.reco-reason-save { background: var(--bg3); border: 1px solid var(--border2); color: var(--text2); font-size: 12px; padding: 5px 10px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; }

/* ── Feedback History ────────────────────────────────────────────────────── */
.feedback-history-wrap { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.feedback-section { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.feedback-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.feedback-section-title.rejection  { color: var(--red-text);   background: var(--red-bg); }
.feedback-section-title.acceptance { color: var(--green-text); background: var(--green-bg); }
.feedback-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.feedback-item:last-child { border-bottom: none; }
.feedback-item.rejection  { border-left: 3px solid var(--red); }
.feedback-item.acceptance { border-left: 3px solid var(--green); }
.feedback-item-content { flex: 1; min-width: 0; }
.feedback-item-sugg { font-size: 13px; color: var(--text); line-height: 1.5; margin-bottom: 4px; }
.feedback-item-reason { font-size: 12px; color: var(--amber-text); margin-bottom: 4px; font-style: italic; }
.feedback-item-date { font-size: 11px; color: var(--text3); }
.feedback-delete-btn { background: transparent; border: 1px solid var(--border); color: var(--text3); font-size: 12px; padding: 4px 8px; border-radius: var(--radius-sm); cursor: pointer; flex-shrink: 0; transition: all 0.12s; }
.feedback-delete-btn:hover { background: var(--red-bg); border-color: var(--red); color: var(--red-text); }

/* ── Tasks Tab ───────────────────────────────────────────────────────────── */
.tasks-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tasks-tab { background: transparent; border: 1px solid var(--border); color: var(--text2); font-size: 13px; font-weight: 500; padding: 7px 16px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.12s; }
.tasks-tab.active { background: var(--blue-bg); border-color: var(--blue); color: var(--blue-text); }
.tasks-tab:hover { border-color: var(--border2); color: var(--text); }

.task-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 10px; }
.task-card.done { opacity: 0.65; }
.task-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.task-source-badge { background: var(--blue-bg); color: var(--blue-text); font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.task-account { font-size: 12px; color: var(--text2); font-weight: 500; }
.task-date { font-size: 11px; color: var(--text3); margin-left: auto; }
.task-suggestion { font-size: 13px; color: var(--text); line-height: 1.6; margin-bottom: 10px; }
.task-action-type { font-size: 11px; font-weight: 600; margin-bottom: 12px; }
.task-action-type.auto   { color: var(--blue-text); }
.task-action-type.manual { color: var(--text3); }
.task-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Audit Log ───────────────────────────────────────────────────────────── */
.audit-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 10px; }
.audit-card.completed { border-left: 3px solid var(--green); }
.audit-card.failed    { border-left: 3px solid var(--red); }
.audit-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.audit-status-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.audit-status-badge.completed { background: var(--green-bg); color: var(--green-text); }
.audit-status-badge.failed    { background: var(--red-bg);   color: var(--red-text); }
.audit-account { font-size: 12px; color: var(--text2); }
.audit-date { font-size: 11px; color: var(--text3); margin-left: auto; }
.audit-action-type { font-size: 13px; font-weight: 600; text-transform: capitalize; margin-bottom: 4px; }
.audit-params { font-size: 11px; color: var(--text3); font-family: monospace; margin-bottom: 4px; word-break: break-all; }
.audit-before { font-size: 11px; color: var(--amber-text); font-family: monospace; word-break: break-all; margin-bottom: 4px; }
.audit-error  { font-size: 11px; color: var(--red-text); font-family: monospace; word-break: break-all; }

/* ── Action Confirm Modal ────────────────────────────────────────────────── */
.confirm-action-box { background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius); padding: 14px 16px; font-size: 13px; color: var(--text); line-height: 1.65; white-space: pre-wrap; margin-bottom: 12px; }
.confirm-warning { background: var(--amber-bg); border: 1px solid var(--amber); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 12px; color: var(--amber-text); line-height: 1.5; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 14px 16px; border-top: 1px solid var(--border); background: var(--bg3); }
.page-btn { background: var(--bg2); border: 1px solid var(--border2); color: var(--text); font-size: 13px; font-weight: 500; padding: 6px 16px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.12s; }
.page-btn:hover:not([disabled]) { background: var(--blue-bg); border-color: var(--blue); color: var(--blue-text); }
.page-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.page-info { font-size: 13px; color: var(--text2); }

/* ── Match Type Modal ────────────────────────────────────────────────────── */
.match-type-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.match-type-option { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: border-color 0.12s; }
.match-type-option:has(input:checked) { border-color: var(--blue); background: var(--blue-bg); }
.match-type-option input[type=radio] { margin-top: 3px; flex-shrink: 0; accent-color: var(--blue); }
.match-type-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.match-type-desc { font-size: 12px; color: var(--text2); line-height: 1.5; margin-bottom: 3px; }
.match-type-example { font-size: 11px; color: var(--text3); font-family: monospace; }
.match-type-preview { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.match-type-preview-title { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.match-type-preview-list { display: flex; flex-wrap: wrap; gap: 6px; }
.kw-chip { background: var(--bg4); border: 1px solid var(--border2); color: var(--text); font-size: 12px; padding: 3px 10px; border-radius: 20px; }
.kw-chip-more { font-size: 12px; color: var(--text3); padding: 3px 0; }

/* ── Secondary button ────────────────────────────────────────────────────── */
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border2); font-size: 12px; font-weight: 600; padding: 7px 14px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.12s; }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary:not(:disabled):hover { background: var(--bg4); border-color: var(--border2); }

/* ── Keyword Modal ───────────────────────────────────────────────────────── */
.kw-modal-body { padding: 16px 22px; overflow-y: auto; max-height: 60vh; display: flex; flex-direction: column; gap: 16px; }
.kw-field-group { display: flex; flex-direction: column; gap: 6px; }
.kw-label { font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; }
.kw-required { color: var(--red-text); }
.kw-select { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 13px; padding: 8px 12px; border-radius: var(--radius-sm); outline: none; width: 100%; }
.kw-select:focus { border-color: var(--blue); }
.kw-select:disabled { opacity: 0.5; }
.kw-level-tabs { display: flex; gap: 4px; }
.kw-level-tab { background: transparent; border: 1px solid var(--border); color: var(--text2); font-size: 12px; font-weight: 500; padding: 6px 14px; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.12s; }
.kw-level-tab.active { background: var(--blue-bg); border-color: var(--blue); color: var(--blue-text); }
.kw-textarea { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); font-size: 13px; padding: 8px 12px; border-radius: var(--radius-sm); outline: none; width: 100%; resize: vertical; font-family: monospace; line-height: 1.6; }
.kw-textarea:focus { border-color: var(--blue); }
.kw-textarea-hint { font-size: 11px; color: var(--text3); }

/* ── Audit log enhancements ──────────────────────────────────────────────── */
.audit-action-icon { font-size: 16px; font-weight: 700; width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.audit-action-icon.red   { background: var(--red-bg);   color: var(--red-text); }
.audit-action-icon.green { background: var(--green-bg); color: var(--green-text); }
.audit-action-icon.amber { background: var(--amber-bg); color: var(--amber-text); }
.audit-action-icon.blue  { background: var(--blue-bg);  color: var(--blue-text); }
.audit-action-icon.gray  { background: var(--bg4);       color: var(--text3); }
.audit-action-label { font-size: 13px; font-weight: 600; flex: 1; }
.audit-source-badge { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; }
.audit-source-badge.ai     { background: var(--blue-bg); color: var(--blue-text); }
.audit-source-badge.google { background: var(--green-bg); color: var(--green-text); }
.audit-keywords { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 4px; }
.audit-meta { font-size: 12px; color: var(--text2); margin: 4px 0; }
