/* =====================================================================
   Tirhal-CRM — Modern SaaS design system (RTL, Arabic-first)
   Light, clean, orange-accented. Backend/markup class names preserved.
   ===================================================================== */

@font-face {
  font-family: "Thmanya";
  src: local("thmanyah Sans"), local("Thmanyah Sans"), local("Thmanya"), local("Thmanyah");
  font-display: swap;
}

:root {
  /* Brand */
  --orange: #f97316;
  --orange-strong: #ea580c;
  --orange-dark: #c2410c;
  --orange-soft: #fff2e6;
  --orange-line: #fed7aa;

  /* Accents */
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eef4ff;
  --green: #16a34a;
  --green-dark: #15803d;
  --green-soft: #e9f9ef;
  --red: #e11d48;
  --red-dark: #be123c;
  --red-soft: #fff1f3;

  /* Neutrals */
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #eaeef4;
  --line-2: #e2e8f0;
  --surface: #ffffff;
  --soft: #f8fafc;
  --soft-2: #f1f5f9;
  --page: #f5f7fb;

  /* Radii */
  --r-xs: 8px;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 18px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.07), 0 2px 6px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
  --ring: 0 0 0 4px rgba(249, 115, 22, 0.16);

  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Dark theme (system default + explicit toggle) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --orange-dark: #fb923c;
    --orange-strong: #fb923c;
    --orange-soft: #34220f;
    --orange-line: #6b3a17;
    --blue-dark: #93b4ff;
    --blue-soft: #16233c;
    --green-dark: #4ade80;
    --green-soft: #123020;
    --red: #fb7185;
    --red-dark: #fb7185;
    --red-soft: #351720;
    --ink: #e6eaf1;
    --ink-2: #c2cad8;
    --muted: #93a0b4;
    --faint: #64707f;
    --line: #262e3a;
    --line-2: #313a48;
    --surface: #161b23;
    --soft: #1b212b;
    --soft-2: #222935;
    --page: #0d1017;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
    --ring: 0 0 0 4px rgba(249, 115, 22, 0.28);
  }
}

:root[data-theme="dark"] {
  --orange-dark: #fb923c;
  --orange-strong: #fb923c;
  --orange-soft: #34220f;
  --orange-line: #6b3a17;
  --blue-dark: #93b4ff;
  --blue-soft: #16233c;
  --green-dark: #4ade80;
  --green-soft: #123020;
  --red: #fb7185;
  --red-dark: #fb7185;
  --red-soft: #351720;
  --ink: #e6eaf1;
  --ink-2: #c2cad8;
  --muted: #93a0b4;
  --faint: #64707f;
  --line: #262e3a;
  --line-2: #313a48;
  --surface: #161b23;
  --soft: #1b212b;
  --soft-2: #222935;
  --page: #0d1017;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.55);
  --ring: 0 0 0 4px rgba(249, 115, 22, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 100% -10%, rgba(249, 115, 22, 0.06), transparent 60%),
    radial-gradient(900px 480px at 0% 0%, rgba(37, 99, 235, 0.05), transparent 55%),
    var(--page);
  font-family: "Thmanya", "Segoe UI", Tahoma, Arial, sans-serif;
  font-weight: 400;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  white-space: nowrap;
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: var(--r-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--faint);
  background-clip: padding-box;
}

/* ---------- Shared typographic bits ---------- */
.eyebrow {
  margin: 0 0 6px;
  color: var(--orange-strong);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
}

.muted,
.panel-note,
.helper-text,
.empty-state,
.section-title span {
  color: var(--muted);
  font-size: 13px;
}

/* =====================================================================
   Login
   ===================================================================== */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 600px at 15% 10%, rgba(249, 115, 22, 0.16), transparent 55%),
    radial-gradient(900px 600px at 90% 90%, rgba(37, 99, 235, 0.14), transparent 55%),
    var(--page);
}

.login-card {
  width: min(430px, 100%);
  border-radius: var(--r-lg);
  padding: 40px 34px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card .brand-mark {
  margin: 0 auto 18px;
}

.login-card .eyebrow {
  text-align: center;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 800;
  margin: 0 0 22px;
  letter-spacing: -0.01em;
}

.login-card form {
  text-align: start;
}

.glass-panel {
  background: var(--surface);
}

/* =====================================================================
   Brand mark
   ===================================================================== */
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--orange), var(--orange-dark));
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  box-shadow: 0 8px 18px rgba(249, 115, 22, 0.32);
}

/* =====================================================================
   Forms
   ===================================================================== */
