/* =============================================
   TaskOrbit — Mobile-First Optimization
   Base styles = mobile, scale up with min-width
   ============================================= */

/* ---- CSS Variables for touch/mobile ---- */
:root {
  --touch-target-min: 44px;
  --touch-target-sm: 36px;
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --bottom-nav-height: 56px;
  --font-xs: 0.7rem;
  --font-sm: 0.8rem;
  --font-base: 0.875rem;
  --font-lg: 1rem;
  --card-radius: 12px;
}

/* ===== BOTTOM NAVIGATION BAR ===== */
.bottom-nav {
  display: none;
}

@media (max-width: 991.98px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bs-body-bg, #fff);
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    z-index: 1050;
    padding: 0;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    min-width: var(--touch-target-min);
    text-decoration: none;
    color: var(--bs-secondary-color, #6c757d);
    font-size: var(--font-xs);
    font-weight: 500;
    gap: 2px;
    transition: color 0.15s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-item i {
    font-size: 1.25rem;
    line-height: 1;
  }

  .bottom-nav-item.active {
    color: var(--primary, #691C32);
    font-weight: 700;
  }

  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    background: var(--primary, #691C32);
    border-radius: 0 0 3px 3px;
  }

  .bottom-nav-item .bottom-nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    font-size: 0.55rem;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    background: #dc3545;
    color: #fff;
  }

  /* Space for bottom nav */
  body {
    padding-bottom: var(--bottom-nav-height);
  }

  /* Toast container above bottom nav */
  #toast-container {
    bottom: calc(var(--bottom-nav-height) + 8px) !important;
  }

  /* Flash container mobile */
  .flash-container {
    top: 60px;
    right: 0.5rem;
    max-width: calc(100% - 1rem);
  }
}

[data-bs-theme="dark"] .bottom-nav {
  background: var(--bs-body-bg, #212529);
  border-color: #495057;
}

/* ===== TOPBAR MOBILE ===== */
@media (max-width: 991.98px) {
  .topbar {
    height: 48px;
    padding: 0 0.75rem !important;
  }

  .topbar .btn {
    padding: 0.35rem 0.5rem;
  }
}

/* ===== PAGE CONTENT MOBILE ===== */
@media (max-width: 575.98px) {
  .page-content {
    padding: 0.75rem 0.5rem !important;
  }

  h1, .h1 { font-size: 1.35rem; }
  h2, .h2 { font-size: 1.15rem; }
  h3, .h3 { font-size: 1.05rem; }
  h4, .h4 { font-size: 1rem; }
}

/* ===== TOUCH-FRIENDLY BUTTONS ===== */

/* Estado buttons -- mobile touch targets */
@media (max-width: 767.98px) {
  .estado-btn-group .btn {
    font-size: var(--font-sm) !important;
    padding: 0.4rem 0.6rem !important;
    min-height: var(--touch-target-sm);
    min-width: var(--touch-target-sm);
  }

  /* Quick action buttons -- mobile */
  .btn-xs,
  .kanban-card-actions .btn,
  .card .btn-xs {
    font-size: var(--font-sm) !important;
    padding: 0.35rem 0.5rem !important;
    min-height: var(--touch-target-sm);
    min-width: var(--touch-target-sm);
  }

  /* Subtarea estado buttons */
  .subtarea-item .btn-group .btn {
    font-size: var(--font-xs) !important;
    padding: 0.3rem 0.45rem !important;
    min-height: 32px;
    min-width: 32px;
  }
}

/* ===== MOBILE CARDS ===== */
@media (max-width: 767.98px) {
  /* Project/task cards -- compact mobile */
  .card-proyecto .card-body {
    padding: 0.75rem !important;
  }

  /* Card action row -- wrap nicely */
  .card-proyecto .d-flex.gap-1.mb-2,
  .card-proyecto .d-flex.gap-2.mt-auto {
    flex-wrap: wrap;
  }

  .card-proyecto .d-flex.gap-2.mt-auto .btn {
    font-size: var(--font-sm);
    padding: 0.4rem 0.6rem;
    min-height: var(--touch-target-sm);
  }

  /* Hide descriptions on very small screens */
  .card-proyecto .text-truncate-2 {
    display: none;
  }
}

@media (max-width: 575.98px) {
  /* Force full width cards on smallest screens */
  .card-proyecto {
    margin-bottom: 0.5rem;
  }
}

/* ===== DASHBOARD MOBILE ===== */

/* Metric cards compact */
@media (max-width: 575.98px) {
  .metric-card .card-body,
  .row.g-3.mb-4 .card .card-body {
    padding: 0.6rem !important;
  }

  .metric-card .metric-icon,
  .row.g-3.mb-4 .card .rounded-3[style*="width:48px"] {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    font-size: 1.1rem;
  }

  .metric-card .fs-3,
  .row.g-3.mb-4 .card .fs-3 {
    font-size: 1.4rem !important;
  }
}

/* Dashboard tables to cards on mobile */
@media (max-width: 767.98px) {
  /* Hide the table, show mobile cards version */
  .dashboard-table-desktop {
    display: none !important;
  }

  .dashboard-cards-mobile {
    display: block !important;
  }
}

@media (min-width: 768px) {
  .dashboard-cards-mobile {
    display: none !important;
  }
}

/* ===== FILTER BAR MOBILE ===== */
@media (max-width: 767.98px) {
  .mobile-filters-toggle {
    display: flex !important;
  }

  .mobile-filters-content {
    display: none;
  }

  .mobile-filters-content.show {
    display: block;
  }

  .filter-bar .form-select,
  .filter-bar .form-control {
    font-size: var(--font-base);
    padding: 0.5rem 0.75rem;
    min-height: var(--touch-target-min);
  }

  /* Filter chips */
  .filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
  }

  .filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 1rem;
    background: var(--bs-primary);
    color: #fff;
    font-size: var(--font-xs);
    font-weight: 600;
  }

  .filter-chip .bi {
    cursor: pointer;
  }
}

