/* ═══════════════════════════════════════════════════════════════════
   ProcuraDesk Responsive CSS
   Mobile (<768px) | Tablet (768-1024px) | Desktop (>1024px)
   ═══════════════════════════════════════════════════════════════════ */

/* ── Mobile hamburger & bottom nav (injected by mobile.js) ─────── */

.mobile-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--fg);
  cursor: pointer;
  padding: 6px;
  margin-right: 4px;
  flex-shrink: 0;
  z-index: 50;
}

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-default);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 56px;
}

.mobile-bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--fg-subtle);
  font-size: 10px;
  cursor: pointer;
  padding: 6px 12px;
  border: none;
  background: none;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}

.mobile-bottom-nav-item.active {
  color: var(--accent);
}

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

/* Sidebar overlay mode */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 89;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.visible { display: block; }

/* Mobile back button for drawer */
.mobile-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  align-items: center;
  gap: 4px;
}

/* ═══════════════════════════════════════════════════════════════════
   MOBILE: < 768px
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {

  /* ── Layout ────────────────────────────────────────────────────── */
  .layout {
    grid-template-columns: 1fr !important;
    grid-template-rows: var(--header-h) 1fr !important;
  }

  /* ── Header ────────────────────────────────────────────────────── */
  .header {
    padding: 0 12px !important;
    gap: 8px !important;
  }

  .mobile-hamburger { display: flex; }

  /* Hide: separators, title, search bar, portal LEDs, flight mode */
  .header-sep,
  .header-title,
  .header-search,
  .header-portals,
  .header-flight,
  .header-badge { display: none !important; }

  .header-logo-img { max-width: 100px; }

  /* ── Sidebar ───────────────────────────────────────────────────── */
  .sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Portal LEDs in sidebar (injected by mobile.js) */
  .sidebar-portals {
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    margin-top: 8px;
  }

  .sidebar-portals-title {
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--fg-subtle);
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 8px;
  }

  .sidebar-portal-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    color: var(--fg-muted);
    font-size: 12px;
  }

  .sidebar-portal-item .portal-led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .sidebar-portal-item .portal-ms {
    color: var(--fg-subtle);
    font-size: 10px;
    margin-left: auto;
  }

  /* ── Bottom Nav ────────────────────────────────────────────────── */
  .mobile-bottom-nav { display: block; }

  /* Add padding to main for bottom nav */
  .main {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* ── KPIs / Dashboard ──────────────────────────────────────────── */
  .kpi-bar {
    grid-template-columns: 1fr 1fr !important;
    padding: 12px 12px 0 !important;
    gap: 8px !important;
  }

  .kpi-card {
    padding: 10px 12px !important;
  }

  .kpi-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
  }

  .kpi-v2-value {
    font-size: 20px !important;
  }

  .kpi-v2-label {
    font-size: 10px !important;
  }

  .kpi-v2-sub {
    font-size: 9px !important;
  }

  .kpi-card-v2 {
    padding: 10px 12px !important;
  }

  .dashboard-kpis {
    padding: 0 12px;
  }

  /* ── Filters ───────────────────────────────────────────────────── */
  .filter-bar {
    padding: 10px 12px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .search-wrap {
    max-width: 100% !important;
    width: 100% !important;
    flex: 1 1 100% !important;
    order: -1;
  }

  .filter-select {
    font-size: 12px !important;
    padding: 6px 8px !important;
    flex: 1 1 calc(50% - 4px) !important;
    min-width: 0 !important;
  }

  .filter-spacer { display: none !important; }
  .filter-count { font-size: 11px !important; flex: 0 0 auto !important; }

  .quick-filters {
    padding: 0 12px 8px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }
  .quick-filters::-webkit-scrollbar { display: none; }

  .quick-filter-tag { white-space: nowrap; flex-shrink: 0; }

  /* ── Table → Card List ─────────────────────────────────────────── */
  .table-wrap {
    overflow-x: visible !important;
    padding: 0 !important;
  }

  .exp-table { display: none !important; }

  .mobile-card-list { display: block !important; }

  /* ── Main Split / Drawer ───────────────────────────────────────── */
  .main-split {
    flex-direction: column !important;
  }

  .main-split.drawer-open .main-content {
    display: none !important;
  }

  .main-split.drawer-open .panel {
    width: 100% !important;
    height: 100% !important;
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    border-left: none !important;
    box-shadow: none !important;
  }

  .panel-overlay { display: none !important; }

  .panel-close { display: none !important; }
  .mobile-back-btn { display: flex !important; }

  .panel-header {
    padding: 12px 14px !important;
  }

  .panel-tabs {
    padding: 0 8px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
  }
  .panel-tabs::-webkit-scrollbar { display: none; }

  .panel-tab {
    padding: 10px 10px !important;
    font-size: 12px !important;
    flex-shrink: 0;
  }

  .panel-body {
    padding: 12px 14px !important;
  }

  .panel-actions {
    padding: 8px 14px 10px !important;
  }

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

  .detail-cell.full {
    grid-column: 1 !important;
  }

  /* ── Email ─────────────────────────────────────────────────────── */
  .email-panel {
    height: calc(100vh - var(--header-h) - 56px - env(safe-area-inset-bottom, 0px)) !important;
  }

  .email-split {
    flex-direction: column !important;
  }

  .email-list-pane {
    width: 100% !important;
    border-right: none !important;
  }

  .email-list-pane.has-detail {
    display: none !important;
  }

  .email-detail-pane {
    position: fixed !important;
    inset: 0 !important;
    z-index: 81;
    background: var(--bg-canvas) !important;
  }

  .email-toolbar {
    padding: 8px 12px !important;
    flex-wrap: wrap;
    gap: 8px !important;
  }

  /* ── Forms ─────────────────────────────────────────────────────── */
  .cf-row {
    flex-direction: column !important;
  }

  .cf-input, .cf-select {
    font-size: 16px !important; /* Prevents iOS zoom */
  }

  .cliente-form {
    padding: 12px !important;
  }

  /* ── Compose modal ─────────────────────────────────────────────── */
  .email-compose-modal {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
  }

  /* ── PDF Viewer (fullscreen on mobile) ────────────────────────── */
  .pdf-editor-left,
  .pdf-editor-right { display: none !important; }

  .pdf-editor-center {
    width: 100% !important;
  }

  /* ── Intervinientes cards ──────────────────────────────────────── */
  .interv-card {
    flex-wrap: wrap;
  }

  /* ── Directorio Juzgados ───────────────────────────────────────── */
  .email-list-pane:not(.has-detail) {
    width: 100% !important;
  }

  /* ── Action buttons ────────────────────────────────────────────── */
  .action-buttons {
    flex-direction: column !important;
    gap: 6px !important;
  }

  .action-btn {
    width: 100% !important;
    text-align: center !important;
    padding: 10px !important;
  }

  /* ── Pagination ────────────────────────────────────────────────── */
  .pagination {
    justify-content: center !important;
    padding: 8px 12px !important;
  }

  .page-btn {
    min-width: 36px;
    min-height: 36px;
  }

  /* ── Misc ──────────────────────────────────────────────────────── */
  .envios-alert-widget {
    margin: 0 12px !important;
    font-size: 12px !important;
  }

  /* Touch optimization */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-item,
  .exp-table tr,
  .doc-card,
  .interv-card,
  .email-row {
    min-height: 44px;
  }
}


