/* ================================================================
   MARTELTECH - Solar Energy Management System
   Brand CSS - الهوية البصرية الموحدة
   Primary Orange : #F5821F
   Primary Teal   : #00A99D
   Dark Navy      : #0D1B2A
   ================================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --mt-orange:       #F5821F;
  --mt-orange-dark:  #D96B10;
  --mt-orange-light: #FFF0E0;
  --mt-teal:         #00A99D;
  --mt-teal-dark:    #007D74;
  --mt-teal-light:   #E0F7F5;
  --mt-navy:         #0D1B2A;
  --mt-navy-mid:     #1A3148;
  --mt-navy-light:   #2A4A68;
  --mt-text:         #2C3E50;
  --mt-muted:        #6C7A89;
  --mt-border:       #E8ECEF;
  --mt-bg:           #F5F7FA;
  --mt-white:        #FFFFFF;
  --mt-shadow-sm:    0 2px 8px rgba(0,0,0,0.08);
  --mt-shadow-md:    0 4px 20px rgba(0,0,0,0.12);
  --mt-shadow-lg:    0 8px 40px rgba(0,0,0,0.16);
  --mt-radius:       10px;
  --mt-radius-lg:    16px;
  --sidebar-width:   270px;
  --sidebar-collapsed: 70px;
  --header-height:   64px;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--mt-bg);
  color: var(--mt-text);
  direction: rtl;
  overflow-x: hidden;
}

a { text-decoration: none; }

/* ================================================================
   HEADER
   ================================================================ */
#header.header {
  background: var(--mt-navy);
  border-bottom: 3px solid var(--mt-teal);
  height: var(--header-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: fixed;
  top: 0; right: 0; left: 0;
  z-index: 1030;
  box-shadow: var(--mt-shadow-md);
  transition: margin-right 0.3s ease, width 0.3s ease;
}

/* شريط برتقالي صغير في الأعلى */
#header.header::before {
  content: '';
  position: absolute;
  top: 0; right: 0; left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--mt-orange), var(--mt-teal));
}

.toggle-sidebar-btn {
  font-size: 1.4rem;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  transition: all 0.25s;
  line-height: 1;
}
.toggle-sidebar-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

/* شعار الهيدر */
.header .logo-container { margin-right: 0.5rem; }
.header .logo img.logo-img {
  height: 42px;
  width: auto;
  filter: brightness(1.05);
}
.header .logo-text {
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  margin-right: 0.75rem;
}

/* معلومات الفرع */
.branch-info {
  background: rgba(0,169,157,0.15);
  border: 1px solid rgba(0,169,157,0.3);
  border-radius: 20px;
  padding: 0.3rem 1rem;
  color: var(--mt-teal);
  font-size: 0.88rem;
  font-weight: 600;
}
.branch-info .user-role { color: rgba(255,255,255,0.5); font-weight: 400; }

/* أيقونات الهيدر */
.header .nav-icon {
  color: rgba(255,255,255,0.75);
  font-size: 1.15rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  transition: all 0.25s;
  position: relative;
}
.header .nav-icon:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}
.header .badge-number {
  position: absolute;
  top: -4px; right: -4px;
  font-size: 0.65rem;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--mt-navy);
}

/* قائمة البروفايل المنسدلة */
.header .nav-profile {
  color: rgba(255,255,255,0.85);
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  display: flex; align-items: center; gap: 0.5rem;
  transition: all 0.25s;
}
.header .nav-profile:hover { background: rgba(255,255,255,0.1); color: #fff; }
.header .profile-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--mt-teal);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--mt-navy-mid);
  flex-shrink: 0;
}
.header .profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.header .profile-avatar i { color: var(--mt-teal); font-size: 1.3rem; }
.header .profile-name { font-size: 0.88rem; font-weight: 600; }

