/* ============================================================================
   Athena Deploy Center — Responsive overrides (Phases 32-36)
   ----------------------------------------------------------------------------
   Extracted VERBATIM from site.css, where this block already sat AFTER every
   page section it overrides. It is linked LAST in _Host.cshtml so that ordering
   is preserved.

   Safe to move past the three site.css sections that used to follow it (Agent
   Log Viewer, Alert count badges, Monitor condition builder): they share no
   selector with anything in here, so nothing changes hands in the cascade.
   ============================================================================ */

/* ============================================================================
   RESPONSIVE DESIGN - Phase 32: Layout Foundation
   Breakpoints: Phone (<768px), Tablet (768-1023px), Desktop (default), Large (1440px+)
   Desktop-first: max-width queries (matching existing codebase pattern)
   ============================================================================ */

/* --- Large screens (1440px+) ---
   User decision: No changes needed. Desktop layout already works well at large sizes.
   Content area uses flex:1 to expand into available width naturally.
   This satisfies LAYOUT-05: "Large screens use available width without wasted whitespace." */

/* --- Tablet (768px - 1023px) --- */
@media (max-width: 1023px) {
    :root {
        --content-padding: 20px;
        --card-padding: 20px;
        --header-margin: 20px;
        --grid-gap: 16px;
        --card-gap: 16px;
    }

    /* Stats grid: force 2 columns on tablet */
    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Tables: horizontal scroll instead of clipping */
    .content-card {
        overflow-x: auto;
    }

    .table {
        min-width: 600px;
    }

    /* Agent detail header: tighter internal spacing */
    .header-top {
        margin-bottom: 20px;
    }

    .agent-title-section {
        gap: 16px;
    }

    /* Stat value: slightly smaller on tablet for stat cards */
    .stat-value {
        font-size: 48px;
    }

    .stat-label {
        font-size: large;
    }

    /* Phase 33: Show hamburger button */
    .hamburger-btn {
        display: flex;
    }

    /* Phase 33: Sidebar becomes fixed overlay, off-screen by default */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        inset-inline-start: calc(-1 * var(--sidebar-width, 250px));
        width: var(--sidebar-width, 250px);
        z-index: 1001;
        transition: inset-inline-start 0.3s ease;
    }

    /* Phase 33: Sidebar open state - slides into view */
    .sidebar.open {
        inset-inline-start: 0;
    }

    /* Phase 33: Dark backdrop when sidebar is open */
    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
    }

    /* Phase 33: Scroll lock when sidebar overlay is open */
    .container.sidebar-open {
        overflow: hidden;
        height: 100vh;
        overscroll-behavior: none;
    }

    /* Phase 33: Main content takes full width (sidebar no longer in flex flow) */
    .main-content {
        width: 100%;
    }

    /* Phase 33: Update header h1 max-width (no sidebar in flow, but hamburger + user-info present) */
    .header h1 {
        max-width: calc(100vw - 140px);
    }

    /* Phase 33: Accessibility - respect reduced motion preference */
    @media (prefers-reduced-motion: reduce) {
        .sidebar {
            transition: none;
        }
        .hamburger-line {
            transition: none;
        }
    }

    /* Phase 34: Horizontal scroll for table containers missing overflow-x */
    .agents-list,
    .scheduler-list {
        overflow-x: auto;
    }

    /* Phase 34: Hide low-priority columns on tablet */
    .agents-table .col-low-priority {
        display: none;
    }

    .audit-table .col-ip,
    .audit-table .col-description {
        display: none;
    }

    .scheduler-table th:nth-child(4),
    .scheduler-table td:nth-child(4) {
        display: none;
    }

    .commands-table th:nth-child(5),
    .commands-table td:nth-child(5),
    .commands-table th:nth-child(6),
    .commands-table td:nth-child(6) {
        display: none;
    }

    /* Phase 35: Two-column fixed grids → single column on tablet */
    .push-update-grid {
        grid-template-columns: 1fr;
    }

    .master-detail-container {
        grid-template-columns: 1fr;
    }

    .split-panel {
        grid-template-columns: 1fr;
    }

    /* Phase 35: Four-column info-grid → two columns on tablet */
    .info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* --- Phone (<768px) --- */
