@import 'tailwindcss';

:root {
  --primary: #6366f1;
  --primary-light: #e0e7ff;
  --violet: #8b5cf6;
  --bg: #f8fafc;
  --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-light: #f8fafc;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 15px rgba(0,0,0,0.1);
  --transition: all 0.3s ease-in-out;
  --sidebar-w: 280px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}
html[dir="rtl"] body {
  font-family: 'Noto Naskh Arabic', 'Segoe UI', Tahoma, sans-serif;
}
[dir="rtl"] .nav-chevron-end {
  transform: scaleX(-1);
}
.locale-switch {
  display: flex; align-items: center; gap: 8px;
}
.locale-switch select {
  min-width: 110px;
  max-width: 180px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Native select arrow overlaps RTL text — use a custom chevron with logical padding */
select:not([multiple]) {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23475569' d='M1.4 0.3L6 4.9 10.6.3 12 1.7 6 7.7 0 1.7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 12px 8px;
  padding-inline-end: 2.25rem;
}
html[dir="rtl"] select:not([multiple]) {
  background-position: left 0.75rem center;
}
/* Keep short "per page" selects readable in RTL */
select:not([multiple])[style*="width:70px"],
select:not([multiple])[style*="width:78px"],
.um-select[style*="width"] {
  min-width: 4.75rem;
}
html[dir="rtl"] .um-select {
  background-position: left 0.75rem center;
}
html[dir="rtl"] .fa-chevron-left,
html[dir="rtl"] .fa-chevron-right,
html[dir="rtl"] .fa-angle-left,
html[dir="rtl"] .fa-angle-right,
html[dir="rtl"] .fa-arrow-left,
html[dir="rtl"] .fa-arrow-right {
  transform: scaleX(-1);
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 50%, #312e81 100%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 4px 0 0; color: #64748b; font-size: 13px; }
.login-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #fff; display: flex; align-items: center; justify-content: center;
}
.login-card label {
  font-size: 13px; font-weight: 600; color: #475569; margin-top: 8px;
  display: flex; align-items: center; gap: 6px;
}
.login-card input, .form-control, .cms-form input, .cms-form select, .cms-form textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1.5px solid var(--border); font-size: 14px; outline: none;
  background: #fff;
}
.login-card input:focus, .form-control:focus, .cms-form input:focus, .cms-form select:focus, .cms-form textarea:focus {
  border-color: var(--primary);
}
.btn-primary, button.btn-primary {
  margin-top: 8px; padding: 12px 16px; border: none; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #fff; font-weight: 700; font-size: 14px;
}
.btn-primary:disabled { opacity: 0.7; cursor: not-allowed; }
.btn-secondary {
  padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--border);
  background: #fff; cursor: pointer; font-weight: 600; color: var(--text-secondary);
}
.btn-danger {
  padding: 8px 12px; border-radius: 8px; border: none; background: #ef4444; color: #fff; cursor: pointer;
}
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; border: none; cursor: pointer; }
.btn-edit { background: var(--primary-light); color: var(--primary); }
.btn-del { background: #fee2e2; color: #b91c1c; }
.alert-error {
  background: #fef2f2; color: #b91c1c; padding: 10px 12px; border-radius: 8px; font-size: 13px;
}
.alert-success {
  background: #ecfdf5; color: #047857; padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px;
}
.login-hint { margin-top: 16px; font-size: 12px; color: #94a3b8; }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; top: 0; left: 0; right: auto; width: var(--sidebar-w); height: 100vh;
  background: var(--sidebar-bg); color: var(--text-light);
  z-index: 1000; display: flex; flex-direction: column;
  box-shadow: 4px 0 15px rgba(0,0,0,0.1); overflow: hidden;
  transition: var(--transition);
}
.sidebar.closed { left: calc(-1 * var(--sidebar-w)); right: auto; }
html[dir="rtl"] .sidebar {
  left: auto;
  right: 0;
  box-shadow: -4px 0 15px rgba(0,0,0,0.1);
}
html[dir="rtl"] .sidebar.closed {
  left: auto;
  right: calc(-1 * var(--sidebar-w));
}
.sidebar-header {
  padding: 24px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: bold; font-size: 20px;
}
.brand-name { font-size: 20px; font-weight: 700; color: #fff; }
.sidebar nav {
  margin-top: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(129, 140, 248, 0.55) transparent;
  scrollbar-gutter: stable;
}
.sidebar nav::-webkit-scrollbar {
  width: 8px;
}
.sidebar nav::-webkit-scrollbar-track {
  margin: 10px 0;
  background: transparent;
  border-radius: 999px;
}
.sidebar nav::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(129, 140, 248, 0.35), rgba(139, 92, 246, 0.55));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.sidebar nav::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(165, 180, 252, 0.7), rgba(167, 139, 250, 0.85));
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 0 12px rgba(99, 102, 241, 0.35);
}
.sidebar nav::-webkit-scrollbar-thumb:active {
  background: linear-gradient(180deg, #818cf8, #8b5cf6);
  background-clip: padding-box;
}
.sidebar nav::-webkit-scrollbar-corner {
  background: transparent;
}
.nav-item, .nav-parent {
  display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  color: rgba(255,255,255,0.7); text-decoration: none; width: 100%;
  border: none; background: transparent; cursor: pointer; font-size: 15px; font-weight: 500;
  transition: var(--transition); text-align: start;
}
.nav-item i, .nav-parent > i:first-child {
  width: 20px; font-size: 18px; text-align: center; flex-shrink: 0;
}
.nav-item.active, .nav-item:hover {
  color: #fff; background: rgba(99,102,241,0.2);
  border-right: 4px solid var(--primary);
  border-left: 0;
}
.nav-item { border-right: 4px solid transparent; border-left: 0; }
html[dir="rtl"] .nav-item.active,
html[dir="rtl"] .nav-item:hover {
  border-right: 0;
  border-left: 4px solid var(--primary);
}
html[dir="rtl"] .nav-item {
  border-right: 0;
  border-left: 4px solid transparent;
}
.nav-child {
  padding-left: 36px; padding-right: 24px; font-size: 14px;
}
html[dir="rtl"] .nav-child {
  padding-left: 24px;
  padding-right: 36px;
}
.nav-child i {
  width: 18px; font-size: 14px; text-align: center; flex-shrink: 0;
}
.sidebar-footer {
  padding: 24px; border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0), rgba(15, 23, 42, 0.65) 35%, rgba(15, 23, 42, 0.9));
}
.logout-btn {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  color: rgba(255,255,255,0.7); background: none; border: none; font-size: 15px; width: 100%;
}
.main-wrap {
  margin-left: var(--sidebar-w);
  margin-right: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  transition: var(--transition);
  width: calc(100% - var(--sidebar-w));
  max-width: calc(100% - var(--sidebar-w));
  min-width: 0;
  overflow-x: hidden;
}
.main-wrap.full {
  margin-left: 0;
  margin-right: 0;
  width: 100%;
  max-width: 100%;
}
html[dir="rtl"] .main-wrap {
  margin-left: 0;
  margin-right: var(--sidebar-w);
}
html[dir="rtl"] .main-wrap.full {
  margin-left: 0;
  margin-right: 0;
}
.topbar {
  height: 70px; background: var(--surface); box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 900;
  border-bottom: 1px solid var(--border);
}
.search-box {
  display: flex; align-items: center; gap: 10px; background: #f1f5f9;
  padding: 10px 16px; border-radius: 24px; width: 300px; max-width: 100%;
}
.search-box input { border: none; outline: none; background: transparent; width: 100%; font-size: 14px; text-align: start; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip > div:last-child { text-align: start; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600;
}
.content { flex: 1; padding: 24px; overflow-y: auto; overflow-x: hidden; min-width: 0; max-width: 100%; }
.app-footer {
  height: 60px; background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  color: var(--text-muted); font-size: 14px; padding: 0 24px;
}
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999;
}

