/* =========================================================
   🎨 VARIABLES
========================================================= */
:root {
    --primary: #5348eb;
    --secondary: #26c165;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
  
    --bg: #f5f6fa;
    --text: #1a1a1a;
    --border: #e5e7eb;
    --nav-dropdown-top: 56px;
  }
  
  /* =========================================================
     🔧 RESET + BASE LAYOUT
  ========================================================= */
  [dir="rtl"] body {
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  }

  [dir="ltr"] body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  }

  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
  
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100vh;
  }
  
  /* =========================================================
     🧱 LAYOUT
  ========================================================= */
  .layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    align-items: stretch;
  }
  
  .layout.sidebar-collapsed {
    grid-template-columns: 1fr;
  }
  
  .layout.sidebar-collapsed .sidebar {
    display: none;
  }
  
  .layout.sidebar-collapsed .footer-container {
    max-width: 100%;
  }
  
  /* Sidebar */
  .sidebar {
    background: #111827;
    color: white;
    padding: 20px;
    height: 100%;
    box-sizing: border-box;
  }

  .sidebar .nav-item {
    color: #e5e7eb;
    text-decoration: none;
  }

  .sidebar .nav-item:hover {
    color: #ffffff;
  }

  .sidebar-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .sidebar-title {
    font-size: 12px;
    color: #9ca3af;
    margin-bottom: 10px;
  }

  .lang-switch {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .lang-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.06);
    color: #e5e7eb;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
  }

  .lang-pill:hover {
    border-color: rgba(255, 255, 255, 0.32);
    color: #ffffff;
  }

  .lang-pill.active {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.42);
    color: #ffffff;
  }
  
  /* =========================================================
     🧩 HEADER + NAV
  ========================================================= */
  .header {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: space-between;
    min-width: 0;
    background: white;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
  }

  .header > h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
  }
  
  .header-logo {
    font-weight: bold;
    font-size: 18px;
    color: var(--primary);
    flex-shrink: 0;
  }

  .menu-toggle {
    display: block;
    flex-shrink: 0;
    font-size: 20px;
    background: none;
    border: none;
    cursor: pointer;
  }

  /* =========================================================
     ✅ CONFIRM DIALOG
  ========================================================= */
  .confirm-dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(17, 24, 39, 0.58);
  }

  .confirm-dialog-overlay[hidden] {
    display: none;
  }

  .confirm-dialog {
    width: min(460px, 100%);
    border-radius: 16px;
    background: #ffffff;
    border: 1px solid var(--border);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
    padding: 22px;
  }

  .confirm-dialog h3 {
    margin: 0 0 10px;
    font-size: 1.15rem;
  }

  .confirm-dialog p {
    margin: 0;
    color: #4b5563;
    line-height: 1.8;
  }

  .confirm-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 20px;
  }
  
  .logo {
    margin-bottom: 20px;
  }
  
  .nav-item {
    display: block;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 5px;
    cursor: pointer;
    color: inherit;
    text-decoration: none;
  }

  .nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
  }
  
  .nav-item.active {
    background: var(--primary);
  }
  
  /* =========================================================
     📦 MAIN
  ========================================================= */
  .main {
    display: flex;
    flex-direction: column;
  }
  
  /* Content */
  .content {
    padding: 20px;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
  }
  
  .section {
    margin-bottom: 40px;
  }
  
  /* =========================================================
     🧩 COMPONENTS
  ========================================================= */
  
  /* Alerts */
  .alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 10px;
    position: relative;
    font-size: 14px;
  }
  
  .alert-success {
    background: #dcfce7;
    color: #166534;
  }
  
  .alert-warning {
    background: #fef3c7;
    color: #92400e;
  }
  
  .alert-danger {
    background: #fee2e2;
    color: #991b1b;
  }
  
  .alert-close {
    position: absolute;
    inset-inline-start: 10px;
    top: 8px;
    cursor: pointer;
    font-size: 18px;
  }
  
  /* Cards */
  .card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
  }
  
  /* Grid */
  .grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
  
  /* Buttons */
  .btn {
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    margin: 5px;
  }
  
  .btn-primary {
    background: var(--primary);
    color: white;
  }
  
  .btn-secondary {
    background: var(--secondary);
    color: white;
  }
  
  .btn-outline {
    border: 1px solid var(--border);
    background: transparent;
  }
  
  .btn-danger {
    background: var(--danger);
    color: white;
  }
  
  /* Input */
  .input {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 100%;
    max-width: 300px;
  }
  
  /* Table */
  .table-container {
    overflow-x: auto;
  }
  
  .table {
    width: 100%;
    border-collapse: collapse;
    background: white;
  }
  
  .table th,
  .table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: start;
  }

  .table thead th {
    font-size: 0.85rem;
    font-weight: 600;
    color: #6b7280;
    background: #f9fafb;
  }
  
  /* =========================================================
     🧱 MODAL + OVERLAY
  ========================================================= */
  .overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: none;
    z-index: 90;
  }
  
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
  }
  
  .modal-overlay.active {
    display: flex;
  }
  
  .modal {
    background: white;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    text-align: center;
  }
  
  .modal-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
  }
  
  /* =========================================================
     🧱 FOOTER
  ========================================================= */
  .footer {
    background: #111827;
    color: #d1d5db;
  }

  .footer a {
    color: #e5e7eb;
    text-decoration: none;
  }

  .footer a:hover {
    color: #ffffff;
    text-decoration: underline;
    text-decoration-color: rgba(255, 255, 255, 0.75);
    text-underline-offset: 3px;
  }
  
  .footer-container {
    max-width: 1100px;
    margin: auto;
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    padding: 20px;
  }
  
  .footer-col {
    flex: 1;
    min-width: 200px;
  }
  
  .footer-bottom {
    border-top: 1px solid #374151;
    padding: 10px;
    text-align: center;
    font-size: 13px;
    color: #9ca3af;
  }
  
  .overlay.active {
    display: block;
  }

  /* =========================================================
     📱 MOBILE
  ========================================================= */
  @media (max-width: 768px) {
  
    .content {
      padding: 15px;
      margin: 0;
      max-width: 100%;
    }
  
    .layout {
      grid-template-columns: 1fr;
    }
  
    .menu-toggle {
      display: block;
    }
  
    .grid-3 {
      grid-template-columns: 1fr;
    }
  
    .sidebar {
      position: fixed;
      left: 12px;
      right: 12px;
      top: var(--nav-dropdown-top, 56px);
      width: auto;
      max-width: none;
      height: auto;
      max-height: min(72vh, 420px);
      overflow-y: auto;
      scrollbar-gutter: stable;
      margin: 0;
      padding: 16px 18px;
      border-radius: 0 0 12px 12px;
      box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
      z-index: 100;
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity 0.25s ease, transform 0.25s ease;
      transform: translateY(-10px);
    }

    .sidebar.active {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
      transform: translateY(0);
    }

    .layout.sidebar-collapsed .sidebar {
      display: block;
    }
  
    .footer-container {
      flex-direction: column;
    }

    /* Tables → بطاقات على الجوال */
    .table-container {
      overflow-x: visible;
    }

    .table {
      border-collapse: separate;
      border-spacing: 0;
      background: transparent;
    }

    .table thead {
      display: none;
    }

    .table tbody tr {
      display: block;
      background: #fff;
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 4px 14px 12px;
      margin-bottom: 12px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .table tbody tr:last-child {
      margin-bottom: 0;
    }

    .table td {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: 4px;
      padding: 10px 0;
      border-bottom: 1px solid var(--border);
      text-align: start;
    }

    .table td:last-child {
      border-bottom: none;
    }

    .table td::before {
      content: attr(data-label);
      font-size: 0.75rem;
      font-weight: 600;
      color: #6b7280;
      line-height: 1.3;
    }

    .table td:not([data-label])::before,
    .table td[data-label=""]::before {
      display: none;
    }

    .table td:not([data-label]),
    .table td[data-label=""] {
      padding-top: 12px;
      border-bottom: none;
    }

    .table td[colspan] {
      display: block;
      padding: 12px 0 0;
      border-bottom: none;
    }

    .table td[colspan]::before {
      display: none;
    }

    .table td .input {
      max-width: 100%;
    }

    .table td .btn {
      margin-inline: 0;
    }

    /* جداول تفاصيل (th + td في نفس الصف) — بطاقة واحدة */
    .table.table-kv {
      display: block;
      background: #fff;
      border: 1px solid var(--border);
      border-radius: 12px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
      overflow: hidden;
    }

    .table.table-kv tbody {
      display: block;
    }

    .table.table-kv tbody tr {
      display: block;
      padding: 10px 14px;
      margin-bottom: 0;
      border: none;
      border-radius: 0;
      box-shadow: none;
      background: transparent;
      border-bottom: 1px solid var(--border);
    }

    .table.table-kv tbody tr:last-child {
      border-bottom: none;
    }

    .table.table-kv tbody th {
      display: block;
      padding: 0 0 4px;
      border: none;
      font-size: 0.75rem;
      font-weight: 600;
      color: #6b7280;
      background: transparent;
    }

    .table.table-kv tbody td {
      display: block;
      padding: 0;
      border: none;
    }

    .table.table-kv tbody td::before {
      display: none;
    }
  }
  
  /* =========================================================
     🛠 FIXES
  ========================================================= */
  * {
    box-sizing: border-box;
  }
  
  html, body {
    overflow-x: hidden;
  }