/*
   =========================================
   رصدان — أداة صاحب الحلال اليومية
   الإصدار 3.0 — تصميم احترافي متكامل
   =========================================
*/

/* ===== Design Tokens (ثابتة) ===== */
:root {
  --font:           'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      18px;
  --radius-xl:      28px;
  --nav-h:          72px;
  --header-h:       64px;
  --sidebar-w:      268px;
  --success:        #10b981;
  --danger:         #ef4444;
  --danger-soft:    #fee2e2;
  --warning:        #f59e0b;
  --info:           #3b82f6;
  --whatsapp:       #25d366;
  --gold:           #b5893b;
  --gold-soft:      #f3e9d4;
  --surface-muted:  #f8fafc;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:      0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg:      0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
  --shadow-xl:      0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}

/* ===== متغيرات التصميم — الوضع النهاري ===== */
:root, [data-theme="light"] {
  --emerald:        #b87a64;
  --emerald-mid:    #a57f60;
  --emerald-light:  #d8a08c;
  --emerald-glow:   rgba(184, 122, 100, 0.16);
  --emerald-soft:   #f1ddd3;
  --wheat:          #8c5a45;
  --wheat-soft:     #f3e6de;
  --slate:          #3f2f27;
  --slate-mid:      #5b463a;
  --slate-light:    #8b7262;
  --slate-faint:    #a99487;
  --bg-main:        #f8f3ee;
  --bg-card:        #fdfbfa;
  --bg-glass:       rgba(253,251,250,0.9);
  --text-primary:   #3f2f27;
  --text-secondary: #8b7262;
  --border-color:   #e8d9cd;
  --sidebar-bg:     #fdfbfa;
  --topbar-bg:      #fdfbfa;
  --login-bg:       radial-gradient(ellipse at top right, #b87a64, #8c5a45 60%);
  --surface-muted:  #f4ece6;
  --field-bg:       #fafbfc;
  --field-border:   #e2e8f0;
  --field-hover:    #f8fafc;
  --surface-elev:   #f1f5f9;
  --glass-border:   1px solid rgba(255,255,255,0.5);
  --border:         1px solid var(--border-color);
}

/* ===== الوضع الليلي — نفس الهوية ===== */
[data-theme="dark"] {
  --emerald:        #d8a08c;
  --emerald-mid:    #b87a64;
  --emerald-light:  #e5b8a4;
  --emerald-glow:   rgba(216, 160, 140, 0.2);
  --emerald-soft:   #4f3328;
  --wheat:          #f0c7b4;
  --wheat-soft:     #4f3328;
  --slate:          #f8f3ee;
  --slate-mid:      #eadfd7;
  --slate-light:    #c8b7ac;
  --slate-faint:    #a88f81;
  --bg-main:        #1f1512;
  --bg-card:        #2b1d18;
  --bg-glass:       rgba(43, 29, 24, 0.9);
  --text-primary:   #f8f3ee;
  --text-secondary: #c8b7ac;
  --border-color:   #4b3329;
  --sidebar-bg:     #261a15;
  --topbar-bg:      #2b1d18;
  --login-bg:       radial-gradient(ellipse at top right, #a57f60, #3a251d 60%);
  --surface-muted:  #35241d;
  --field-bg:       #2c1e18;
  --field-border:   #5a3e33;
  --field-hover:    #38261f;
  --surface-elev:   #3a281f;
  --glass-border:   1px solid rgba(255,255,255,0.5);
  --border:         1px solid var(--border-color);
}

/* ===== أساسيات ===== */
*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-main);
  color: var(--text-primary);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }
.btn-login,
button,
input,
select,
textarea {
  font-family: var(--font);
}
.hidden { display: none !important; }
.required { color: var(--danger); }

/* ===== الأنيميشن ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes toastIn {
  0%   { opacity: 0; transform: translateX(-50%) translateY(16px); }
  12%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  88%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-12px); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== شاشة الدخول ===== */
.btn-theme-login {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.btn-theme-login:hover {
  background: rgba(255,255,255,0.35);
  transform: scale(1.05);
}

#screen-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--login-bg);
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-bg::before, .login-bg::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: var(--emerald-light);
  filter: blur(120px);
  opacity: 0.08;
}
.login-bg::before { width: 600px; height: 600px; top: -250px; right: -200px; }
.login-bg::after  { width: 500px; height: 500px; bottom: -200px; left: -150px; }

