/* ============================================================
   WORDCRAFT GLOBAL RESPONSIVE STYLES
   Injected into all authenticated app pages.
   Covers 375px, 768px, and 1024px+ breakpoints.
   ============================================================ */

/* ── PREVENT HORIZONTAL PAGE SCROLL ────────────────────────── */
html, body {
  overflow-x: hidden;
  max-width: 100%;
}

/* ── NAV: HAMBURGER MENU (injected by mobile-nav.js) ────────── */

/* Desktop: hide hamburger */
@media (min-width: 769px) {
  .mob-hamburger { display: none !important; }
  .mob-menu-overlay { display: none !important; }
}

/* Mobile: hide desktop nav links, show hamburger */
@media (max-width: 768px) {
  .nav-left .nav-link,
  .nav-left a:not(.logo) { display: none !important; }

  /* Also hide existing overflow menus/buttons that aren't needed with hamburger */
  .nav-overflow-btn { display: none !important; }
  .nav-overflow-menu { display: none !important; }
  .nav-right { display: none !important; }

  nav {
    padding: 14px 20px !important;
    flex-wrap: nowrap !important;
    position: relative;
    justify-content: space-between !important;
    align-items: center !important;
  }

  .nav-left {
    flex-wrap: nowrap !important;
    gap: 0 !important;
  }

  /* Hamburger button style */
  .mob-hamburger {
    display: flex !important;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--parchment, #f5f0e8);
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
    margin-left: auto;
  }
}

/* Mobile menu overlay (full-screen) */
.mob-menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(13, 13, 13, 0.98);
  z-index: 9999;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mob-menu-overlay.mob-open {
  display: flex;
}

.mob-menu-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(212, 168, 83, 0.15);
  flex-shrink: 0;
}

