/* Marketing Engine web app. Light theme, Asmal Digital palette.
   Mobile first: 16px gutters, no horizontal page scroll, tables scroll inside their own wrapper. */
:root {
  --navy: #0A1628;
  --cyan: #06B6D4;
  --teal: #14B8A6;
  --orange: #FF6B35;
  --orange-ink: #D2521E;
  --slate: #1E293B;
  --gray: #64748B;
  --light: #E2E8F0;
  --paper: #F8FAFC;
  --white: #FFFFFF;
  --red: #B91C1C;
  --green: #0F766E;
  --amber: #B45309;
  --radius: 12px;
  --gutter: 16px;
  --head: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --shadow: 0 1px 2px rgba(10, 22, 40, 0.06), 0 4px 16px rgba(10, 22, 40, 0.05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0; background: var(--paper); color: var(--slate); font-family: var(--body); font-size: 16px; line-height: 1.5;
  overflow-x: hidden; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3, h4 { font-family: var(--head); color: var(--navy); margin: 0 0 8px; line-height: 1.2; font-weight: 700; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; font-weight: 500; }
p { margin: 0 0 12px; }
a { color: var(--navy); }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--gray); }
.eyebrow { font-family: var(--head); font-weight: 500; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--orange-ink); margin-bottom: 4px; }
.error { color: var(--red); font-size: 14px; }
.small { font-size: 14px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* header + tabs */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter); padding-top: calc(12px + env(safe-area-inset-top)); background: var(--white); border-bottom: 1px solid var(--light);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-family: var(--head); font-weight: 700; font-size: 18px; color: var(--navy); min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mark { width: 28px; height: 28px; flex: none; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.who { font-size: 13px; color: var(--gray); display: none; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 8px var(--gutter) 0; background: var(--white); border-bottom: 1px solid var(--light); }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 8px 12px 10px; text-decoration: none; color: var(--gray); font-weight: 500; font-size: 15px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--navy); border-bottom-color: var(--orange); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--orange); color: var(--white); font-size: 12px; font-weight: 600; text-align: center; line-height: 20px; margin-left: 4px; }

/* layout */
.view { padding: 16px var(--gutter) 40px; max-width: 1080px; margin: 0 auto; width: 100%; }
.card { background: var(--white); border: 1px solid var(--light); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; min-width: 0; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--cyan); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.stack > * + * { margin-top: 12px; }
.head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { flex: 1 1 140px; }
.empty { color: var(--gray); padding: 24px 0; text-align: center; }

/* controls */
.btn { border: 1px solid var(--light); background: var(--white); color: var(--navy); padding: 10px 16px; border-radius: 10px; font-family: var(--head); font-weight: 700; font-size: 15px; cursor: pointer; line-height: 1.2; }
.btn:hover { border-color: var(--cyan); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--navy); color: var(--white); border-color: var(--navy); }
.btn.primary:hover { background: var(--cyan); border-color: var(--cyan); color: var(--navy); }
.btn.accent { background: var(--cyan); border-color: var(--cyan); color: var(--navy); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
label { display: block; font-size: 14px; font-weight: 500; color: var(--slate); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--light); border-radius: 10px; background: var(--white); color: var(--slate); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--cyan); outline-offset: 1px; border-color: var(--cyan); }
textarea { min-height: 96px; resize: vertical; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; margin: 0; cursor: pointer; }
.switch input { width: auto; margin: 0; accent-color: var(--teal); transform: scale(1.3); }

/* pills */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--light); color: var(--slate); white-space: nowrap; }
.pill.pending, .pill.running { background: #FFF1EA; color: var(--orange-ink); }
.pill.approved, .pill.ok, .pill.executed, .pill.valid { background: #E6F7F4; color: var(--green); }
.pill.rejected, .pill.failed, .pill.invalid, .pill.blocked { background: #FEE2E2; color: var(--red); }
.pill.expired, .pill.skipped, .pill.partial, .pill.unknown { background: #FEF3C7; color: var(--amber); }
.pill.auto { background: #E0F7FB; color: #0E7490; }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--light); border-radius: var(--radius); background: var(--white); }
table { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 560px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--light); vertical-align: top; }
th { font-family: var(--head); font-weight: 500; font-size: 13px; color: var(--gray); background: var(--paper); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #F1F8FA; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* approvals */
.approval-title { font-family: var(--head); font-weight: 700; font-size: 17px; color: var(--navy); }
.preview { white-space: pre-wrap; word-break: break-word; background: var(--paper); border: 1px solid var(--light); border-radius: 10px; padding: 12px; font-size: 15px; max-height: 60vh; overflow: auto; }
.args pre { white-space: pre-wrap; word-break: break-word; background: var(--paper); border: 1px solid var(--light); border-radius: 10px; padding: 12px; margin: 0; }
.decide { display: grid; grid-template-columns: 1fr; gap: 8px; }
.hint { border-left: 3px solid var(--orange); background: #FFF7F2; padding: 8px 12px; border-radius: 0 8px 8px 0; font-size: 14px; color: var(--slate); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--white); border: 1px solid var(--light); border-radius: var(--radius); padding: 14px; }
.stat .label { font-size: 13px; color: var(--gray); }
.stat .value { font-family: var(--head); font-weight: 700; font-size: 24px; color: var(--navy); }
.stat .sub { font-size: 12px; color: var(--gray); }
.bar { height: 6px; background: var(--light); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--teal); }
.bar > i.warn { background: var(--orange); }

/* chat */
.chat { display: flex; flex-direction: column; min-height: calc(100vh - 220px); }
.messages { flex: 1; display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.msg.user { align-self: flex-end; background: var(--navy); color: var(--white); border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--white); border: 1px solid var(--light); border-bottom-left-radius: 4px; }
.msg.thinking { color: var(--gray); font-style: italic; }
.composer { display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--paper); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
.composer textarea { min-height: 44px; max-height: 160px; }
.composer button { flex: none; }

/* login */
.login { max-width: 420px; margin: 32px auto; }
.login h1 { margin-bottom: 4px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: var(--white); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 20; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--red); }

@media (min-width: 720px) {
  .who { display: inline; }
  .grid.two { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .decide { grid-template-columns: 1fr 1fr 1fr; }
  .view { padding: 24px var(--gutter) 48px; }
  h1 { font-size: 32px; }
}