@media (min-width: 768px) {
  .mobile-filters-toggle {
    display: none !important;
  }
}

/* ===== KANBAN MOBILE ===== */
@media (max-width: 767.98px) {
  .kanban-board {
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.75rem;
    gap: 0.5rem;
    /* Hint that there's more content */
    mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
  }

  .kanban-column {
    scroll-snap-align: start;
    min-width: calc(85vw - 1rem);
    max-width: calc(85vw - 1rem);
    flex: 0 0 auto;
  }

  .kanban-col-body {
    max-height: 60vh;
  }

  .kanban-card {
    padding: 0.75rem;
  }

  .kanban-card-title {
    font-size: var(--font-base);
    -webkit-line-clamp: 2;
  }

  .kanban-card-actions {
    margin-top: 0.5rem;
    gap: 0.35rem;
  }

  .kanban-card-actions .btn {
    font-size: var(--font-sm) !important;
    padding: 0.35rem 0.5rem !important;
    min-height: var(--touch-target-sm);
  }

  /* Scroll hint indicator */
  .kanban-scroll-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    color: var(--bs-secondary-color, #6c757d);
    font-size: var(--font-xs);
  }

  .kanban-scroll-hint i {
    animation: swipeHint 2s ease-in-out infinite;
  }

  @keyframes swipeHint {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(8px); }
  }
}

@media (min-width: 768px) {
  .kanban-scroll-hint {
    display: none;
  }
}

