/* =========================================
   DASHBOARD STYLES
========================================= */

/* Page Header */
.page-header {
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-color);
  margin: 0 0 0.25rem 0;
}

.page-subtitle {
  font-size: 0.875rem;
  color: #999;
  margin: 0;
}

/* =========================================
   SUMMARY CARDS
========================================= */

.dashboard-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
  width: 100%;
}

.stat-card {
  background-color: var(--card-bg);
  border-radius: 14px;
  padding: 1.35rem 1.5rem;
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: box-shadow 0.22s ease, transform 0.22s ease, border-color 0.22s ease;
  border: 1px solid var(--border);
}

.stat-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-3px);
  border-color: rgba(29,78,216,0.18);
}

.stat-card:active {
  transform: translateY(-1px) scale(0.985);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.stat-card:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Critical stock card gets a subtle danger border */
.stat-card-alert {
  border-color: rgba(211, 47, 47, 0.3);
}

/* Arrow indicator on cards */
.stat-card-arrow {
  font-size: 1.15rem;
  color: #d0d0d0;
  flex-shrink: 0;
  margin-left: auto;
  transition: transform 0.2s ease, color 0.2s ease;
  align-self: center;
}

.stat-card:hover .stat-card-arrow {
  transform: translateX(4px);
  color: var(--primary-color);
}

body.dark .stat-card-arrow {
  color: #444;
}

body.dark .stat-card:hover .stat-card-arrow {
  color: var(--primary-color);
}

body.dark .stat-card {
  background-color: var(--card-bg);
  color: var(--text-color);
  border-color: var(--border);
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  background-color: rgba(29,78,216,0.09);
  color: var(--accent);
}

body.dark .stat-icon {
  background-color: var(--accent-light);
  color: var(--accent);
}

.stat-icon-alert {
  background-color: #FFEBEE;
  color: #D32F2F;
}

body.dark .stat-icon-alert {
  background-color: rgba(211,47,47,0.15);
  color: #ef5350;
}

.stat-card-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.stat-card-info h3 {
  margin: 0 0 0.25rem 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
  white-space: normal;
  overflow: visible;
  line-height: 1.3;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-color);
  margin: 0;
  line-height: 1;
  letter-spacing: -0.5px;
}

/* Critical count turns red when > 0 */
.stat-value.alert-value {
  color: #D32F2F;
}

body.dark .stat-value.alert-value {
  color: #ef5350;
}

/* =========================================
   SECTION STRUCTURE
========================================= */

.dash-section {
  margin-bottom: 2rem;
}

.dash-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-left: 0.75rem;
  border-left: 3px solid var(--accent);
}

.dash-section-title i {
  font-size: 1.1rem;
  color: var(--accent);
}

/* =========================================
   ALERTS GRID
========================================= */

.alerts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  align-items: start;
}

.alert-box {
  background-color: var(--card-bg);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
  border: 1px solid var(--border);
  border-top: 3px solid transparent;
}

body.dark .alert-box {
  background-color: var(--card-bg);
  border-color: var(--border);
}

.alert-box { border-top-color: var(--accent); }
body.dark .alert-box { border-top-color: var(--accent); }