/* القوائم المنسدلة */
.header .dropdown-menu {
  border: none;
  box-shadow: var(--mt-shadow-lg);
  border-radius: var(--mt-radius-lg);
  padding: 0.5rem;
  min-width: 300px;
  border-top: 3px solid var(--mt-teal);
  animation: dropFade 0.25s ease;
}
@keyframes dropFade {
  from { opacity:0; transform:translateY(-8px); }
  to   { opacity:1; transform:translateY(0); }
}
.header .dropdown-header {
  padding: 0.75rem 1rem;
  font-weight: 700;
  color: var(--mt-navy);
  background: var(--mt-teal-light);
  border-radius: 8px;
  margin-bottom: 0.25rem;
}
.header .dropdown-item {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  transition: all 0.2s;
  color: var(--mt-text);
  display: flex; align-items: center; gap: 0.6rem;
}
.header .dropdown-item:hover {
  background: var(--mt-teal-light);
  color: var(--mt-teal-dark);
}
.header .dropdown-item.text-danger:hover {
  background: #fff0f0;
  color: #c0392b;
}
.header .dropdown-footer {
  padding: 0.6rem 1rem;
  text-align: center;
  border-top: 1px solid var(--mt-border);
}
.header .dropdown-footer a { color: var(--mt-teal); font-weight: 600; font-size: 0.87rem; }

/* عناصر الإشعارات */
.notification-item, .message-item {
  display: flex; align-items: flex-start; gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  transition: background 0.2s;
  cursor: pointer;
}
.notification-item:hover, .message-item:hover { background: var(--mt-bg); }
.notification-content h6, .message-content h6 { font-size: 0.87rem; margin-bottom: 0.2rem; color: var(--mt-navy); }
.notification-content p, .message-content p { font-size: 0.78rem; color: var(--mt-muted); margin-bottom: 0.2rem; }
.notification-time, .message-time { font-size: 0.72rem; color: var(--mt-muted); }

/* ================================================================
   SIDEBAR
   ================================================================ */
#sidebar.sidebar {
  position: fixed;
  top: 0; right: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--mt-navy);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: width 0.3s ease;
  overflow: hidden;
}

/* الهيدر داخل السايدبار */
.sidebar-header {
  height: var(--header-height);
  padding: 0 1rem;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--mt-navy);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.6rem;
  overflow: hidden; white-space: nowrap;
}
.sidebar-brand .brand-logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--mt-orange);
}
.sidebar-brand .brand-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
  transition: opacity 0.3s;
}
.sidebar-brand .brand-name span {
  display: block;
  font-size: 0.7rem;
  color: var(--mt-teal);
  font-weight: 500;
}
.sidebar-toggle {
  background: rgba(255,255,255,0.06);
  border: none; color: rgba(255,255,255,0.5);
  font-size: 1rem;
  width: 30px; height: 30px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: all 0.25s;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* قائمة التنقل */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.sidebar-nav .nav-item { margin: 0.1rem 0.75rem; }

/* فاصل أقسام */
.nav-section-title {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.3);
  padding: 0.9rem 1.25rem 0.4rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.3s;
}

/* روابط السايدبار */
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-radius: 9px;
  color: rgba(255,255,255,0.65);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  transition: all 0.25s;
  position: relative;
}
.sidebar-nav .nav-link i {
  font-size: 1.1rem;
  flex-shrink: 0;
  width: 20px; text-align: center;
}
.sidebar-nav .nav-link span { flex: 1; }
.sidebar-nav .nav-link .ms-auto { flex-shrink: 0; font-size: 0.8rem; transition: transform 0.3s; }

.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
}
.sidebar-nav .nav-link.active {
  background: linear-gradient(90deg, var(--mt-teal) 0%, rgba(0,169,157,0.75) 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,169,157,0.3);
}
.sidebar-nav .nav-link.active i { color: #fff; }

/* حد برتقالي على يمين العنصر النشط */
.sidebar-nav .nav-link.active::after {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--mt-orange);
  border-radius: 0 3px 3px 0;
}

/* السهم عند فتح القائمة الفرعية */
.sidebar-nav .nav-link:not(.collapsed) .ms-auto { transform: rotate(-90deg); }

