/* =============================================
   PIPA OS — Responsive / Mobile Overrides
   Puramente aditivo — não modifica CSS existente
   3 breakpoints: 1024px, 768px, 480px
   ============================================= */


/* ===========================================
   SMALL DESKTOP (≤1024px)
   =========================================== */
@media (max-width: 1024px) {

  /* --- Layout --- */
  .main {
    padding: 1.5rem;
  }

  /* --- Metrics grid: 3 cols --- */
  .metrics {
    grid-template-columns: repeat(3, 1fr);
  }

  /* --- Financeiro cards --- */
  .fin-cards {
    grid-template-columns: 1fr 1fr;
  }

  /* --- Kanban cols slightly narrower --- */
  .kanban-col {
    min-width: 220px;
  }
}


/* ===========================================
   TABLET (≤768px)
   =========================================== */
@media (max-width: 768px) {

  /* --- Body: space for bottom tab bar --- */
  body {
    padding-bottom: 70px;
  }

  /* --- Header → compact top bar --- */
  .header {
    flex-wrap: wrap;
    height: auto;
    padding: 0.5rem 1rem;
  }

  .header-logo {
    font-size: 0.9rem;
  }

  /* --- Nav → fixed bottom tab bar --- */
  .header-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0.5rem;
    display: flex;
    justify-content: space-around;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0;
  }

  .header-nav button {
    font-size: 0.7rem;
    padding: 0.5rem 0.4rem;
    flex-direction: column;
    display: flex;
    align-items: center;
    gap: 0.15rem;
    min-width: 0;
    white-space: nowrap;
    border-radius: 6px;
  }

  /* --- Header right: compact --- */
  .header-right {
    gap: 0.4rem;
  }

  .clock {
    font-size: 0.7rem;
  }

  /* --- Main content --- */
  .main {
    padding: 1rem;
    padding-bottom: 80px;
  }

  /* --- Welcome --- */
  .welcome h1 {
    font-size: 1.2rem;
  }

  /* --- Sections --- */
  .section {
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
  }

  /* --- Metrics: 2 cols --- */
  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  .metric-card .value {
    font-size: 1.3rem;
  }

  /* --- Kanban: stack vertically --- */
  .kanban {
    flex-direction: column;
    overflow-x: visible;
  }

  .kanban-col {
    min-width: unset;
    width: 100%;
  }

  /* --- Leads search bar --- */
  .leads-search-bar {
    flex-direction: column;
  }

  /* --- Calendário / Agenda --- */
  /* Hide calendar grid, show only sidebar list */
  .cal-grid {
    display: none !important;
  }

  /* Force two-col to single column (override inline styles) */
  .two-col,
  .two-col[style] {
    grid-template-columns: 1fr !important;
  }

  /* Calendar section with hidden grid: hide it entirely */
  #tab-agenda .two-col > .section:first-child {
    display: none;
  }

  /* Sidebar becomes the main view */
  .cal-sidebar {
    display: block;
    width: 100%;
    min-width: unset;
  }

  /* Filters: horizontal scrollable row, not vertical stack */
  .cal-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.4rem;
    padding-bottom: 0.5rem;
  }

  .cal-filter {
    flex-shrink: 0;
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
  }

  /* Add button: compact, inline with filters */
  .cal-add-btn {
    flex-shrink: 0;
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
  }

  /* --- Financeiro --- */
  .gauge {
    width: 130px;
    height: 130px;
  }

  .gauge-wrap {
    flex-direction: column;
    align-items: center;
  }

  .gauge-label .num {
    font-size: 1.6rem;
  }

  .rev-chart {
    overflow-x: auto;
  }

  .fin-cards {
    grid-template-columns: 1fr 1fr;
  }

  .month-nav .month-label {
    font-size: 1rem;
  }

  /* --- Orçamento --- */
  .orc-staff-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .orc-staff-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .orc-actions {
    flex-direction: column;
  }

  .orc-actions button {
    width: 100%;
  }

  .orc-extras-grid {
    gap: 0.2rem;
  }

  .orc-extra-row {
    flex-wrap: wrap;
    gap: 0.3rem;
    padding: 0.4rem 0.5rem;
  }

  .orc-extra-controls {
    width: 100%;
    padding-left: 1.4rem;
  }

  .orc-extra-obs {
    flex: 1;
    min-width: 60px;
  }

  .orc-extras-grid {
    gap: 0.15rem;
  }

  #orcResultado {
    padding: 1rem;
  }

  /* --- Gestão: table wrappers --- */
  .tarefas-table-wrap,
  .backup-table-wrap,
  .relatorios-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tarefas-table {
    min-width: 600px;
  }

  .token-chart-7d {
    overflow-x: auto;
  }

  /* --- Profile toggle: compact --- */
  .profile-toggle {
    font-size: 0.8rem;
  }

  /* --- Chat fab: above bottom bar --- */
  .chat-fab {
    bottom: 80px !important;
    right: 16px !important;
  }

  /* --- Touch improvements --- */
  button,
  .kanban-card,
  .orc-extra-card {
    -webkit-tap-highlight-color: rgba(247, 148, 29, 0.2);
  }

  .orc-num-btn {
    min-width: 40px;
    min-height: 40px;
  }

  .orc-staff-mini-ctrl button {
    min-width: 32px;
    min-height: 36px;
  }

  /* --- Scrollbars: thinner on touch --- */
  ::-webkit-scrollbar {
    width: 3px;
  }
}