/* ═══════════════════════════════════════════════════════════════════
   TABLET: 768px - 1024px
   ═══════════════════════════════════════════════════════════════════ */

@media (min-width: 768px) and (max-width: 1024px) {

  /* ── Layout ────────────────────────────────────────────────────── */
  :root {
    --sidebar-w: 56px;
  }

  /* ── Sidebar: icon-only, expand on hover ───────────────────────── */
  .sidebar {
    width: var(--sidebar-w) !important;
    transition: width .2s ease;
    overflow: visible !important;
    z-index: 30;
  }

  .sidebar:hover {
    width: 220px !important;
    box-shadow: var(--shadow);
  }

  .sidebar-section-label,
  .sidebar-section-toggle span:first-child {
    display: none;
  }

  .sidebar:hover .sidebar-section-label,
  .sidebar:hover .sidebar-section-toggle span:first-child {
    display: inline;
  }

  .sidebar-item {
    padding: 8px 16px !important;
    justify-content: center;
    overflow: hidden;
    white-space: nowrap;
  }

  .sidebar:hover .sidebar-item {
    justify-content: flex-start;
  }

  .sidebar-item span:not(.sidebar-count),
  .sidebar-count {
    display: none;
  }

  .sidebar:hover .sidebar-item span:not(.sidebar-count),
  .sidebar:hover .sidebar-count {
    display: inline;
  }

  .sidebar-section-toggle {
    padding: 6px 16px !important;
    justify-content: center;
    overflow: hidden;
  }

  .sidebar:hover .sidebar-section-toggle {
    justify-content: flex-start;
  }

  /* ── Header ────────────────────────────────────────────────────── */
  .header {
    padding: 0 14px !important;
  }

  .header-title { display: none !important; }

  /* ── Table: hide less important columns ────────────────────────── */
  .col-cuantia,
  .col-obs,
  .col-nig,
  .col-ref,
  .col-lexnet,
  .col-usuario,
  .col-situacion {
    display: none !important;
  }

  /* ── Drawer ────────────────────────────────────────────────────── */
  .main-split.drawer-open .main-content {
    flex: 0 0 40% !important;
  }

  .main-split.drawer-open .panel {
    width: 60% !important;
  }

  /* ── KPIs ──────────────────────────────────────────────────────── */
  .kpi-bar {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    padding: 12px 14px 0 !important;
  }

  /* ── Filters ───────────────────────────────────────────────────── */
  .filter-bar {
    padding: 12px 14px !important;
  }

  .search-wrap {
    max-width: 280px !important;
  }

  /* ── Email ─────────────────────────────────────────────────────── */
  .email-list-pane.has-detail {
    width: 280px !important;
  }
}


