/* MKJ Cloud - Theme-Agnostic Custom Styles */
/* Works with both Bootswatch Flatly (light) and Darkly (dark) themes */

/* ============================================================================
   ALERT CODE TAG STYLING - High Contrast for WCAG Compliance
   ============================================================================ */

/* Alert code tag styling - works with both Flatly (light) and Darkly (dark) themes */
.alert code {
    background-color: rgba(0, 0, 0, 0.15);
    color: #000;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    border: 1px solid rgba(0, 0, 0, 0.2);
    display: inline-block;
    font-weight: 500;
}

/* Dark theme adjustments (Bootswatch Darkly) */
[data-bs-theme='dark'] .alert code,
.darkly .alert code {
    background-color: #2a3038;
    color: #f0f6fc;
    border-color: #30363d;
}

/* Specific high-contrast styling for info alerts */
.alert-info code {
    background-color: rgba(0, 0, 0, 0.12);
    border-color: rgba(0, 0, 0, 0.18);
}

[data-bs-theme='dark'] .alert-info code,
.darkly .alert-info code {
    background-color: #0d1117;
    color: #79c0ff;
    border-color: #1f6feb;
}

/* ============================================================================
   CRITICAL STRUCTURAL FIXES
   ============================================================================ */

/* Prevent horizontal scroll bars */
body {
    overflow-x: hidden;
}

.container-fluid {
    max-width: 100%;
    overflow-x: hidden;
}

.table-responsive {
    overflow-x: auto;
}

/* ============================================================================
   CUSTOM COMPONENTS
   ============================================================================ */

/* Status Indicators with Pulse Animation */
.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.75rem;
    position: relative;
    transition: all 0.2s ease-in-out;
}

.status-indicator.online {
    animation: pulse-online 2s infinite;
}