.login-container {
  width: 100%;
  max-width: 420px;
  z-index: 10;
  animation: fadeInScale 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-brand {
  text-align: center;
  margin-bottom: 36px;
  color: white;
}

.login-logo {
  height: 80px;
  width: auto;
  max-width: 200px;
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
  object-fit: contain;
}

.login-brand h1 {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 8px;
}

.login-brand p {
  opacity: 0.75;
  font-size: 15px;
  font-weight: 500;
}

.login-card {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.6);
  padding: 40px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(255,255,255,0.1);
}

.login-card h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 12px;
  text-align: center;
  color: var(--slate);
}

.login-hint {
  font-size: 13px;
  color: var(--slate-light);
  text-align: center;
  margin-bottom: 20px;
  font-weight: 600;
}

.login-note {
  font-size: 11px;
  color: rgba(255,255,255,0.35);
  text-align: center;
  margin-top: 12px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.install-prompt {
  background: var(--emerald-soft);
  border: 1px solid rgba(184,122,100,0.28);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.install-prompt span {
  font-size: 12px;
  font-weight: 700;
  color: var(--emerald);
}

.btn-install-app {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--emerald);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-install-app:hover {
  background: var(--emerald-mid);
  transform: translateY(-1px);
}

.login-footer {
  text-align: center;
  color: rgba(255,255,255,0.4);
  font-size: 12px;
  margin-top: 20px;
}

.input-group {
  margin-bottom: 18px;
  position: relative;
}

.input-group i {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate-light);
  font-size: 17px;
  z-index: 1;
}

.input-group input {
  width: 100%;
  padding: 15px 46px 15px 18px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--field-border);
  background: var(--field-bg);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: all 0.25s;
  color: var(--slate);
}

.input-group input:focus {
  border-color: var(--emerald-light);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px var(--emerald-glow);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  text-align: center;
  min-height: 20px;
}

/* ===== أزرار رئيسية ===== */
.btn-login {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
  color: white;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(184,122,100,0.35);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-login:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(184,122,100,0.45);
}

.btn-login:active { transform: translateY(0); }
.btn-login:disabled { opacity: 0.7; transform: none; cursor: not-allowed; }

.btn-submit-main {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 40px;
  padding: 18px 32px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
  color: white;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(184,122,100,0.35);
  transition: all 0.3s ease;
}

.btn-submit-main:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(184,122,100,0.45);
}

.btn-cancel {
  flex: 1;
  padding: 14px;
  border: 1.5px solid var(--field-border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--slate-light);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel:hover { background: var(--field-hover); color: var(--slate); }

/* ===== هيكل التطبيق ===== */
#app {
  display: flex;
  min-height: 100vh;
}

/* ===== الشريط الجانبي ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-left: var(--border);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px 28px;
  border-bottom: var(--border);
  margin-bottom: 20px;
}

.sidebar-logo-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 26px;
  background: var(--emerald-glow);
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px;
  border: 1px solid var(--emerald-soft);
  flex-shrink: 0;
}

.sidebar-brand h2 {
  font-size: 21px;
  font-weight: 900;
  color: var(--emerald);
  line-height: 1;
}

.sidebar-tagline {
  font-size: 11px;
  color: var(--slate-light);
  font-weight: 500;
  margin-top: 3px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 800;
  color: var(--slate-faint);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0 12px 10px;
}

.nav-list { flex: 1; }
.nav-item { margin-bottom: 4px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--slate-mid);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
}

.nav-link i { font-size: 18px; }
.nav-link .nav-sheep { font-size: 18px; line-height: 1; }

.nav-link:hover {
  background: var(--bg-main);
  color: var(--emerald);
}

.nav-active {
  background: var(--emerald-glow) !important;
  color: var(--emerald) !important;
  font-weight: 700;
}

.btn-add-floating {
  background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
  color: white;
  border: none;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 14px;
  font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer;
  margin-top: 20px;
  box-shadow: 0 4px 12px rgba(184,122,100,0.25);
  transition: all 0.3s;
}

.btn-add-floating:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(184,122,100,0.35);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: var(--border);
}

.sidebar-export-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
  color: #fff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 6px 16px rgba(184,122,100,0.28);
}

.sidebar-export-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow: 0 10px 20px rgba(184,122,100,0.36);
}

.sidebar-plain-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  text-decoration: none;
  color: var(--slate-light);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 4px 2px;
  background: transparent;
  border: none;
  transition: color 0.2s ease, transform 0.2s ease;
}

.sidebar-plain-link:hover {
  color: var(--emerald);
  transform: translateY(-1px);
}

/* ===== المحتوى الرئيسي ===== */
.main-wrapper {
  flex: 1;
  background: var(--bg-main);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.top-bar {
  height: var(--header-h);
  background: var(--topbar-bg);
  border-bottom: var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.page-title-main {
  font-size: 19px;
  font-weight: 800;
  color: var(--slate);
}

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--emerald-glow);
  color: var(--emerald);
  padding: 7px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid var(--emerald-soft);
}

