/* ============================================================
   ADNOC Talabati — Global Portal
   responsive.css — every media query, nothing else.
   Desktop-first: 1600 → 1280 → 1024 → 768 → 480
   Mobile matches the dedicated mobile designs:
   sidebar → bottom tab bar, panels/modals → bottom sheets.
   ============================================================ */

/* ---------------- ≤1600 ---------------- */
@media (max-width: 1600px) {
  .kpi-grid.cols-5 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------------- ≤1280 ---------------- */
@media (max-width: 1280px) {
  :root { --sidebar-width: 240px; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-grid.cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bento { grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .main-nav a { font-size: 15px; padding: 12px 14px; }
}

/* ---------------- ≤1024 ---------------- */
@media (max-width: 1024px) {
  :root { --topbar-height: 72px; }
  .kpi-grid, .kpi-grid.cols-3, .kpi-grid.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bento { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: 20px 22px 56px; }
  .site-header { padding: 0 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
}

/* ---------------- ≤768 — the mobile app layout ---------------- */
@media (max-width: 768px) {
  :root { --topbar-height: 64px; }

  /* sidebar off, bottom tab bar on (same markup, restyled) */
  .site-sidebar { display: none; }
  .bottom-nav { display: block; }
  body { padding-bottom: var(--bottombar-height); }

  /* app-bar header: avatar + "ADNOC Talabati" + page title + bell (matches mobile design) */
  :root { --topbar-height: 76px; }
  .site-header { gap: 12px; padding: 0 16px; }
  .site-header .header-search { display: none; }
  .site-header .header-avatar { display: none; }
  .mobile-app-head { display: flex; }
  .site-header .header-bell { width: 44px; height: 44px; }
  .notif-dropdown { width: min(300px, calc(100vw - 32px)); }

  .page-content { padding: 16px 16px 40px; }
  /* page title lives in the app header on mobile (as in the mobile design) */
  .page-head .page-title, .page-head .page-sub { display: none; }
  .page-head > h1.page-title + .page-actions { margin-top: 0; }

  /* grids collapse */
  .kpi-grid, .kpi-grid.cols-3, .kpi-grid.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .stat-tile .stat-value { font-size: 20px; }
  .kpi-card { padding: 14px; }
  .kpi-card .kpi-value { font-size: 24px; }

  /* toolbars wrap */
  .filter-bar { gap: 8px; }
  .filter-bar .search-input { min-width: 100%; order: -1; }
  .page-head { gap: 10px; }
  .page-head .page-actions { width: 100%; }
  .page-head .page-actions .btn { flex: 1; }

  /* tables scroll horizontally inside cards */
  .data-table { font-size: 13px; }
  .data-table th, .data-table td { padding: 10px 10px; }

  /* --- card-table: table rows become stacked cards (matches the mobile design) ---
     Same HTML table; every td carries a role class:
     c-id, c-status, c-title, c-meta, c-row (label/value), c-foot, c-actions, c-hide */
  .table-scroll:has(.card-table) { overflow: visible; }
  .data-table.card-table { display: block; font-size: 13px; }
  .data-table.card-table thead { display: none; }
  .data-table.card-table tbody { display: flex; flex-direction: column; gap: 12px; }
  .data-table.card-table tr {
    display: flex; flex-wrap: wrap; align-items: center; row-gap: 3px; column-gap: 8px;
    padding: 16px; background: #fff; border-radius: 16px; box-shadow: var(--shadow-card);
  }
  .data-table.card-table tr:hover { background: #fff; }
  .data-table.card-table td { display: block; border: none; padding: 0; }
  .data-table.card-table .c-id { order: 1; flex: 1; font-weight: 700; color: var(--rp-primary); font-size: 14px; white-space: nowrap; }
  .data-table.card-table .c-status { order: 2; margin-left: auto; }
  .data-table.card-table .c-title { order: 3; width: 100%; font-weight: 600; font-size: 15px; color: var(--rp-text); margin-top: 2px; }
  .data-table.card-table .c-title .entity-cell { gap: 10px; }
  .data-table.card-table .c-meta { order: 4; width: 100%; font-size: 12.5px; color: var(--rp-text-2); }
  .data-table.card-table .c-meta[data-label]::before { content: attr(data-label) ": "; font-weight: 600; }
  .data-table.card-table .c-row {
    order: 5; width: 100%; display: flex; align-items: center; justify-content: space-between;
    gap: 12px; font-size: 13px; color: var(--rp-text); padding: 2px 0;
  }
  .data-table.card-table .c-row::before { content: attr(data-label); color: var(--rp-text-2); font-weight: 500; }
  .data-table.card-table .c-foot {
    order: 6; flex: 1; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--rp-border);
    font-size: 12.5px; color: var(--rp-text-2); display: flex; align-items: center; white-space: nowrap;
  }
  .data-table.card-table .c-actions {
    order: 7; margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--rp-border);
    display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 2;
  }
  .data-table.card-table .c-actions .cell-actions { display: flex; gap: 8px; }
  .data-table.card-table .c-hide { display: none; }
  /* the white host card flattens so each row-card sits on the canvas like the mobile design */
  .rp-card:has(.data-table.card-table) {
    background: transparent !important; box-shadow: none !important;
    padding: 0 !important; border-radius: 0 !important; overflow: visible !important;
  }
  .rp-card:has(.data-table.card-table) > .action-list-head,
  .rp-card:has(.data-table.card-table) .card-table-head { padding-left: 2px; padding-right: 2px; border-bottom: none; }

  /* --- modals & side panels become bottom sheets (same markup) --- */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box, .modal-box.modal-wide {
    width: 100%; max-height: 86svh; border-radius: 22px 22px 0 0;
    transform: translateY(100%); opacity: 1;
    transition: transform .32s cubic-bezier(.4,0,.2,1);
  }
  .modal-overlay.open .modal-box { transform: translateY(0); }
  .side-panel-overlay .side-panel, .side-panel-overlay .side-panel.panel-wide {
    top: auto; bottom: 0; height: auto; max-height: 88svh; width: 100%;
    border-radius: 22px 22px 0 0;
    transform: translateY(100%); box-shadow: 0 -12px 40px rgba(0,0,0,.18);
  }
  .side-panel-overlay.open .side-panel { transform: translateY(0); }
  .modal-box .modal-head::before, .side-panel .panel-head::before {
    content: ""; position: absolute; left: 50%; transform: translateX(-50%); top: 8px;
    width: 44px; height: 4px; border-radius: 4px; background: var(--neutral-300);
  }
  .modal-box .modal-head, .side-panel .panel-head { position: relative; padding-top: 24px; }
  .modal-box .modal-foot .btn, .side-panel .panel-foot .btn { flex: 1; }

  /* charts a bit shorter */
  .chart-box { max-height: 240px; }

  /* bigger touch targets */
  .icon-btn { width: 38px; height: 38px; }
  .btn.btn-sm { height: 40px; }

  .back-to-top { bottom: calc(var(--bottombar-height) + 16px); }
  .toast { left: 16px; right: 16px; bottom: calc(var(--bottombar-height) + 12px); }

  .launcher-card { padding: 32px 22px; }
  .launcher-links { grid-template-columns: 1fr; }
}



/* ---------------- ≤480 ---------------- */
@media (max-width: 480px) {
  .kpi-grid, .kpi-grid.cols-3, .kpi-grid.cols-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg-pill { width: 100%; }
  .seg-pill button { flex: 1; padding: 7px 8px; font-size: 12px; }
  .overview-head .overview-value { font-size: 26px; }
  .site-header .header-avatar { display: none; }
  .action-row { grid-template-columns: 1fr; }
  .action-row .order-actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  .modal-box, .side-panel { animation: none !important; transition: none !important; }
}