/* ===== VIEW SWITCHER MOBILE ===== */
@media (max-width: 575.98px) {
  .view-switcher {
    display: flex;
    width: 100%;
    gap: 0;
    background: var(--bs-body-bg, #f8f9fa);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.5rem;
    padding: 0.2rem;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .view-switcher .nav-item {
    flex: 1;
  }

  .view-switcher .nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.25rem;
    font-size: var(--font-xs);
    border-radius: 0.35rem;
    white-space: nowrap;
    min-height: var(--touch-target-sm);
  }

  .view-switcher .nav-link span {
    display: none;
  }

  .view-switcher .nav-link i {
    margin: 0 !important;
    font-size: 1.1rem;
  }
}

/* ===== TAREAS LISTA MOBILE ===== */
@media (max-width: 767.98px) {
  /* Task card header -- stack vertically */
  .card[data-tarea-id] > .card-header {
    flex-wrap: wrap !important;
    padding: 0.6rem !important;
    gap: 0.5rem !important;
  }

  /* Task name area */
  .card[data-tarea-id] > .card-header > .d-flex.align-items-center.gap-2.flex-fill {
    width: 100%;
  }

  /* Actions row -- separate line */
  .card[data-tarea-id] > .card-header > .d-flex.align-items-center.gap-2.flex-shrink-0 {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  /* Show priority badge on mobile */
  .card[data-tarea-id] .badge[class*="badge-prioridad"].d-none.d-md-inline {
    display: inline-flex !important;
  }

  /* Hide date on mobile in card header -- too crowded */
  .card[data-tarea-id] .d-none.d-lg-inline {
    display: none !important;
  }

  /* Subtareas section */
  .card[data-tarea-id] .subtarea-item {
    padding: 0.5rem 0.6rem;
  }

  .card[data-tarea-id] .subtarea-item .d-flex {
    flex-wrap: wrap;
    gap: 0.4rem;
  }
}

/* ===== USER GROUP MOBILE ===== */
@media (max-width: 575.98px) {
  .user-group-header {
    padding: 0.6rem 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .user-group-stats {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .user-group-stat {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
  }

  .user-group-body {
    padding: 0.5rem;
  }

  .user-group-body .card .card-body {
    padding: 0.6rem !important;
  }
}

/* ===== TIMELINE MOBILE ===== */
@media (max-width: 767.98px) {
  .timeline {
    padding-left: 1.5rem;
  }

  .timeline::before {
    left: 0.45rem;
  }

  .timeline-group-label {
    margin-left: -1.5rem;
    padding-left: 1.6rem;
    font-size: 0.68rem;
  }

  .timeline-group-label::before {
    left: 0.2rem;
  }

  .timeline-dot {
    left: -1.25rem;
  }

  .timeline-card {
    padding: 0.6rem;
    font-size: var(--font-sm);
  }

  /* Show summary on mobile for timeline */
  .timeline-summary-mobile {
    display: block !important;
  }
}

@media (min-width: 768px) {
  .timeline-summary-mobile {
    display: none !important;
  }
}

/* ===== NOTAS PANEL MOBILE ===== */
@media (max-width: 575.98px) {
  .notas-panel .nota-item {
    padding: 0.5rem !important;
  }

  .notas-panel .nota-item .d-flex.gap-1 .btn {
    min-height: 32px;
    min-width: 32px;
    padding: 0.25rem 0.35rem;
  }

  .notas-add-form textarea {
    min-height: 60px;
  }

  .notas-add-form .btn {
    min-height: var(--touch-target-sm);
  }
}

/* ===== MODAL/OFFCANVAS MOBILE ===== */
@media (max-width: 575.98px) {
  /* Make modals full-width on mobile */
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal .form-control,
  .modal .form-select {
    min-height: var(--touch-target-min);
    font-size: var(--font-base);
  }

  .modal .btn,
  .offcanvas .btn {
    min-height: var(--touch-target-sm);
    font-size: var(--font-sm);
  }

  /* Offcanvas full width on mobile */
  .offcanvas-end {
    width: 100% !important;
  }

  .offcanvas .form-control,
  .offcanvas .form-select {
    min-height: var(--touch-target-min);
    font-size: var(--font-base);
  }
}

/* ===== NOTIFICATIONS DROPDOWN MOBILE ===== */
@media (max-width: 575.98px) {
  .dropdown-notifications {
    width: calc(100vw - 1rem) !important;
    max-width: 340px;
    right: -0.5rem;
  }

  .notif-item {
    padding: 0.75rem;
    min-height: var(--touch-target-min);
  }
}

/* ===== SEMAFORO SUMMARY MOBILE ===== */
@media (max-width: 575.98px) {
  .semaforo-summary-card .semaforo-count {
    font-size: 1.3rem;
  }

  .semaforo-summary-card .semaforo-label {
    font-size: 0.6rem;
  }
}

/* ===== BREADCRUMB MOBILE ===== */
@media (max-width: 575.98px) {
  .breadcrumb {
    font-size: 0.75rem;
    padding: 0;
    margin-bottom: 0.5rem;
  }
}

/* ===== FORMS MOBILE ===== */
@media (max-width: 575.98px) {
  .form-control,
  .form-select {
    font-size: var(--font-base);
  }

  .form-control-sm,
  .form-select-sm {
    min-height: 38px;
    font-size: var(--font-base);
  }

  /* Login form optimization */
  .login-container .form-control {
    min-height: var(--touch-target-min);
    font-size: 1rem;
  }

  .login-container .btn {
    min-height: var(--touch-target-min);
    font-size: 1rem;
  }
}

/* ===== DASHBOARD MOBILE CARDS ===== */
.dashboard-user-card {
  border-left: 3px solid var(--bs-border-color);
  border-radius: var(--card-radius);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.dashboard-user-card .user-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.dashboard-user-card .user-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 50px;
}

.dashboard-user-card .user-metric-value {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.dashboard-user-card .user-metric-label {
  font-size: 0.65rem;
  color: var(--bs-secondary-color, #6c757d);
}

/* Project progress mobile card */
.dashboard-project-card {
  border-radius: var(--card-radius);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--bs-border-color, #dee2e6);
}

.dashboard-project-card .progress {
  height: 6px;
  margin-top: 0.4rem;
}

/* ===== SAFE AREAS for notched phones ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  }

  body {
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  }
}

/* ===== UTILITY CLASSES ===== */
.mobile-only {
  display: none;
}

.desktop-only {
  display: block;
}

@media (max-width: 767.98px) {
  .mobile-only {
    display: block;
  }

  .desktop-only {
    display: none !important;
  }

  /* Flex variant */
  .mobile-only-flex {
    display: flex;
  }
}

/* ===== SCROLL BEHAVIOR ===== */
@media (max-width: 767.98px) {
  /* Smooth scroll on mobile */
  html {
    scroll-behavior: smooth;
  }

  /* Hide scrollbar for kanban on mobile but keep scrollable */
  .kanban-board::-webkit-scrollbar {
    display: none;
  }
  .kanban-board {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
}

/* ===== CHARTS MOBILE ===== */
@media (max-width: 575.98px) {
  #chart-estados,
  #chart-usuarios {
    max-height: 220px !important;
  }

  /* Charts section collapsed by default hint */
  .chart-collapse-hint {
    display: block;
  }
}

@media (min-width: 576px) {
  .chart-collapse-hint {
    display: none;
  }
}

/* ===== DARK MODE for mobile-specific elements ===== */
[data-bs-theme="dark"] .dashboard-user-card {
  border-color: #495057;
  background: var(--bs-body-bg);
}

[data-bs-theme="dark"] .dashboard-project-card {
  border-color: #495057;
  background: var(--bs-body-bg);
}

[data-bs-theme="dark"] .filter-chip {
  background: #691C32;
}

[data-bs-theme="dark"] .view-switcher {
  background: #2c3035;
  border-color: #495057;
}

/* ===== ACCESSIBILITY - Focus visible for touch ===== */
@media (max-width: 767.98px) {
  .btn:focus-visible,
  .form-control:focus-visible,
  .form-select:focus-visible,
  .nav-link:focus-visible {
    outline: 2px solid var(--primary, #691C32);
    outline-offset: 2px;
  }
}