/* ═══════════════════════════════════════════════════════════════════
   Mobile Card List (replaces table on mobile)
   ═══════════════════════════════════════════════════════════════════ */

.mobile-card-list {
  display: none;
  padding: 0 12px 12px;
}

.mobile-card {
  background: var(--bg-default);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}

.mobile-card:active {
  background: var(--bg-subtle);
}

.mobile-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
  gap: 8px;
}

.mobile-card-proc {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  font-family: var(--font-mono);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-card-plazo {
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.mobile-card-plazo.critico {
  background: var(--red-dim);
  color: var(--red);
}

.mobile-card-plazo.proximo {
  background: var(--yellow-dim);
  color: var(--yellow);
}

.mobile-card-plazo.ok {
  background: var(--green-dim);
  color: var(--green);
}

.mobile-card-cliente {
  font-size: 12px;
  color: var(--fg);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-card-juzgado {
  font-size: 11px;
  color: var(--fg-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.mobile-card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-card-interno {
  font-size: 11px;
  color: var(--fg-subtle);
  font-family: var(--font-mono);
}

.mobile-card-fecha {
  font-size: 11px;
  color: var(--fg-muted);
  white-space: nowrap;
}


/* ═══════════════════════════════════════════════════════════════════
   Email attachment chips - clickeable
   ═══════════════════════════════════════════════════════════════════ */

.email-attach-chip[data-attach-enhanced] {
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.email-attach-chip[data-attach-enhanced]:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}


/* ═══════════════════════════════════════════════════════════════════
   PWA standalone mode adjustments
   ═══════════════════════════════════════════════════════════════════ */

@media (display-mode: standalone) {
  .header {
    padding-top: env(safe-area-inset-top, 0px);
  }

  .mobile-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}


/* ═══════════════════════════════════════════════════════════════════
   Touch & accessibility improvements
   ═══════════════════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
  .sidebar-item,
  .email-row,
  .doc-card,
  .interv-card,
  .mobile-card,
  .action-btn,
  .quick-filter-tag,
  .page-btn {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .exp-table td {
    padding: 12px !important;
  }

  /* Disable hover effects on touch devices */
  .sidebar-item:hover,
  .kpi-card:hover,
  .kpi-card-v2:hover {
    background: inherit;
    border-color: inherit;
  }
}