@keyframes pulse-online {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Timer Controls */
.timer-controls {
    border-radius: 6px;
    padding: 4px 8px;
    margin: 0 4px;
}

.timer-controls input[type='number'] {
    font-size: 11px;
    text-align: center;
}

.timer-controls .btn {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Device Controls Layout */
.device-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-width: 280px;
}

.device-controls .btn-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

/* Real-time Status Display */
.status-display {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.real-time-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    opacity: 0.8;
}

.real-time-indicator i {
    animation: pulse-realtime 2s infinite;
}

@keyframes pulse-realtime {
    0%,
    100% {
        opacity: 0.4;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

/* User Table Accordion */
.user-row-collapsed {
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}

.user-row-expanded td {
    padding-top: 0 !important;
    padding-bottom: 1rem !important;
}

.user-expanded-details {
    padding: 1rem;
    border-radius: 6px;
    margin-top: 0.5rem;
}

.user-expanded-details dl.row {
    margin-bottom: 0;
}

.user-expanded-details dt {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-expanded-details dd {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.user-expanded-details dd:last-child {
    margin-bottom: 0;
}

.expand-icon {
    transition: transform 0.2s ease-in-out;
    font-size: 0.9rem;
}

.expand-icon:hover {
    /* hover transform removed */
}

/* ============================================================================
   MOBILE-RESPONSIVE DESIGN
   ============================================================================ */

/* Mobile Device Card Layout (<768px) */
.device-card {
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.2s ease-in-out;
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
}

.device-card-header .device-name {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1;
    word-break: break-word;
}

.device-card-header .badge {
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.device-card-body {
    padding: 1rem;
}

.device-card-body .last-seen-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

/* Collapsible Device Details */
.device-details {
    margin-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 0.75rem;
}

.device-details summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.5rem 0;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.device-details dl {
    margin: 0.75rem 0 0 0;
    padding: 0.75rem;
    border-radius: 6px;
}

.device-details dt {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.5rem;
}

.device-details dt:first-child {
    margin-top: 0;
}

.device-details dd {
    margin: 0.25rem 0 0 0;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.85rem;
    word-break: break-all;
}

.device-card-actions {
    padding: 0 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.device-card-actions .btn {
    width: 100%;
    min-height: 44px; /* Touch-friendly */
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Reset device-details spacing when used as mobile accordion wrapper */
.device-card > .device-details {
    margin-top: 0;
    border-top: none;
    padding-top: 0;
}

/* Override summary styles when it's the card header (mobile accordion) */
.device-details summary.device-card-header {
    padding: 1rem;
    font-weight: normal;
    color: inherit;
    font-size: inherit;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Hide disclosure marker */
.device-details summary.device-card-header::marker,
.device-details summary.device-card-header::-webkit-details-marker {
    display: none;
}

/* Cards container - now used for unified view on user dashboard (all screen sizes) */
#devices-cards-container {
    display: block;
}

/* Organizations & Firmware: Always show accordion */
#organizations-cards-container,
#firmware-cards-container {
    display: block;
}

/* ============================================================================
   SUPER ADMIN MANAGEMENT PAGE
   ============================================================================ */

/* Hide mobile accordion by default (shown only on mobile) */
#mobile-management-accordion {
    display: none;
}

/* Management Accordion Styles */
.mgmt-accordion-section {
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.mgmt-accordion-details {
    border: none;
}

.mgmt-accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
    transition: background-color 0.2s ease-in-out;
}

.mgmt-accordion-header::-webkit-details-marker {
    display: none;
}

.mgmt-accordion-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.mgmt-accordion-title i {
    font-size: 1.25rem;
}

.mgmt-accordion-header .badge {
    font-size: 0.9rem;
    padding: 0.4rem 0.75rem;
    min-width: 2.5rem;
    text-align: center;
    margin-left: auto;
    margin-right: 0.5rem;
}

.mgmt-accordion-body {
    padding: 1rem;
}

/* Accordion expand/collapse animation */
.mgmt-accordion-details summary::after {
    content: '\f078'; /* FontAwesome chevron-down */
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    transition: transform 0.2s ease-in-out;
}

.mgmt-accordion-details[open] summary::after {
    transform: rotate(180deg);
}

/* ============================================================================
   PHASE 4: OFFLINE QUEUE BADGE (FLOATING BUTTON)
   ============================================================================ */

/* Queue Badge Container */
#queue-badge {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s ease-in-out;
}

/* Badge Button */
#queue-badge .badge-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.15),
        0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease-in-out;
    position: relative;
}

#queue-badge:hover .badge-button {
    box-shadow:
        0 6px 16px rgba(0, 0, 0, 0.2),
        0 3px 6px rgba(0, 0, 0, 0.15);
}

#queue-badge:active .badge-button {
    transform: translateY(0px);
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.15),
        0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Badge Icon */
#queue-badge .badge-icon {
    font-size: 20px;
    position: absolute;
    transition: opacity 0.2s ease-in-out;
}

/* Badge Count */
#queue-badge-count {
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

/* Pulse Animation (when there are queued items) */
@keyframes badge-pulse {
    0%,
    100% {
        box-shadow:
            0 4px 12px rgba(0, 0, 0, 0.15),
            0 2px 4px rgba(0, 0, 0, 0.1);
    }
    50% {
        box-shadow:
            0 4px 16px rgba(0, 0, 0, 0.25),
            0 2px 6px rgba(0, 0, 0, 0.15),
            0 0 0 6px rgba(0, 0, 0, 0.1);
    }
}

#queue-badge.badge-pulse .badge-button {
    animation: badge-pulse 2s infinite;
}

/* ============================================================================
   PHASE 4: OFFLINE QUEUE MODAL
   ============================================================================ */

/* Modal Loading State */
.queue-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
}

.queue-loading p {
    margin: 0;
}

/* Modal Empty State */
.queue-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
}

.queue-empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.queue-empty-state p {
    font-size: 1.1rem;
    margin: 0;
}