/* Page chrome */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 22px; font-weight: 700; }
.card {
  background: var(--surface); border-radius: 14px; padding: 20px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
}
.table-wrap { overflow-x: auto; }
table.cms-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.cms-table th, table.cms-table td {
  padding: 12px 14px; text-align: start; border-bottom: 1px solid var(--border);
}
table.cms-table th {
  background: #f8fafc; color: var(--text-secondary); font-weight: 600; font-size: 13px;
}
table.cms-table tr:hover td { background: #f8fafc; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .main-wrap,
  html[dir="rtl"] .main-wrap {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
  .search-box { display: none; }
}
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 2000;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 720px;
  padding: 24px; box-shadow: var(--shadow-md);
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi {
  background: #fff; border-radius: 14px; padding: 18px; border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.kpi .label { color: var(--text-muted); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--text); }
.kpi.accent { border-top: 3px solid var(--primary); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar input[type=text] {
  padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--border); min-width: 220px;
}
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--primary-light); color: var(--primary);
}
.badge.green { background: #d1fae5; color: #047857; }
.badge.red { background: #fee2e2; color: #b91c1c; }
.badge.gray { background: #e2e8f0; color: #475569; }
.empty { text-align: center; color: var(--text-muted); padding: 40px; }
.actions { display: flex; gap: 8px; }
@media (max-width: 900px) { .kpi-grid { grid-template-columns: 1fr 1fr; } }
