@media (max-width: 760px) {
  html,
  body {
    min-width: 0;
    width: 100%;
  }

  .app-shell {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100svh;
    width: 100%;
  }

  .sidebar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.14);
    gap: 12px;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: 14px 12px;
    position: relative;
    top: auto;
    width: 100%;
  }

  .brand {
    justify-content: flex-start;
    min-height: 48px;
    padding: 0 2px 10px;
  }

  .brand-logo {
    height: 44px;
    width: 44px;
  }

  .nav-list {
    display: flex;
    gap: 8px;
    min-height: 48px;
    overflow-x: auto;
    padding: 0 0 6px;
    scrollbar-width: none;
    width: 100%;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-list:empty::before {
    align-items: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--radius);
    color: var(--sidebar-muted);
    content: "جاري تحميل القائمة...";
    display: flex;
    min-height: 44px;
    padding: 0 12px;
    width: 100%;
  }

  .nav-button {
    flex: 0 0 auto;
    min-width: 138px;
    width: auto;
  }

  .sidebar-footer {
    display: none;
  }

  .main {
    box-sizing: border-box;
    max-width: 100vw;
    min-width: 0;
    overflow: hidden;
    padding: 14px 12px 84px;
    width: 100%;
  }

  .topbar {
    align-items: stretch;
    display: grid;
    gap: 12px;
    justify-content: stretch;
    margin-bottom: 14px;
    min-height: 0;
  }

  .topbar-actions {
    align-items: stretch;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .user-session:empty {
    display: none;
  }

  .user-session {
    justify-content: space-between;
    width: 100%;
  }

  .search-box {
    grid-column: 1 / -1;
    width: 100%;
  }

  .search-box input {
    min-width: 0;
    width: 100%;
  }

  #appView:empty::before {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    color: var(--muted);
    content: "جاري تحميل بيانات النظام...";
    display: flex;
    min-height: 96px;
    padding: 18px;
  }

  .view,
  .panel,
  .panel-grid,
  .metric-grid,
  .ops-hero,
  .list-card,
  .employee-card,
  .conversation-card,
  .maintenance-card,
  .zid-page,
  .zid-order-card {
    max-width: 100%;
    min-width: 0;
    width: 100%;
  }

  .table-wrap {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    width: 100%;
  }

  table {
    max-width: none;
  }
}

.mobile-menu-toggle {
  display: none;
}

.sync-status {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  gap: 7px;
  min-height: 38px;
  padding: 8px 10px;
  white-space: nowrap;
}

.sync-dot {
  background: #98a2b3;
  border-radius: 999px;
  display: inline-block;
  height: 8px;
  width: 8px;
}

.sync-status.saving .sync-dot,
.sync-status.checking .sync-dot {
  background: var(--gold);
}

.sync-status.saved .sync-dot,
.sync-status.updated .sync-dot,
.sync-status.idle .sync-dot {
  background: var(--green);
}

.sync-status.failed {
  color: #9f2945;
}

.sync-status.failed .sync-dot {
  background: var(--rose);
}

.conversation-list {
  max-height: 68vh;
  overflow-y: auto;
  padding-inline-end: 4px;
}

.conversation-card {
  background: #ffffff;
}

.conversation-card h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-card p {
  line-height: 1.45;
  max-height: 2.9em;
  overflow: hidden;
}

.chat-window {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.48)),
    #eef4ef;
}

.messages {
  background: rgba(255, 255, 255, 0.46);
  border: 1px solid rgba(227, 233, 231, 0.82);
  border-radius: var(--radius);
  padding: 14px;
  scroll-behavior: smooth;
}

.message {
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.message.customer {
  border-start-start-radius: 2px;
}

.message.agent {
  background: #dff7dc;
  border-color: #b7e3b0;
  border-start-end-radius: 2px;
}

.message small {
  text-align: left;
}

.reply-box textarea {
  line-height: 1.6;
}

@media (max-width: 760px) {
  .sidebar {
    box-shadow: 0 12px 30px rgba(6, 33, 58, 0.16);
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .brand {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .mobile-menu-toggle {
    align-items: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius);
    color: #ffffff;
    display: grid;
    gap: 6px;
    grid-template-columns: 30px auto minmax(0, 1fr);
    min-height: 46px;
    padding: 8px 10px;
    text-align: right;
    width: 100%;
  }

  .mobile-menu-toggle strong {
    color: var(--sidebar-muted);
    font-size: 12px;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-icon,
  .mobile-menu-icon::before,
  .mobile-menu-icon::after {
    background: #ffffff;
    border-radius: 999px;
    display: block;
    height: 2px;
    width: 20px;
  }

  .mobile-menu-icon {
    position: relative;
  }

  .mobile-menu-icon::before,
  .mobile-menu-icon::after {
    content: "";
    position: absolute;
    right: 0;
  }

  .mobile-menu-icon::before {
    top: -6px;
  }

  .mobile-menu-icon::after {
    bottom: -6px;
  }

  .nav-list {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    display: none;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: min(56svh, 420px);
    overflow-y: auto;
    padding: 8px;
  }

  body.mobile-nav-open .nav-list,
  .nav-list:empty {
    display: grid;
  }

  .nav-list:empty {
    grid-template-columns: 1fr;
  }

  .nav-button {
    align-content: center;
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    display: grid;
    gap: 5px;
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 72px;
    min-width: 0;
    padding: 9px 7px;
    position: relative;
    text-align: center;
    white-space: normal;
    width: 100%;
  }

  .nav-button.active {
    background: #ffffff;
    color: var(--sidebar);
    transform: none;
  }

  .nav-button.active .nav-icon {
    background: var(--brand-soft);
    color: var(--brand-strong);
  }

  .nav-icon {
    height: 30px;
    width: 30px;
  }

  .nav-button > span:not(.nav-icon):not(.nav-count) {
    font-size: 12px;
    font-weight: 900;
    line-height: 1.3;
  }

  .nav-count {
    inset-inline-end: 6px;
    position: absolute;
    top: 6px;
  }

  .topbar-actions {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .topbar-actions .sync-status {
    grid-column: 1;
    grid-row: 1;
  }

  .topbar-actions #notificationButton {
    grid-column: 2;
    grid-row: 1;
  }

  .topbar-actions .user-session {
    grid-column: 1 / -1;
  }

  .sync-status {
    justify-content: center;
    min-height: 40px;
    width: 100%;
  }

  .split-layout {
    grid-template-columns: 1fr;
  }

  .conversation-list {
    max-height: 320px;
  }

  .chat-window {
    min-height: 520px;
  }

  .messages {
    max-height: 380px;
    padding: 10px;
  }

  .reply-box {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 360px) {
  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
