:root {
  --paper: #fafaf8;
  --ink: #141413;
  --ink-2: #52524d;
  --stone: #8a8a84;
  --copper: #c06b3e;
  --copper-dark: #9b4d2b;
  --line: rgba(20, 20, 19, 0.12);
  --soft: #f2f0eb;
  --white: rgba(255, 255, 253, 0.86);
  --success: #2e7451;
  --danger: #b84b3d;
  --warning: #b57932;
  --font: "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: "Chakra Petch", "IBM Plex Sans Arabic", sans-serif;
  --radius-xl: 34px;
  --radius-lg: 24px;
  --radius-md: 16px;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  background-image:
    linear-gradient(rgba(20, 20, 19, 0.032) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20, 20, 19, 0.032) 1px, transparent 1px);
  background-size: 54px 54px;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.topbar {
  width: min(1440px, calc(100% - 40px));
  height: 92px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand img { width: 42px; height: 30px; object-fit: contain; }
.brand span { display: grid; direction: ltr; text-align: left; line-height: 1; }
.brand b { font: 600 18px/1 var(--display); letter-spacing: 0.12em; }
.brand small { margin-top: 7px; color: var(--stone); font: 500 9px/1 var(--display); letter-spacing: 0.32em; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.live-pill, .ghost-button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}
.ghost-button:hover { border-color: rgba(192, 107, 62, 0.45); color: var(--copper-dark); }
.live-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 5px rgba(46, 116, 81, 0.08); }
main { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 70px; }
.hero { min-height: 420px; padding: 74px 0 52px; display: grid; grid-template-columns: 1fr 0.82fr; gap: 60px; align-items: end; }
.eyebrow { display: block; color: var(--copper-dark); font: 600 11px/1 var(--display); letter-spacing: 0.18em; direction: ltr; text-align: right; }
.hero h1 { max-width: 760px; margin: 18px 0 20px; font-size: clamp(42px, 5.3vw, 78px); line-height: 1.17; letter-spacing: -0.04em; }
.hero p { max-width: 650px; margin: 0; color: var(--ink-2); font-size: 17px; line-height: 1.9; }
.flow-card {
  min-height: 245px;
  padding: 28px;
  border-radius: var(--radius-xl);
  background: var(--ink);
  color: #fff;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-content: center;
  gap: 14px;
  box-shadow: 0 28px 70px rgba(20, 20, 19, 0.14);
}
.flow-step { min-height: 58px; padding: 0 15px; border: 1px solid rgba(255,255,255,.12); border-radius: 16px; display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.64); font-size: 13px; }
.flow-step i { color: rgba(255,255,255,.35); font: 500 10px/1 var(--display); font-style: normal; }
.flow-step.active { border-color: rgba(192,107,62,.6); background: rgba(192,107,62,.14); color: #fff; }
.flow-step.active i { color: #e4a37f; }
.flow-card > b { align-self: center; color: rgba(255,255,255,.24); font-weight: 400; }
.integration-strip { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--white); }
.integration-strip div { min-height: 66px; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; border-inline-end: 1px solid var(--line); }
.integration-strip div:last-child { border: 0; }
.integration-strip span { color: var(--stone); font: 500 11px/1 var(--display); }
.integration-strip b { color: var(--warning); font-size: 12px; }
.integration-strip b.on { color: var(--success); }
.integration-value { display: flex; align-items: center; gap: 8px; }
.mini-button { min-height: 28px; padding: 0 10px; border: 1px solid rgba(192,107,62,.28); border-radius: 999px; background: rgba(192,107,62,.08); color: var(--copper-dark); font-size: 9px; font-weight: 600; }
.mini-button:hover { background: rgba(192,107,62,.14); }
.mini-button.danger { border-color: rgba(184,75,61,.28); background: rgba(184,75,61,.07); color: var(--danger); }
.mini-button.danger:hover { background: rgba(184,75,61,.14); }
.mini-button:disabled { cursor: wait; opacity: .55; }
.stats { margin: 22px 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stats article { min-height: 122px; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--white); display: flex; flex-direction: column; justify-content: space-between; }
.stats span { color: var(--stone); font-size: 12px; }
.stats strong { font: 600 36px/1 var(--display); direction: ltr; text-align: right; }
.workspace-grid { display: grid; grid-template-columns: minmax(330px, .72fr) minmax(520px, 1.28fr); gap: 18px; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: var(--radius-xl); background: rgba(250,250,248,.9); box-shadow: 0 18px 50px rgba(20,20,19,.045); }
.intake-panel { padding: 28px; position: sticky; top: 18px; }
.queue-panel { padding: 28px; min-height: 640px; }
.panel-heading { min-height: 64px; margin-bottom: 24px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel-heading h2 { margin: 9px 0 0; font-size: 25px; line-height: 1.3; }
.number { color: rgba(20,20,19,.14); font: 600 30px/1 var(--display); }
.icon-button { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 20px; transition: transform .25s var(--ease), border-color .2s; }
.icon-button:hover { transform: rotate(-25deg); border-color: var(--copper); }
form { display: grid; }
label { margin: 0 2px 8px; color: var(--ink-2); font-size: 12px; font-weight: 600; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.8); color: var(--ink); outline: 0; transition: border-color .2s, box-shadow .2s; }
input { height: 50px; padding: 0 15px; margin-bottom: 18px; }
textarea { padding: 15px; resize: vertical; line-height: 1.8; }
select { height: 50px; padding: 0 14px; margin-bottom: 18px; cursor: pointer; }
input:focus, textarea:focus, select:focus { border-color: rgba(192,107,62,.65); box-shadow: 0 0 0 4px rgba(192,107,62,.08); }
.form-note { margin: 9px 2px 22px; display: flex; justify-content: space-between; gap: 15px; color: var(--stone); font-size: 10px; }
.primary-button { min-height: 58px; padding: 0 22px; border: 0; border-radius: 999px; background: var(--copper); color: #fff; display: flex; align-items: center; justify-content: space-between; font-weight: 600; box-shadow: 0 16px 32px rgba(192,107,62,.24); transition: transform .2s, background .2s; }
.primary-button:hover { transform: translateY(-2px); background: var(--copper-dark); }
.primary-button:disabled { opacity: .55; cursor: wait; transform: none; }
.primary-button b { direction: ltr; font-size: 20px; }
.listings { display: grid; gap: 12px; }
.empty-state { min-height: 480px; border: 1px dashed var(--line); border-radius: 24px; display: grid; place-items: center; align-content: center; text-align: center; }
.empty-state img { width: 84px; height: 54px; opacity: .12; margin-bottom: 24px; }
.empty-state h3 { margin: 0 0 7px; font-size: 17px; }
.empty-state p { margin: 0; color: var(--stone); font-size: 12px; }
.listing-card { padding: 19px; border: 1px solid var(--line); border-radius: 20px; background: #fff; }
.listing-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.listing-source { display: block; color: var(--copper-dark); font-size: 10px; font-weight: 600; }
.listing-card h3 { margin: 5px 0 0; font-size: 17px; line-height: 1.5; }
.status { flex: none; padding: 7px 10px; border-radius: 999px; background: var(--soft); color: var(--ink-2); font-size: 9px; font-weight: 600; }
.status.needs_review { color: var(--warning); background: rgba(181,121,50,.09); }
.status.approved { color: var(--success); background: rgba(46,116,81,.09); }
.status.rejected, .status.failed { color: var(--danger); background: rgba(184,75,61,.08); }
.listing-meta { margin: 14px 0; padding: 12px 0; display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); gap: 10px; }
.listing-meta span { display: grid; gap: 4px; min-width: 0; }
.listing-meta small { color: var(--stone); font-size: 9px; }
.listing-meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.listing-copy { margin: 0; color: var(--ink-2); font-size: 12px; line-height: 1.85; white-space: pre-wrap; }
.listing-warning { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; color: var(--danger); background: rgba(184,75,61,.06); font-size: 10px; }
.card-actions { margin-top: 15px; display: flex; gap: 8px; }
.card-actions button { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); font-size: 11px; font-weight: 600; }
.card-actions .approve { border-color: rgba(46,116,81,.28); color: var(--success); }
.card-actions .reject { border-color: rgba(184,75,61,.24); color: var(--danger); }
.card-actions button:hover { background: var(--soft); }
.toast { position: fixed; z-index: 20; left: 24px; bottom: 24px; max-width: min(390px, calc(100% - 48px)); padding: 15px 18px; border-radius: 14px; background: var(--ink); color: #fff; font-size: 12px; line-height: 1.6; box-shadow: 0 20px 50px rgba(20,20,19,.24); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .25s var(--ease); }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }
.qr-dialog { width: min(440px, calc(100% - 28px)); padding: 26px; border: 1px solid var(--line); border-radius: 27px; background: var(--paper); color: var(--ink); box-shadow: 0 30px 100px rgba(20,20,19,.28); }
.qr-dialog::backdrop { background: rgba(20,20,19,.48); backdrop-filter: blur(5px); }
.qr-dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.qr-dialog h2 { margin: 8px 0 0; font-size: 24px; }
.dialog-close { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: #fff; color: var(--ink); font-size: 22px; }
.qr-dialog > p { margin: 18px 0; color: var(--ink-2); font-size: 12px; line-height: 1.8; }
.qr-dialog > small { display: block; margin-top: 13px; color: var(--stone); text-align: center; font-size: 9px; }
.qr-canvas { aspect-ratio: 1; padding: 12px; border: 1px solid var(--line); border-radius: 20px; background: #fff; display: grid; place-items: center; overflow: hidden; }
.qr-canvas svg { width: 100%; height: 100%; display: block; }
.qr-canvas span { color: var(--stone); font-size: 11px; }

.settings-panel { margin-top: 18px; padding: 34px; scroll-margin-top: 18px; }
.settings-heading { margin-bottom: 30px; display: flex; align-items: flex-start; justify-content: space-between; gap: 28px; }
.settings-heading h2 { margin: 10px 0 8px; font-size: 30px; }
.settings-heading p, .rules-heading p { margin: 0; color: var(--stone); font-size: 12px; line-height: 1.8; }
.settings-save-state { flex: none; padding: 9px 13px; border-radius: 999px; background: var(--soft); color: var(--stone); font-size: 10px; }
#settingsForm { gap: 26px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.settings-card { min-width: 0; margin: 0; padding: 24px; border: 1px solid var(--line); border-radius: 22px; background: #fff; }
.settings-card legend { padding: 0 8px; color: var(--ink); font-size: 16px; font-weight: 600; }
.settings-card legend span { margin-left: 7px; color: var(--copper); font: 600 10px/1 var(--display); }
.settings-card input, .settings-card select { margin-bottom: 13px; }
.field-help { margin: -4px 2px 17px; color: var(--stone); font-size: 10px; line-height: 1.7; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toggle-row { min-height: 64px; margin: 3px 0 0; padding: 11px 14px; border: 1px solid var(--line); border-radius: 16px; display: flex; align-items: center; gap: 13px; cursor: pointer; }
.toggle-row span { flex: 1; display: grid; gap: 4px; }
.toggle-row b { color: var(--ink); font-size: 12px; }
.toggle-row small { color: var(--stone); font-size: 9px; font-weight: 400; }
.toggle-row input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.toggle-row i { position: relative; flex: none; width: 40px; height: 23px; border-radius: 999px; background: #d9d7d0; transition: background .2s; }
.toggle-row i::after { content: ""; position: absolute; top: 3px; right: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(20,20,19,.18); transition: transform .2s var(--ease); }
.toggle-row input:checked + i { background: var(--copper); }
.toggle-row input:checked + i::after { transform: translateX(-17px); }
.toggle-row:focus-within { border-color: rgba(192,107,62,.65); box-shadow: 0 0 0 4px rgba(192,107,62,.08); }
.settings-note { margin-top: 16px; padding: 15px 17px; border-radius: 16px; background: rgba(192,107,62,.07); }
.settings-note b { color: var(--copper-dark); font-size: 11px; }
.settings-note p { margin: 5px 0 0; color: var(--ink-2); font-size: 10px; line-height: 1.75; }
.rules-section { padding: 28px; border: 1px solid var(--line); border-radius: 24px; background: rgba(255,255,255,.48); }
.rules-heading { margin-bottom: 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.rules-heading h3 { margin: 8px 0 4px; font-size: 22px; }
.secondary-button { min-height: 46px; padding: 0 17px; border: 1px solid rgba(192,107,62,.28); border-radius: 999px; background: #fff; color: var(--copper-dark); font-size: 11px; font-weight: 600; }
.secondary-button:hover { background: rgba(192,107,62,.07); }
.secondary-button b { margin-left: 4px; font-size: 17px; }
.rules-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rule-item { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 19px; background: #fff; }
.rule-top { margin-bottom: 15px; display: flex; align-items: center; gap: 10px; }
.rule-number { color: rgba(20,20,19,.2); font: 600 19px/1 var(--display); }
.toggle-row.compact { min-height: 48px; margin: 0; padding: 7px 10px; flex: 1; border: 0; background: var(--soft); }
.toggle-row.compact i { width: 35px; height: 20px; }
.toggle-row.compact i::after { width: 14px; height: 14px; }
.toggle-row.compact input:checked + i::after { transform: translateX(-15px); }
.remove-rule { min-height: 37px; padding: 0 11px; border: 1px solid rgba(184,75,61,.18); border-radius: 999px; background: #fff; color: var(--danger); font-size: 9px; }
.remove-rule:hover { background: rgba(184,75,61,.06); }
.rule-fields { display: grid; grid-template-columns: 1.35fr .65fr; gap: 10px; }
.rule-item input, .rule-item select { height: 44px; margin-bottom: 12px; }
.rule-item textarea { min-height: 92px; }
.rules-empty { grid-column: 1 / -1; min-height: 150px; border: 1px dashed var(--line); border-radius: 18px; display: grid; place-content: center; gap: 6px; text-align: center; }
.rules-empty b { font-size: 13px; }
.rules-empty span { color: var(--stone); font-size: 10px; }
.settings-footer { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.settings-footer p { max-width: 660px; margin: 0; color: var(--stone); font-size: 10px; line-height: 1.75; }
.settings-footer p b { color: var(--ink-2); }
.save-settings { width: min(310px, 100%); flex: none; }

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; gap: 30px; }
  .flow-card { min-height: 210px; }
  .workspace-grid { grid-template-columns: 1fr; }
  .intake-panel { position: static; }
  .settings-grid, .rules-list { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .topbar, main { width: min(100% - 24px, 1440px); }
  .topbar { height: 74px; }
  .ghost-button { display: none; }
  .brand img { width: 35px; }
  .brand b { font-size: 15px; }
  .hero { min-height: auto; padding: 50px 0 34px; }
  .hero h1 { font-size: 39px; }
  .hero p { font-size: 14px; }
  .flow-card { padding: 19px; grid-template-columns: 1fr; }
  .flow-card > b { display: none; }
  .integration-strip, .stats { grid-template-columns: 1fr 1fr; }
  .integration-strip div { border-bottom: 1px solid var(--line); }
  .integration-strip div:nth-child(2) { border-inline-end: 0; }
  .integration-strip div:last-child { border-bottom: 0; }
  .stats article { min-height: 100px; }
  .panel, .intake-panel, .queue-panel { padding: 19px; border-radius: 25px; }
  .listing-meta { grid-template-columns: 1fr 1fr; }
  .form-note { display: grid; }
  .settings-panel { padding: 20px; }
  .settings-heading, .rules-heading, .settings-footer { display: grid; }
  .settings-save-state { width: fit-content; }
  .field-pair, .rule-fields { grid-template-columns: 1fr; }
  .rules-section { padding: 17px; }
  .rule-top { align-items: flex-start; flex-wrap: wrap; }
  .toggle-row.compact { min-width: calc(100% - 42px); }
  .save-settings { width: 100%; }
}
