/**
 * e-Chapas — layout responsivo (mobile / tablet)
 * Carregado após styles.css e echapas-components.css
 */

/* ===== Toast ===== */
#toast.ec-toast {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  left: auto;
  max-width: min(420px, calc(100vw - 32px));
  background: var(--ec-n800, #123b66);
  color: #fff;
  padding: 13px 18px;
  border-radius: 9px;
  z-index: 300;
  box-shadow: 0 8px 25px rgba(15, 23, 42, 0.25);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-line;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#toast.ec-toast--show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* ===== Menu hambúrguer + overlay ===== */
#menuBtn {
  display: none;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--ec-border, #dce3ea);
  border-radius: var(--ec-radius-md, 9px);
  background: var(--ec-bg-subtle, #f8fafc);
  color: var(--ec-n800, #123b66);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  place-items: center;
}

#menuBtn:hover {
  background: #fff;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 19;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(15, 23, 42, 0.48);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app.sidebar-open .sidebar-backdrop {
  display: block;
}

body.ec-nav-open {
  overflow: hidden;
}

/* ===== Tablet (até 1024px) — menu lateral off-canvas ===== */
@media (max-width: 1024px) {
  .app .sidebar {
    transform: translateX(-100%);
    z-index: 21;
    transition: transform 0.22s ease;
    width: min(290px, 88vw);
    box-shadow: none;
  }

  .app .sidebar.open {
    transform: none;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.28);
  }

  .app main {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 0;
  }

  #menuBtn {
    display: grid;
  }

  .brand-logo--header {
    display: flex !important;
  }

  header {
    min-height: 72px;
    padding: 12px 16px;
    gap: 10px;
  }

  header h1 {
    font-size: 1.15rem;
  }

  header p {
    font-size: 12px;
  }

  #content {
    padding: 18px 16px 24px;
  }

  .grid {
    gap: 14px;
  }

  .span-3,
  .span-4,
  .span-5,
  .span-6,
  .span-7,
  .span-8 {
    grid-column: span 6;
  }
}

/* ===== Mobile (até 768px) ===== */
@media (max-width: 768px) {
  .span-3,
  .span-4,
  .span-5,
  .span-6,
  .span-7,
  .span-8,
  .span-12 {
    grid-column: span 12;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .kanban {
    grid-template-columns: 1fr;
  }

  header {
    flex-wrap: wrap;
    align-items: center;
    min-height: auto;
    padding: 10px 12px;
  }

  .header-titles {
    order: 3;
    flex: 1 1 100%;
    padding-top: 2px;
  }

  .user {
    margin-left: auto;
    gap: 8px;
  }

  .user > div:not(.avatar) {
    display: none;
  }

  .user b {
    max-width: none;
  }

  #content {
    padding: 14px 12px 20px;
  }

  .card {
    padding: 16px;
    border-radius: 12px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .toolbar > div:first-child {
    min-width: 0;
  }

  .toolbar .footer-actions {
    width: 100%;
    justify-content: stretch;
    flex-direction: column;
  }

  .toolbar > .btn,
  .toolbar .footer-actions .btn {
    width: 100%;
  }

  .footer-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .footer-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin: 0 -4px;
    padding: 0 4px;
  }

  .table-wrap table {
    min-width: 520px;
  }

  .steps {
    flex-direction: column;
    gap: 6px;
  }

  .step {
    border-radius: 8px;
  }

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
  }

  .tab {
    flex: none;
    white-space: nowrap;
  }

  .metric b {
    font-size: 22px;
  }

  .modal-backdrop {
    padding: 12px;
    align-items: flex-end;
  }

  .help-modal,
  .protocol-modal {
    width: 100% !important;
    max-width: none;
    max-height: min(92vh, calc(100dvh - 24px));
    overflow: auto;
    border-radius: 16px 16px 0 0;
    padding: 22px 18px;
    -webkit-overflow-scrolling: touch;
  }

  .protocol-summary {
    grid-template-columns: 1fr;
  }

  .document-preview {
    flex-direction: column;
  }

  .rep-diligence-hero__head {
    flex-direction: column;
    gap: 12px;
  }

  .rep-diligence-hero__deadline {
    width: 100%;
  }

  .rep-diligence-hero__actions,
  .rep-slate-focus-actions .footer-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .rep-diligence-hero__actions .btn,
  .rep-slate-focus-actions .btn {
    width: 100%;
  }

  .rep-workflow-steps {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .composition-header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .composition-header-actions .btn {
    width: 100%;
  }

  .composition-next-bar__actions {
    flex-direction: column;
  }

  .composition-next-bar__actions .btn {
    width: 100%;
  }

  .sec-process-actions {
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
  }

  .sec-process-actions .btn {
    width: 100%;
  }

  .admin-invite-toolbar {
    grid-template-columns: 1fr;
  }

  .petition-scope-hint {
    flex-direction: column;
    align-items: flex-start;
  }

  .signature-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .signature-actions .btn {
    width: 100%;
  }

  .inline-search {
    flex-direction: column;
    align-items: stretch;
  }

  .process-flow {
    flex-direction: column;
  }

  .flow-arrow {
    transform: rotate(90deg);
  }

  .flow-stage {
    width: 100%;
  }

  #toast.ec-toast {
    right: 12px;
    left: 12px;
    max-width: none;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* ===== Telas muito estreitas (até 480px) ===== */
@media (max-width: 480px) {
  header h1 {
    font-size: 1.05rem;
  }

  .btn {
    min-height: 44px;
    padding: 11px 14px;
  }

  .btn.xs {
    min-height: 38px;
    padding: 8px 12px;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }

  .protocol-filter {
    gap: 6px;
  }

  .filter-chip {
    flex: 1 1 auto;
    text-align: center;
  }

  .login-screen--v2 .login-panel {
    padding: 20px 14px 28px;
  }

  .login-screen--v2 .login-card {
    padding: 22px 16px;
  }
}

/* ===== Tablet paisagem / desktop estreito — grids intermediários ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  .rep-slate-focus-grid {
    grid-template-columns: 1fr;
  }

  .conference-indicators {
    grid-template-columns: 1fr 1fr;
  }
}