.stack {
  display: grid;
  gap: 16px;
}
.compact {
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  min-width: 0;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 11px 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  font-weight: 400;
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-inline-start: 13px;
  padding-inline-end: 36px;
}

textarea {
  resize: vertical;
  min-height: 96px;
  line-height: 1.7;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--faint);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--orange);
  box-shadow: var(--ring);
  background: var(--surface);
}

/* Buttons */
.primary-button,
.secondary-button,
.ghost-button,
.icon-button,
.quick-action {
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform var(--transition), box-shadow var(--transition),
    background var(--transition), border-color var(--transition), color var(--transition);
}

.primary-button {
  background: linear-gradient(140deg, var(--orange), var(--orange-strong));
  color: #fff;
  box-shadow: 0 8px 20px rgba(249, 115, 22, 0.28);
}
.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(249, 115, 22, 0.34);
}
.primary-button:active {
  transform: translateY(0);
}
.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.secondary-button {
  background: var(--surface);
  color: var(--ink-2);
  border-color: var(--line-2);
  box-shadow: var(--shadow-xs);
}
.secondary-button:hover {
  border-color: var(--orange-line);
  color: var(--orange-strong);
  background: var(--orange-soft);
}

.ghost-button {
  background: var(--soft-2);
  color: var(--ink-2);
  border-color: transparent;
}
.ghost-button:hover {
  background: var(--red-soft);
  color: var(--red-dark);
}

.icon-button {
  background: transparent;
  color: var(--red);
  border-color: var(--line-2);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
}
.icon-button:hover {
  background: var(--red-soft);
  border-color: var(--red-soft);
  color: var(--red-dark);
}

.quick-action {
  background: var(--surface);
  color: var(--orange-strong);
  border: 1px solid var(--orange-line);
  box-shadow: var(--shadow-xs);
}
.quick-action:hover {
  background: var(--orange-soft);
  transform: translateY(-1px);
}

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

.full {
  width: 100%;
}

/* =====================================================================
   App shell
   ===================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px 0;
}
.brand strong {
  display: block;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 4px;
  flex: 1;
  align-content: start;
  min-width: 0;
}

.nav-list .nav-section {
  margin: 12px 10px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--faint);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  transition: background var(--transition), color var(--transition);
}

.nav-item svg {
  width: 19px;
  height: 19px;
  flex: none;
  stroke: currentColor;
  opacity: 0.9;
}

.nav-item:hover {
  background: var(--soft-2);
  color: var(--ink);
}

.nav-item.active {
  background: var(--orange-soft);
  color: var(--orange-dark);
}
.nav-item.active svg {
  opacity: 1;
}
.nav-item.active::after {
  content: "";
  position: absolute;
  inset-inline-end: -18px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  border-radius: var(--r-pill);
  background: var(--orange);
}

.sidebar-footer {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px solid var(--line);
}
.user-card::before {
  content: "";
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--r-pill);
  background: linear-gradient(140deg, var(--orange), var(--blue));
  box-shadow: inset 0 0 0 2px #fff;
}
.user-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}
.user-card strong {
  display: block;
  font-weight: 700;
  font-size: 14px;
  margin-top: 1px;
}

/* =====================================================================
   Workspace + topbar
   ===================================================================== */
.workspace {
  width: 100%;
  max-width: 1360px;
  padding: 28px 30px 40px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 2px 22px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.25;
  font-weight: 800;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.topbar p:last-child {
  max-width: 640px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.topbar .eyebrow {
  color: var(--orange-strong);
}

/* Flash notices */
.notice-list {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.notice {
  position: relative;
  border-radius: var(--r-sm);
  padding: 13px 15px 13px 15px;
  padding-inline-start: 44px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  border: 1px solid rgba(37, 99, 235, 0.16);
  font-size: 14px;
  font-weight: 500;
}
.notice::before {
  content: "";
  position: absolute;
  inset-inline-start: 15px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E") center / contain no-repeat;
}
.notice.error {
  background: var(--red-soft);
  color: var(--red-dark);
  border-color: rgba(225, 29, 72, 0.18);
}
.notice.success {
  background: var(--green-soft);
  color: var(--green-dark);
  border-color: rgba(22, 163, 74, 0.18);
}
.notice.success::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}

/* =====================================================================
   Dashboard: metrics + quick grid
   ===================================================================== */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
  min-width: 0;
}

.metric-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}
.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.metric-card .metric-icon {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  background: var(--orange-soft);
  color: var(--orange-strong);
}
.metric-card .metric-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}
.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.metric-card strong {
  display: block;
  margin-top: 4px;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.accent-orange .metric-icon { background: var(--orange-soft); color: var(--orange-strong); }
.accent-blue .metric-icon { background: var(--blue-soft); color: var(--blue-dark); }
.accent-green .metric-icon { background: var(--green-soft); color: var(--green-dark); }
.accent-red .metric-icon { background: var(--red-soft); color: var(--red-dark); }

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.action-card {
  position: relative;
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 20px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.action-card .action-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  background: var(--orange-soft);
  color: var(--orange-strong);
  transition: background var(--transition), color var(--transition);
}
.action-card .action-icon svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
}
.action-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.action-card strong {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
}
.action-card::after {
  content: "";
  position: absolute;
  top: 22px;
  inset-inline-start: 20px;
  width: 18px;
  height: 18px;
  opacity: 0;
  transform: translateX(6px);
  background: var(--orange-strong);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5M12 5l-7 7 7 7'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5M12 5l-7 7 7 7'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: opacity var(--transition), transform var(--transition);
}
.action-card:hover {
  transform: translateY(-3px);
  border-color: var(--orange-line);
  box-shadow: var(--shadow);
}
.action-card:hover .action-icon {
  background: linear-gradient(140deg, var(--orange), var(--orange-strong));
  color: #fff;
}
.action-card:hover::after {
  opacity: 1;
  transform: translateX(0);
}