.alert-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.alert-box-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-color);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.alert-box-title i { color: #888; }
body.dark .alert-box-title i { color: #777; }

/* Count badge in alert header */
.alert-count {
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  background-color: #f0f0f0;
  color: #555;
}

body.dark .alert-count {
  background-color: #333;
  color: #ccc;
}



.alert-box-body {
  max-height: 220px;
  overflow-y: auto;
  padding: 0.35rem 0;
}

.alert-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
}

.alert-item:last-child {
  border-bottom: none;
}

.alert-item-name {
  font-size: 0.85rem;
  color: var(--text-color);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Small colored badge on alert items */
.alert-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-danger  { background-color: #FFCDD2; color: #B71C1C; }
.badge-warning { background-color: #FFE0B2; color: #E65100; }
.badge-info    { background-color: #BBDEFB; color: #0D47A1; }

body.dark .badge-danger  { background-color: rgba(211, 47, 47, 0.25);  color: #ef5350; }
body.dark .badge-warning { background-color: rgba(245, 124, 0, 0.25);  color: #ffa726; }
body.dark .badge-info    { background-color: rgba(25, 118, 210, 0.25); color: #64b5f6; }

/* ── Alert item action buttons ────────────────────────────────── */
.alert-item-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.alert-item-meta {
  font-size: 0.78rem;
  color: #999;
  white-space: nowrap;
}

body.dark .alert-item-meta { color: #666; }

.alert-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: #9ca3af;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s, color 0.15s, transform 0.1s;
}

.alert-icon-btn:hover {
  background-color: rgba(29, 78, 216, 0.1);
  color: #1D4ED8;
  transform: scale(1.08);
}

body.dark .alert-icon-btn:hover {
  background-color: rgba(96, 165, 250, 0.12);
  color: #60a5fa;
}

/* ── Alert detail modal — compact overrides ───────────────────── */
#alert-detail-overlay .detail-dialog {
  padding: 16px 18px 14px;
  width: min(490px, 94vw);
}

#alert-detail-overlay .detail-dialog-header {
  margin-bottom: 10px;
  padding-bottom: 8px;
}

#alert-detail-overlay .detail-info-grid {
  gap: 7px 10px;
}

#alert-detail-overlay .detail-info-label {
  font-size: .72rem;
}

#alert-detail-overlay .detail-info-value {
  font-size: .84rem;
}

#alert-detail-overlay .alert-detail-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

#alert-detail-overlay .alert-detail-btn,
#alert-detail-overlay .alert-detail-actions .admin-button {
  white-space: nowrap;
  flex: 0 0 auto;
}

#alert-detail-overlay .alert-detail-btn {
  padding: 0.6rem 0.9rem;
}

#alert-detail-overlay .alert-detail-actions .admin-button {
  padding: 0.6rem 0.9rem;
  font-size: 0.88rem;
}

.alert-empty {
  text-align: center;
  padding: 1.25rem;
  color: #999;
  font-size: 0.85rem;
  margin: 0;
}

/* =========================================
   ACTIVITY TABLE BADGES
========================================= */