/* Commands List Container */
.queue-commands-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Command Card */
.queue-command-card {
    border-radius: 8px;
    padding: 1rem;
    transition: all 0.2s ease-in-out;
}

/* Command Status Colors */
.queue-command-card.status-pending {
    border-left: 3px solid;
}

.queue-command-card.status-syncing {
    border-left: 3px solid;
}

.queue-command-card.status-failed {
    border-left: 3px solid;
}

/* Command Header */
.command-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.command-number {
    font-weight: 700;
    font-size: 0.9rem;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
}

.command-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.command-status i {
    font-size: 0.9rem;
}

/* Command Body */
.command-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.command-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.command-label {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.command-value {
    font-size: 0.9rem;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    text-align: right;
    word-break: break-word;
}

/* Command Error Display */
.command-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: 6px;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.command-error i {
    flex-shrink: 0;
    font-size: 1rem;
}

/* Modal Action Buttons */
.queue-modal-actions {
    margin-top: 1rem;
    padding-top: 1rem;
}

.queue-modal-actions .btn {
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* ============================================================================
   ORG ADMIN DASHBOARD - USER CARD LAYOUT (MOBILE)
   ============================================================================ */

/* User Card Container */
.user-card {
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.2s ease-in-out;
}

/* User Card Header */
.user-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.user-card-header .user-name {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1 1 auto;
    min-width: 120px;
    word-break: break-word;
}

.user-card-header .user-badges {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.user-card-header .badge {
    flex-shrink: 0;
}

/* Batch mode checkbox in card header */
.user-card-header .batch-checkbox {
    margin-right: 0.75rem;
    transform: scale(1.3);
    cursor: pointer;
}

/* User Card Body */
.user-card-body {
    padding: 1rem;
}

.user-card-body .user-email {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    word-break: break-word;
}

.user-card-body .user-email i {
    flex-shrink: 0;
}

.user-card-body .user-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.user-card-body .user-info-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-card-body .user-info-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.user-card-body .user-info-value {
    font-size: 0.85rem;
}

/* Collapsible User Details */
.user-details {
    margin-top: 0.75rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 0.75rem;
}

.user-details summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.5rem 0;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Override summary styles when it's the card header (mobile accordion) */
.user-details summary.user-card-header {
    padding: 1rem;
    font-weight: normal;
    color: inherit;
    font-size: inherit;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

/* Hide the default disclosure marker when header is the summary */
.user-details summary.user-card-header::marker,
.user-details summary.user-card-header::-webkit-details-marker {
    display: none;
}

/* Reset user-details spacing when used as mobile accordion wrapper */
.user-card > .user-details {
    margin-top: 0;
    border-top: none;
    padding-top: 0;
}

.user-details dl {
    margin: 0.75rem 0 0 0;
    padding: 0.75rem;
    border-radius: 6px;
}

.user-details dt {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 0.5rem;
}

.user-details dt:first-child {
    margin-top: 0;
}

.user-details dd {
    margin: 0.25rem 0 0 0;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.85rem;
    word-break: break-all;
}

/* User Card Actions */
.user-card-actions {
    padding: 0 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.user-card-actions .btn {
    width: 100%;
    min-height: 44px;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Users cards container (mobile only) */
#users-cards-container {
    display: none;
}

/* ============================================================================
   INVITATION, FIRMWARE, UNCLAIMED, ORGANIZATION, POLICY CARDS
   (Following same patterns as above - layout only, no theme colors)
   ============================================================================ */

/* Shared card action button styles for consistency */
.card-actions .btn,
[class*='-card-actions'] .btn {
    width: 100%;
    min-height: 44px;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Invitation Card */
.invitation-card {
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.2s ease-in-out;
}

.invitation-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.invitation-card-header .invitation-email {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    flex: 1 1 auto;
    min-width: 150px;
    word-break: break-word;
}

.invitation-card-body {
    padding: 1rem;
}

.invitation-card-body .invitation-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.invitation-card-actions {
    padding: 0 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.invitation-card-actions .btn {
    width: 100%;
    min-height: 44px;
}

#invitations-cards-container {
    display: block;
}

/* Organization Card */
.org-card {
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.2s ease-in-out;
}

.org-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    cursor: pointer;
    list-style: none;
}

.org-card-body {
    padding: 1rem;
}

.org-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0;
}

.org-info-item-full {
    grid-column: 1 / -1;
}

.org-info-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Firmware Info Grid (matches org-info-grid pattern) */
.firmware-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0;
}

.firmware-info-item-full {
    grid-column: 1 / -1;
}

.firmware-info-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.firmware-info-label {
    font-size: 0.875rem;
    font-weight: 500;
}

.firmware-info-value {
    font-size: 0.9375rem;
}

.firmware-card-actions {
    padding: 0;
}

.firmware-card-actions .btn {
    width: 100%;
    min-height: 44px;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Policy Card */
.policy-card {
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.2s ease-in-out;
}

.policy-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.policy-card-body {
    padding: 1rem;
}

.policy-card-body .policy-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.policy-card-actions {
    padding: 0 1rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.policy-card-actions .btn {
    width: 100%;
    min-height: 44px;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

#policies-cards-container {
    display: block;
}

/* Unclaimed Device Card */
.unclaimed-card {
    border-radius: 10px;
    margin-bottom: 1rem;
    overflow: visible;
    transition: all 0.2s ease-in-out;
}

.unclaimed-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    cursor: pointer;
    list-style: none;
}

.unclaimed-card-body {
    padding: 1rem;
}

.unclaimed-card-actions .dropdown {
    width: 100%;
}

.unclaimed-card-actions .dropdown-menu {
    width: 100%;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1050;
}

/* ============================================================================
   NAVBAR GLOBAL STYLES
   ============================================================================ */

/* Navbar brand as non-clickable text (span) */
.navbar-brand {
    cursor: default;
    color: #fff;
    font-weight: 500;
}

/* Theme toggle icon spacing (desktop) */
#theme-toggle i {
    margin-right: 0.5rem !important;
}

/* Ensure hamburger icon is visible on bg-primary navbar */
.navbar-toggler {
    border: none !important;
}

.navbar-toggler:focus {
    box-shadow: none !important;
}

.navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.85%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

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

/* Tablet (768px - 992px): Simplified Table */
@media (max-width: 992px) {
    /* Hide Serial Number column on tablet */
    .table thead th:nth-child(3),
    .table tbody td:nth-child(3) {
        display: none;
    }

    /* Adjust stats cards to 2-up on tablet */
    .col-md-4 {
        flex: 0 0 auto;
        width: 50%;
    }

    /* Smaller button text on tablet */
    .btn-sm {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
    }
}

/* Tablet: Admin dashboard stats - 3 per row */
@media (max-width: 992px) and (min-width: 768px) {
    .row.mb-4 > .col-md-2:not(.col-lg-2) {
        flex: 0 0 auto;
        width: 33.333333%;
    }
}

/* Organization Selector Card (User Dashboard) */
.org-selector-card {
    transition: all 0.2s ease-in-out;
}

.org-selector-card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.org-selector-card.border-primary {
    border-width: 2px;
}

.org-card-actions {
    padding: 0;
}

/* Organizations & Firmware: Always hide desktop containers, always show accordion */
#organizations-container,
#firmware-versions-container {
    display: none !important;
}

/* Organizations: Hide Refresh button (show Create button) */
#orgs-refresh-btn {
    display: none !important;
}

/* Mobile (<768px): Card Layout + Hide Table */
@media (max-width: 767px) {
    /* Hide advanced features on mobile */
    #advanced-user-management,
    #batch-mode-btn,
    #users-export-btn,
    #users-refresh-btn,
    #devices-refresh-btn,
    #devices-claim-btn,
    #time-policies-section {
        display: none !important;
    }

    /* Super admin: Hide firmware section on mobile */
    #firmware-section {
        display: none !important;
    }

    /* Hide non-essential buttons */
    #firmware-upload-btn,
    #unclaimed-refresh-btn {
        display: none !important;
    }

    /* Super admin stats: 2 cards per row on mobile */
    .row.mb-4 > .col-md-3 {
        flex: 0 0 auto;
        width: 50%;
    }

    /* Typography adjustments */
    h1 {
        font-size: 1.75rem;
    }

    h5 {
        font-size: 1.1rem;
    }

    /* Stats cards full width on mobile */
    .col-md-4 {
        flex: 0 0 auto;
        width: 100%;
    }

    /* Reduce stats card padding */
    .card.bg-info .card-body,
    .card.bg-success .card-body,
    .card.bg-danger .card-body,
    .card.bg-primary .card-body {
        padding: 0.75rem;
    }

    .card.bg-info .card-body h2,
    .card.bg-success .card-body h2,
    .card.bg-danger .card-body h2,
    .card.bg-primary .card-body h2 {
        font-size: 2rem;
    }

    /* Hide table, show cards */
    .table-responsive {
        display: none !important;
    }

    /* Exception: Keep WebAuthn Security Devices table visible on mobile */
    /* (No card view exists for user-settings page) */
    #webauthn-devices-table .table-responsive {
        display: block !important;
    }

    #users-cards-container,
    #invitations-cards-container {
        display: block !important;
    }

    /* Card header adjustments */
    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-header h5 {
        font-size: 1rem;
        margin: 0;
    }

    /* Mobile Navbar - Bootstrap Collapsible */
    .navbar {
        padding: 0.5rem 0.25rem; /* Reduced horizontal padding for edge-to-edge feel */
    }

    /* Reduce container-fluid padding inside navbar for tighter spacing */
    .navbar .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .navbar-brand {
        font-size: 1rem;
        flex-shrink: 0;
    }

    .navbar-brand img {
        height: 28px !important;
        margin-right: 6px !important;
    }

    /* Hamburger button */
    .navbar-toggler {
        padding: 0.25rem 0.5rem;
        font-size: 1rem;
        border-color: rgba(255, 255, 255, 0.5);
        border: 2px solid rgba(255, 255, 255, 0.5);
    }

    .navbar-toggler:focus {
        box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
        border-color: rgba(255, 255, 255, 0.75);
    }

    /* Ensure hamburger icon is visible on dark navbar */
    .navbar-toggler-icon {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.85%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
        width: 1.5em;
        height: 1.5em;
    }

    /* Hamburger button positioning - left side */
    .navbar-toggler {
        order: -1;
        margin-right: 0.5rem;
    }

    /* Center logo on mobile when hamburger is on left */
    .navbar-brand {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        margin: 0;
    }

    /* Offcanvas slide-out menu from left */
    .offcanvas.offcanvas-start {
        width: 280px;
        background-color: var(--bs-primary);
    }

    .offcanvas-header {
        background-color: var(--bs-primary);
        color: white;
        padding: 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .offcanvas-title {
        color: white;
        font-weight: 600;
        font-size: 1.25rem;
    }

    .btn-close {
        filter: invert(1);
        opacity: 0.8;
    }

    .btn-close:hover {
        opacity: 1;
    }

    .offcanvas-body {
        background-color: var(--bs-primary);
        padding: 0;
    }

    .offcanvas-body .navbar-nav {
        width: 100%;
        padding-left: 0;
        margin-left: 0;
        list-style: none;
    }

    .offcanvas-body .navbar-nav .nav-link {
        color: rgba(255, 255, 255, 0.85);
        padding: 0.75rem 1rem;
        display: flex;
        align-items: center;
    }

    .offcanvas-body .navbar-nav .nav-link:hover {
        color: white;
        background-color: rgba(255, 255, 255, 0.1);
    }

    .offcanvas-body .navbar-nav .nav-link.active {
        color: white;
        background-color: rgba(255, 255, 255, 0.15);
        border-left: 4px solid white;
    }

    .offcanvas-body hr {
        border-color: rgba(255, 255, 255, 0.2);
        margin: 0;
    }

    /* Collapsible content (hidden on mobile) */
    .navbar-collapse {
        /* Bootstrap handles collapse/expand */
    }

    /* Navigation links */
    .navbar-nav .nav-link {
        padding: 0.75rem 0.5rem; /* Touch-friendly padding with tighter horizontal spacing */
        font-size: 1rem; /* Readable text */
        min-height: 44px; /* Touch-friendly minimum */
        display: flex; /* Align icon and text */
        align-items: center;
    }

    .navbar-nav .nav-link i {
        margin-right: 0.5rem; /* Icon spacing */
        width: 1.25rem; /* Consistent icon width */
    }

    /* User area */
    #navbar-user {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    #navbar-user .nav-link {
        padding: 0.75rem 0.5rem; /* Match nav-link spacing */
        min-height: 44px;
    }

    #navbar-user .btn-sm {
        min-height: 44px;
        padding: 0.75rem 0.5rem; /* Match nav-link spacing */
        font-size: 1rem;
        white-space: nowrap;
    }

    /* Navbar actions container */
    #navbar-actions {
        margin-top: 1rem; /* Spacing in collapsed mode */
    }

    /* Make buttons touch-friendly (min 44px) */
    .btn {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }

    .btn-sm {
        min-height: 38px;
        padding: 0.4rem 0.8rem;
        font-size: 0.875rem;
    }

    /* Reduce margins for mobile */
    .mb-4 {
        margin-bottom: 1rem !important;
    }

    .mt-4 {
        margin-top: 1rem !important;
    }

    /* Adjust container padding */
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Queue badge adjustments */
    #queue-badge {
        bottom: 16px;
        right: 16px;
    }

    #queue-badge .badge-button {
        width: 48px;
        height: 48px;
    }

    #queue-badge .badge-icon {
        font-size: 18px;
    }

    #queue-badge-count {
        font-size: 14px;
    }

    /* Queue modal adjustments */
    .modal-dialog {
        margin: 0.5rem;
    }

    .queue-command-card {
        padding: 0.75rem;
    }

    .command-info-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .command-value {
        text-align: left;
    }

    /* Timer controls responsive */
    .timer-controls {
        margin: 2px 0;
        padding: 2px 4px;
    }

    .timer-controls input[type='number'] {
        width: 45px !important;
        font-size: 10px;
    }

    .timer-controls .btn {
        font-size: 10px;
        padding: 1px 4px;
    }

    /* Super Admin Management Page - Mobile */
    #filter-controls,
    #managementTabs,
    #managementTabContent {
        display: none !important;
    }

    /* Show mobile accordion */
    #mobile-management-accordion {
        display: block !important;
    }

    /* Hide Time Policies accordion on mobile */
    #mobile-management-accordion .mgmt-accordion-section:nth-child(4) {
        display: none !important;
    }

    /* Admin dashboard stats: 2 cards per row */
    .row.mb-4 > .col-md-2:not(.col-lg-2) {
        flex: 0 0 auto;
        width: 50%;
    }

    /* Header action buttons: Stack vertically */
    .page-header .d-flex.gap-2,
    .card-header .d-flex.gap-2 {
        flex-direction: column;
        width: 100%;
    }

    .page-header .d-flex.gap-2 .btn,
    .card-header .d-flex.gap-2 .btn {
        width: 100%;
    }

    /* Batch mode button */
    #batch-mode-text {
        display: none;
    }
}