/* =====================================================================
   Panels + layout grids
   ===================================================================== */
.operations-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  align-items: start;
  min-width: 0;
}

.primary-column,
.side-column {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.panel-heading .eyebrow {
  margin-bottom: 3px;
}
.panel-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.panel-note {
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: var(--soft-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.workflow-panel,
.composer-panel {
  border-top: none;
}
.compact-panel {
  padding: 20px;
}

/* Upload */
.upload-box {
  display: grid;
  gap: 14px;
}

.file-drop {
  position: relative;
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
  min-height: 150px;
  align-content: center;
  padding: 24px;
  border: 1.5px dashed var(--orange-line);
  border-radius: var(--r);
  background: linear-gradient(var(--orange-soft), var(--orange-soft)) padding-box, var(--surface);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.file-drop:hover {
  border-color: var(--orange);
  background: #fff7ee;
}
.file-drop > span:first-of-type {
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
}
.file-drop small {
  color: var(--muted);
  line-height: 1.7;
  max-width: 340px;
}
.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.file-picker {
  margin-top: 6px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--orange-line);
  color: var(--orange-strong);
  font-size: 13px;
  font-weight: 700;
}

.upload-insights {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}
.compact-insights {
  grid-template-columns: 1fr 1fr;
}
.upload-insights div {
  padding: 12px 13px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px solid var(--line);
  min-width: 0;
}
.upload-insights span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
}
.upload-insights strong {
  display: block;
  overflow: hidden;
  font-weight: 700;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.compact-insights div:first-child {
  grid-column: 1 / -1;
}

.variables-box {
  margin-top: 14px;
  padding: 15px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px solid var(--line);
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.section-title strong {
  font-weight: 700;
  font-size: 14px;
}
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.variables-box .chip-list {
  max-height: 160px;
  overflow: auto;
}
.chip {
  border: 1px solid var(--orange-line);
  background: var(--surface);
  color: var(--orange-strong);
  border-radius: var(--r-pill);
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
}
.chip:hover {
  background: var(--orange-soft);
  transform: translateY(-1px);
}

/* Form grids */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.wide-field,
.form-actions {
  grid-column: 1 / -1;
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.check-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--ink-2);
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px solid var(--line);
}
.check-row input {
  width: 18px;
  height: 18px;
  flex: none;
  accent-color: var(--orange);
  cursor: pointer;
}

/* Lists */
.item-list {
  display: grid;
  gap: 10px;
  margin-top: 4px;
  max-height: 360px;
  overflow: auto;
  padding-inline-end: 2px;
}
.item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px solid var(--line);
  transition: border-color var(--transition), background var(--transition);
}
.item:hover {
  border-color: var(--line-2);
  background: var(--surface);
}
.item strong {
  font-weight: 700;
  font-size: 14px;
}
.item p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tight .item {
  align-items: center;
  padding: 10px 13px;
}
.tight .item strong {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.empty-state {
  margin: 4px 0 0;
  padding: 20px 16px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px dashed var(--line-2);
  text-align: center;
  color: var(--muted);
}
.compact-empty {
  margin-top: 4px;
}
.helper-text {
  color: var(--muted);
}

/* =====================================================================
   Admins
   ===================================================================== */
.admin-panel {
  min-width: 0;
}
.admin-layout {
  display: grid;
  grid-template-columns: minmax(340px, 0.8fr) minmax(0, 1.2fr);
  gap: 20px;
  align-items: start;
}
.admin-create,
.admin-directory,
.admin-card {
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.admin-create,
.admin-directory {
  padding: 20px;
}
.admin-create {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 18px;
}
.admin-form-head,
.admin-directory-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.admin-form-head h2,
.admin-directory-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.35;
  font-weight: 800;
}
.admin-form-section,
.admin-card-section {
  display: grid;
  gap: 12px;
  min-width: 0;
}
.admin-list {
  display: grid;
  gap: 12px;
  max-height: 760px;
  overflow: auto;
  padding-inline-end: 2px;
}
.admin-card {
  display: grid;
  gap: 16px;
  padding: 16px;
  border-radius: var(--r-sm);
  background: var(--soft);
  box-shadow: var(--shadow-xs);
}
.admin-card:hover {
  border-color: var(--line-2);
  background: var(--surface);
}
.admin-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.admin-identity {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.admin-avatar {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: linear-gradient(140deg, var(--orange), var(--blue));
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
}
.admin-card-head strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-weight: 800;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-card-head span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-card .form-grid {
  gap: 12px;
}
.admin-card .form-actions,
.admin-create .form-actions {
  justify-content: flex-end;
  margin-top: 0;
}

.permissions-field {
  display: grid;
  gap: 12px;
}
.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.permission-check {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--line-2);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition), box-shadow var(--transition);
}
.permission-check:hover {
  border-color: var(--orange-line);
}
.permission-check:has(input:checked) {
  background: var(--orange-soft);
  border-color: var(--orange-line);
  color: var(--orange-dark);
}
.permission-check:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.78;
}
.permission-check input {
  width: 17px;
  height: 17px;
  flex: none;
  accent-color: var(--orange);
  cursor: pointer;
}
.permission-check input:disabled {
  cursor: not-allowed;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 58px;
  border-radius: var(--r-pill);
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 700;
}
.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: currentColor;
}
.status-pill.owner {
  color: var(--orange-dark);
  background: var(--orange-soft);
}
.status-pill.active {
  color: var(--green-dark);
  background: var(--green-soft);
}
.status-pill.inactive {
  color: var(--red-dark);
  background: var(--red-soft);
}

