/* =====================================================================
   iValue Platform — Restyled RTL consulting dashboard
   Brand Identity: Navy (#000B5C) & Gold (#E5A924)
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&display=swap');

:root {
  --primary: #000B5C;
  --primary-light: #00129C;
  --primary-rgb: 0, 11, 92;
  --primary-hover: #000636;
  --gold: #E5A924;
  --gold-hover: #c48e1b;
  --gold-rgb: 229, 169, 36;
  --canvas: #f0f3f8;
  --surface: #ffffff;
  --line: #e2e8f0;
  --text: #1a202c;
  --text-dark: #0f172a;
  --muted: #64748b;
  --danger: #ef4444;
  --ok: #10b981;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 4px 6px -1px rgba(0, 11, 92, 0.03), 0 2px 4px -1px rgba(0, 11, 92, 0.02);
  --shadow-hover: 0 20px 25px -5px rgba(0, 11, 92, 0.07), 0 10px 10px -5px rgba(0, 11, 92, 0.04);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-width: 270px;
}

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

html, body {
  height: 100%;
}

body {
  font-family: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--canvas);
  color: var(--text);
  direction: rtl;
  line-height: 1.6;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary-light);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--primary);
  text-decoration: none;
}

/* ---- App Shell ---- */
.app {
  display: flex;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.content {
  flex: 1;
  padding: 30px 40px;
  min-width: 0;
  transition: var(--transition);
}

.content.sidebar-collapsed {
  /* Dynamic spacing shift if layout changes */
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--primary) 0%, #000636 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: var(--transition);
  box-shadow: 4px 0 25px rgba(0, 11, 92, 0.15);
  z-index: 100;
}

.brand {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  transition: var(--transition);
}

.brand .logo-container {
  background: rgba(255, 255, 255, 0.95);
  padding: 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.06), 0 4px 12px rgba(0, 0, 11, 0.15);
  transition: var(--transition);
}

.brand .logo-container img {
  max-height: 38px;
  object-fit: contain;
  transition: var(--transition);
}

