/* Akwan (الأكوان) — Design System
   Inspired by Sakani Pro glassmorphism + adapted for internal tool
   Colors: Professional navy/teal/gold
   Fonts: Cairo (body), Amiri (Arabic headings)
*/

/* ============================================================
   CSS VARIABLES
   ============================================================ */
:root {
  /* Primary — Al Akwan Brand */
  --navy: #003468;
  --navy-light: #0a4a8a;
  --navy-mid: #002550;
  --teal: #a7bfdb;
  --teal-dark: #8aa8c9;
  --gold: #e2d5c0;
  --gold-dark: #c9b89e;

  /* Semantic */
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #3B82F6;

  /* Neutrals — Al Akwan Brand */
  --white: #FFFFFF;
  --pearl: #f0ece4;
  --sand: #e2d5c0;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #2a2829;

  /* Glass */
  --glass-bg: rgba(0, 52, 104, 0.6);
  --glass-border: rgba(167, 191, 219, 0.2);
  --glass-blur: 20px;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 64px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
  --shadow-xl: 0 20px 25px rgba(0,0,0,0.15);
  --gold-glow: 0 4px 12px rgba(0,52,104,0.3);

  /* Transitions */
  --transition: all 0.3s ease;
}

/* ============================================================
   FONTS
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Somar+Sans:wght@300;400;500;600;700;800;900&family=Amiri:wght@400;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Somar Sans', sans-serif;
  background: var(--pearl);
  color: var(--gray-800);
  min-height: 100vh;
  line-height: 1.8;
  letter-spacing: 0.01em;
}

body.rtl {
  direction: rtl;
  text-align: right;
}

body.ltr {
  direction: ltr;
  text-align: left;
}

h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.3;
}

.rtl h1, .rtl h2, .rtl h3 {
  font-family: 'Amiri', serif;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-mid) 50%, var(--navy-light) 100%);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 40%, rgba(0,212,170,0.08) 0%, transparent 50%),
              radial-gradient(circle at 70% 60%, rgba(0,52,104,0.06) 0%, transparent 50%);
  animation: float 20s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(-2%, -2%); }
}

.login-card {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 2.5rem;
  color: var(--gold);
  font-family: 'Amiri', serif;
  margin-bottom: 4px;
}

.login-logo p {
  color: var(--gray-400);
  font-size: 0.875rem;
}

/* ============================================================
   APP SHELL (sidebar + header + main)
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--navy);
  color: var(--white);
  position: fixed;
  top: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: var(--transition);
}

.rtl .sidebar { right: 0; }
.ltr .sidebar { left: 0; }

.sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header h2 {
  font-family: 'Amiri', serif;
  color: var(--gold);
  font-size: 1.5rem;
}

.sidebar-header small {
  display: block;
  color: var(--gray-400);
  font-size: 0.75rem;
}

.sidebar-section {
  padding: 16px 0;
}

.sidebar-section-title {
  text-transform: uppercase;
  font-size: 0.65rem;
  color: rgba(0,52,104,0.6);
  letter-spacing: 0.1em;
  padding: 0 24px;
  margin-bottom: 8px;
  font-weight: 600;
}

.sidebar-nav {
  list-style: none;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: var(--gray-300);
  text-decoration: none;
  font-size: 0.95rem;
  transition: var(--transition);
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
}

.rtl .sidebar-nav a { border-right: 3px solid transparent; border-left: none; }
.ltr .sidebar-nav a { border-left: 3px solid transparent; border-right: none; }

.sidebar-nav a:hover {
  background: rgba(255,255,255,0.05);
  color: var(--white);
}

.sidebar-nav a.active {
  color: var(--gold);
  background: rgba(0,52,104,0.08);
}

.rtl .sidebar-nav a.active { border-right-color: var(--gold); }
.ltr .sidebar-nav a.active { border-left-color: var(--gold); }

.sidebar-nav .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-nav .badge {
  margin-inline-start: auto;
  background: var(--danger);
  color: var(--white);
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

/* Header */
.main-header {
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: fixed;
  top: 0;
  right: 0;
  left: var(--sidebar-width);
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.rtl .main-header { right: var(--sidebar-width); left: 0; }

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-left h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--navy);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-lang {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--gray-300);
  background: transparent;
  color: var(--gray-600);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Somar Sans', sans-serif;
}

.btn-lang:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--gray-100);
  border-radius: 20px;
  font-size: 0.8rem;
}

.user-badge .role {
  color: var(--teal);
  font-weight: 600;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: calc(var(--header-height) + 24px) 24px 24px;
}

.rtl .main-content { margin-right: var(--sidebar-width); }
.ltr .main-content { margin-left: var(--sidebar-width); }

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--white);
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  transition: var(--transition);
}

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

.kpi-card .kpi-label {
  font-size: 0.9rem;
  color: var(--gray-500);
  margin-bottom: 8px;
}

.kpi-card .kpi-value {
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--navy);
}

.kpi-card .kpi-sub {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-top: 4px;
}

.kpi-card .kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 12px;
}

.kpi-icon.blue { background: rgba(59,130,246,0.1); color: var(--info); }
.kpi-icon.green { background: rgba(16,185,129,0.1); color: var(--success); }
.kpi-icon.gold { background: rgba(0,52,104,0.1); color: var(--gold); }
.kpi-icon.red { background: rgba(239,68,68,0.1); color: var(--danger); }
.kpi-icon.teal { background: rgba(0,212,170,0.1); color: var(--teal); }

/* ============================================================
   CARDS & PANELS
   ============================================================ */
