/**
 * Mobile-Responsive Styles for Character Manager
 * Optimizes the character sheet for phones and tablets
 */

/* ========================================
   TOAST NOTIFICATIONS (Mobile Roll Results)
   ======================================== */

/* Toast container positioning */
.toast-container {
  pointer-events: none;
}

.toast-container .toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 90vw;
  color: white;
  font-weight: 500;
}

.toast .toast-body {
  padding: 1rem;
}

/* Toast colors for different roll results */
.toast.bg-success {
  background-color: #198754 !important;
}

.toast.bg-danger {
  background-color: #dc3545 !important;
}

.toast.bg-secondary {
  background-color: #6c757d !important;
}

/* ========================================
   COLLAPSIBLE SECTIONS
   ======================================== */

.collapsible-header {
  user-select: none;
  transition: background-color 0.2s ease;
}

.collapsible-header:hover {
  background-color: rgba(255, 255, 255, 0.05) !important;
}

.collapsible-header .collapse-icon {
  transition: transform 0.2s ease;
  display: inline-block;
}

/* Rotate icon when collapsed/expanded */
.collapsible-header .collapse-icon.bi-chevron-right {
  transform: rotate(0deg);
}

.collapsible-header .collapse-icon.bi-chevron-down {
  transform: rotate(0deg);
}

/* ========================================
   MOBILE BREAKPOINTS
   ======================================== */

/* Small devices (phones, less than 768px) */
@media (max-width: 767px) {

  /* === COLLAPSIBLE SECTIONS === */
  /* Add visual indicator that sections are collapsible */
  .collapsible-header::after {
    content: " (tap to expand/collapse)";
    font-size: 0.7rem;
    opacity: 0.5;
    margin-left: 0.5rem;
  }

  /* Start some sections collapsed on mobile to reduce scrolling */
  #collapseDeathSaves,
  #collapsePortrait,
  #collapseNotes {
    /* These sections start collapsed on mobile */
  }

  /* === TOAST NOTIFICATIONS === */
  /* Ensure toasts are visible and well-positioned on mobile */
  .toast-container {
    padding: 1rem !important;
    width: 100%;
    max-width: 100vw;
  }

  .toast-container .toast {
    width: 100%;
    max-width: calc(100vw - 2rem);
    margin: 0 auto;
  }

  /* === HEADER & TOOLBAR === */
  .container-fluid > .row > .col-12 > h1 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
  }

  /* Character selector and buttons toolbar */
  .d-flex.justify-content-between.align-items-center.mb-3 {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem;
  }

  .d-flex.justify-content-between.align-items-center.mb-3 .d-flex {
    width: 100%;
    justify-content: space-between;
  }

  #charSelect {
    font-size: 0.9rem;
  }

  /* Button groups */
  .btn-group {
    flex-wrap: wrap;
  }

  .btn-sm {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
  }

  /* === ROLL HISTORY === */
  #rollHistoryPanel .card-body {
    max-height: 200px !important;
  }

  /* Toggle button for roll history */
  #rollHistoryToggle {
    display: inline-block;
  }

  #rollHistoryPanel.collapsed .card-body {
    display: none;
  }

  /* === PORTRAIT === */
  #portraitContainer {
    height: 200px !important;
  }

  .portrait-frame {
    height: 200px !important;
  }

  /* === CARDS === */
  .card {
    margin-bottom: 0.75rem !important;
    scroll-margin-top: 80px; /* Offset for fixed navbar when scrolling */
  }

  .card-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
  }

  .card-body {
    padding: 0.75rem;
  }

  /* Smooth transitions for collapsible sections */
  .collapse {
    transition: height 0.25s ease;
  }

  /* === TABS === */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .nav-tabs::-webkit-scrollbar {
    height: 4px;
  }

  .nav-tabs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
  }

  .nav-tabs .nav-link {
    white-space: nowrap;
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
  }

  /* === ABILITY SCORES === */
  .ability-score-box {
    min-width: auto;
  }

  /* Make ability score grid more compact */
  .row.g-2.text-center > div[class*="col-"] {
    padding: 0.25rem !important;
  }

  /* === SAVING THROWS === */
  .save-pill {
    padding: 0.4rem;
    font-size: 0.85rem;
    flex-wrap: wrap;
  }

  .save-pill label {
    font-size: 0.75rem !important;
  }

  .save-pill input[type="number"] {
    width: 45px;
    font-size: 0.85rem;
  }

  .save-pill .btn-group {
    flex-wrap: nowrap;
  }

  .save-pill button {
    padding: 0.15rem 0.3rem !important;
    font-size: 0.75rem;
  }

  /* === SKILLS TABLE === */
  .table {
    font-size: 0.85rem;
  }

  .table th,
  .table td {
    padding: 0.4rem 0.3rem;
  }

  .table input[type="checkbox"] {
    width: 16px;
    height: 16px;
  }

  .table input[type="number"] {
    font-size: 0.85rem;
    padding: 0.25rem;
  }

  .table .btn-group {
    flex-wrap: nowrap;
  }

  .table .btn-sm {
    padding: 0.15rem 0.3rem;
    font-size: 0.75rem;
  }

  /* === HP & COMBAT === */
  .btn-group.w-100 .btn {
    font-size: 0.75rem;
    padding: 0.4rem 0.2rem;
  }

  /* === DEATH SAVES === */
  #deathSaveGrid {
    font-size: 0.85rem;
  }

  #deathSaveGrid input[type="checkbox"] {
    width: 18px;
    height: 18px;
  }

  /* === SPELL SLOTS === */
  .spell-slot-row {
    font-size: 0.85rem;
  }

  .spell-slot-checkbox {
    width: 22px;
    height: 22px;
  }

  /* === ATTACKS LIST === */
  .list-group-item {
    padding: 0.5rem;
    font-size: 0.85rem;
  }

  .list-group-item .btn-sm {
    padding: 0.2rem 0.4rem;
    font-size: 0.75rem;
  }

  /* === FORMS === */
  .form-control-sm,
  .form-select-sm {
    font-size: 0.85rem;
    padding: 0.375rem 0.5rem;
  }

  .form-label {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
  }

  .form-text {
    font-size: 0.75rem;
  }

  /* === MODALS === */
  .modal-dialog {
    margin: 0.5rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    padding: 0.75rem;
  }

  /* === WIZARD === */
  #characterCreationModal .modal-dialog {
    max-width: 95%;
  }

  #wizardBody {
    font-size: 0.9rem;
  }

  #wizardBody input,
  #wizardBody select {
    font-size: 0.9rem;
  }

  #wizardBody .btn-lg {
    font-size: 1rem;
    padding: 0.5rem 1rem;
  }

  /* === UTILITY === */
  .mb-3 {
    margin-bottom: 0.75rem !important;
  }

  .gap-2 {
    gap: 0.35rem !important;
  }

  /* Make scrollable areas more obvious */
  .overflow-auto {
    -webkit-overflow-scrolling: touch;
  }
}

