/* Sidebar — Arabic Khat AI premium navigation */

:root {
  --sidebar-width: 272px;
  --sidebar-width-collapsed: 80px;
  --sidebar-bg-top: #081222;
  --sidebar-bg-bottom: #0d1b34;
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #64748b;
  --sidebar-link: #94a3b8;
  --sidebar-border: rgba(148, 163, 184, 0.1);
  --sidebar-teal: #14b8a6;
  --sidebar-teal-dark: #0d9488;
  --sidebar-cyan: #22d3ee;
  --sidebar-gold: #c9a962;
}

.app-layout {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
}

/* ── Shell ── */
.app-sidebar,
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  color: var(--sidebar-text);
  background: linear-gradient(
    175deg,
    var(--sidebar-bg-top) 0%,
    #0a1628 42%,
    var(--sidebar-bg-bottom) 100%
  );
  border-right: 1px solid var(--sidebar-border);
  box-shadow:
    4px 0 32px rgba(4, 13, 26, 0.35),
    inset -1px 0 0 rgba(255, 255, 255, 0.04);
  transition:
    width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.app-sidebar::before,
.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 45% at 0% 0%, rgba(20, 184, 166, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(201, 169, 98, 0.06), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.app-sidebar::after,
.sidebar::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48'%3E%3Cpath d='M24 0 L48 24 L24 48 L0 24 Z' fill='none' stroke='%23c9a962' stroke-width='0.5'/%3E%3C/svg%3E");
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.app-sidebar > *,
.sidebar > * {
  position: relative;
  z-index: 1;
}

/* ── Brand ── */
.sidebar-brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  flex-shrink: 0;
}

.sidebar-brand-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: #fff;
  font-size: 1.15rem;
  background: linear-gradient(145deg, var(--sidebar-teal-dark), var(--sidebar-teal));
  border: 1px solid rgba(34, 211, 238, 0.3);
  box-shadow:
    0 8px 24px rgba(20, 184, 166, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.brand-text {
  min-width: 0;
  flex: 1;
}

.brand-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.2;
  color: #f8fafc;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-subtitle {
  margin: 3px 0 0;
  font-size: 0.7rem;
  color: rgba(148, 163, 184, 0.85);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-collapse-btn {
  width: 32px;
  height: 32px;
  margin-top: 4px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: #94a3b8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
  transition:
    background 0.22s ease,
    color 0.22s ease,
    border-color 0.22s ease,
    transform 0.22s ease;
}

.sidebar-collapse-btn:hover {
  background: rgba(20, 184, 166, 0.12);
  border-color: rgba(34, 211, 238, 0.3);
  color: var(--sidebar-cyan);
}

body.sidebar-collapsed .sidebar-collapse-btn i {
  transform: rotate(180deg);
}

/* ── Navigation ── */
.sidebar-nav,
.sidebar-menu {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 10px 12px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.35) transparent;
}

.sidebar-nav::-webkit-scrollbar,
.sidebar-menu::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb,
.sidebar-menu::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.35);
  border-radius: 999px;
}

.sidebar-group + .sidebar-group {
  margin-top: 2px;
}

.sidebar-group-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: rgba(100, 116, 139, 0.9);
  text-transform: uppercase;
  margin: 16px 12px 6px;
  padding-left: 4px;
  user-select: none;
}

.sidebar-group:first-child .sidebar-group-label {
  margin-top: 4px;
}

/* ── Menu links ── */
.sidebar-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  margin-bottom: 3px;
  border-radius: 14px;
  border: 1px solid transparent;
  color: var(--sidebar-link);
  text-decoration: none;
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.25;
  transition:
    background 0.22s ease,
    color 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease,
    transform 0.22s ease;
}

.sidebar-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.08);
  transition:
    background 0.22s ease,
    border-color 0.22s ease,
    box-shadow 0.22s ease,
    transform 0.22s ease;
}

.sidebar-icon {
  font-size: 1rem;
  color: #94a3b8;
  transition: color 0.22s ease, transform 0.22s ease;
}

.sidebar-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link:hover {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(148, 163, 184, 0.1);
}

.sidebar-link:hover .sidebar-icon-wrap {
  background: rgba(20, 184, 166, 0.1);
  border-color: rgba(34, 211, 238, 0.18);
}

.sidebar-link:hover .sidebar-icon {
  color: var(--sidebar-cyan);
  transform: scale(1.05);
}

.sidebar-link.active {
  color: #ffffff;
  background: linear-gradient(
    135deg,
    rgba(13, 148, 136, 0.35) 0%,
    rgba(8, 145, 178, 0.28) 100%
  );
  border-color: rgba(34, 211, 238, 0.22);
  box-shadow:
    0 6px 20px rgba(20, 184, 166, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.sidebar-link.active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 52%;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--sidebar-cyan), var(--sidebar-teal));
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.5);
}

.sidebar-link.active .sidebar-icon-wrap {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.sidebar-link.active .sidebar-icon {
  color: #ffffff;
}

/* ── Footer ── */
.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 12px 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
  background: linear-gradient(180deg, transparent, rgba(4, 13, 26, 0.35));
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(148, 163, 184, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition:
    background 0.22s ease,
    border-color 0.22s ease;
}

.sidebar-user-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(34, 211, 238, 0.15);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(20, 184, 166, 0.2), rgba(8, 145, 178, 0.15));
  border: 1px solid rgba(34, 211, 238, 0.2);
  color: var(--sidebar-cyan);
  font-size: 0.95rem;
  flex-shrink: 0;
}