/* Extra small mobile (<400px) */
@media (max-width: 400px) {
    h1 {
        font-size: 1.5rem;
    }

    .device-card-header .device-name {
        font-size: 1rem;
    }

    .card.bg-info .card-body h2,
    .card.bg-success .card-body h2,
    .card.bg-danger .card-body h2,
    .card.bg-primary .card-body h2 {
        font-size: 1.75rem;
    }

    .navbar-brand {
        font-size: 1rem;
    }

    /* Queue badge extra small */
    #queue-badge {
        bottom: 12px;
        right: 12px;
    }

    #queue-badge .badge-button {
        width: 44px;
        height: 44px;
    }

    #queue-badge .badge-icon {
        font-size: 16px;
    }

    #queue-badge-count {
        font-size: 13px;
    }

    /* Admin dashboard stats: 1 card per row */
    .row.mb-4 > .col-md-2:not(.col-lg-2) {
        flex: 0 0 auto;
        width: 100%;
    }
}

/* Landscape mobile orientation */
@media (max-width: 767px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    .device-card {
        margin-bottom: 0.5rem;
    }

    .device-card-body {
        padding: 0.75rem;
    }

    .device-card-header {
        padding: 0.75rem;
    }

    .card.bg-info .card-body,
    .card.bg-success .card-body,
    .card.bg-danger .card-body,
    .card.bg-primary .card-body {
        padding: 0.5rem;
    }

    #queue-badge {
        bottom: 12px;
        right: 12px;
    }
}