.brand .tag {
  font-size: 11px;
  color: rgba(226, 232, 240, 0.65);
  margin-top: 10px;
  text-align: center;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section {
  padding: 18px 20px 6px;
  font-size: 10.5px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0.85;
}

.nav {
  list-style: none;
  padding: 4px 12px;
  overflow-y: auto;
  flex: 1;
}

.nav li {
  margin-bottom: 4px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #cbd5e1;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  transform: translateX(-4px);
}

.nav a.active {
  background: linear-gradient(90deg, rgba(229, 169, 36, 0.15) 0%, rgba(229, 169, 36, 0.02) 100%);
  color: #ffffff;
  border-right: 4px solid var(--gold);
  font-weight: 600;
  padding-right: 10px; /* offset border-right width */
}

.nav a .ico {
  font-size: 16px;
  width: 20px;
  text-align: center;
  color: var(--gold);
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.nav .empty {
  color: #94a3b8;
  font-size: 12.5px;
  padding: 10px 14px;
  font-style: italic;
}

.sidebar .foot {
  padding: 18px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.15);
}

.sidebar .foot .who {
  color: #ffffff;
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar .foot .who i {
  color: var(--gold);
}

.sidebar .foot a {
  color: #94a3b8;
  display: inline-block;
  margin-top: 4px;
  font-weight: 500;
}

.sidebar .foot a:hover {
  color: var(--danger);
  transform: translateX(-2px);
}

/* ---- Collapsed Sidebar (Desktop) ---- */
.sidebar.collapsed {
  width: 80px;
}

.sidebar.collapsed .brand {
  padding: 16px 8px;
}

.sidebar.collapsed .brand .logo-container {
  padding: 6px;
}

.sidebar.collapsed .brand .logo-container img {
  max-height: 25px;
}

.sidebar.collapsed .brand .tag,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .nav a span:not(.ico),
.sidebar.collapsed .foot .who span,
.sidebar.collapsed .foot a span {
  display: none !important;
}

.sidebar.collapsed .nav a {
  justify-content: center;
  padding: 12px;
}

.sidebar.collapsed .nav a .ico {
  font-size: 18px;
  margin: 0;
}

.sidebar.collapsed .foot {
  padding: 16px 8px;
  text-align: center;
}

.sidebar.collapsed .foot .who {
  justify-content: center;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 20px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(0, 11, 92, 0.05);
  padding-bottom: 18px;
}

.topbar h1 {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1 i {
  color: var(--gold);
}

.topbar .sub {
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 4px;
  font-weight: 500;
}

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

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  overflow: hidden;
  transition: var(--transition);
}

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

.card .card-h {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(90deg, rgba(0, 11, 92, 0.01) 0%, rgba(255, 255, 255, 0) 100%);
}

.card .card-h h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card .card-h h2 i {
  color: var(--gold);
  font-size: 16px;
}

.card .card-b {
  padding: 24px;
}

/* ---- Stat Tiles ---- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 110px;
}

.tile:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.tile::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-light) 100%);
}

.tile.gold::before {
  background: linear-gradient(180deg, var(--gold) 0%, #d89617 100%);
}

.tile.accent::before {
  background: linear-gradient(180deg, var(--ok) 0%, #059669 100%);
}

.tile .n {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.tile.gold .n {
  color: #b58010;
}

.tile.accent .n {
  color: #065f46;
}

.tile .l {
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile .l i {
  font-size: 14px;
}

.tile .tile-icon {
  position: absolute;
  left: 20px;
  bottom: 15px;
  font-size: 44px;
  color: rgba(0, 11, 92, 0.05);
  pointer-events: none;
  transition: var(--transition);
}

.tile:hover .tile-icon {
  transform: scale(1.1) rotate(-8deg);
  color: rgba(0, 11, 92, 0.08);
}

.tile.gold .tile-icon {
  color: rgba(229, 169, 36, 0.07);
}
.tile.gold:hover .tile-icon {
  color: rgba(229, 169, 36, 0.12);
}

/* ---- Promo & Campaign Graphics ---- */
.promo-section-header {
  margin: 32px 0 16px;
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  border-right: 4px solid var(--gold);
  padding-right: 12px;
}

.promo-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

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

.promo-card {
  background: linear-gradient(135deg, #000B5C 0%, #001fcc 100%);
  color: #ffffff;
  border: none;
  position: relative;
  overflow: hidden;
}

.promo-card .card-h {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
}

.promo-card .card-h h2 {
  color: #ffffff;
}

.promo-card .card-h h2 i {
  color: var(--gold);
}

.promo-badge-tag {
  background: var(--gold);
  color: var(--primary-hover);
  font-weight: 800;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 4px 10px rgba(229, 169, 36, 0.3);
}

.promo-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.promo-item {
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: var(--transition);
}

.promo-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(-4px);
}

.promo-item-details h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 4px;
}

.promo-item-details p {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
}

.promo-item-metric {
  text-align: left;
}

.promo-item-metric .num {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
}

.promo-item-metric .lbl {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.6);
}

/* Beautiful custom progress bars */
.metric-progress-container {
  margin-top: 15px;
}
.metric-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 5px;
  color: rgba(255, 255, 255, 0.8);
}
.metric-progress-bar {
  background: rgba(255, 255, 255, 0.15);
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
}
.metric-progress-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--gold) 0%, #fff7d6 100%);
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Live Search inputs ---- */
.search-wrapper {
  position: relative;
  margin-bottom: 18px;
}

.search-wrapper input {
  padding-right: 40px; /* Space for search icon */
}

.search-wrapper i {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: right;
}

th, td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

thead th {
  background: #f8fafc;
  color: var(--text-dark);
  font-weight: 700;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--line);
}

tbody tr {
  transition: var(--transition);
}

tbody tr:hover {
  background: rgba(0, 11, 92, 0.015);
}

td.actions {
  white-space: nowrap;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  background-color: var(--primary-light);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 6px rgba(0, 18, 156, 0.15);
}

.btn:hover {
  background-color: var(--primary);
  box-shadow: 0 6px 12px rgba(0, 11, 92, 0.25);
  transform: translateY(-1px);
  text-decoration: none;
  color: #ffffff;
}

.btn:active {
  transform: translateY(1px);
}

.btn.ghost {
  background: transparent;
  color: var(--primary-light);
  border-color: var(--primary-light);
  box-shadow: none;
}

.btn.ghost:hover {
  background: rgba(0, 18, 156, 0.04);
  color: var(--primary);
  border-color: var(--primary);
}