.sidebar-user-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-user-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.68rem;
  color: var(--sidebar-muted);
  text-transform: capitalize;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 7px 10px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.1);
  background: rgba(255, 255, 255, 0.02);
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 500;
  transition:
    background 0.22s ease,
    color 0.22s ease,
    border-color 0.22s ease;
}

.sidebar-icon-wrap-logout {
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-logout:hover {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(248, 113, 113, 0.2);
}

.sidebar-logout:hover .sidebar-icon-wrap {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(248, 113, 113, 0.25);
}

.sidebar-logout:hover .sidebar-icon {
  color: #fca5a5;
}

.sidebar-version {
  margin-top: 10px;
  text-align: center;
  font-size: 0.62rem;
  color: rgba(71, 85, 105, 0.9);
  letter-spacing: 0.06em;
}

/* ── Main content ── */
.main-content {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
  min-width: 0;
  min-height: 100vh;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  padding: 0 0 1.25rem;
  -webkit-overflow-scrolling: touch;
  transition:
    margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-backdrop {
  display: none;
}

/* ── Topbar toggle ── */
.sidebar-toggle-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  flex-shrink: 0;
  transition:
    background 0.22s ease,
    border-color 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease;
}

.sidebar-toggle-btn:hover {
  background: rgba(20, 184, 166, 0.08);
  border-color: rgba(20, 184, 166, 0.35);
  color: var(--sidebar-teal-dark);
  box-shadow: 0 4px 12px rgba(20, 184, 166, 0.12);
}

/* ── Collapsed desktop ── */
body.sidebar-collapsed {
  --sidebar-width: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed .app-sidebar,
body.sidebar-collapsed .sidebar {
  width: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .sidebar-group-label,
body.sidebar-collapsed .sidebar-text,
body.sidebar-collapsed .sidebar-user-meta,
body.sidebar-collapsed .sidebar-version {
  display: none;
}

body.sidebar-collapsed .sidebar-brand {
  flex-direction: column;
  align-items: center;
  padding-inline: 10px;
  gap: 10px;
}

body.sidebar-collapsed .sidebar-brand-main {
  justify-content: center;
}

body.sidebar-collapsed .sidebar-collapse-btn {
  display: inline-flex !important;
  margin-top: 0;
}

body.sidebar-collapsed .sidebar-link,
body.sidebar-collapsed .sidebar-logout {
  justify-content: center;
  padding-inline: 8px;
  gap: 0;
}

body.sidebar-collapsed .sidebar-user-card {
  justify-content: center;
  padding-inline: 8px;
}

body.sidebar-collapsed .sidebar-link.active::before {
  left: 2px;
  height: 40%;
}

body.sidebar-collapsed .sidebar-link[data-tooltip],
body.sidebar-collapsed .sidebar-logout[data-tooltip] {
  position: relative;
}

body.sidebar-collapsed .sidebar-link[data-tooltip]:hover::after,
body.sidebar-collapsed .sidebar-logout[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(34, 211, 238, 0.2);
  color: #f8fafc;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 28px rgba(4, 13, 26, 0.4);
  z-index: 1100;
  pointer-events: none;
  animation: sidebarTooltipIn 0.18s ease;
}

@keyframes sidebarTooltipIn {
  from {
    opacity: 0;
    transform: translateY(-50%) translateX(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }
}

@media (max-width: 991.98px) {
  .main-content {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
    padding: 0 1.125rem 1.125rem;
  }

  .app-sidebar,
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
    box-shadow: 16px 0 48px rgba(4, 13, 26, 0.45);
  }

  body.sidebar-open .app-sidebar,
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-collapsed .app-sidebar,
  body.sidebar-collapsed .sidebar {
    width: var(--sidebar-width);
  }

  body.sidebar-collapsed .brand-text,
  body.sidebar-collapsed .sidebar-group-label,
  body.sidebar-collapsed .sidebar-text,
  body.sidebar-collapsed .sidebar-user-meta,
  body.sidebar-collapsed .sidebar-version {
    display: block;
  }

  body.sidebar-collapsed .sidebar-brand {
    flex-direction: row;
    align-items: flex-start;
    padding-inline: 16px;
  }

  body.sidebar-collapsed .sidebar-brand-main {
    justify-content: flex-start;
  }

  body.sidebar-collapsed .sidebar-link,
  body.sidebar-collapsed .sidebar-logout {
    justify-content: flex-start;
    gap: 10px;
    padding-inline: 10px;
  }

  body.sidebar-collapsed .sidebar-user-card {
    justify-content: flex-start;
    padding-inline: 12px;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(4, 13, 26, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 1035;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
    opacity: 1;
    visibility: visible;
  }

  .sidebar-collapse-btn {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .main-content {
    padding: 0 1rem 1rem;
  }
}

@media (max-width: 480px) {
  .main-content {
    padding: 0 0.75rem 0.75rem;
  }

  .app-sidebar,
  .sidebar {
    width: min(var(--sidebar-width), 88vw);
  }
}

@media print {
  .app-sidebar,
  .sidebar,
  .sidebar-backdrop,
  .sidebar-toggle-btn {
    display: none !important;
  }

  .main-content {
    height: auto !important;
    overflow: visible !important;
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .sidebar,
  .main-content,
  .sidebar-link,
  .sidebar-logout,
  .sidebar-backdrop,
  .sidebar-icon-wrap,
  .sidebar-icon {
    transition: none;
  }

  body.sidebar-collapsed .sidebar-link[data-tooltip]:hover::after,
  body.sidebar-collapsed .sidebar-logout[data-tooltip]:hover::after {
    animation: none;
  }
}
