/* =====================================================
   Responsive — responsive.css
   ===================================================== */

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
  :root { --sidebar-w: 240px; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .messages-layout { grid-template-columns: 280px 1fr; }
  .contact-info-panel { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .top-navbar .nav-search { max-width: 260px; }
  .login-left .feature-grid { grid-template-columns: 1fr; }

  /* Tables horizontal scroll on tablet */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.data-table { min-width: 700px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  :root { --sidebar-w: 240px; }

  /* Sidebar off-canvas */
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.show {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0,0,0,0.3);
  }
  .main-content {
    margin-left: 0 !important;
    padding-bottom: 70px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Hamburger toggle visible */
  .hamburger-btn { display: block; }

  /* Top navbar compact */
  .top-navbar { padding: 0 12px; height: 56px; }
  .top-navbar .nav-search { display: none; }
  .top-navbar .nav-title { flex: 1; min-width: 0; }
  .top-navbar .nav-title h4 { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-navbar .nav-title .breadcrumb-text { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-navbar .nav-icon-btn { width: 32px; height: 32px; font-size: 14px; }
  .top-navbar .nav-actions { gap: 6px; }
  .top-navbar .user-dropdown .user-info { display: none; }
  .top-navbar .user-dropdown { padding: 2px; }
  .top-navbar .user-dropdown .avatar-circle { width: 28px; height: 28px; font-size: 11px; }

  /* Content area padding reduced */
  .content-area {
    padding: 12px;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Page header stack */
  .page-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px;
    margin-bottom: 14px;
  }
  .page-header > div:first-child { width: 100%; }
  .page-header h1 { font-size: 18px; }
  .page-header .actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }
  .page-header .actions .btn {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 12px;
  }
  .page-header .actions .btn i { font-size: 11px; }

  /* Stat cards single column */
  .stat-cards {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 14px;
  }
  .stat-card {
    padding: 14px;
    gap: 12px;
  }
  .stat-card .stat-icon {
    width: 42px;
    height: 42px;
    font-size: 17px;
  }
  .stat-card .stat-number { font-size: 22px; }
  .stat-card .stat-label { font-size: 11px; }
  .stat-card .stat-growth { font-size: 11px; }

  /* Grid layouts collapse */
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Cards padding reduce */
  .card { border-radius: 10px; }
  .card-header { padding: 12px 14px; }
  .card-body { padding: 14px; }
  .card-title { font-size: 12px; }

  /* Tables — horizontal scroll */
  .table-wrap {
    border-radius: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap > div[style*="overflow-x"] { overflow-x: auto; }
  table.data-table { min-width: 700px; }
  table.data-table thead th {
    padding: 10px 12px;
    font-size: 10px;
    white-space: nowrap;
  }
  table.data-table tbody td {
    padding: 10px 12px;
    font-size: 12px;
    white-space: nowrap;
  }
  table.data-table .user-cell .avatar {
    width: 30px;
    height: 30px;
    font-size: 11px;
  }
  table.data-table .user-cell .info .name { font-size: 12px; }
  table.data-table .user-cell .info .sub { font-size: 10px; }

  /* Table toolbar stack */
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 8px;
  }
  .table-toolbar .toolbar-left { width: 100%; }
  .table-toolbar .toolbar-right {
    margin-left: 0;
    flex-wrap: wrap;
    gap: 6px;
  }
  .table-toolbar form {
    width: 100% !important;
    flex-direction: column;
    gap: 6px;
  }
  .table-toolbar input,
  .table-toolbar select {
    width: 100% !important;
    height: 34px;
    font-size: 12px;
  }
  .table-toolbar .btn { width: 100%; }

  /* Pagination stack */
  .pagination {
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
  }
  .pagination .info {
    width: 100%;
    text-align: center;
    font-size: 11px;
  }
  .pagination .pages { flex-wrap: wrap; justify-content: center; }
  .pagination .pages a,
  .pagination .pages span {
    min-width: 28px;
    height: 28px;
    font-size: 12px;
  }

  /* Form inputs */
  .form-control, .form-select {
    height: 38px;
    font-size: 13px;
  }
  .grid-2 > .form-group,
  .grid-3 > .form-group,
  .grid-4 > .form-group {
    grid-column: span 1;
  }
  /* Force form grids to stack */
  .card-body .grid-2,
  .card-body .grid-3,
  .card-body .grid-4,
  form .grid-2,
  form .grid-3,
  form .grid-4 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }
  form > .grid-2,
  form > .grid-3,
  form > .grid-4 {
    grid-template-columns: 1fr;
  }

  /* Modal full-screen on mobile */
  .modal-dialog {
    margin: 8px;
    max-width: calc(100vw - 16px);
  }
  .modal-body { padding: 14px; }

  /* Quick actions */
  .quick-actions { grid-template-columns: 1fr 1fr; gap: 8px; }
  .quick-action-tile {
    padding: 14px 8px;
  }
  .quick-action-tile .icon {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }
  .quick-action-tile .label { font-size: 11px; }

  /* Department progress */
  .dept-progress .dept-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .dept-progress .dept-row .dept-pct { width: 100%; text-align: left; }

  /* Recent list */
  .recent-list .recent-item { padding: 10px 12px; gap: 8px; }
  .recent-list .recent-item .avatar {
    width: 32px;
    height: 32px;
    font-size: 11px;
  }
  .recent-list .recent-item .info .title { font-size: 12px; }
  .recent-list .recent-item .info .subtitle { font-size: 11px; }
  .recent-list .recent-item .meta .time { font-size: 10px; }

  /* Alerts */
  .alert {
    margin: 12px !important;
    padding: 10px 12px;
    font-size: 12px;
    flex-wrap: wrap;
  }

  /* Profile banner stack */
  .profile-banner {
    flex-direction: column;
    text-align: center;
    padding: 16px;
  }
  .profile-banner .avatar-big {
    width: 64px;
    height: 64px;
    font-size: 22px;
    margin: 0 auto;
  }
  .profile-banner .meta .tags {
    justify-content: center;
    flex-wrap: wrap;
  }

  /* Detail grid stack */
  .detail-grid { grid-template-columns: 1fr; }

  /* Messages layout */
  .messages-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 500px;
  }
  .messages-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
  }
  .messages-sidebar.show { display: flex; }
  .chat-panel { min-height: 60vh; }
  .contact-info-panel { display: none; }

  /* Chat input */
  .chat-input { padding: 10px 12px; gap: 6px; }
  .chat-input input { font-size: 12px; height: 36px; }
  .chat-input .send-btn { width: 36px; height: 36px; }
  .chat-input .icon-btn { width: 32px; height: 32px; }

  /* Mobile bottom nav visible */
  .mobile-bottom-nav { display: flex; }
  .sidebar-footer { display: none; }

  /* Charts */
  .chart-wrap { height: 220px; }
  .chart-wrap.mini { height: 160px; }

  /* Department cards */
  .grid-4[style*="repeat(4, 1fr)"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Settings tabs horizontal scroll */
  .settings-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .settings-tabs a {
    padding: 10px 14px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* Buttons smaller on mobile */
  .btn { padding: 8px 14px; font-size: 12px; }
  .btn-lg { padding: 10px 18px; font-size: 13px; }
  .btn-sm { padding: 6px 10px; font-size: 11px; }

  /* Status pills */
  .status-pill { font-size: 10px; padding: 3px 8px; }

  /* Empty state */
  .empty-state { padding: 40px 16px; }
  .empty-state .icon { font-size: 36px; }
  .empty-state .title { font-size: 14px; }
  .empty-state .desc { font-size: 12px; }

  /* Invoice/billing view */
  .card-body[style*="padding: 32px"] { padding: 16px !important; }
  .card-body[style*="padding: 24px"] { padding: 14px !important; }

  /* Profile dropdown full width on mobile */
  .dropdown-menu-custom {
    position: fixed;
    top: 56px;
    right: 8px;
    left: 8px;
    min-width: auto;
    max-width: none;
    width: auto;
  }
  #user-dropdown { right: 8px; left: 8px; }
}

@media (max-width: 480px) {
  /* Very small phones */
  .content-area { padding: 10px; }

  .stat-cards { gap: 8px; }
  .stat-card { padding: 12px; gap: 10px; }
  .stat-card .stat-icon {
    width: 38px;
    height: 38px;
    font-size: 15px;
  }
  .stat-card .stat-number { font-size: 20px; }

  .quick-actions { grid-template-columns: 1fr; }

  .top-navbar { padding: 0 10px; }
  .top-navbar .nav-title h4 { font-size: 13px; }
  .top-navbar .nav-actions { gap: 4px; }
  .top-navbar .nav-icon-btn {
    width: 30px;
    height: 30px;
    font-size: 13px;
  }
  .top-navbar .nav-icon-btn .badge {
    min-width: 14px;
    height: 14px;
    font-size: 9px;
  }

  .page-header h1 { font-size: 16px; }
  .page-header .actions .btn { font-size: 11px; padding: 7px 10px; }

  .login-card h3 { font-size: 20px; }
  .card-body { padding: 12px; }
  .table-toolbar { padding: 8px 10px; }
  table.data-table { min-width: 600px; }
  table.data-table thead th { padding: 8px 10px; font-size: 9px; }
  table.data-table tbody td { padding: 8px 10px; font-size: 11px; }

  .mobile-bottom-nav a { padding: 4px 8px; font-size: 9px; }
  .mobile-bottom-nav a i { font-size: 16px; }
}

/* ---------- Print ---------- */
@media print {
  .app-sidebar, .top-navbar, .mobile-bottom-nav, .page-header .actions { display: none; }
  .main-content { margin: 0 !important; }
  .content-area { padding: 0; }
  .card { border: 1px solid #ccc; box-shadow: none; }
}

/* ---------- Tablet landscape fix ---------- */
@media (min-width: 769px) and (max-width: 1024px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .quick-actions { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Fix overflow issues ---------- */
html, body {
  overflow-x: hidden;
  max-width: 100%;
}
.app-wrapper {
  max-width: 100%;
  overflow-x: hidden;
}
.main-content {
  min-width: 0;
}
.card {
  min-width: 0;
  overflow: hidden;
}
.table-wrap {
  min-width: 0;
}