/* =================================================================
   CSP COMPLIANCE - Phase 3
   ================================================================= */

/* Scrollable User List in Policy Modals */
.user-list-scroll {
    max-height: 120px;
    overflow-y: auto;
}

/* =================================================================
   MULTI-ORG GROUPED DEVICE DISPLAY
   ================================================================= */

/* Organization Header Row (Desktop Table) */
.org-header-row {
    transition: background-color 0.2s ease;
    user-select: none;
}

.org-header-row:hover {
    background-color: #e9ecef !important;
}

/* Collapse Indicator Animation */
.collapse-indicator {
    transition: transform 0.3s ease;
    display: inline-block;
}

/* Rotate chevron when expanded */
.org-header-row[aria-expanded='true'] .collapse-indicator {
    transform: rotate(180deg);
}

/* Organization Badge Styling */
.org-header-row .badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

/* Organization Stats in Header */
.org-header-row .badge.bg-success,
.org-header-row .badge.bg-danger {
    font-weight: normal;
}

/* Mobile Accordion Organization Headers */
.accordion-button {
    font-size: 1rem;
}

.accordion-button:not(.collapsed) {
    background-color: #f8f9fa;
    color: inherit;
}

/* Accordion Border Radius Fix */
.accordion-item {
    border-radius: 0.375rem !important;
    overflow: visible;
    margin-bottom: 1rem;
    border-top: 1px solid var(--bs-accordion-border-color, rgba(0, 0, 0, 0.125)) !important;
}

