:root {
  /* ═══ Brand Colors — JB Studio (سماوي ثابت، خارج نطاق تحديث ألوان التصور) ═══ */
  --color-primary: #00d4e8;
  --color-primary-light: #33dded;
  --color-primary-dark: #00a8b8;
  --color-primary-glow: rgba(0, 212, 232, 0.15);

  /* ═══ Dark Background System — مطابقة لألوان التصور المقترح ═══ */
  --color-bg: #0c0e13;
  --color-surface: #151922;
  --color-bg-alt: #1b202b;
  --color-surface-hover: #1f2530;
  --color-border: #262c39;
  --color-border-accent: rgba(0, 212, 232, 0.25);

  /* ═══ Text Colors ═══ */
  --color-text: #eef0f4;
  --color-text-muted: #9aa2b4;
  --color-text-dim: #666e80;

  /* ═══ Status Colors ═══ */
  --color-danger: #d03b3b;
  --color-success: #0ca30c;
  --color-warning: #fab219;
  --color-neutral: #828a9c;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "IBM Plex Sans Arabic", Tahoma, sans-serif;
  direction: rtl;
  text-align: right;
  background: var(--color-bg);
  color: var(--color-text);
}

h1, h2, h3 {
  font-family: "Noto Kufi Arabic", "IBM Plex Sans Arabic", sans-serif;
  font-weight: 900;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar__brand {
  display: flex;
  align-items: center;
}

.topbar__logo {
  display: block;
  height: 34px;
  width: auto;
}

.topbar__nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.topbar__nav a {
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: 0.4rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar__nav a:hover {
  background: var(--color-primary-glow);
  color: var(--color-primary);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.3rem 0.35rem;
}

.user-chip__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-chip__avatar--fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-glow);
  color: var(--color-primary);
  font-size: 0.8rem;
  font-weight: 700;
}

.user-chip__name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
}

.user-chip__logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-bg-alt);
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.user-chip__logout:hover {
  background: var(--color-critical-soft);
  color: var(--color-danger);
}

.content {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.footer {
  flex-shrink: 0;
  text-align: center;
  padding: 1.5rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--color-border);
}

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

.page-placeholder {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  padding: 2rem;
}

/* صفحة تسجيل الدخول */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 212, 232, 0.12) 0%, transparent 60%),
    var(--color-bg);
}

.auth-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  padding: 3rem 2.5rem;
  text-align: center;
  max-width: 380px;
  width: 100%;
}

.auth-box h1 {
  font-size: 1.4rem;
  margin: 0 0 1.5rem;
  color: var(--color-primary);
}

.btn-discord {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem 1.5rem;
  background: #5865f2;
  color: #fff;
  border-radius: 0.5rem;
  text-decoration: none;
  font-weight: 700;
  transition: opacity 0.15s ease;
}

.btn-discord:hover {
  opacity: 0.9;
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.alert-error {
  background: var(--color-critical-soft);
  color: var(--color-danger);
  border: 1px solid rgba(208, 59, 59, 0.3);
}

/* شارات الحالة */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-not-started {
  background: var(--color-neutral-soft);
  color: var(--color-neutral);
}

.badge-in-progress {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.badge-delivered {
  background: var(--color-good-soft);
  color: var(--color-success);
}

.badge-unpaid {
  background: var(--color-critical-soft);
  color: var(--color-danger);
}

.badge-partial {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.badge-paid {
  background: var(--color-good-soft);
  color: var(--color-success);
}

.alert-success {
  background: var(--color-good-soft);
  color: var(--color-success);
  border: 1px solid rgba(12, 163, 12, 0.3);
}

/* إشعارات Toast — تحوّل .alert من شريط داخل الصفحة إلى إشعار عائم أعلى الشاشة يختفي تلقائياً */
.toast-container {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  width: calc(100% - 3rem);
  max-width: 420px;
}

.toast-container .alert {
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.25s ease both;
}

.toast-container .alert.toast-hide {
  animation: toastOut 0.25s ease both;
}

.toast-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
  opacity: 0.6;
  flex-shrink: 0;
}

.toast-close:hover {
  opacity: 1;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-12px);
  }
}

@media (max-width: 640px) {
  .toast-container {
    width: calc(100% - 2rem);
    max-width: none;
  }
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-header h2 {
  margin: 0;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
  transition: border-color 0.3s ease, background 0.3s ease;
}

.card h3 {
  margin-top: 0;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 0.6rem 0.5rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
}

.table td .small,
.table td .muted {
  white-space: normal;
}

.table th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.table tr:hover td {
  background: var(--color-surface-hover);
}

.table tr.row-late td {
  background: rgba(208, 59, 59, 0.07);
}

.small {
  font-size: 0.8rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  padding: 0.55rem 0.7rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--color-text);
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-grid .span-2 {
  grid-column: span 2;
}

.checkbox-inline {
  flex-direction: row !important;
  align-items: center;
  gap: 0.4rem !important;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid .span-2 {
    grid-column: span 1;
  }
}

.inline-form,
.filters-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.inline-form input,
.inline-form select,
.filters-form input,
.filters-form select {
  padding: 0.5rem 0.65rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--color-text);
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.btn-primary,
.btn-ghost,
.btn-danger {
  display: inline-block;
  padding: 0.55rem 1.1rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--color-primary);
  color: #000000;
}

.btn-primary:hover {
  background: var(--color-primary-light);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(0, 212, 232, 0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-border-accent);
  font-weight: 600;
}

.btn-ghost:hover {
  background: var(--color-primary-glow);
  border-color: var(--color-primary);
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
}