.badge-in,
.badge-out {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-in,
.badge-out,
.badge-os,
.badge-sale {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.badge-in   { background-color: rgba(52,168,83,0.12);   color: #2d8c4e; }
.badge-out  { background-color: rgba(204,76,76,0.12);   color: #cc4c4c; }
.badge-os   { background-color: rgba(66,133,244,0.12);  color: #2563eb; }
.badge-sale { background-color: rgba(139,92,246,0.12);  color: #6d28d9; }

body.dark .badge-in   { background-color: rgba(52,168,83,0.14);   color: #5cb87a; }
body.dark .badge-out  { background-color: rgba(204,76,76,0.12);   color: #ef9a9a; }
body.dark .badge-os   { background-color: rgba(66,133,244,0.10);  color: #60a5fa; }
body.dark .badge-sale { background-color: rgba(139,92,246,0.10);  color: #a78bfa; }

/* =========================================
   ACTIVITY TOOLBAR (filters + rows-per-page)
========================================= */

.activity-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.activity-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.activity-page-size {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #888;
  white-space: nowrap;
}

.activity-page-size select {
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid #d0d0d0;
  background-color: transparent;
  color: var(--text-color);
  cursor: pointer;
}

body.dark .activity-page-size select {
  border-color: #444;
  color: var(--text-color);
  background-color: var(--sidebar-color);
}

.activity-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-color);
  background-color: transparent;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

/* keep Entrada and Saída the same width */
.activity-filter-btn[data-filter="stock-in"],
.activity-filter-btn[data-filter="stock-out"] {
  min-width: 80px;
  justify-content: center;
}

.activity-filter-btn:hover {
  border-color: var(--primary-color);
  background-color: rgba(29,78,216,0.07);
}

.activity-filter-btn.active {
  border-color: var(--primary-color);
  background-color: var(--primary-color);
  color: #ffffff;
  font-weight: 600;
}

body.dark .activity-filter-btn {
  border-color: #3a3b3c;
}

body.dark .activity-filter-btn:hover {
  border-color: var(--primary-color);
  background-color: rgba(29,78,216,0.08);
}

body.dark .activity-filter-btn.active {
  border-color: var(--primary-color);
  background-color: var(--primary-color);
  color: #ffffff;
}

/* =========================================
   PAGINATION
========================================= */

.activity-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem 0.85rem;
  border-top: 1px solid var(--border);
}

body.dark .activity-pagination { border-top-color: #2e2f30; }

.pag-info {
  font-size: 0.8rem;
  color: #aaa;
}

body.dark .pag-info { color: #666; }

.pag-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.pag-page {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-color);
  min-width: 48px;
  text-align: center;
}

.pag-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 7px;
  background-color: transparent;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--text-color);
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.pag-btn:hover:not(:disabled) {
  background-color: rgba(29,78,216,0.14);
  color: var(--primary-color);
}

.pag-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* =========================================
   ACTIVITY DETAIL MODAL
========================================= */
.act-modal-cancel-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem 1rem;
  background-color: transparent;
  color: var(--text-color);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.875rem;
  font-family: inherit;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.act-modal-cancel-btn:hover { background-color: rgba(0,0,0,0.05); border-color: #ccc; }
body.dark .act-modal-cancel-btn { border-color: #555; }
body.dark .act-modal-cancel-btn:hover { background-color: rgba(255,255,255,0.06); }

/* =========================================
   SCROLLBAR STYLING
========================================= */

.alert-box-body::-webkit-scrollbar { width: 4px; }
.alert-box-body::-webkit-scrollbar-track { background: transparent; }
.alert-box-body::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }
body.dark .alert-box-body::-webkit-scrollbar-thumb { background: #555; }

/* =========================================
   ACTIVITY TABLE — DETAIL BUTTON (CSS hover, no JS inline)
========================================= */

/* Activity table wrapper: scrolls on mobile, hidden overflow on desktop */
#activity-table ~ * { overflow-x: hidden; }
.admin-table-wrapper:has(#activity-table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Stable layout: fixed columns so filters don't reflow the table */
#activity-table {
  table-layout: fixed;
  width: 100%;
}
/* Distribute space proportionally across all columns */
#activity-table th:nth-child(1),
#activity-table td:nth-child(1) {
  width: 30%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 1rem;
}
#activity-table th:nth-child(2),
#activity-table td:nth-child(2) { width: 12%; } /* Tipo */
#activity-table th:nth-child(3),
#activity-table td:nth-child(3) { width: 14%; } /* Valor/Qtd */
#activity-table th:nth-child(4),
#activity-table td:nth-child(4) {
  width: 13%; /* Origem */
  white-space: normal;
  overflow-wrap: anywhere;
}
#activity-table th:nth-child(5),
#activity-table td:nth-child(5) {
  width: 21%; /* Data */
  white-space: normal;
  overflow-wrap: anywhere;
}
#activity-table th:nth-child(6),
#activity-table td:nth-child(6) { width: 4%; text-align: center; } /* ações */
.act-detail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  font-size: 1.1rem;
  color: #1976D2;
  transition: background-color 0.15s ease, color 0.15s ease;
  outline: none;
}
.act-detail-btn:hover {
  background-color: rgba(25,118,210,0.1);
  color: #1554C8;
}
.act-detail-btn:focus-visible {
  outline: 2px solid rgba(25,118,210,0.35);
  outline-offset: 2px;
}

/* =========================================
   ALERTS — empty state collapse
========================================= */
.alert-box.empty .alert-box-body { display: none; }
.alert-box.empty { opacity: 0.6; }

/* Alert count badge — colored when active */
.alert-count.has-danger  { background-color: #FFCDD2; color: #B71C1C; }
.alert-count.has-warning { background-color: #FFE0B2; color: #E65100; }
.alert-count.has-info    { background-color: #BBDEFB; color: #0D47A1; }

body.dark .alert-count.has-danger  { background-color: rgba(211,47,47,0.25);  color: #ef5350; }
body.dark .alert-count.has-warning { background-color: rgba(245,124,0,0.25);  color: #ffa726; }
body.dark .alert-count.has-info    { background-color: rgba(25,118,210,0.25); color: #64b5f6; }

/* Ver mais link inside alert box */
.alert-more-link {
  display: block;
  text-align: center;
  padding: 0.45rem 1.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-color);
  border-top: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.alert-more-link:hover { background-color: rgba(29,78,216,0.04); }

/* =========================================
   CONFIRM DIALOG (dashboard alerts)
========================================= */

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem 1rem;
  background-color: transparent;
  color: var(--text-color);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  font-family: inherit;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-secondary:hover { background-color: rgba(0,0,0,0.05); border-color: #ccc; }
body.dark .btn-secondary { border-color: #555; }
body.dark .btn-secondary:hover { background-color: rgba(255,255,255,0.06); border-color: #666; }

.po-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.18s ease;
  backdrop-filter: blur(2px);
}

.po-confirm-overlay.visible { opacity: 1; }

.po-confirm-dialog {
  background: var(--sidebar-color);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.28);
  padding: 2rem 1.75rem 1.5rem;
  width: min(100%, 380px);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  transform: scale(0.94) translateY(-10px);
  transition: transform 0.18s ease, opacity 0.18s ease;
  opacity: 0;
}

.po-confirm-overlay.visible .po-confirm-dialog {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.po-confirm-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.65rem;
  margin-bottom: 0.35rem;
  flex-shrink: 0;
}

.po-confirm-icon-receive {
  background-color: rgba(52,168,83,0.14);
  color: #2d8c4e;
}

body.dark .po-confirm-icon-receive {
  background-color: rgba(52,168,83,0.12);
  color: #5cb87a;
}

.po-confirm-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-color);
}

.po-confirm-message {
  margin: 0.1rem 0 0.5rem;
  font-size: 0.875rem;
  color: #888;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
}

body.dark .po-confirm-message { color: #777; }
.po-confirm-message strong { color: var(--text-color); }

.po-confirm-detail {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: #aaa;
}

.po-confirm-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
  margin-top: 0.5rem;
  width: 100%;
}

.po-confirm-actions .btn-secondary,
.po-confirm-actions .admin-button {
  flex: 1;
  justify-content: center;
}

.po-confirm-btn-receive {
  background-color: #2d8c4e !important;
}

.po-confirm-btn-receive:hover { background-color: #246e3e !important; }
body.dark .po-confirm-btn-receive { background-color: #2d8c4e !important; }

/* =========================================
   RESPONSIVE
========================================= */

@media (max-width: 768px) {
  .dashboard-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .alerts-grid {
    grid-template-columns: 1fr;
  }

  /* Activity toolbar: stack on narrow screens */
  .activity-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .activity-filters {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .activity-page-size {
    align-self: flex-end;
  }

  /* Hide Origem column to free up width */
  #activity-table th:nth-child(4),
  #activity-table td:nth-child(4) { display: none; }

  /* Redistribute column widths */
  #activity-table th:nth-child(1),
  #activity-table td:nth-child(1) { width: 36%; }
  #activity-table th:nth-child(2),
  #activity-table td:nth-child(2) { width: 18%; }
  #activity-table th:nth-child(3),
  #activity-table td:nth-child(3) { width: 18%; }
  #activity-table th:nth-child(5),
  #activity-table td:nth-child(5) { width: 20%; }
  #activity-table th:nth-child(6),
  #activity-table td:nth-child(6) { width: 8%; }
}

@media (max-width: 480px) {
  .dashboard-cards {
    grid-template-columns: 1fr;
  }

  /* Also hide Data column on very small screens */
  #activity-table th:nth-child(5),
  #activity-table td:nth-child(5) { display: none; }

  /* Redistribute remaining 3 columns + actions */
  #activity-table th:nth-child(1),
  #activity-table td:nth-child(1) { width: 52%; }
  #activity-table th:nth-child(2),
  #activity-table td:nth-child(2) { width: 24%; }
  #activity-table th:nth-child(3),
  #activity-table td:nth-child(3) { width: 16%; }
  #activity-table th:nth-child(6),
  #activity-table td:nth-child(6) { width: 8%; }

  .activity-filter-btn {
    padding: 0.38rem 0.75rem;
    font-size: 0.78rem;
  }
}