.btn-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--surface-muted);
  color: var(--slate-light);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}

.btn-icon:hover { background: var(--gold-soft); color: var(--slate); }
.btn-icon-danger:hover { background: var(--danger-soft) !important; color: var(--danger) !important; }

#content {
  padding: 28px 32px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

/* ===== الصفحات (Views) — إصلاح حرج ===== */
.view { display: none; }
.view.active {
  display: block;
  animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ===== لوحة التحكم ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 36px;
}

.widget-card {
  background: var(--bg-card);
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: var(--border);
  display: flex;
  align-items: center;
  gap: 20px;
  transition: all 0.3s;
}

.widget-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.widget-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.wc-1 .widget-icon { background: rgba(184,122,100,0.14); color: var(--emerald); }
.wc-2 .widget-icon { background: rgba(30,41,59,0.08); color: var(--slate-mid); }
.wc-3 .widget-icon { background: rgba(181,137,59,0.12); color: var(--gold); }
.wc-4 .widget-icon {
  background: rgba(51,65,85,0.12);
  color: var(--slate-mid);
}

.widget-info { flex: 1; min-width: 0; }

.widget-val {
  font-size: 26px;
  font-weight: 900;
  color: var(--slate);
  letter-spacing: -0.5px;
  line-height: 1.15;
}

.widget-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-light);
  margin-top: 4px;
}

.section-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--slate);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title i { color: var(--wheat); }

/* ===== شبكة الخراف ===== */
.sheep-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.sheep-premium-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: var(--border);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.sheep-premium-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(181,137,59,0.35);
}

.card-img-wrapper {
  height: 260px;
  position: relative;
  background: var(--surface-elev);
  overflow: hidden;
}

.card-img-wrapper img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.sheep-premium-card:hover .card-img-wrapper img {
  transform: scale(1.04);
}

.card-img-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 72px;
  background: linear-gradient(135deg, var(--surface-elev), var(--field-border));
}

.card-video-badge {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.65);
  color: white;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  backdrop-filter: blur(4px);
}

.status-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(8px);
  color: white;
}

.status-for-sale { background: rgba(184,122,100,0.9); }
.status-reserved { background: rgba(217,119,6,0.9); }
.status-sold     { background: rgba(100,116,139,0.85); }

.card-content { padding: 18px 20px 20px; }

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
  gap: 8px;
}

.card-name {
  font-size: 17px;
  font-weight: 800;
  color: var(--slate);
  line-height: 1.3;
}

.card-price {
  font-size: 17px;
  font-weight: 900;
  color: var(--emerald);
  white-space: nowrap;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.meta-chip {
  background: var(--bg-main);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-mid);
  border: var(--border);
}

.card-profit-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: var(--border);
  font-size: 13px;
}

.text-profit { color: var(--success) !important; }
.text-loss   { color: var(--danger) !important; }

/* ===== شريط البحث ===== */
.search-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--bg-card);
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.search-input-wrap {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-input-wrap i {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate-faint);
  font-size: 16px;
}

.search-input-wrap input {
  width: 100%;
  padding: 11px 42px 11px 16px;
  border: 1.5px solid var(--field-border);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: all 0.2s;
  background: var(--field-bg);
}

