:root {
  --accent: #0f7b63;
  --accent-dark: #0a5a48;
  --accent-soft: #e3f1ec;
  --ground: #f3f4f1;
  --surface: #ffffff;
  --text: #1d2327;
  --muted: #5e6a71;
  --border: #e2e5e3;
  --danger: #b42318;
  --danger-soft: #fdecec;
  --warn-soft: #fff4e5;
  --warn: #8a4b00;
  --radius: 14px;
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
  color: var(--text);
  background: var(--ground);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 15px; margin: 8px 0 0; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  min-height: 40px; padding: 8px 12px; border: 1px solid #c9cfcb; border-radius: 10px; background: #fff; width: 100%;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { display: grid; place-items: center; min-height: 100vh; }
.empty { padding: 24px 12px; text-align: center; color: var(--muted); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.row-wrap { display: flex; gap: 10px; flex-wrap: wrap; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px;
  border-radius: 10px; border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none; background: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); color: #fff; }
.btn-outline { border-color: #c9cfcb; background: #fff; color: var(--text); }
.btn-outline:hover:not(:disabled) { background: #f6f7f5; color: var(--text); }
.btn-danger-outline { border-color: #e8b4ae; background: #fff; color: var(--danger); }
.btn-ghost { min-height: 40px; padding: 0 10px; color: var(--text); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.icon-btn { width: 44px; padding: 0; flex: none; }

/* shell */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap; padding: 10px 16px;
  background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 19px; margin: 0; }
.brand p { margin: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { padding: 8px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px; }
.tab:hover { background: #f3f4f1; color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent-dark); }
.topbar-end { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; flex-wrap: wrap; }
.project-select select { min-height: 38px; width: auto; max-width: 260px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; background: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-ok { background: #1f8a4c; }
.dot-live { background: #d97706; }
.page { padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 1500px; width: 100%; margin: 0 auto; }

/* cards, notices, forms */
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.notice { padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.6; }
.notice-info { background: #eef3f1; }
.notice-error { background: var(--danger-soft); color: #8a1c12; }
.notice-ok { background: var(--accent-soft); color: var(--accent-dark); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; }
.field-hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid > h2, .form-grid > h3, .form-grid > .notice, .span-all { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 18px; height: 18px; min-height: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 6px; }
.inline-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; min-width: 160px; }

/* badges */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--accent-soft); color: var(--accent-dark); }
.badge-muted { background: #f0f1ef; color: #4a545a; }
.badge-danger { background: var(--danger); color: #fff; }
.badge-warn { background: var(--danger-soft); color: #8a1c12; }
.badge-count { background: var(--accent); color: #fff; min-width: 20px; justify-content: center; }
.badge-project { background: #eef0f6; color: #34406b; }
.status-running { background: var(--accent-soft); color: var(--accent-dark); }
.status-paused { background: var(--warn-soft); color: var(--warn); }
.status-draft { background: #f0f1ef; color: #4a545a; }
.status-completed { background: #eef0f6; color: #34406b; }
.status-cancelled { background: var(--danger-soft); color: #8a1c12; }

/* overview */
.overview { display: flex; flex-direction: column; gap: 12px; }
.stats-skeleton { height: 180px; border-radius: var(--radius); background: #e9ece9; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.stat strong { font-size: 26px; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-sub { font-size: 12px; color: var(--muted); }
.campaign-bar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 16px 24px; }
.campaign-bar .grow { flex: 999 1 380px; display: flex; flex-direction: column; gap: 8px; }
.mini { display: flex; flex-direction: column; gap: 6px; font-size: 13px; flex: 1 1 200px; }
.progress { height: 10px; border-radius: 999px; background: #e9ece9; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .6s ease; }
.alert-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: 12px;
  background: var(--danger-soft); border: 1px solid #f3b8b3; color: #8a1c12;
}
.alert-bar > div { flex: 1 1 300px; }

/* inbox */
.inbox-page { max-width: none; }
.inbox {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; height: calc(100vh - 110px); min-height: 520px;
}
.conv-list { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); }
.conv-tools { padding: 12px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--border); }
.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-radius: 10px; background: var(--ground); color: var(--muted); }
.search input { border: 0; background: transparent; padding: 0; min-height: 40px; }
.search input:focus-visible { outline: none; }
.chips { display: flex; gap: 6px; }
.chip { flex: 1; min-height: 34px; border-radius: 999px; border: 1px solid #d5d9d6; background: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.conv-scroll { overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.conv {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 0; border-bottom: 1px solid #eef0ee;
  background: #fff; text-align: right; cursor: pointer;
}
.conv:hover { background: #f6f7f5; }
.conv.selected { background: #eef3f1; }
.avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.conv-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-time.unread { color: var(--accent); font-weight: 700; }
.conv-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.badges { display: flex; gap: 4px; flex: none; }
.sentinel { padding: 12px; text-align: center; font-size: 12px; color: var(--muted); min-height: 30px; }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-empty { display: grid; place-items: center; }
.chat-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.chat-name { font-weight: 700; }
.chat-head .back { display: none; }
.thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column-reverse; background: #f7f6f2; }
.thread-inner { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.bubble-wrap { display: flex; flex-direction: column; gap: 4px; max-width: min(560px, 82%); }
.bubble-wrap.out { align-self: flex-end; align-items: flex-start; }
.bubble-wrap.in { align-self: flex-start; }
.bubble { padding: 8px 12px 6px; border-radius: 14px; font-size: 14px; line-height: 1.7; }
.bubble.out { background: var(--accent-soft); border: 1px solid #cfe6dd; border-bottom-left-radius: 4px; }
.bubble.in { background: #fff; border: 1px solid var(--border); border-bottom-right-radius: 4px; }
.bubble.pending { opacity: .75; }
.bubble-tag { font-size: 11px; font-weight: 600; color: var(--accent-dark); }
.bubble-text { white-space: pre-line; overflow-wrap: anywhere; }
.bubble-meta { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: 11px; color: var(--muted); margin-top: 2px; }
.fail-note { font-size: 12px; color: var(--danger); }
.composer { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.compose-row { display: flex; align-items: flex-end; gap: 8px; }
.compose-row textarea { min-height: 44px; max-height: 140px; }
.tpl-panel { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 12px; background: #f7f6f2; border: 1px solid var(--border); }
.tpl-preview { white-space: pre-line; font-size: 14px; line-height: 1.7; background: #fff; border: 1px dashed #c9cfcb; border-radius: 10px; padding: 10px 12px; }

/* tables */
.table-card { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid #eef0ee; text-align: right; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbf9; white-space: nowrap; }
td.actions { white-space: nowrap; }
td.actions .btn + .btn { margin-inline-start: 6px; }
.card table th { background: transparent; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); gap: 14px; }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inbox { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 140px); }
  .inbox .chat { display: none; }
  .inbox.show-chat .conv-list { display: none; }
  .inbox.show-chat .chat { display: flex; }
  .chat-head .back { display: inline-flex; }
  .conv-list { border-left: 0; }
  .topbar-end { margin-inline-start: 0; }
  .topbar { position: static; padding: 8px 12px; gap: 8px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; width: 100%; }
  .tab { white-space: nowrap; }
  .project-select select { max-width: 200px; }
  .page { padding: 10px; }
}
@media (prefers-reduced-motion: reduce) { .progress-fill { transition: none; } }