/* =====================================================================
   Tables (history)
   ===================================================================== */
.history-panel {
  padding: 8px;
}
.history-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: var(--r-xs);
  background: var(--surface);
  color: var(--orange-strong);
  border: 1px solid var(--orange-line);
  font-size: 12px;
  font-weight: 700;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.mini-button:hover {
  background: var(--orange-soft);
  border-color: var(--orange);
}
.campaign-tracker {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
  padding: 20px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.tracker-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.tracker-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.35;
  font-weight: 800;
}
.tracker-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.stop-button {
  border: 1px solid var(--red);
  background: var(--red-soft);
  color: var(--red-dark);
  border-radius: var(--r-sm);
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.stop-button:hover {
  background: var(--red);
  color: #fff;
}
/* Live pulse on an actively-sending campaign */
.tracker-head .status.running::before,
.tracker-head .status.sending::before {
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.tracker-progress {
  display: grid;
  gap: 9px;
}
.tracker-progress-meta,
.tracker-time {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  flex-wrap: wrap;
}
.tracker-progress-meta strong {
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
}
.tracker-time strong {
  color: var(--ink-2);
}
.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--soft-2);
  border: 1px solid var(--line);
}
.progress-track.mini {
  height: 7px;
  min-width: 96px;
}
.progress-fill {
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--orange), var(--green));
  transition: width var(--transition);
}
.tracker-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.tracker-grid div {
  padding: 12px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px solid var(--line);
  min-width: 0;
}
.tracker-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.tracker-grid strong {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.2;
  font-weight: 800;
}
.tracking-lists {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.tracking-list {
  padding: 16px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.tracking-list.sent {
  border-color: rgba(22, 163, 74, 0.22);
}
.tracking-list.failed {
  border-color: rgba(225, 29, 72, 0.22);
}
.table-progress {
  display: grid;
  gap: 6px;
  min-width: 120px;
}
.table-progress span {
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 800;
}
.campaign-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.campaign-summary div,
.result-list {
  padding: 16px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.campaign-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.campaign-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 800;
  color: var(--ink);
}
.result-lists {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.result-list.sent {
  border-color: rgba(22, 163, 74, 0.22);
}
.result-list.failed {
  border-color: rgba(225, 29, 72, 0.22);
}
.result-list.skipped {
  border-color: rgba(249, 115, 22, 0.24);
}
.number-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}
.number-item {
  display: grid;
  gap: 3px;
  padding: 10px 11px;
  border-radius: var(--r-xs);
  background: var(--soft);
  border: 1px solid var(--line);
  min-width: 0;
}
.number-item strong {
  direction: ltr;
  text-align: right;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}
.number-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  word-break: break-word;
}
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  border-radius: var(--r);
}
table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  direction: rtl;
}
th,
td {
  text-align: right;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--soft);
  position: sticky;
  top: 0;
}
th:first-child { border-start-start-radius: var(--r); }
th:last-child { border-start-end-radius: var(--r); }
tbody tr {
  transition: background var(--transition);
}
tbody tr:hover {
  background: var(--soft);
}
tbody tr:last-child td {
  border-bottom: none;
}
td {
  font-variant-numeric: tabular-nums;
}
td:first-child {
  font-weight: 600;
  color: var(--ink);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 76px;
  border-radius: var(--r-pill);
  padding: 5px 11px;
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 700;
}
.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: var(--r-pill);
  background: currentColor;
}
.status.completed {
  background: var(--green-soft);
  color: var(--green-dark);
}
.status.sent {
  background: var(--green-soft);
  color: var(--green-dark);
}
.status.failed,
.status.cancelled {
  background: var(--red-soft);
  color: var(--red-dark);
}
.status.running,
.status.sending,
.status.queued,
.status.draft,
.status.skipped,
.status.paused {
  background: var(--orange-soft);
  color: var(--orange-dark);
}