.search-input-wrap input:focus {
  border-color: var(--emerald-light);
  box-shadow: 0 0 0 3px var(--emerald-glow);
  background: var(--bg-card);
}

.search-bar select {
  padding: 11px 14px;
  border: 1.5px solid var(--field-border);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--slate);
  background: var(--field-bg);
  outline: none;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 130px;
}

.search-bar select:focus {
  border-color: var(--emerald-light);
  box-shadow: 0 0 0 3px var(--emerald-glow);
}

.flock-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--slate-light);
  margin-bottom: 16px;
  padding: 0 4px;
}

/* ===== الحالة الفارغة ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--slate-light);
}

.empty-state p {
  font-size: 18px;
  font-weight: 700;
  margin: 16px 0 8px;
  color: var(--slate-mid);
}

.empty-state small {
  font-size: 14px;
  display: block;
  margin-bottom: 24px;
}

.btn-add-empty {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--emerald-glow);
  color: var(--emerald);
  border: 1.5px solid var(--emerald-soft);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-add-empty:hover { background: var(--emerald-soft); }

/* ===== نموذج الإضافة ===== */
.add-view-actions {
  max-width: 820px;
  margin: 0 auto 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-start;
}

.btn-add-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--slate);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-add-nav:hover {
  background: var(--field-hover);
}

.btn-add-reset {
  color: var(--wheat);
}

.form-container {
  max-width: 820px;
  margin: 0 auto;
  display: grid;
  gap: 28px;
}

.form-segment {
  background: var(--bg-card);
  padding: 36px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: var(--border);
}

.segment-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--emerald);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: var(--border);
}

.form-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.costs-grid {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.form-field { margin-bottom: 20px; }
.form-field:last-child { margin-bottom: 0; }

.form-field label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--slate-mid);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid var(--field-border);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  color: var(--slate);
  transition: all 0.2s;
  background: var(--field-bg);
  outline: none;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--emerald-light);
  box-shadow: 0 0 0 4px var(--emerald-glow);
  background: var(--bg-card);
}

.form-field textarea { resize: vertical; line-height: 1.6; }

.cost-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-main);
  border-radius: var(--radius-md);
  margin-top: 4px;
  border: var(--border);
}

.cost-total-row span:first-child {
  font-weight: 700;
  color: var(--slate-light);
  font-size: 14px;
}

.cost-total-val {
  font-size: 22px;
  font-weight: 900;
  color: var(--emerald);
}

/* ===== رفع الوسائط ===== */
.media-upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.upload-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--slate-mid);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-optional {
  background: var(--bg-main);
  color: var(--slate-faint);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  border: var(--border);
}

.upload-area {
  border: 2px dashed var(--field-border);
  border-radius: var(--radius-lg);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--field-bg);
  transition: all 0.25s;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.upload-area:hover {
  border-color: var(--emerald-light);
  background: var(--emerald-glow);
}

.upload-area p {
  font-weight: 700;
  font-size: 14px;
  color: var(--slate-mid);
  margin: 8px 0 4px;
}

.upload-area small {
  font-size: 11px;
  color: var(--slate-faint);
}

.upload-icon {
  font-size: 36px;
  color: var(--slate-faint);
}

.upload-area img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius-lg) - 4px);
}

.upload-area video {
  width: 100%;
  max-height: 180px;
  border-radius: calc(var(--radius-lg) - 4px);
}

.upload-progress {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--field-border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--emerald), var(--emerald-light));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.upload-progress span {
  font-size: 12px;
  font-weight: 700;
  color: var(--slate-light);
  white-space: nowrap;
}

.images-gallery-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}

.image-thumb-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  height: 90px;
}