/* ===========================================
   PHONE (≤480px)
   =========================================== */
@media (max-width: 480px) {

  /* --- Header logo: hide text, keep icon --- */
  .header-logo span,
  .header-logo .logo-text {
    display: none;
  }

  .header-logo {
    font-size: 0;
  }

  .header-logo img,
  .header-logo svg,
  .header-logo::before {
    font-size: 1.2rem;
    display: inline-block;
  }

  /* --- Clock hidden --- */
  .clock {
    display: none;
  }

  /* --- Nav buttons: smaller --- */
  .header-nav button {
    font-size: 0.6rem;
    padding: 0.4rem 0.3rem;
  }

  /* --- Metrics: single column --- */
  .metrics {
    grid-template-columns: 1fr;
  }

  /* --- Pipeline summary --- */
  .pipeline-summary {
    flex-direction: column;
  }

  /* --- Calendário --- */
  .cal-filters {
    gap: 0.3rem;
  }

  .cal-add-btn {
    width: auto;
    margin-left: 0;
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
  }

  .cal-sidebar-item {
    padding: 0.6rem;
  }

  .cal-sidebar-item .sb-main {
    font-size: 0.8rem;
  }

  /* --- Financeiro: single column cards --- */
  .fin-cards {
    grid-template-columns: 1fr;
  }

  /* --- Orçamento pacotes --- */
  .orc-pacotes-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* --- Gestão: tokens summary --- */
  .tokens-summary {
    grid-template-columns: 1fr;
  }

  /* --- Chat widget: fullscreen above bottom bar --- */
  .chat-panel {
    width: 100vw;
    height: calc(100vh - 70px);
    bottom: 70px;
    right: 0;
    border-radius: 0;
    border: none;
  }

  .chat-fab {
    bottom: 80px;
    right: 12px;
  }

  /* --- Search / Modals --- */
  .search-box {
    max-width: 95vw;
    margin: 0 auto;
  }

  .detail-modal {
    max-width: 95vw;
    max-height: 90vh;
    border-radius: 12px;
  }

  /* --- Welcome smaller --- */
  .welcome h1 {
    font-size: 1rem;
  }

  /* --- Sections tighter --- */
  .section {
    padding: 0.75rem;
  }

  .main {
    padding: 0.5rem;
    padding-bottom: 80px;
  }
}
