:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef0fb;
  --text: #1a1a2e;
  --muted: #6b7280;
  --line: #e0e0e0;
  --blue: #3B3BB8;
  --primary: #3B3BB8;
  --primary-dark: #2626A0;
  --primary-light: #EDEDFF;
  --brand-red: #E81C1C;
  --green: #11865b;
  --amber: #b7791f;
  --red: #c2413a;
  --shadow: 0 6px 18px rgba(38, 38, 160, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Cairo", "Tahoma", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: linear-gradient(160deg, #3B3BB8 0%, #2626A0 55%, #1a1a70 100%);
  color: #f8fafc;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #ffffff;
  color: var(--primary);
  font-weight: 800;
  overflow: hidden;
  flex: 0 0 auto;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-mark-fallback {
  display: none;
  font-size: 22px;
  color: var(--primary);
}

.user-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b8c4ce;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button,
.compact-nav button {
  width: 100%;
  border: 0;
  background: transparent;
  color: #d9e2ea;
  text-align: start;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.nav button.active,
.nav button:hover {
  background: #263541;
  color: #ffffff;
}

.compact-nav {
  display: none;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.compact-nav button {
  width: auto;
  flex: 0 0 auto;
  color: #34424e;
  background: #eef3f6;
  white-space: nowrap;
}

.compact-nav button.active,
.compact-nav button:hover {
  color: #ffffff;
  background: var(--blue);
}

.context-box {
  margin-top: auto;
  padding: 12px;
  border: 1px solid #324554;
  border-radius: 6px;
  color: #d9e2ea;
  font-size: 12px;
  line-height: 1.5;
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 92px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 26px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#view {
  padding: 18px 24px 36px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.panel-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.panel-body {
  padding: 18px;
}

.stat {
  padding: 18px;
}

.stat span {
  color: var(--muted);
  display: block;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 28px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.span-all {
  margin-top: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

label {
  font-weight: 650;
  color: #2f3b45;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.button {
  border: 0;
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 13px;
  font-weight: 700;
  cursor: pointer;
  background: var(--blue);
  color: #ffffff;
}

.button.secondary {
  background: #e9eef3;
  color: #24313a;
}

.button.danger {
  background: var(--red);
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 750;
}

.pill.neutral {
  background: #e9eef3;
  color: #394955;
}

.pill.ok {
  background: #dcf7eb;
  color: #0b704a;
}

.pill.warn {
  background: #fff4d6;
  color: #80580d;
}

.pill.bad {
  background: #fee2df;
  color: #9b2c25;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: start;
  vertical-align: top;
}

th {
  color: #40505c;
  background: #f0f4f7;
  font-size: 12px;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.notice {
  padding: 12px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: #34424e;
  line-height: 1.5;
}

.notice.warn {
  background: #fff7df;
  color: #7a530a;
}

.notice.ok-note {
  background: #e9f8f0;
  color: #0b704a;
}

.file-status {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  display: grid;
  align-content: center;
  gap: 4px;
  background: #f7fafc;
}

.file-status span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.file-status strong {
  overflow-wrap: anywhere;
}

.split-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.embed-banner {
  border: 1px solid var(--line);
  background: #eef6fb;
  color: #24313a;
  border-radius: 6px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.embed-banner.connected {
  background: #e9f8f0;
  border-color: #b9e6d2;
}

.embed-banner strong,
.embed-banner span {
  display: block;
}

.embed-banner span {
  margin-top: 3px;
  color: var(--muted);
}

.action-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
}

.action-panel {
  min-width: 0;
}

.action-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.action-card {
  min-height: 154px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
  border-radius: 6px;
  padding: 14px;
  text-align: start;
  cursor: pointer;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.action-card:hover,
.action-card.active {
  border-color: var(--blue);
  box-shadow: 0 8px 18px rgba(31, 117, 203, 0.15);
  transform: translateY(-1px);
}

.action-card span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  min-width: 58px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e7f1fb;
  color: #195e9f;
  font-size: 12px;
  font-weight: 800;
}

.action-card strong {
  display: block;
  margin-top: 14px;
  font-size: 16px;
}

.action-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.guide-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 18px;
  box-shadow: var(--shadow);
}

.guide-panel h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

.steps-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.steps-list li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  position: relative;
}

.steps-list li::before {
  content: counter(step);
  counter-increment: step;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e7f1fb;
  color: #195e9f;
  font-weight: 800;
  grid-row: 1 / span 2;
}

.steps-list {
  counter-reset: step;
}

.steps-list strong,
.steps-list span {
  display: block;
  grid-column: 2;
}

.steps-list span {
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.4;
}

.steps-list.compact {
  gap: 14px;
}

.guide-note {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.workflow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.workflow span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 10px;
  text-align: center;
  color: var(--muted);
  background: #f7fafc;
  font-weight: 800;
  font-size: 12px;
}

.workflow span.done {
  background: #e9f8f0;
  color: #0b704a;
  border-color: #b9e6d2;
}

.action-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.checkbox-field {
  margin-top: 14px;
}

.checkbox-field span {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.checkbox-field input {
  width: 16px;
  min-height: 16px;
}

.check-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  min-width: 0;
}

.check-header {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.check-header strong,
.check-header span {
  display: block;
}

.check-header span {
  color: var(--muted);
  font-size: 12px;
}

.check-list {
  max-height: 220px;
  overflow: auto;
  display: grid;
  gap: 2px;
  padding: 8px;
}

.check-list.no-max {
  max-height: none;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 6px;
  font-weight: 650;
}

.check-row:hover {
  background: var(--surface-soft);
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.sticky-actions {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #2f3b45;
}

body.embedded {
  background: #ffffff;
}

body.embedded .app-shell {
  min-height: 100vh;
  grid-template-columns: 1fr;
}

body.embedded .sidebar {
  display: none;
}

body.embedded .compact-nav {
  display: flex;
}

body.embedded .topbar {
  min-height: auto;
  padding: 12px;
}

body.embedded .topbar h1 {
  font-size: 20px;
}

body.embedded .topbar p {
  font-size: 13px;
}

body.embedded #view {
  padding: 12px;
}

body.embedded .topbar-actions {
  width: 100%;
  justify-content: space-between;
}

body.embedded .action-layout,
body.embedded .action-cards,
body.embedded .form-grid,
body.embedded .action-form,
body.embedded .grid.two,
body.embedded .grid.three {
  grid-template-columns: 1fr;
}

body.embedded .action-card {
  min-height: auto;
}

body.embedded .embed-banner {
  align-items: flex-start;
  flex-direction: column;
}

[dir="rtl"] .compact-nav {
  direction: rtl;
}

[dir="rtl"] .table-wrap {
  direction: rtl;
}

[dir="rtl"] input,
[dir="rtl"] select,
[dir="rtl"] textarea {
  direction: rtl;
}

[dir="rtl"] input[type="password"],
[dir="rtl"] input[type="url"],
[dir="rtl"] input#baseUrl,
[dir="rtl"] input#apiToken {
  direction: ltr;
  text-align: left;
}

[dir="rtl"] .steps-list li {
  grid-template-columns: minmax(0, 1fr) 28px;
}

[dir="rtl"] .steps-list li::before {
  grid-column: 2;
}

[dir="rtl"] .steps-list strong,
[dir="rtl"] .steps-list span {
  grid-column: 1;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .grid.two,
  .grid.three,
  .form-grid,
  .action-layout,
  .action-cards,
  .action-form,
  .workflow {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* ============================================================
   شاشة تسجيل الدخول (Chatwoot SSO)
   ============================================================ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(145deg, #3B3BB8 0%, #2626A0 55%, #1a1a70 100%);
}

.login-overlay[hidden] {
  display: none;
}

.login-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 80%, rgba(232, 28, 28, 0.18) 0%, transparent 55%),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.06) 0%, transparent 50%);
  pointer-events: none;
}

.login-box {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border-radius: 24px;
  padding: 40px 36px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.login-logo {
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-logo img {
  width: 84px;
  height: 84px;
  object-fit: contain;
}

.login-logo-fallback {
  display: none;
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  font-weight: 900;
  align-items: center;
  justify-content: center;
}

.login-logo-fallback span {
  color: var(--brand-red);
  font-size: 16px;
  margin-inline-start: 2px;
}

.login-box h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--text);
}

.login-subtitle {
  margin: 4px 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.login-cw-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 22px;
  padding: 5px 14px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(59, 59, 184, 0.15);
}

.login-err {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 13px;
}

.login-err[hidden] {
  display: none;
}

.login-field {
  text-align: start;
  margin-bottom: 14px;
}

.login-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.login-field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

.login-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 59, 184, 0.15);
}

.login-btn {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.login-btn:hover {
  background: var(--primary-dark);
}

.login-btn:disabled {
  opacity: 0.7;
  cursor: default;
}

.login-hint {
  margin: 14px 0 0;
  font-size: 11px;
  color: var(--muted);
}