.image-thumb-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-thumb-remove {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(22, 12, 8, 0.76);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

/* ===== نافذة التفاصيل / المودال ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeInScale 0.25s ease;
}

.modal-content {
  background: var(--bg-card);
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius-xl);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: fadeInUp 0.35s cubic-bezier(0.16,1,0.3,1);
}

.modal-large { max-width: 680px; }

.modal-header {
  padding: 22px 28px;
  border-bottom: var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 10;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal-title-text {
  font-size: 18px;
  font-weight: 900;
  color: var(--slate);
}

.modal-close-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--bg-main);
  color: var(--slate-light);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.2s;
}

.modal-close-btn:hover { background: var(--danger-soft); color: var(--danger); }

.modal-body { padding: 28px; }

.modal-footer {
  padding: 20px 28px;
  border-top: var(--border);
  background: var(--field-bg);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.confirm-modal-content {
  max-width: 460px;
}

.confirm-message-text {
  font-size: 16px;
  line-height: 1.8;
  color: var(--slate);
  font-weight: 600;
  text-align: right;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-actions .btn-cancel,
.confirm-actions .btn-login {
  flex: 1;
}

/* ===== تفاصيل الخروف داخل المودال ===== */
.detail-media {
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
  background: var(--bg-main);
  position: relative;
}

.detail-media img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
}

.detail-media video {
  width: 100%;
  max-height: 280px;
  display: block;
  background: black;
}

.detail-media-tabs {
  display: flex;
  gap: 2px;
  padding: 8px;
  background: var(--bg-main);
}

.media-tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-light);
  cursor: pointer;
  transition: all 0.2s;
}

.media-tab-btn.active {
  background: var(--bg-card);
  color: var(--emerald);
  box-shadow: var(--shadow-sm);
}

.detail-placeholder {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 80px;
}

.detail-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-item {
  background: var(--bg-main);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: var(--border);
}

.detail-item .di-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--slate-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-item .di-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--slate);
}

.detail-costs-box {
  background: var(--bg-main);
  padding: 18px;
  border-radius: var(--radius-md);
  border: var(--border);
  margin-bottom: 16px;
}

.detail-costs-box .dcb-title {
  font-weight: 800;
  color: var(--emerald);
  margin-bottom: 12px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-costs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 13px;
  color: var(--slate-mid);
  margin-bottom: 12px;
}

.detail-costs-total {
  padding-top: 12px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 15px;
}

.detail-sale-box {
  background: rgba(59,130,246,0.05);
  border: 1px solid rgba(59,130,246,0.15);
  padding: 18px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.detail-notes-box {
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  color: var(--slate-mid);
}

/* ===== أزرار التفاصيل ===== */
.detail-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-detail {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.25s;
}

.btn-detail-primary {
  background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
  color: white;
  box-shadow: 0 4px 12px rgba(184,122,100,0.3);
}

.btn-detail-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(184,122,100,0.4); }

.btn-detail-whatsapp {
  background: #25d366;
  color: white;
  box-shadow: 0 4px 12px rgba(37,211,102,0.3);
}

.btn-detail-whatsapp:hover { transform: translateY(-1px); filter: brightness(1.05); }

.btn-detail-warning {
  background: var(--wheat-soft);
  color: var(--wheat);
  border: 1px solid #fde68a;
}

.btn-detail-warning:hover { background: #fde68a; }

.btn-detail-ghost {
  background: var(--bg-main);
  color: var(--slate-light);
  border: var(--border);
}

.btn-detail-ghost:hover { background: var(--field-hover); color: var(--slate); }

.btn-detail-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.btn-detail-danger:hover { background: #fca5a5; }

/* ===== نموذج البيع ===== */
.sell-cost-info {
  padding: 14px 18px;
  background: var(--wheat-soft);
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
  margin-bottom: 22px;
  font-size: 14px;
  color: #92400e;
  font-weight: 600;
}

.sell-cost-hint {
  font-size: 12px;
  opacity: 0.75;
  margin-top: 4px;
}

/* ===== التحليلات ===== */
.analytics-header {
  background: linear-gradient(135deg, var(--emerald) 0%, #7a4f3d 100%);
  padding: 36px;
  border-radius: var(--radius-lg);
  color: white;
  margin-bottom: 28px;
  box-shadow: var(--shadow-lg);
}

.analytics-header h2 {
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.analytics-header p { opacity: 0.75; font-weight: 500; }

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 24px;
}

.premium-analysis-card {
  background: var(--bg-card);
  padding: 28px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: var(--border);
}

.premium-analysis-card h3 {
  font-size: 16px;
  font-weight: 800;
  color: var(--slate);
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.analysis-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px dashed var(--surface-elev);
  animation: fadeInUp 0.4s ease forwards;
}

.analysis-row:last-child { border-bottom: none; }
.row-info { display: flex; flex-direction: column; gap: 3px; }
.row-label { font-weight: 800; color: var(--slate); font-size: 14px; }
.row-sub { font-size: 12px; color: var(--slate-light); font-weight: 600; }
.row-val { font-weight: 900; font-size: 15px; color: var(--slate); }

.analytics-bar-wrap {
  flex: 1;
  margin: 0 14px;
  height: 6px;
  background: var(--surface-elev);
  border-radius: 3px;
  overflow: hidden;
}

.analytics-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--emerald), var(--emerald-light));
  border-radius: 3px;
  transition: width 0.8s ease;
}