.mob-menu-close {
  background: none;
  border: none;
  color: var(--parchment, #f5f0e8);
  font-size: 22px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.mob-menu-close:hover { color: var(--amber, #d4a853); }

.mob-menu-links {
  display: flex;
  flex-direction: column;
  padding: 8px 0;
}
.mob-menu-links a {
  display: flex;
  align-items: center;
  padding: 14px 28px;
  color: var(--warm-gray, #8a8274);
  text-decoration: none;
  font-size: 15px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: 'Space Grotesk', sans-serif;
  border-bottom: 1px solid rgba(212, 168, 83, 0.06);
  min-height: 48px;
  transition: color 0.2s, background 0.2s;
}
.mob-menu-links a:last-child { border-bottom: none; }
.mob-menu-links a:hover,
.mob-menu-links a.mob-active {
  color: var(--amber, #d4a853);
  background: rgba(212, 168, 83, 0.05);
}

/* ── CONTAINER ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .container { padding: 24px 20px !important; }
}
@media (max-width: 480px) {
  .container { padding: 16px 16px !important; }
}

/* ── PAGE HEADER ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 16px !important;
    margin-bottom: 24px !important;
  }
  .page-header h1,
  .page-header-left h1 {
    font-size: 26px !important;
  }
  .header-actions,
  .header-controls {
    width: 100%;
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
  .header-actions .btn,
  .header-controls .btn {
    flex: 1;
    min-width: 120px;
    justify-content: center !important;
    text-align: center;
    white-space: nowrap;
  }
}

/* ── BUTTONS — 44px MIN TAP TARGET ──────────────────────────── */
@media (max-width: 768px) {
  .btn {
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  .btn-sm, .btn-small {
    min-height: 40px !important;
  }
}

/* ── INPUTS / FORMS — 44px TARGETS, 16px FONT ───────────────── */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="url"],
  input[type="search"],
  input[type="tel"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px !important; /* Prevent iOS auto-zoom */
    min-height: 44px;
  }
  textarea {
    min-height: 80px;
  }

  /* Form grids → single column */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  .form-row {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .form-group {
    width: 100% !important;
  }

  /* Full-width selects & inputs in filter rows */
  .filter-row {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
  .filter-row input,
  .filter-row select {
    flex: 1 1 calc(50% - 8px) !important;
    min-width: 120px !important;
    width: auto !important;
  }
}

/* ── STATS GRIDS ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .stats,
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }
}
@media (max-width: 480px) {
  .stats,
  .stats-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── DATA TABLES — HORIZONTAL SCROLL WRAPPER ────────────────── */
@media (max-width: 768px) {
  /* Tables not already inside a scroll wrapper get min-width so content doesn't crush */
  table {
    min-width: 560px;
  }
  /* Any element with class table-wrap, table-container, or table-responsive scrolls */
  .table-wrap,
  .table-container,
  .table-responsive,
  .mob-table-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    /* Scroll shadow cue */
    background: linear-gradient(to right, transparent 70%, rgba(0,0,0,0.04)) local,
                linear-gradient(to right, rgba(212,168,83,0.07), transparent) scroll;
  }
}

/* ── KANBAN — STACK VERTICALLY ON MOBILE ────────────────────── */
@media (max-width: 768px) {
  .kanban {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* ── SIDE PANELS → FULL SCREEN ON MOBILE ────────────────────── */
@media (max-width: 768px) {
  .side-panel {
    width: 100vw !important;
    max-width: 100vw !important;
    border-left: none !important;
    border-top: 1px solid rgba(212, 168, 83, 0.15);
  }
  .panel-header {
    padding: 16px 20px 14px !important;
  }
  .panel-body {
    padding: 20px !important;
  }
}

/* ── MODALS → FULL-SCREEN BOTTOM SHEET ON MOBILE ────────────── */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
  }
  .modal {
    max-width: 100vw !important;
    width: 100% !important;
    max-height: 90vh !important;
    border-radius: 16px 16px 0 0 !important;
    margin: 0 !important;
  }
}

/* ── TWO-COLUMN GRIDS → SINGLE COLUMN ──────────────────────── */
@media (max-width: 768px) {
  .two-col,
  .grid-2,
  .col-2 {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* ── THREE-COLUMN GRIDS ─────────────────────────────────────── */
@media (max-width: 1024px) {
  .grid-3,
  .col-3 {
    grid-template-columns: 1fr 1fr !important;
  }
}
@media (max-width: 640px) {
  .grid-3,
  .col-3 {
    grid-template-columns: 1fr !important;
  }
}

/* ── CARDS / POST CARDS — STACK ON MOBILE ───────────────────── */
@media (max-width: 768px) {
  .post-card {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 16px !important;
  }
  .post-actions {
    margin-left: 0 !important;
    flex-wrap: wrap !important;
    width: 100%;
  }
}

/* ── FILTER TABS — SCROLLABLE ───────────────────────────────── */
@media (max-width: 640px) {
  .filter-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .filter-tabs::-webkit-scrollbar { display: none; }
}

/* ── VIEW TOGGLE — FULL WIDTH ───────────────────────────────── */
@media (max-width: 480px) {
  .view-toggle {
    width: 100%;
    justify-content: stretch;
  }
  .view-btn {
    flex: 1;
    text-align: center;
  }
}

/* ── PIPELINE BAR — STACK ON MOBILE ────────────────────────── */
@media (max-width: 768px) {
  .pipeline-bar {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }
  .pipeline-step {
    flex-shrink: 0;
    min-width: 90px;
  }
}

/* ── CALENDAR — HORIZONTAL SCROLL ──────────────────────────── */
@media (max-width: 768px) {
  /* Wrap calendar-grid with a scroll container (via mobile-nav.js) */
  .calendar-scroll-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .calendar-scroll-wrap .calendar-grid {
    min-width: 700px;
  }
  .calendar-scroll-wrap .calendar-header-cell {
    padding: 10px 4px;
    font-size: 10px;
  }
  .calendar-scroll-wrap .calendar-day {
    min-height: 72px;
    padding: 6px;
  }
  .calendar-scroll-wrap .day-number {
    font-size: 11px;
    width: 22px;
    height: 22px;
  }
  /* Header controls wrap */
  .header-controls {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }
  .month-nav {
    gap: 10px !important;
  }
  .month-title {
    font-size: 18px !important;
    min-width: 140px !important;
  }
}

/* ── TOAST — FULL WIDTH ON MOBILE ───────────────────────────── */
@media (max-width: 768px) {
  .toast {
    bottom: 16px !important;
    right: 16px !important;
    left: 16px !important;
    max-width: none !important;
  }
}

/* ── GENERATE FORM (Dashboard) ──────────────────────────────── */
@media (max-width: 768px) {
  .generate-section {
    padding: 20px !important;
  }
}

/* ── SEQUENCES / STEP BUILDERS ──────────────────────────────── */
@media (max-width: 768px) {
  /* Step lists & editors */
  .step-card,
  .sequence-step {
    padding: 16px !important;
  }
}

/* ── SETTINGS — TABS ────────────────────────────────────────── */
@media (max-width: 768px) {
  .settings-tabs,
  .tab-bar {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }
  .settings-tabs::-webkit-scrollbar,
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-btn,
  .settings-tab {
    flex-shrink: 0;
    white-space: nowrap;
  }
}

/* ── BILLING — PLAN CARDS ───────────────────────────────────── */
@media (max-width: 768px) {
  .plan-cards,
  .pricing-grid {
    grid-template-columns: 1fr !important;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ── AD COPY — PLATFORM TABS ────────────────────────────────── */
@media (max-width: 768px) {
  .platform-tabs {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
  }
  .platform-tabs::-webkit-scrollbar { display: none; }
  .platform-tab {
    flex-shrink: 0;
  }
}

/* ── POST VIEWER — READABLE ON MOBILE ──────────────────────── */
@media (max-width: 768px) {
  .post-body,
  .post-content {
    font-size: 16px !important;
    line-height: 1.75 !important;
  }
  .copy-btn,
  .copy-html-btn {
    width: 100%;
    justify-content: center !important;
    margin-bottom: 8px !important;
  }
}

/* ── NEWSLETTER EDITOR ──────────────────────────────────────── */
@media (max-width: 768px) {
  .nl-toolbar {
    flex-wrap: wrap !important;
  }
}

/* ── APPROVALS — CARD ACTIONS ───────────────────────────────── */
@media (max-width: 768px) {
  .approval-actions {
    flex-direction: column !important;
    gap: 8px !important;
  }
  .approval-actions .btn {
    width: 100%;
  }
}

/* ── ANALYTICS — CHART PANELS ───────────────────────────────── */
@media (max-width: 768px) {
  .analytics-grid,
  .charts-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── SEO — KEYWORD TABLE ────────────────────────────────────── */
@media (max-width: 768px) {
  .seo-table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── PAGES/LANDING PAGES — CARD GRID ───────────────────────── */
@media (max-width: 768px) {
  .pages-grid,
  .landing-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── GENERAL FLEX STACKING ──────────────────────────────────── */
@media (max-width: 480px) {
  .flex-mobile-col {
    flex-direction: column !important;
    align-items: stretch !important;
  }
}

/* ── ENSURE NO ELEMENTS OVERFLOW VIEWPORT ──────────────────── */
@media (max-width: 768px) {
  img, video, iframe, canvas {
    max-width: 100%;
    height: auto;
  }
}

/* ── POST VIEWER — ARTICLE LAYOUT ───────────────────────────── */
@media (max-width: 768px) {
  .article-container {
    padding: 24px 20px !important;
  }
  .article-body {
    font-size: 16px !important;
    line-height: 1.8 !important;
  }
  .article-body h2 {
    font-size: 22px !important;
    margin: 28px 0 12px !important;
  }
  .article-body h3 {
    font-size: 18px !important;
  }
  .action-bar {
    flex-wrap: wrap !important;
    gap: 10px !important;
    margin-top: 32px !important;
  }
  .action-bar .btn {
    flex: 1;
    min-width: 140px;
    justify-content: center !important;
    text-align: center;
  }
}

/* ── SETTINGS — PLATFORM CARDS ──────────────────────────────── */
@media (max-width: 768px) {
  .platform-card {
    padding: 20px !important;
  }
  .platform-header {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }
  .platform-actions {
    width: 100%;
    flex-wrap: wrap !important;
  }
  .platform-actions .btn {
    flex: 1;
    min-width: 100px;
    justify-content: center !important;
  }
  .autopost-row {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }
}

/* ── BILLING — PLAN CARDS / INVOICE TABLE ───────────────────── */
@media (max-width: 768px) {
  .billing-grid,
  .plan-grid {
    grid-template-columns: 1fr !important;
  }
  .invoice-row,
  .invoice-item {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
}

/* ── NEWSLETTERS — COMPOSER ─────────────────────────────────── */
@media (max-width: 768px) {
  .nl-editor,
  .newsletter-editor {
    padding: 16px !important;
  }
  .nl-toolbar,
  .editor-toolbar {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .nl-stats-row {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* ── AUTOMATIONS — FLOW CARDS ───────────────────────────────── */
@media (max-width: 768px) {
  .automation-card,
  .automation-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px !important;
  }
  .automation-actions {
    width: 100%;
    flex-wrap: wrap !important;
  }
}

/* ── SEQUENCES — STEP EDITOR ────────────────────────────────── */
@media (max-width: 768px) {
  .sequence-header {
    flex-direction: column !important;
    gap: 12px !important;
  }
  .step-editor {
    padding: 16px !important;
  }
}

/* ── FORMS — FORM BUILDER ────────────────────────────────────── */
@media (max-width: 768px) {
  .form-builder-layout,
  .builder-cols {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
}

/* ── CAMPAIGNS — CARD GRID ───────────────────────────────────── */
@media (max-width: 768px) {
  .campaigns-grid,
  .campaign-list {
    grid-template-columns: 1fr !important;
  }
  .campaign-card {
    padding: 16px !important;
  }
}

/* ── PRODUCTS — PRODUCT GRID ────────────────────────────────── */
@media (max-width: 768px) {
  .products-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  .product-card {
    padding: 16px !important;
  }
}

/* ── LEADS — TABLE ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .leads-table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── APPROVALS — CONTENT CARD ────────────────────────────────── */
@media (max-width: 768px) {
  .approval-card {
    padding: 16px !important;
  }
  .approval-header {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
  .approval-actions {
    flex-direction: column !important;
    gap: 8px !important;
    width: 100%;
  }
  .approval-actions .btn {
    width: 100% !important;
    justify-content: center !important;
  }
}

/* ── TEAM — MEMBER CARDS ─────────────────────────────────────── */
@media (max-width: 768px) {
  .team-grid {
    grid-template-columns: 1fr !important;
  }
  .team-member {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
  .member-actions {
    flex-wrap: wrap !important;
    width: 100%;
  }
}

/* ── NEWSLETTERS — STATS ROW & SECTION HEADER ───────────────── */
@media (max-width: 768px) {
  .stats-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }
  .section-header {
    flex-wrap: wrap !important;
    gap: 12px !important;
  }
  .section-header .btn {
    flex: 1;
    min-width: 120px;
    justify-content: center !important;
  }
}
@media (max-width: 480px) {
  .stats-row {
    grid-template-columns: 1fr !important;
  }
}

/* ── ANALYTICS — CHARTS LAYOUT ───────────────────────────────── */
@media (max-width: 768px) {
  .analytics-row,
  .chart-row {
    flex-direction: column !important;
    gap: 16px !important;
  }
  .chart-panel {
    width: 100% !important;
  }
}

/* ── SEO — RESULTS TABLE ─────────────────────────────────────── */
@media (max-width: 768px) {
  .seo-results {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .keyword-analysis-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ── ANALYTICS — SPECIFIC GRIDS ─────────────────────────────── */
@media (max-width: 768px) {
  .charts-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  .breakdown-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  .premium-bar {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }
  .chart-header {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
}

/* ── PAGES — LANDING PAGE CARDS ─────────────────────────────── */
@media (max-width: 768px) {
  .page-card {
    padding: 16px !important;
  }
  .page-card-actions {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
}