.accordion-item:first-child {
    border-top-left-radius: 0.375rem !important;
    border-top-right-radius: 0.375rem !important;
}

.accordion-item:last-child {
    border-bottom-left-radius: 0.375rem !important;
    border-bottom-right-radius: 0.375rem !important;
}

.accordion-button {
    border-top-left-radius: 0.375rem !important;
    border-top-right-radius: 0.375rem !important;
}

.accordion-button.collapsed {
    border-radius: 0.375rem !important;
}

/* Device Cards Within Organization Sections (Mobile) */
.accordion-body .card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 0.375rem;
}

.accordion-body .card:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* Spacing for Grouped Views */
.org-header-row + tr {
    border-top: none;
}

/* ============================================================================
   LEFT SIDEBAR NAVIGATION (Desktop >= lg breakpoint)
   ============================================================================ */

/* Desktop Sidebar - Fixed left */
@media (min-width: 992px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 1000;
    }

    .sidebar-header {
        display: flex;
        align-items: center;
    }

    .sidebar .navbar-brand {
        color: white;
        font-size: 1.25rem;
        font-weight: bold;
        display: flex;
        align-items: center;
    }

    .sidebar .nav-link {
        color: rgba(255, 255, 255, 0.85);
        padding: 0.75rem 1.25rem;
        border-left: 3px solid transparent;
        transition: all 0.2s ease;
    }

    .sidebar .nav-link:hover {
        color: white;
        background-color: rgba(255, 255, 255, 0.1);
        border-left-color: rgba(255, 255, 255, 0.5);
    }

    .sidebar .nav-link.active {
        color: white;
        background-color: rgba(255, 255, 255, 0.15);
        border-left-color: white;
    }

    .sidebar .nav-link i {
        width: 20px;
        text-align: center;
        margin-right: 0.75rem;
    }

    /* Main content offset for sidebar */
    .main-content {
        margin-left: 280px;
        min-height: 100vh;
    }

    /* Scrollbar styling for sidebar */
    .sidebar::-webkit-scrollbar {
        width: 6px;
    }

    .sidebar::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.1);
    }

    .sidebar::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 3px;
    }

    .sidebar::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.5);
    }
}