/* ===== التنبيه (Toast) ===== */
/* FIX #9: على الديسكتوب 28px كافية، على الموبايل نرفعه فوق الـ FAB */
.toast-premium {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--slate);
  color: white;
  padding: 13px 24px;
  border-radius: 50px;
  font-weight: 700;
  font-size: 14px;
  z-index: 9999;
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  animation: toastIn 3.2s ease forwards;
  pointer-events: none;
}

/* ===== زر الهامبرجر ===== */
.btn-hamburger {
  display: none;
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  border: var(--border);
  background: var(--bg-card);
  color: var(--slate);
  align-items: center;
  justify-content: center;
  font-size: 22px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-hamburger:hover { background: var(--bg-main); }

/* ===== Drawer (قائمة الموبايل) ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(3px);
  z-index: 490;
  animation: fadeInScale 0.2s ease;
}

.mobile-drawer {
  position: fixed;
  top: 0;
  right: -300px;
  width: 280px;
  height: 100vh;
  background: var(--sidebar-bg);
  z-index: 500;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  overflow-y: auto;
}

.mobile-drawer.open { right: 0; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: var(--border);
}
.drawer-logo-img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
}

.drawer-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drawer-footer {
  padding-top: 16px;
  border-top: var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-logout-btn {
  color: var(--danger) !important;
  width: 100%;
}

.drawer-logout-btn:hover {
  background: var(--danger-soft) !important;
  color: var(--danger) !important;
}

/* ===== زر الإضافة العائم (FAB) ===== */
.fab-add {
  display: none;
  position: fixed;
  bottom: 28px;
  left: 24px;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--emerald), var(--emerald-light));
  color: white;
  border: none;
  font-size: 26px;
  box-shadow: 0 8px 24px rgba(184,122,100,0.45);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.fab-add:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 32px rgba(184,122,100,0.55);
}

/* ===== موبايل ===== */
@media (max-width: 1024px) {
  .sidebar { display: none; }
  .top-bar { padding: 0 16px; gap: 12px; }
  #content { padding: 20px 16px 100px; }
  .btn-hamburger { display: flex; }
  .fab-add { display: flex; }
  /* FIX #9: رفع Toast فوق زر FAB */
  .toast-premium { bottom: 100px; }

  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .form-row-grid { grid-template-columns: 1fr; }
  .media-upload-grid { grid-template-columns: 1fr; }
  .detail-actions-grid { grid-template-columns: 1fr; }
  .detail-info-grid { grid-template-columns: 1fr 1fr; }
  .search-input-wrap { min-width: 0; width: 100%; }
  .search-bar select { min-width: 0; width: 100%; }
}

@media (max-width: 640px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .user-chip span { display: none; }
  .search-bar { padding: 12px; }
  .detail-info-grid { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .sheep-grid { grid-template-columns: 1fr; }
  .add-view-actions { position: sticky; top: 74px; z-index: 30; padding: 10px; background: var(--bg-main); border: var(--border); border-radius: var(--radius-md); }
  .form-segment { padding: 24px 20px; }
  .modal-body { padding: 20px; }
  .modal-footer { padding: 16px 20px; }
  .add-view-actions { flex-wrap: wrap; }
  .btn-add-nav, .btn-add-reset, .btn-save, .btn-sell, .btn-install-app { min-height: 46px; font-size: 15px; }
  .modal-content { width: min(96vw, 520px); margin: 0 auto; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