.card {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th {
  background: var(--gray-100);
  padding: 14px 18px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-600);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

table td {
  padding: 14px 18px;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
  line-height: 1.6;
}

table tr:hover td {
  background: var(--gray-100);
}

.rtl table th, .rtl table td {
  text-align: right;
}

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  gap: 4px;
}

.badge-success { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.1); color: var(--info); }
.badge-gold { background: rgba(0,52,104,0.1); color: var(--gold); }
.badge-teal { background: rgba(0,212,170,0.1); color: var(--teal); }
.badge-gray { background: rgba(107,114,128,0.1); color: var(--gray-500); }

/* Compliance badge */
.compliance-ok { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.compliance-fail { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--border-radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  font-family: 'Somar Sans', sans-serif;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  color: var(--white);
}

.btn-primary:hover {
  box-shadow: 0 4px 12px rgba(0,52,104,0.3);
  transform: translateY(-1px);
}

.btn-teal {
  background: var(--teal);
  color: var(--white);
}

.btn-teal:hover {
  background: var(--teal-dark);
}

.btn-outline {
  border: 1px solid var(--gray-300);
  background: transparent;
  color: var(--gray-700);
}

.btn-outline:hover {
  border-color: var(--gold);
  color: var(--gold);
}

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

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius-sm);
  font-size: 0.95rem;
  font-family: 'Somar Sans', sans-serif;
  transition: var(--transition);
  background: var(--white);
  color: var(--gray-800);
  line-height: 1.5;
}

.form-control:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(0,52,104,0.1);
}

.form-control::placeholder {
  color: var(--gray-400);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.rtl select.form-control {
  background-position: left 12px center;
  padding-left: 36px;
  padding-right: 14px;
}

/* Login form on dark background */
.login-card .form-control {
  background: rgba(6,13,26,0.5);
  border-color: rgba(255,255,255,0.1);
  color: var(--white);
  backdrop-filter: blur(10px);
}

.login-card .form-control:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(0,52,104,0.15);
}

.login-card .form-control::placeholder {
  color: var(--gray-500);
}

.login-card label {
  color: var(--gray-400);
}

/* ============================================================
   PIPELINE (7-step leasing)
   ============================================================ */
.pipeline {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.pipeline-step {
  flex: 1;
  min-width: 160px;
  background: var(--gray-100);
  border-radius: var(--border-radius);
  padding: 12px;
}

.pipeline-step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--gray-300);
}

.pipeline-step-header .step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--white);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pipeline-step-header .step-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-700);
}

.pipeline-step-header .step-count {
  font-size: 0.7rem;
  color: var(--gray-400);
}

.pipeline-card {
  background: var(--white);
  border-radius: var(--border-radius-sm);
  padding: 10px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  cursor: pointer;
  transition: var(--transition);
}

.pipeline-card:hover {
  box-shadow: var(--shadow-md);
}

.pipeline-card .tenant-name {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.pipeline-card .unit-info {
  font-size: 0.75rem;
  color: var(--gray-500);
}

/* ============================================================
   MOMRAH COMPLIANCE GRID
   ============================================================ */
.compliance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.compliance-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--white);
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--gray-200);
}

.compliance-item .check-label {
  font-size: 0.875rem;
  font-weight: 500;
}

.compliance-item .check-value {
  font-weight: 700;
  font-size: 0.9rem;
}

/* ============================================================
   ESCALATION INDICATOR
   ============================================================ */
.escalation-bar {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.escalation-bar .level {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--gray-200);
}

.escalation-bar .level.active-1 { background: var(--warning); }
.escalation-bar .level.active-2 { background: #F97316; }
.escalation-bar .level.active-3 { background: var(--danger); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,22,40,0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: var(--border-radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--gray-100);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--gray-500);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--gray-200);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
/* Mobile overlay for sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

.sidebar-overlay.active {
  display: block;
}

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: var(--shadow-xl);
  }

  .rtl .sidebar {
    transform: translateX(100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-header {
    left: 0 !important;
    right: 0 !important;
  }

  .main-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: calc(var(--header-height) + 16px) 16px 16px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .pipeline {
    flex-direction: column;
  }

  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }

  .modal {
    max-width: 95vw !important;
    margin: 16px;
    max-height: 85vh;
  }

  .login-card {
    margin: 16px;
    padding: 32px 24px;
  }

  .btn-mobile-menu {
    display: block !important;
  }
}

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

  .header-right {
    gap: 8px;
  }

  .user-badge span:first-child {
    display: none;
  }

  .flex.justify-between {
    flex-direction: column;
    gap: 12px;
  }

  .flex.items-center.gap-4 {
    flex-wrap: wrap;
  }

  .form-control {
    font-size: 16px !important; /* prevents iOS zoom on focus */
  }

  table {
    font-size: 0.85rem;
  }

  table th, table td {
    padding: 10px 12px;
  }

  .escalation-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tabs, .fin-tabs, .settings-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* iOS safe area */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .main-content {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* Touch-friendly tap targets */
@media (pointer: coarse) {
  .btn {
    min-height: 44px;
    min-width: 44px;
  }
  .btn-sm {
    min-height: 38px;
    min-width: 38px;
  }
  .sidebar-nav a {
    padding: 14px 24px;
  }
  .tab, .fin-tab, .settings-tab {
    padding: 14px 20px;
  }
  table td, table th {
    padding: 14px 16px;
  }
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-center { text-align: center; }
.text-gold { color: var(--gold); }
.text-teal { color: var(--teal); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 0.8rem; }
.text-lg { font-size: 1.25rem; }
.font-bold { font-weight: 700; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.gap-4 { gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.hidden { display: none; }
.w-full { width: 100%; }