.btn-danger {
  background: var(--color-critical-soft);
  color: var(--color-danger);
  border: 1px solid rgba(208, 59, 59, 0.3);
}

.btn-danger:hover {
  background: rgba(208, 59, 59, 0.24);
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: none;
  padding: 0;
  font-family: inherit;
}

.btn-link-danger {
  color: var(--color-danger);
}

.delete-form {
  margin-top: 1.25rem;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: border-color 0.3s ease;
}

.stat-box__label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.stat-box__value {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--color-text);
}

.stat-box--highlight {
  border-color: var(--color-border-accent);
}

.stat-box--highlight .stat-box__value {
  color: var(--color-primary);
}

.stat-box--danger .stat-box__value {
  color: var(--color-danger);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.finance-grid {
  padding-top: 1rem;
  border-top: 1px dashed var(--color-border);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}

.activity-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}

/* ═══════════════════════════════════════════════════════
   لوحة تحكم — تصميم موسّع للرئيسية وصفحة المشاريع
   ═══════════════════════════════════════════════════════ */

/* خلفيات "soft" لألوان الحالة — مطابقة لدرجات الشفافية في التصور المقترح */
:root {
  --color-critical-soft: rgba(208, 59, 59, 0.16);
  --color-warning-soft: rgba(250, 178, 25, 0.18);
  --color-good-soft: rgba(12, 163, 12, 0.16);
  --color-neutral-soft: rgba(130, 138, 156, 0.16);
}

/* ── كروت KPI ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 900px) {
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .kpi-row {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 1rem;
  padding: 1.1rem 1.25rem;
  transition: border-color 0.3s ease;
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

.kpi-icon {
  width: 28px;
  height: 28px;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--color-text);
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.3rem;
}

/* ── شريط توزيع حالة المشاريع ── */
.stack-bar {
  display: flex;
  gap: 2px;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--color-bg-alt);
}

.stack-seg {
  height: 100%;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1rem;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.legend-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-row .lbl {
  flex: 1;
}

.legend-row .val {
  font-weight: 700;
  color: var(--color-text);
}

/* ── أشرطة تركيبة القيمة (ربح/حصص، مدفوع/متبقي) ── */
.comp-block + .comp-block {
  margin-top: 1.1rem;
}

.comp-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
}

.comp-labels b {
  color: var(--color-text);
  font-weight: 700;
}

.comp-bar {
  display: flex;
  gap: 2px;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  background: var(--color-bg-alt);
}

/* ── صف التحليلات: اتجاه الإيرادات + توزيع الحالة + تركيبة القيمة بصف واحد ── */
.analytics-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1.5rem;
}

.analytics-row .card {
  margin-bottom: 0;
}

@media (max-width: 1080px) {
  .analytics-row {
    grid-template-columns: 1fr;
  }
}

/* ── رسم اتجاه الإيرادات ── */
.trend-total {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--color-text);
}

.trend-total span {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-inline-start: 0.4rem;
}

.trend-wrap {
  position: relative;
  margin-top: 0.5rem;
}

#trendTooltip {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 5;
}

#trendTooltip b {
  display: block;
  font-size: 0.85rem;
  color: var(--color-text);
}

/* ── قائمة آخر التحديثات وأقرب المواعيد ── */
.feed-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .feed-row {
    grid-template-columns: 1fr;
  }
}

.feed-item {
  display: flex;
  gap: 0.65rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-border);
}

.feed-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.feed-ic {
  width: 26px;
  height: 26px;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.feed-text {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.feed-text b {
  color: var(--color-text);
  font-weight: 700;
}

.feed-time {
  font-size: 0.72rem;
  color: var(--color-text-dim);
  margin-top: 0.15rem;
}

.deadline-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-border);
}

.deadline-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.deadline-date {
  width: 48px;
  text-align: center;
  flex-shrink: 0;
  border-radius: 0.5rem;
  padding: 0.35rem 0;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
}

.deadline-date .d {
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--color-text);
}

.deadline-date .m {
  font-size: 0.62rem;
  color: var(--color-text-muted);
}

.deadline-main {
  flex: 1;
  min-width: 0;
}

.deadline-main a {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
}

.deadline-main a:hover {
  color: var(--color-primary);
}

.deadline-client {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-top: 0.1rem;
}

/* ── شارة إلحاح (تستخدمها deadline_urgency()) ── */
.urgency-chip {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 1rem;
  padding: 0.2rem 0.55rem;
  flex-shrink: 0;
  white-space: nowrap;
}

.urgency-critical {
  background: var(--color-critical-soft);
  color: var(--color-danger);
}

.urgency-warning {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.urgency-good {
  background: var(--color-good-soft);
  color: var(--color-success);
}

.urgency-neutral {
  background: var(--color-neutral-soft);
  color: var(--color-neutral);
}

/* ── فلاتر segmented (روابط عادية بدون JS) ── */
.seg-filters {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.seg {
  display: flex;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 0.6rem;
  padding: 3px;
  gap: 2px;
}

.seg a {
  display: inline-block;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 0.45rem;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg a:hover {
  color: var(--color-text);
}

.seg a.active {
  background: var(--color-primary);
  color: #000000;
}

/* ── جدول المشاريع الموسّع ── */
.row-stripe {
  box-shadow: inset 3px 0 0 0 var(--stripe-color);
}

.client-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.client-avatar {
  width: 22px;
  height: 22px;
  border-radius: 0.4rem;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.paid-track {
  width: 72px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-bg-alt);
  margin-top: 0.35rem;
  overflow: hidden;
}

.paid-fill {
  height: 100%;
  background: var(--color-success);
  border-radius: 2px;
}