.btn.gold {
  background-color: var(--gold);
  color: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(229, 169, 36, 0.2);
}

.btn.gold:hover {
  background-color: var(--gold-hover);
  box-shadow: 0 6px 15px rgba(229, 169, 36, 0.35);
  color: var(--primary-hover);
}

.btn.danger {
  background-color: var(--danger);
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.2);
}

.btn.danger:hover {
  background-color: #dc2626;
  box-shadow: 0 6px 15px rgba(239, 68, 68, 0.35);
}

.btn.sm {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 6px;
  box-shadow: none;
}

/* ---- Forms ---- */
.form-row {
  margin-bottom: 20px;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 13.5px;
  color: var(--text-dark);
}

input[type=text],
input[type=password],
input[type=url],
textarea,
select {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  background-color: #ffffff;
  color: var(--text-dark);
  transition: var(--transition);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(0, 18, 156, 0.08);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.help {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 6px;
  line-height: 1.4;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.check input[type=checkbox] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ---- Badges & Alerts ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge.on {
  background-color: #d1fae5;
  color: #065f46;
}

.badge.off {
  background-color: #fee2e2;
  color: #991b1b;
}

.badge.src {
  background-color: #f1f5f9;
  color: #475569;
}

.alert {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  margin-bottom: 22px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.02);
  border: 1px solid transparent;
}

.alert.success {
  background-color: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

.alert.error {
  background-color: #fef2f2;
  color: #991b1b;
  border-color: #fca5a5;
}

/* ---- Notes Block ---- */
.notes {
  background-color: #fcfcfd;
  border: 1px solid var(--line);
  border-inline-start: 4px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  color: #334155;
  font-size: 14px;
  line-height: 1.6;
}

/* ---- Login View ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(0, 11, 92, 0.82) 0%, rgba(0, 77, 37, 0.82) 50%, rgba(229, 169, 36, 0.15) 100%), url('../img/riyadh_towers.png') no-repeat center center;
  background-size: cover;
  padding: 20px;
  position: relative;
}

.login-wrap::before {
  content: "";
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: rgba(229, 169, 36, 0.18);
  top: -100px;
  right: -100px;
  filter: blur(80px);
  pointer-events: none;
}

.login-wrap::after {
  content: "";
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: rgba(0, 108, 53, 0.25);
  bottom: -50px;
  left: -50px;
  filter: blur(80px);
  pointer-events: none;
}

.login-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 11, 92, 0.25);
  padding: 40px 36px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  position: relative;
  z-index: 10;
  transition: var(--transition);
}

.login-card:hover {
  transform: translateY(-4px);
}

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

.login-card .logo img {
  max-height: 65px;
  object-fit: contain;
}

.login-card .tag {
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  margin-bottom: 30px;
  font-weight: 600;
}

/* ---- Editor ---- */
.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

#save-status {
  font-size: 13.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ---- Permission Matrix ---- */
.matrix td, .matrix th {
  text-align: center;
}

.matrix td:first-child, .matrix th:first-child {
  text-align: right;
}

.matrix input[type=checkbox] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

.matrix .adminrow td {
  background-color: #f8fafc;
  color: var(--muted);
}

/* ---- Responsive ---- */
@media (max-width: 820px) {
  .app {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  }
  .sidebar.collapsed {
    width: 100%;
  }
  .sidebar.collapsed .brand .tag,
  .sidebar.collapsed .nav-section,
  .sidebar.collapsed .nav a span:not(.ico),
  .sidebar.collapsed .foot .who span,
  .sidebar.collapsed .foot a span {
    display: block !important;
  }
  .sidebar.collapsed .brand {
    padding: 24px 20px;
  }
  .sidebar.collapsed .brand .logo-container {
    padding: 10px;
  }
  .sidebar.collapsed .brand .logo-container img {
    max-height: 38px;
  }
  .sidebar.collapsed .nav a {
    justify-content: flex-start;
    padding: 11px 14px;
  }
  .sidebar.collapsed .nav a .ico {
    font-size: 16px;
    margin-left: 12px;
  }
  .sidebar.collapsed .foot {
    padding: 18px 20px;
    text-align: right;
  }
  .sidebar.collapsed .foot .who {
    justify-content: flex-start;
  }
  .nav {
    max-height: 300px;
  }
  .content {
    padding: 24px 20px;
  }
}
