/* ═══════════════════════════════════════════════════════
   SHIVAM AI — MOBILE RESPONSIVE
   Mobile-first, app-like experience
   Breakpoint: 768px and below
═══════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ── LAYOUT ──────────────────────────────────────── */
  .app {
    display: block;
    padding-bottom: 70px; /* space for bottom nav */
  }

  .page {
    margin-left: 0 !important;
    min-height: calc(100vh - 70px);
  }

  .page-body {
    padding: 16px !important;
  }

  /* ── TOPBAR ──────────────────────────────────────── */
  .topbar {
    padding: 0 16px !important;
    height: 56px;
  }
  .topbar-left h1 { font-size: 1.1rem !important; }
  .topbar-left p  { display: none; }

  /* ── SIDEBAR → HIDDEN ON MOBILE ──────────────────── */
  .sidebar {
    display: none !important;
  }

  /* ── BOTTOM NAVIGATION BAR ───────────────────────── */
  .bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 70px;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--sidebar-border);
    z-index: 1000;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom);
    justify-content: space-around;
    align-items: center;
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 12px;
    text-decoration: none;
    color: #64748b;
    font-size: 10px;
    font-weight: 500;
    min-width: 56px;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-item.active {
    color: #fff;
    background: var(--brand);
  }

  .bottom-nav-item svg {
    width: 22px;
    height: 22px;
  }

  .bottom-nav-item span {
    font-size: 10px;
    line-height: 1;
  }

  /* ── STATS ROW ───────────────────────────────────── */
  .stats-row {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
    margin-bottom: 16px !important;
  }

  .stat-card {
    padding: 16px !important;
  }

  .stat-card-value {
    font-size: 1.5rem !important;
  }

  /* ── CARDS ───────────────────────────────────────── */
  .card { border-radius: 12px !important; }
  .card-body { padding: 16px !important; }
  .card-header { padding: 16px !important; }
  .card-footer { padding: 12px 16px !important; }

  /* ── GRIDS ───────────────────────────────────────── */
  .grid-2, .grid-3 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* ── TABLES → CARD LIST ──────────────────────────── */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
  }

  .data-table {
    display: block;
    width: 100%;
  }

  .data-table thead { display: none; }

  .data-table tbody { display: block; }

  .data-table tr {
    display: flex;
    flex-direction: column;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    gap: 6px;
  }

  .data-table tr:last-child { border-bottom: none; }

  .data-table td {
    display: flex;
    align-items: center;
    padding: 0 !important;
    border: none !important;
    font-size: 13px;
  }

  /* Content table specific */
  .content-table-row {
    display: flex !important;
    flex-direction: column !important;
    padding: 14px 16px !important;
    border-bottom: 1px solid var(--border) !important;
    gap: 8px !important;
    cursor: pointer;
  }

  .content-table-row td {
    display: block !important;
    padding: 0 !important;
    border: none !important;
  }

  .content-title-cell {
    order: 1;
    font-weight: 600 !important;
    font-size: 14px !important;
    color: var(--text) !important;
  }

  .content-meta-row {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
    order: 2;
  }

  .content-actions-cell {
    order: 3;
    justify-content: flex-end !important;
    padding-top: 4px !important;
  }

  /* Hide less important columns on mobile */
  .hide-mobile { display: none !important; }

  /* ── MODALS → BOTTOM SHEET ───────────────────────── */
  .modal-container {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    transform: none !important;
    max-width: 100% !important;
    width: 100% !important;
    max-height: 90vh !important;
    border-radius: 20px 20px 0 0 !important;
    overflow-y: auto !important;
    margin: 0 !important;
    animation: slideUp 0.3s ease !important;
  }

  @keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  .modal-container::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto 0;
  }

  .modal-header { padding: 16px 20px 12px !important; }
  .modal-body   { padding: 16px 20px !important; }
  .modal-footer {
    padding: 12px 20px !important;
    flex-direction: column !important;
    gap: 8px !important;
  }
  .modal-footer .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* ── BUTTONS ─────────────────────────────────────── */
  .btn { min-height: 40px; }
  .btn-lg { min-height: 48px; font-size: 15px !important; }

  /* ── FILTERS BAR ─────────────────────────────────── */
  .filters-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .filter-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    gap: 6px !important;
    flex-wrap: nowrap !important;
  }

  .filter-tab {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 6px 12px !important;
    font-size: 12px !important;
  }

  /* ── SEARCH ──────────────────────────────────────── */
  .search-input { width: 100% !important; }

  /* ── PAGE HEADER ─────────────────────────────────── */
  .page-header {
    flex-direction: column !important;
    gap: 12px !important;
    margin-bottom: 16px !important;
  }

  .page-header-right {
    width: 100%;
    flex-direction: column !important;
  }

  .page-header-right .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* ── AUTH PAGES ──────────────────────────────────── */
  .auth-page {
    grid-template-columns: 1fr !important;
  }

  .auth-left { display: none !important; }

  .auth-right {
    padding: 24px 20px !important;
    align-items: flex-start !important;
    padding-top: 48px !important;
  }

  .auth-box { max-width: 100% !important; }

  /* ── DASHBOARD SPECIFIC ──────────────────────────── */
  .dash-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* Setup steps — 2 columns on mobile */
  .setup-steps {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    padding: 12px 16px !important;
  }

  .setup-step {
    padding: 10px 12px !important;
    gap: 8px !important;
  }

  /* Hide step description text on mobile */
  .setup-step .text-sm,
  .setup-step p,
  .step-desc {
    display: none !important;
  }

  /* Hide the desc div (second child of inner div) */
  .setup-step > div > div:nth-child(2) {
    display: none !important;
  }

  /* Step label font size */
  .setup-step > div > div:first-child {
    font-size: 12px !important;
  }

  .step-label {
    font-size: 12px !important;
    line-height: 1.3 !important;
  }

  .step-circle {
    width: 26px !important;
    height: 26px !important;
    flex-shrink: 0 !important;
  }

  /* Setup banner header compact */
  #setupBanner > div:first-child {
    padding: 14px 16px !important;
  }

  /* Stats — force 2 columns */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 16px !important;
  }

  /* Stat box compact */
  .stat-box {
    padding: 14px 12px !important;
  }

  .stat-box .stat-value,
  .stat-box [class*="stat-val"],
  .stat-box h2,
  .stat-box .text-2xl {
    font-size: 1.4rem !important;
  }

  /* Topbar greeting — smaller */
  .topbar-greeting {
    font-size: 14px !important;
  }

  /* Hide topbar subtitle */
  .topbar-subtitle { display: none !important; }

  /* Topbar buttons — icon only on mobile */
  .topbar-right .btn-text { display: none !important; }
  .topbar-right .btn {
    padding: 8px 10px !important;
    font-size: 12px !important;
  }

  /* Greeting emoji */
  .greeting-emoji { font-size: 16px !important; }

  /* ── SETTINGS ────────────────────────────────────── */
  .settings-nav {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    gap: 4px !important;
    padding-bottom: 4px !important;
    -webkit-overflow-scrolling: touch;
  }

  .settings-nav-item {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 8px 14px !important;
    font-size: 13px !important;
  }

  /* ── ANALYTICS ───────────────────────────────────── */
  .analytics-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── CONTENT VIEW MODAL ──────────────────────────── */
  #viewBody {
    max-height: 50vh !important;
    overflow-y: auto !important;
  }

  /* ── CONTENT TABLE HEADER — HIDE ON MOBILE ─────── */
  #contentTable thead { display: none !important; }

  /* Fix colspan empty state */
  #contentTableBody tr td[colspan] {
    display: table-cell !important;
  }

  /* ── CONTENT TABLE → CARD LIST ON MOBILE ────────── */

  /* Hide table header */
  #contentTable thead { display: none !important; }

  /* Each row = card */
  #contentTableBody tr.content-table-row {
    display: block !important;
    padding: 14px 16px !important;
    border-bottom: 1px solid var(--border) !important;
  }

  /* Hide all cells */
  #contentTableBody tr.content-table-row td {
    display: none !important;
    padding: 0 !important;
    border: none !important;
  }

  /* Show title cell */
  #contentTableBody tr.content-table-row td:first-child {
    display: block !important;
    width: 100% !important;
  }

  /* Show status cell */
  #contentTableBody tr.content-table-row td:nth-child(2) {
    display: block !important;
    margin-top: 8px !important;
  }

  /* Show actions cell */
  #contentTableBody tr.content-table-row td:last-child {
    display: flex !important;
    justify-content: flex-end !important;
    margin-top: 10px !important;
  }

  /* Title cell flex fix */
  .content-title-cell {
    display: flex !important;
    align-items: flex-start !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .content-icon { flex-shrink: 0 !important; }

  .content-title-cell > div:last-child {
    flex: 1 !important;
    min-width: 0 !important;
  }

  /* Title text */
  .content-title-text {
    display: block !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    line-height: 1.5 !important;
    color: var(--text) !important;
    word-break: break-word !important;
  }

  /* Empty state fix */
  #contentTableBody tr td[colspan] {
    display: table-cell !important;
  }

    /* ── CONTENT VIEW MODAL ──────────────────────────── */
  #viewBody {
    max-height: 50vh !important;
    overflow-y: auto !important;
  }

  /* ── CONTENT TABLE HEADER — HIDE ON MOBILE ─────── */
  #contentTable thead { display: none !important; }

  /* Fix colspan empty state */
  #contentTableBody tr td[colspan] {
    display: table-cell !important;
  }

  /* ── CONTENT TABLE → CARD LIST ON MOBILE ────────── */
  #contentTableBody tr.content-table-row {
    display: block !important;
    padding: 14px 16px !important;
    border-bottom: 1px solid var(--border) !important;
    cursor: pointer;
  }

  /* Hide all td by default */
  #contentTableBody tr.content-table-row td {
    display: none !important;
    padding: 0 !important;
    border: none !important;
  }

  /* Show: title(2nd), status(3rd), actions(last) */
  #contentTableBody tr.content-table-row td:nth-child(2) {
    display: block !important;
  }

  #contentTableBody tr.content-table-row td:nth-child(3) {
    display: inline-block !important;
    margin-top: 6px !important;
  }

  #contentTableBody tr.content-table-row td:last-child {
    display: flex !important;
    justify-content: flex-end !important;
    margin-top: 8px !important;
  }

  /* Status cell — show as inline */
  #contentTableBody tr.content-table-row td:nth-child(2) {
    display: inline-block !important;
    margin-top: 6px !important;
  }

  /* Actions — right aligned */
  #contentTableBody tr.content-table-row td:last-child {
    margin-top: 8px !important;
    display: flex !important;
    justify-content: flex-end !important;
  }

  /* Title text */
  .content-title-text {
    font-size: 13px !important;
    font-weight: 600 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
  }

  /* Content stat cards in topbar */
  #contentStats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* ── SOCIAL CARDS ────────────────────────────────── */
  .social-platforms {
    grid-template-columns: 1fr !important;
  }

  /* ── SCHEDULE ────────────────────────────────────── */
  .schedule-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── PUBLISHING ──────────────────────────────────── */
  .publish-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── FORM GROUPS ─────────────────────────────────── */
  .form-row {
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* ── TOPBAR ACTION BUTTONS ───────────────────────── */
  .topbar-actions {
    gap: 8px !important;
  }

  .topbar-actions .btn span {
    display: none;
  }

  /* ── CONTENT GENERATE MODAL ──────────────────────── */
  .word-count-options {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .word-count-btn {
    flex: 1 !important;
    min-width: calc(33% - 6px) !important;
  }

  /* ── SCROLLBARS ──────────────────────────────────── */
  ::-webkit-scrollbar { width: 0; height: 0; }

  /* ── TYPOGRAPHY ──────────────────────────────────── */
  h1 { font-size: 1.25rem !important; }
  h2 { font-size: 1.1rem !important; }

  /* ── SAFE AREA ───────────────────────────────────── */
  .page {
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }

  /* ── ANALYTICS PAGE ──────────────────────────────── */
  .an-grid-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .an-grid-2 {
    grid-template-columns: 1fr !important;
  }

  /* Override inline grid styles on analytics */
  .page-body [style*="repeat(5,1fr)"],
  .page-body [style*="repeat(4,1fr)"],
  .page-body [style*="repeat(3,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .page-body [style*="repeat(12,1fr)"],
  .page-body [style*="repeat(7,1fr)"] {
    grid-template-columns: repeat(6, 1fr) !important;
  }

  /* Analytics heatmap — scroll horizontally */
  .heatmap-grid {
    grid-template-columns: repeat(7, 1fr) !important;
    font-size: 10px !important;
  }

  /* Analytics month comparison */
  .page-body [style*="1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Schedule page — publishing list */
  .page-body [style*="120px 1fr 100px 160px 80px"] {
    grid-template-columns: 1fr auto !important;
    font-size: 12px !important;
  }

  /* Social platforms grid */
  .page-body [style*="repeat(6,1fr)"] {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* Publishing page */
  .page-body [style*="repeat(3,1fr)"] {
    grid-template-columns: 1fr !important;
  }
}

/* ── BOTTOM NAV HIDDEN ON DESKTOP ────────────────── */
.bottom-nav { display: none; }

/* ── TABLET ──────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .page { margin-left: var(--sidebar-width); }
  .stats-row { grid-template-columns: repeat(2, 1fr) !important; }
  .page-body { padding: var(--sp-5) var(--sp-6) !important; }
}