/* =====================================================================
   Character counter (progressive enhancement)
   ===================================================================== */
.char-counter {
  justify-self: end;
  margin-top: -4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.char-counter.near {
  color: var(--orange-strong);
}

/* =====================================================================
   Theme toggle
   ===================================================================== */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  background: var(--soft);
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.theme-toggle:hover {
  border-color: var(--orange-line);
  color: var(--orange-strong);
}
.theme-toggle svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
}
.theme-toggle .theme-toggle-moon {
  display: none;
}
:root[data-theme="dark"] .theme-toggle .theme-toggle-sun {
  display: none;
}
:root[data-theme="dark"] .theme-toggle .theme-toggle-moon {
  display: inline;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .theme-toggle-sun {
    display: none;
  }
  :root:not([data-theme="light"]) .theme-toggle .theme-toggle-moon {
    display: inline;
  }
}

/* =====================================================================
   Flash notice enter / auto-dismiss
   ===================================================================== */
@keyframes notice-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.notice {
  animation: notice-in 220ms cubic-bezier(0.4, 0, 0.2, 1);
}
.notice.dismissing {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 320ms ease, transform 320ms ease;
}

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-inline-start: 0;
    border-bottom: 1px solid var(--line);
    gap: 18px;
  }
  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .nav-item.active::after {
    display: none;
  }
  .nav-section {
    display: none;
  }
  .sidebar-footer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  .operations-grid {
    grid-template-columns: 1fr;
  }
  .admin-layout {
    grid-template-columns: 1fr;
  }
  .admin-create {
    position: static;
  }
}

@media (max-width: 820px) {
  .workspace {
    padding: 20px 18px 32px;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .topbar h1 {
    font-size: 23px;
  }
  .metrics-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .campaign-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .tracker-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .tracking-lists {
    grid-template-columns: 1fr;
  }
  .result-lists {
    grid-template-columns: 1fr;
  }
  .quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid,
  .upload-insights,
  .compact-insights {
    grid-template-columns: 1fr;
  }
  .compact-insights div:first-child,
  .upload-insights div:first-child {
    grid-column: auto;
  }
  .panel-heading {
    flex-direction: column;
    align-items: flex-start;
  }
  .admin-create,
  .admin-directory {
    padding: 18px;
  }
  .admin-form-head,
  .admin-directory-head {
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .sidebar {
    padding: 14px;
  }
  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .nav-item {
    justify-content: flex-start;
    min-height: 42px;
  }
  .topbar h1 {
    font-size: 21px;
  }
  .metrics-strip {
    grid-template-columns: 1fr 1fr;
  }
  .campaign-summary {
    grid-template-columns: 1fr;
  }
  .campaign-tracker {
    padding: 18px;
  }
  .tracker-head {
    flex-direction: column;
  }
  .tracker-grid {
    grid-template-columns: 1fr;
  }
  .quick-grid {
    grid-template-columns: 1fr;
  }
  .panel {
    padding: 18px;
  }
  .permission-grid {
    grid-template-columns: 1fr;
  }
  .form-actions .primary-button,
  .form-actions .secondary-button {
    width: 100%;
  }
  .quick-action,
  .ghost-button {
    width: 100%;
  }
  .login-card {
    padding: 30px 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