/* القوائم الفرعية */
.nav-content {
  background: rgba(0,0,0,0.2);
  border-radius: 9px;
  margin: 0.25rem 0.5rem;
  padding: 0.35rem 0;
  overflow: hidden;
}
.nav-content li a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 1rem 0.55rem 1.5rem;
  border-radius: 7px;
  color: rgba(255,255,255,0.55);
  font-size: 0.85rem;
  margin: 0.1rem 0.5rem;
  transition: all 0.2s;
}
.nav-content li a i { font-size: 0.95rem; flex-shrink: 0; }
.nav-content li a:hover {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.9);
}
.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 0.4rem 1rem;
}

/* تذييل السايدبار */
.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  background: rgba(0,0,0,0.2);
}
.sidebar-footer .user-info {
  display: flex; align-items: center; gap: 0.65rem;
  margin-bottom: 0.6rem;
  overflow: hidden;
}
.sidebar-footer .user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mt-orange), var(--mt-teal));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.1rem;
  flex-shrink: 0;
}
.sidebar-footer .user-name { font-size: 0.85rem; font-weight: 600; color: #fff; }
.sidebar-footer .user-role { font-size: 0.75rem; color: rgba(255,255,255,0.45); }
.sidebar-footer .logout-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.55rem 1rem;
  background: rgba(220,53,69,0.15);
  border: 1px solid rgba(220,53,69,0.25);
  color: #f87171;
  border-radius: 8px;
  font-size: 0.87rem; font-weight: 600;
  transition: all 0.25s;
  white-space: nowrap;
}
.sidebar-footer .logout-btn:hover {
  background: rgba(220,53,69,0.25);
  color: #fff;
}

/* ================================================================
   COLLAPSED STATE
   ================================================================ */
#sidebar.collapsed {
  width: var(--sidebar-collapsed);
}
#sidebar.collapsed .sidebar-brand .brand-name,
#sidebar.collapsed .nav-section-title,
#sidebar.collapsed .sidebar-nav .nav-link span,
#sidebar.collapsed .sidebar-nav .nav-link .ms-auto,
#sidebar.collapsed .sidebar-nav .nav-link .badge,
#sidebar.collapsed .sidebar-footer .user-details,
#sidebar.collapsed .sidebar-footer .logout-btn span,
#sidebar.collapsed .nav-content {
  display: none !important;
}
#sidebar.collapsed .sidebar-nav .nav-link {
  justify-content: center;
  padding: 0.7rem;
}
#sidebar.collapsed .sidebar-nav .nav-link i { width: auto; }
#sidebar.collapsed .sidebar-footer .user-info { justify-content: center; }
#sidebar.collapsed .sidebar-footer .logout-btn {
  justify-content: center;
  padding: 0.55rem;
}

/* layout managed by layout.css */

/* ================================================================
   PAGE TITLE
   ================================================================ */
.page-title {
  margin-bottom: 1.5rem;
}
.page-title h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--mt-navy);
  margin-bottom: 0.2rem;
}
.page-title .breadcrumb {
  background: none;
  padding: 0; margin: 0;
  font-size: 0.82rem;
}
.page-title .breadcrumb-item a { color: var(--mt-teal); }
.page-title .breadcrumb-item.active { color: var(--mt-muted); }
.page-title .breadcrumb-item + .breadcrumb-item::before { color: var(--mt-border); }

/* ================================================================
   CARDS
   ================================================================ */
.card {
  border: 1px solid var(--mt-border);
  border-radius: var(--mt-radius-lg);
  box-shadow: var(--mt-shadow-sm);
  background: var(--mt-white);
  transition: box-shadow 0.25s, transform 0.25s;
}
.card:hover { box-shadow: var(--mt-shadow-md); }
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--mt-border);
  padding: 1rem 1.25rem;
  font-weight: 700;
  color: var(--mt-navy);
  border-radius: var(--mt-radius-lg) var(--mt-radius-lg) 0 0 !important;
}