@media (max-width: 767px) {
    :root {
        --content-padding: 12px;
        --card-padding: 12px;
        --header-margin: 12px;
        --grid-gap: 10px;
        --card-gap: 10px;
    }

    /* Main content: prevent any overflow */
    .main-content {
        min-width: 0;
        overflow-x: hidden;
    }

    /* Header: allow wrapping for very long titles, compact spacing */
    .header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .header h1 {
        max-width: calc(100vw - 120px); /* Phase 33: No sidebar in flow, just hamburger + user-info */
        font-size: clamp(0.875rem, 0.75rem + 0.5vw, 1.25rem);
    }

    /* Stats grid: single column stack on phone */
    .stats {
        grid-template-columns: 1fr;
    }

    /* Stat cards: compact horizontal layout */
    .stat-card {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 10px 12px;
    }

    .stat-value {
        font-size: 28px;
        min-width: 0;
    }

    .stat-content {
        align-items: flex-start;
        min-width: 0;
    }

    .stat-label {
        font-size: small;
        text-align: left;
        margin-bottom: 2px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .stat-trend {
        font-size: 12px;
        text-align: left;
    }

    /* Card headers: stack title and button vertically */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 12px;
        padding-bottom: 10px;
    }

    .card-title {
        font-size: 1rem;
    }

    /* Tables: horizontal scroll with minimum width */
    .content-card {
        overflow-x: auto;
        padding: 10px;
    }

    .table {
        min-width: 500px;
        font-size: 12px;
    }

    .table th,
    .table td {
        padding: 8px 6px;
    }

    /* Agent detail header: compact layout */
    .header-top {
        margin-bottom: 12px;
    }

    .agent-title-section {
        gap: 8px;
    }

    /* Quick actions grid (Command page): tighter gaps */
    .quick-actions {
        gap: var(--card-gap, 10px);
    }

    /* Stats bar (Command page) */
    .stats-bar {
        gap: var(--grid-gap, 10px);
        flex-wrap: wrap;
    }

    /* Buttons: compact for phone */
    .btn {
        padding: 6px 12px;
        font-size: 13px;
    }

    .btn-fixed {
        min-width: 120px;
    }

    /* Phase 33: Hide username text on phone, show only avatar */
    .user-info > span:first-child {
        display: none;
    }

    /* ============================================
       Phase 34: Phone Card Layout for Data Tables
       Tables transform into stacked cards with labeled fields.
       Uses CSS ::before + attr(data-label) for field labels.
       ============================================ */

    /* --- Agents table card layout --- */
    .agents-list .agents-table {
        min-width: 0;
    }

    .agents-list .agents-table thead {
        position: absolute;
        left: -9999px;
    }

    .agents-list .agents-table,
    .agents-list .agents-table tbody {
        display: block;
    }

    .agents-list .agents-table tbody tr {
        display: block;
        margin-bottom: 12px;
        background: white;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 8px;
        padding: 12px;
        cursor: pointer;
    }

    .agents-list .agents-table tbody tr:hover {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .agents-list .agents-table tbody tr.offline {
        border-color: #fecaca;
        background: #fef2f2;
    }

    .agents-list .agents-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: 1px solid #f0f0f0;
        font-size: 13px;
    }

    .agents-list .agents-table tbody td:last-child {
        border-bottom: none;
    }

    .agents-list .agents-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted, #6b7280);
        font-size: 12px;
        flex-shrink: 0;
        margin-inline-end: 12px;
    }

    /* Hide low-priority columns in card layout */
    .agents-list .agents-table .col-low-priority {
        display: none;
    }

    /* Action buttons: wrap in card mode */
    .agents-list .list-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: flex-end;
    }

    /* --- Audit table card layout --- */
    .audit-list .audit-table {
        min-width: 0;
    }

    .audit-list .audit-table thead {
        position: absolute;
        left: -9999px;
    }

    .audit-list .audit-table,
    .audit-list .audit-table tbody {
        display: block;
    }

    .audit-list .audit-table tbody tr {
        display: block;
        margin-bottom: 12px;
        background: white;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 8px;
        padding: 12px;
        cursor: pointer;
    }

    .audit-list .audit-table tbody tr.row-failed {
        border-color: #fecaca;
        background: #fef2f2;
    }

    .audit-list .audit-table tbody tr.row-warning {
        border-color: #fde68a;
        background: #fffbeb;
    }

    .audit-list .audit-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: 1px solid #f0f0f0;
        font-size: 13px;
    }

    .audit-list .audit-table tbody td:last-child {
        border-bottom: none;
    }

    .audit-list .audit-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted, #6b7280);
        font-size: 12px;
        flex-shrink: 0;
        margin-inline-end: 12px;
    }

    /* Expandable detail row: exempt from card label pattern */
    .audit-list .audit-table tbody tr.event-details-row {
        margin-top: -12px;
        border-top: none;
        border-radius: 0 0 8px 8px;
        padding: 0;
        cursor: default;
    }

    .audit-list .audit-table tbody tr.event-details-row td {
        display: block;
        padding: 12px;
    }

    .audit-list .audit-table tbody tr.event-details-row td::before {
        display: none;
    }

    /* --- Scheduler table card layout --- */
    .scheduler-list .scheduler-table {
        min-width: 0;
    }

    .scheduler-list .scheduler-table thead {
        position: absolute;
        left: -9999px;
    }

    .scheduler-list .scheduler-table,
    .scheduler-list .scheduler-table tbody {
        display: block;
    }

    .scheduler-list .scheduler-table tbody tr {
        display: block;
        margin-bottom: 12px;
        background: white;
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 8px;
        padding: 12px;
        cursor: pointer;
    }

    .scheduler-list .scheduler-table tbody tr:hover {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .scheduler-list .scheduler-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: 1px solid #f0f0f0;
        font-size: 13px;
    }

    .scheduler-list .scheduler-table tbody td:last-child {
        border-bottom: none;
    }

    .scheduler-list .scheduler-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted, #6b7280);
        font-size: 12px;
        flex-shrink: 0;
        margin-inline-end: 12px;
    }

    /* Action buttons: wrap in card mode */
    .scheduler-list .action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: flex-end;
    }

    /* ============================================
       Phase 35: Grid Collapse for Phone
       Two-column grids → single column stack.
       ============================================ */

    /* Two-column equal grids → single column */
    .agent-info,
    .form-row,
    .step-form-grid,
    .advanced-grid,
    .form-grid,
    .detail-form-row,
    .task-type-selector {
        grid-template-columns: 1fr;
    }

    /* Four-column info-grid → single column on phone */
    .info-grid {
        grid-template-columns: 1fr;
    }

    /* ============================================
       Phase 35: Tab Navigation Adaptation for Phone
       Tabs scroll horizontally instead of wrapping.
       Side-nav converts to horizontal tab strip.
       ============================================ */

    /* Settings tabs: horizontal scroll instead of wrap */
    .settings-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .settings-tabs::-webkit-scrollbar {
        display: none;
    }

    .settings-tabs .tab-btn {
        padding: 8px 14px;
        font-size: 13px;
        flex-shrink: 0;
    }

    /* Detail tabs (PackageTemplates): horizontal scroll */
    .detail-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .detail-tabs::-webkit-scrollbar {
        display: none;
    }

    .detail-tabs .detail-tab {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Agent side-nav: vertical sidebar → horizontal scrollable strip */
    .agent-side-nav {
        max-height: none;
        height: auto;
        overflow-x: auto;
        overflow-y: hidden;
        display: flex;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        border-bottom: 2px solid var(--border-color, #e5e7eb);
        border-inline-end: none;
        gap: 0;
        width: 100%;
        padding: 0;
    }

    .agent-side-nav::-webkit-scrollbar {
        display: none;
    }

    .side-nav-section {
        display: flex;
        flex-shrink: 0;
        border-bottom: none;
    }

    .side-nav-header {
        display: none;
    }

    .side-nav-item {
        flex-shrink: 0;
        white-space: nowrap;
        border-inline-start: none;
        border-bottom: 3px solid transparent;
        margin-bottom: -2px;
        padding: 10px 14px;
        font-size: 13px;
    }

    .side-nav-item.active {
        border-inline-start-color: transparent;
        border-bottom-color: var(--primary-color, #3b82f6);
        background: transparent;
    }

    .side-nav-item .icon {
        font-size: 14px;
    }

    /* ============================================
       Phase 36: Touch Targets (WCAG 2.5.5 — 44px)
       Enforce minimum 44px touch target on all
       interactive elements for mobile usability.
       ============================================ */

    /* Generic buttons — min-height 44px with flex centering */
    .btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Small button variant */
    .btn.btn-sm {
        min-height: 44px;
    }

    /* Action buttons */
    .action-btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Scoped action button containers */
    .action-buttons .btn,
    .service-action-buttons .btn,
    .services-quick-actions .btn,
    .filter-actions .btn {
        min-height: 44px;
    }

    /* Select action button */
    .select-action-btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Icon buttons — fixed 44x44px */
    .btn-icon {
        width: 44px;
        height: 44px;
    }

    .table-icon-btn {
        width: 44px;
        height: 44px;
    }

    .close-btn {
        width: 44px;
        height: 44px;
    }

    /* Small icon button — enlarge to 44px with flex centering */
    .btn-icon-sm {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Tab buttons — min-height without changing padding */
    .tab-btn {
        min-height: 44px;
    }

    .settings-tabs .tab-btn {
        min-height: 44px;
    }

    .detail-tabs .detail-tab {
        min-height: 44px;
    }

    .side-nav-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Pagination buttons — 44x44px minimum */
    .page-btn {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Tag chips */
    .tag-chip {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Toggle button (scheduler) */
    .toggle-btn {
        min-height: 44px;
    }

    /* Menu items */
    .menu-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Hamburger button */
    .hamburger-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Chip remove — 32px visual compromise */
    .chip-remove {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    /* Form controls — min-height for consistency */
    .form-control,
    .form-select {
        min-height: 44px;
    }

    /* Checkbox wrapper — label approach for touch area */
    .checkbox-wrapper {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .checkbox-wrapper label {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-block: 8px;
    }

    /* Agent checkbox in selection lists */
    .agent-checkbox {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Toggle switch — expand touch area */
    .toggle {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Avatar — enlarge from 40px to 44px on phone */
    .avatar {
        width: 44px;
        height: 44px;
    }

    /* ============================================
       Phase 36: Adjacent Spacing (TOUCH-02 — 8px minimum)
       Ensure adjacent interactive elements have at
       least 8px gap to prevent accidental taps.
       ============================================ */

    /* Settings tabs — increase from 4px to 8px */
    .settings-tabs {
        gap: 8px;
    }

    /* Detail tabs — ensure 8px gap */
    .detail-tabs {
        gap: 8px;
    }

    /* Agents list card action buttons — override 4px to 8px */
    .agents-list .list-actions {
        gap: 8px;
    }

    /* Scheduler card action buttons — override 4px to 8px */
    .scheduler-list .action-buttons {
        gap: 8px;
    }
}

/* ============================================
   Phase 36: Rotate Hint
   Show landscape suggestion on portrait phone
   for complex pages (Command, Scheduler).
   ============================================ */
.rotate-hint {
    display: none;
}

@media (orientation: portrait) and (max-width: 767px) {
    .rotate-hint {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 16px;
        margin-bottom: 12px;
        background: var(--bg-secondary, #1e293b);
        border: 1px solid var(--border-color, #334155);
        border-radius: 8px;
        font-size: 13px;
        color: var(--text-secondary, #94a3b8);
    }

    .rotate-hint .rotate-icon {
        font-size: 20px;
        flex-shrink: 0;
    }

    .rotate-hint .rotate-dismiss {
        margin-inline-start: auto;
        background: none;
        border: none;
        color: var(--text-secondary, #94a3b8);
        font-size: 18px;
        cursor: pointer;
        padding: 4px;
        line-height: 1;
    }
}