/* Mobile - No sidebar, content full width */
@media (max-width: 991.98px) {
    .main-content {
        margin-left: 0;
    }
}

/* ============================================================================
   USER LIST ITEMS (Mobile-First Design)
   ============================================================================ */

/* Clickable user list items */
.user-list-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #dee2e6;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.user-list-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.user-list-item:active {
    background-color: rgba(0, 0, 0, 0.08);
}

.user-list-item:focus {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
    background-color: rgba(0, 0, 0, 0.03);
}

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

/* Dark theme adjustments */
[data-bs-theme='dark'] .user-list-item,
.darkly .user-list-item {
    border-bottom-color: #495057;
}

[data-bs-theme='dark'] .user-list-item:hover,
.darkly .user-list-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

[data-bs-theme='dark'] .user-list-item:active,
.darkly .user-list-item:active {
    background-color: rgba(255, 255, 255, 0.08);
}

[data-bs-theme='dark'] .user-list-item:focus,
.darkly .user-list-item:focus {
    background-color: rgba(255, 255, 255, 0.03);
}

/* ============================================================================
   DEVICE LIST ITEMS (Mobile-First Design)
   ============================================================================ */

/* Clickable device list items */
.device-list-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #dee2e6;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.device-list-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.device-list-item:active {
    background-color: rgba(0, 0, 0, 0.08);
}