/* بطاقات الإحصاء */
.stat-card {
  border-radius: var(--mt-radius-lg);
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
  color: #fff;
  border: none;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: -30px; left: -30px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.stat-card::after {
  content: '';
  position: absolute;
  bottom: -20px; right: -20px;
  width: 90px; height: 90px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
}
.stat-card .stat-icon {
  font-size: 2.2rem;
  opacity: 0.85;
  position: relative; z-index: 1;
}
.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
  position: relative; z-index: 1;
}
.stat-card .stat-label {
  font-size: 0.85rem;
  opacity: 0.85;
  position: relative; z-index: 1;
}
.stat-card .stat-change {
  font-size: 0.78rem;
  opacity: 0.8;
  position: relative; z-index: 1;
}

.stat-card.orange { background: linear-gradient(135deg, var(--mt-orange), #E67E22); }
.stat-card.teal   { background: linear-gradient(135deg, var(--mt-teal),   #16A085); }
.stat-card.navy   { background: linear-gradient(135deg, var(--mt-navy-mid), var(--mt-navy-light)); }
.stat-card.green  { background: linear-gradient(135deg, #27AE60, #2ECC71); }
.stat-card.red    { background: linear-gradient(135deg, #E74C3C, #C0392B); }
.stat-card.purple { background: linear-gradient(135deg, #8E44AD, #9B59B6); }

/* ================================================================
   TABLES
   ================================================================ */
.table {
  border-collapse: separate;
  border-spacing: 0;
}
.table thead th {
  background: var(--mt-navy);
  color: rgba(255,255,255,0.85);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.9rem 1rem;
  border: none;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.table thead th:first-child { border-radius: 0 9px 0 0; }
.table thead th:last-child  { border-radius: 9px 0 0 0; }
.table tbody tr {
  transition: background 0.2s;
}
.table tbody tr:hover td { background: var(--mt-teal-light); }
.table tbody td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--mt-border);
  font-size: 0.9rem;
  vertical-align: middle;
}
.table-striped tbody tr:nth-of-type(even) td {
  background: rgba(0,169,157,0.03);
}

/* ================================================================
   FORMS
   ================================================================ */
.form-control, .form-select {
  border: 1.5px solid var(--mt-border);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  font-size: 0.9rem;
  color: var(--mt-text);
  transition: border-color 0.25s, box-shadow 0.25s;
  background: var(--mt-white);
}
.form-control:focus, .form-select:focus {
  border-color: var(--mt-teal);
  box-shadow: 0 0 0 3px rgba(0,169,157,0.15);
  outline: none;
}
.form-label {
  font-weight: 600;
  font-size: 0.87rem;
  color: var(--mt-navy);
  margin-bottom: 0.4rem;
}
.input-group-text {
  background: var(--mt-bg);
  border: 1.5px solid var(--mt-border);
  color: var(--mt-teal);
}

/* ================================================================
   BUTTONS
   ================================================================ */
.btn { border-radius: 8px; font-weight: 600; font-size: 0.9rem; padding: 0.55rem 1.25rem; transition: all 0.25s; }

.btn-primary {
  background: var(--mt-teal);
  border-color: var(--mt-teal);
  color: #fff;
}
.btn-primary:hover {
  background: var(--mt-teal-dark);
  border-color: var(--mt-teal-dark);
  box-shadow: 0 4px 12px rgba(0,169,157,0.35);
  transform: translateY(-1px);
}

.btn-orange {
  background: var(--mt-orange);
  border-color: var(--mt-orange);
  color: #fff;
}
.btn-orange:hover {
  background: var(--mt-orange-dark);
  border-color: var(--mt-orange-dark);
  box-shadow: 0 4px 12px rgba(245,130,31,0.35);
  transform: translateY(-1px);
  color: #fff;
}

.btn-navy {
  background: var(--mt-navy);
  border-color: var(--mt-navy);
  color: #fff;
}
.btn-navy:hover {
  background: var(--mt-navy-mid);
  border-color: var(--mt-navy-mid);
  color: #fff;
}

.btn-outline-teal {
  border: 1.5px solid var(--mt-teal);
  color: var(--mt-teal);
  background: transparent;
}
.btn-outline-teal:hover {
  background: var(--mt-teal);
  color: #fff;
}

/* ================================================================
   BADGES
   ================================================================ */
.badge-orange  { background: var(--mt-orange-light); color: var(--mt-orange-dark); border: 1px solid var(--mt-orange); }
.badge-teal    { background: var(--mt-teal-light);   color: var(--mt-teal-dark);   border: 1px solid var(--mt-teal); }
.badge-navy    { background: #E8EDF2; color: var(--mt-navy); }

/* ================================================================
   ALERTS
   ================================================================ */
.alert { border-radius: var(--mt-radius); border: none; font-size: 0.9rem; }
.alert-success { background: #E9FBF0; color: #1D7A45; border-right: 4px solid #27AE60; }
.alert-danger  { background: #FEE8E8; color: #952828; border-right: 4px solid #E74C3C; }
.alert-warning { background: #FFF8E1; color: #8A6100; border-right: 4px solid var(--mt-orange); }
.alert-info    { background: var(--mt-teal-light); color: var(--mt-teal-dark); border-right: 4px solid var(--mt-teal); }

/* ================================================================
   FOOTER
   ================================================================ */
footer.footer {
  background: var(--mt-white);
  border-top: 1px solid var(--mt-border);
  padding: 0.9rem 1.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--mt-muted);
}
footer.footer strong { color: var(--mt-teal); }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 991px) {
  #sidebar.sidebar {
    transform: translateX(100%);
    box-shadow: var(--mt-shadow-lg);
  }
  #sidebar.sidebar.mobile-open {
    transform: translateX(0);
    width: var(--sidebar-width) !important;
  }
  #sidebar.sidebar.mobile-open .sidebar-brand .brand-name,
  #sidebar.sidebar.mobile-open .nav-section-title,
  #sidebar.sidebar.mobile-open .sidebar-nav .nav-link span,
  #sidebar.sidebar.mobile-open .sidebar-nav .nav-link .ms-auto,
  #sidebar.sidebar.mobile-open .sidebar-footer .user-details,
  #sidebar.sidebar.mobile-open .sidebar-footer .logout-btn span,
  #sidebar.sidebar.mobile-open .nav-content {
    display: block !important;
  }
  #sidebar.sidebar.mobile-open .sidebar-nav .nav-link {
    justify-content: flex-start;
    padding: 0.7rem 1rem;
  }
  #main.main {
    margin-right: 0 !important;
    padding: 1rem;
  }
  #header.header {
    margin-right: 0 !important;
    width: 100% !important;
  }
  .mt-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
  }
  .mt-overlay.active { display: block; }
}

/* ================================================================
   UTILITIES
   ================================================================ */
.text-teal    { color: var(--mt-teal) !important; }
.text-orange  { color: var(--mt-orange) !important; }
.text-navy    { color: var(--mt-navy) !important; }
.bg-teal      { background: var(--mt-teal) !important; }
.bg-orange    { background: var(--mt-orange) !important; }
.bg-navy      { background: var(--mt-navy) !important; }
.bg-teal-light  { background: var(--mt-teal-light) !important; }
.bg-orange-light { background: var(--mt-orange-light) !important; }

.shadow-teal { box-shadow: 0 4px 16px rgba(0,169,157,0.25) !important; }
.shadow-orange { box-shadow: 0 4px 16px rgba(245,130,31,0.25) !important; }

.border-teal   { border-color: var(--mt-teal) !important; }
.border-orange { border-color: var(--mt-orange) !important; }

.rounded-mt { border-radius: var(--mt-radius) !important; }
.rounded-mt-lg { border-radius: var(--mt-radius-lg) !important; }