/* Medium devices (tablets, 768px to 991px) */
@media (min-width: 768px) and (max-width: 991px) {

  /* Roll history - still collapsible but larger */
  #rollHistoryPanel .card-body {
    max-height: 300px !important;
  }

  /* Portrait slightly larger */
  #portraitContainer {
    height: 250px !important;
  }

  .portrait-frame {
    height: 250px !important;
  }

  /* Tabs can show more */
  .nav-tabs .nav-link {
    font-size: 0.9rem;
  }

  /* Skills table more readable */
  .table {
    font-size: 0.9rem;
  }
}

/* === ROLL HISTORY STICKY (any 2-column layout: md+) === */
@media (min-width: 768px) {
  #rollHistoryPanel {
    position: sticky;
    top: 70px;
  }
}

/* === COLLAPSIBLE ROLL HISTORY (all screen sizes) === */

/* Collapsed state hides the body everywhere */
#rollHistoryPanel.collapsed {
  margin-bottom: 0.5rem;
}

#rollHistoryPanel.collapsed .card-body {
  display: none;
}

/* Chevron rotates to indicate state */
#rollHistoryPanel .collapse-icon {
  transition: transform 0.2s ease;
}

#rollHistoryPanel.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

/* === LANDSCAPE MOBILE === */
@media (max-width: 767px) and (orientation: landscape) {
  /* Use more horizontal space */
  .col-6 {
    flex: 0 0 50%;
  }

  /* Ability scores in 2 rows instead of 3 */
  .ability-score-box {
    min-width: 80px;
  }

  /* Roll history even more compact */
  #rollHistoryPanel .card-body {
    max-height: 150px !important;
  }
}

/* === TOUCH IMPROVEMENTS === */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .btn {
    min-height: 38px;
    min-width: 38px;
  }

  .form-check-input {
    width: 1.25rem;
    height: 1.25rem;
  }

  /* Roll buttons easier to tap */
  [data-skill-roll],
  [data-save-roll],
  [data-attack-roll],
  [data-hp-adjust] {
    min-width: 38px;
    min-height: 38px;
  }

  /* Spell slot checkboxes */
  .spell-slot-checkbox {
    width: 26px !important;
    height: 26px !important;
    margin: 0.2rem;
  }

  /* Death save checkboxes */
  #deathSaveGrid input[type="checkbox"] {
    width: 22px !important;
    height: 22px !important;
  }
}

/* === PRINT STYLES === */
@media print {
  /* Hide roll history and buttons when printing */
  #rollHistoryPanel,
  .btn,
  .btn-group,
  .modal,
  nav {
    display: none !important;
  }

  /* Make portrait smaller */
  #portraitContainer {
    height: 150px !important;
  }

  /* Expand all collapsed sections */
  .collapse:not(.show) {
    display: block !important;
  }

  /* Remove colors for better printing */
  .card,
  .table {
    border: 1px solid #000 !important;
    background: white !important;
    color: black !important;
  }
}