.device-list-item:focus {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
    background-color: rgba(0, 0, 0, 0.03);
}

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

/* Dark theme adjustments */
[data-bs-theme='dark'] .device-list-item,
.darkly .device-list-item {
    border-bottom-color: #495057;
}

[data-bs-theme='dark'] .device-list-item:hover,
.darkly .device-list-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

[data-bs-theme='dark'] .device-list-item:active,
.darkly .device-list-item:active {
    background-color: rgba(255, 255, 255, 0.08);
}

[data-bs-theme='dark'] .device-list-item:focus,
.darkly .device-list-item:focus {
    background-color: rgba(255, 255, 255, 0.03);
}

/* ============================================================================
   CAPABILITIES JSON PREVIEW - Dark Mode Support
   ============================================================================ */

/* Light mode styling (default) */
#capabilities-json-preview {
    background-color: #f8f9fa;
    color: #212529;
    border: 1px solid #dee2e6;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
}

/* Dark mode styling */
[data-bs-theme='dark'] #capabilities-json-preview {
    background-color: #0d1117;
    color: #79c0ff;
    border: 1px solid #30363d;
}

/* ============================================================================
   DEVICE TYPE MODAL - CONTROL CARD OPTIMIZATION
   ============================================================================ */

/* Reduced padding for control cards in device type modal */
.control-card .card-body {
    padding: 0.75rem;
}

.control-card .card-header {
    padding: 0.5rem 0.75rem;
}
