/* ========================================
   SecRaptor - Mobile Responsive Stylesheet
   Global mobile-friendly overrides for all pages.
   Loaded after main.css via base.html.
   ======================================== */

/* ========================================
   Prevent iOS auto-zoom on input focus
   ======================================== */
@media (max-width: 768px) {
    input.form-control,
    select.form-control,
    textarea.form-control,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="url"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ========================================
   Touch-friendly targets (min 44px)
   ======================================== */
@media (max-width: 768px) {
    .btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 14px;
    }

    .btn-sm {
        min-height: 36px;
        padding: 6px 12px;
        font-size: 13px;
    }

    .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 10px 12px !important;
    }

    .dropdown-item {
        min-height: 44px;
        padding: 10px 16px;
        display: flex;
        align-items: center;
    }

    .form-check-label {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-left: 4px;
    }

    .custom-control-label {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-top: 4px;
    }
}

/* ========================================
   Typography scaling for mobile
   ======================================== */
@media (max-width: 768px) {
    h1, .h1 { font-size: 1.5rem; }
    h2, .h2 { font-size: 1.25rem; }
    h3, .h3 { font-size: 1.125rem; }
    h4, .h4 { font-size: 1rem; }
    h5, .h5 { font-size: 0.9375rem; }
}

@media (max-width: 480px) {
    h1, .h1 { font-size: 1.3rem; }
    h2, .h2 { font-size: 1.15rem; }
    h3, .h3 { font-size: 1.05rem; }
}

/* ========================================
   Base navbar (non-dashboard pages)
   ======================================== */
@media (max-width: 768px) {
    .navbar-custom {
        padding: 8px 0;
    }

    .navbar-custom .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    .navbar-toggler {
        width: 36px;
        height: 36px;
        padding: 0;
        border: 1px solid transparent;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--bg-secondary, #f1f5f9);
        color: var(--primary, #3b98c6);
        box-shadow: 0 1px 3px rgba(15,23,42,0.06);
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
    }

    .navbar-toggler:hover {
        background: var(--bg-tertiary, #e2e8f0);
        box-shadow: 0 2px 8px rgba(15,23,42,0.10);
        transform: scale(1.04);
    }

    .navbar-toggler:active {
        transform: scale(0.96);
    }

    .dark .navbar-toggler {
        background: rgba(255,255,255,0.06);
        border-color: rgba(255,255,255,0.08);
        color: var(--primary, #2b8db0);
        box-shadow: 0 1px 4px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.04);
    }

    .dark .navbar-toggler:hover {
        background: rgba(255,255,255,0.10);
        border-color: rgba(255,255,255,0.12);
        box-shadow: 0 2px 10px rgba(0,0,0,0.35);
        transform: scale(1.04);
    }

    .navbar-toggler .fas.fa-bars {
        font-size: 16px;
    }

    .dark .navbar-toggler .fas.fa-bars {
        color: var(--primary, #2b8db0) !important;
    }

    .navbar-collapse {
        background: var(--bg-elevated, #fff);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-top: 8px;
        padding: 8px;
        box-shadow: var(--shadow-md);
    }

    .dark .navbar-collapse {
        background: var(--bg-secondary, #0f1219);
    }

    .navbar-nav {
        padding: 4px 0;
    }

    .navbar-nav .nav-item {
        margin: 2px 0;
    }

    .navbar-nav .nav-link {
        padding: 10px 12px !important;
        border-radius: 6px;
    }

    .navbar-nav .org-badge {
        display: block;
        padding: 8px 12px;
        font-size: 13px;
    }

    .navbar-nav .dropdown-menu {
        position: static !important;
        float: none;
        border: none;
        box-shadow: none;
        padding: 0 0 0 12px;
        margin: 0;
        background: transparent;
    }

    /* Get Started button full width on mobile */
    .navbar-nav .btn {
        width: 100%;
        margin: 4px 0;
        text-align: center;
    }
}

/* ========================================
   Cards
   ======================================== */
@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem;
        border-radius: 8px;
    }

    .card-body {
        padding: 12px;
    }

    .card-header {
        padding: 10px 12px;
        font-size: 14px;
    }
}

/* ========================================
   Tables - responsive card layout
   ======================================== */
@media (max-width: 768px) {
    .table-responsive {
        border: none;
        margin: 0 -4px;
    }

    /* Generic responsive tables: hide header, stack cells */
    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody tr {
        display: block;
        background: var(--bg-card, #fff);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 12px;
    }

    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 6px 0 !important;
        border: none !important;
        font-size: 13px;
    }

    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        margin-right: 12px;
        flex-shrink: 0;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }
}

/* ========================================
   Forms
   ======================================== */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 14px;
    }

    .form-row > .col,
    .form-row > [class*="col-"] {
        padding-right: 5px;
        padding-left: 5px;
    }

    .form-row {
        margin-right: -5px;
        margin-left: -5px;
    }

    /* Stack form-row columns on small screens */
    .form-row > .col-md-3,
    .form-row > .col-md-4,
    .form-row > .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 8px;
    }

    .input-group {
        flex-wrap: nowrap;
    }
}

/* ========================================
   Modals
   ======================================== */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 8px;
        max-width: calc(100% - 16px);
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: calc(100% - 16px);
    }

    .modal-body {
        padding: 12px;
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-footer {
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* ========================================
   Scan detail modal mobile
   ======================================== */
@media (max-width: 768px) {
    /* Modal title: truncate long URLs */
    #scanModal .modal-title,
    #scanModalLabel {
        font-size: 14px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: calc(100vw - 100px);
    }

    /* Summary card: stack to single column */
    #modal-summary .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
        padding: 4px 12px;
        margin-bottom: 2px;
        font-size: 13px;
    }

    #modal-summary .card-body {
        padding: 10px;
    }

    /* Break long URLs/values */
    #modal-summary .row > [class*="col-"] {
        word-break: break-all;
        overflow-wrap: break-word;
    }

    #modal-summary strong {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: var(--text-secondary);
        display: block;
        margin-bottom: 1px;
    }
}

@media (max-width: 480px) {
    #scanModal .modal-title,
    #scanModalLabel {
        font-size: 13px;
        max-width: calc(100vw - 80px);
    }

    #modal-summary .row > [class*="col-"] {
        font-size: 12px;
        padding: 3px 10px;
    }
}

/* ========================================
   Flash messages
   ======================================== */
@media (max-width: 768px) {
    .flash-messages,
    #alert-container {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        max-width: none;
        z-index: 1050;
    }

    .alert {
        font-size: 13px;
        padding: 10px 12px;
    }
}

/* ========================================
   Tab + health badges layout (all sizes)
   ======================================== */

/* Desktop: tabs and badges side by side */
.tab-health-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tab-health-row .dashboard-tab-bar {
    flex: 1 1 auto;
    min-width: 0;
}

.health-inline-badges-row {
    flex: 0 0 auto;
}

/* ========================================
   Dashboard-specific mobile styles
   ======================================== */
@media (max-width: 768px) {
    .dashboard-header,
    .dashboard-header-plain {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
        padding-bottom: 12px;
        margin-bottom: 14px;
    }

    .dashboard-header .d-flex,
    .dashboard-header-plain .d-flex {
        width: 100%;
    }

    .dashboard-title {
        font-size: 1.4rem !important;
        line-height: 1.25;
    }

    .dashboard-subtitle {
        font-size: 0.85rem;
    }

    /* KPI cards */
    .kpi-card {
        margin-bottom: 8px;
    }

    .kpi-value {
        font-size: 1.75rem !important;
    }

    .kpi-label, .kpi-lbl {
        font-size: 9px;
    }

    /* Chart cards */
    .chart-card {
        margin-bottom: 10px;
    }

    .chart-wrap {
        padding: 10px;
        min-height: 180px;
    }

    /* Priority alerts */
    .priority-alert {
        padding: 10px;
    }

    .priority-alert .priority-domain {
        font-size: 0.95rem;
    }

    .priority-alert .priority-subline {
        flex-wrap: wrap;
        font-size: 12px;
    }

    /* Compact priority alert rows on mobile */
    .priority-alert .pa-badges {
        flex-wrap: wrap;
        gap: 3px;
    }

    .priority-alert .pa-domain {
        white-space: normal;
        word-break: break-word;
    }

    /* Badges */
    .badge-sev {
        font-size: 0.65rem;
        padding: 3px 6px;
    }

    .dist-badges {
        flex-wrap: wrap;
        gap: 4px;
    }

    /* Risk gauge */
    #risk-gauge-wrap {
        display: none !important;
    }

    /* ---- Tab bar + health inline badges ---- */
    .tab-health-row {
        flex-direction: column;
        align-items: stretch !important;
    }

    .dashboard-tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 4px;
        padding: 4px;
        width: 100%;
    }

    .dashboard-tab-bar .nav-link {
        padding: 8px 12px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* Health inline badges (Threat Intel / Certificates) - wrap below tabs */
    .health-inline-badges-row,
    #health-inline-badges {
        flex-wrap: wrap;
        padding: 6px 0 !important;
        gap: 6px !important;
    }

    .health-inline-badges-row .badge,
    #health-inline-badges .badge {
        font-size: 11px;
        padding: 5px 10px;
        white-space: nowrap;
    }

    /* Grid layouts */
    .pa-grid,
    .trends-grid,
    .dd-grid {
        grid-template-columns: 1fr !important;
    }

    .dashboard-kpi-row,
    .kpi-row {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    /* ---- Previous Scans tab: table → card layout ---- */
    #prev-scans-tab .table-responsive {
        overflow-x: visible;
        overflow-y: visible;
    }

    #prev-scans-tab .scan-table thead,
    #prev-scans-tab .table thead {
        display: none;
    }

    #prev-scans-tab .scan-table tbody tr,
    #prev-scans-tab .table tbody tr {
        display: block;
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius, 8px);
        margin-bottom: 10px;
        padding: 10px 12px;
        background: var(--bg-card, #fff);
        box-shadow: var(--shadow-sm);
    }

    #prev-scans-tab .scan-table tbody td,
    #prev-scans-tab .table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 5px 0 !important;
        border: none !important;
        font-size: 13px;
        gap: 8px;
        word-break: break-word;
    }

    #prev-scans-tab .scan-table tbody td::before,
    #prev-scans-tab .table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        flex: 0 0 5.5rem;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        padding-top: 2px;
    }

    #prev-scans-tab .scan-table tbody td.actions-cell,
    #prev-scans-tab .table tbody td.actions-cell {
        flex-direction: column;
        align-items: stretch;
        padding-top: 8px !important;
        border-top: 1px solid var(--border-color) !important;
        margin-top: 4px;
    }

    #prev-scans-tab .scan-table tbody td.actions-cell .btn,
    #prev-scans-tab .table tbody td.actions-cell .btn {
        width: 100%;
        justify-content: center;
        min-height: 40px;
    }

    /* Severity distribution badges inside table cards */
    #prev-scans-tab .dist-badges {
        flex-wrap: wrap;
        gap: 3px;
    }

    /* Overrides tab table similarly */
    .overrides-table thead {
        display: none;
    }

    .overrides-table tbody tr {
        display: block;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 10px 12px;
        background: var(--bg-card, #fff);
    }

    .overrides-table tbody td {
        display: flex;
        justify-content: space-between;
        padding: 4px 0 !important;
        border: none !important;
        font-size: 13px;
    }

    /* Org health dropdown on mobile */
    .dashboard-org-health-dropdown summary {
        font-size: 13px;
    }

    /* Separator lines */
    .sep-line {
        flex-wrap: wrap;
        gap: 6px;
        margin: 12px 0 10px;
    }

    .sep-label {
        width: 100%;
    }

    .sep-rule {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .dashboard-kpi-row,
    .kpi-row {
        grid-template-columns: 1fr !important;
    }

    .dashboard-title {
        font-size: 1.2rem !important;
    }

    .kpi-value {
        font-size: 1.5rem !important;
    }

    /* Even more compact table cards */
    #prev-scans-tab .scan-table tbody td::before,
    #prev-scans-tab .table tbody td::before {
        flex: 0 0 4.5rem;
        font-size: 10px;
    }

    #prev-scans-tab .scan-table tbody td,
    #prev-scans-tab .table tbody td {
        font-size: 12px;
    }

    .dashboard-tab-bar .nav-link {
        padding: 6px 10px;
        font-size: 11px;
    }
}

/* ========================================
   Scan workspace (new_scan.html) mobile
   ======================================== */
@media (max-width: 768px) {
    .page-title {
        margin-top: 8px;
        margin-bottom: 8px;
        padding-bottom: 6px;
    }

    .page-title h1 {
        font-size: 1.25rem;
    }

    .scan-input {
        font-size: 1rem;
        height: calc(2.25rem + 2px);
    }

    .btn-scan {
        font-size: 0.95rem;
        height: auto;
        min-height: 44px;
        width: 100%;
    }

    .scan-output-box {
        font-size: 0.8rem;
        height: 180px;
        padding: 8px;
    }

    .scan-actions {
        gap: 4px;
    }

    .scan-actions .btn {
        font-size: 12px;
        padding: 6px 10px;
    }

    .scan-actions .btn-group {
        width: 100%;
    }

    .scan-actions .btn-group .btn {
        flex: 1;
    }

    /* Vulnerability accordion */
    #vuln-accordion .vuln-row-toggle {
        font-size: 13px;
        gap: 4px;
    }

    .triage-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .llm-finding-meta {
        grid-template-columns: 1fr;
        padding: 8px;
    }

    .progress-card {
        padding: 8px;
    }

    .module-row {
        flex-direction: column;
        gap: 2px;
        padding: 6px 0;
    }
}

/* ========================================
   Previous scans page (standalone) mobile
   ======================================== */
@media (max-width: 768px) {
    .previous-scans-toolbar {
        flex-direction: column;
        gap: 8px;
    }

    .previous-scans-toolbar input,
    .previous-scans-toolbar .btn {
        width: 100%;
    }

    /* Standalone previous_scans.html table → card layout */
    .dashboard-main > .table-responsive {
        overflow-x: visible;
        overflow-y: visible;
    }

    .dashboard-main > .table-responsive .table thead {
        display: none;
    }

    .dashboard-main > .table-responsive .table tbody tr {
        display: block;
        border: 1px solid var(--border-color);
        border-radius: var(--border-radius, 8px);
        margin-bottom: 10px;
        padding: 10px 12px;
        background: var(--bg-card, #fff);
        box-shadow: var(--shadow-sm);
    }

    .dashboard-main > .table-responsive .table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 5px 0 !important;
        border: none !important;
        font-size: 13px;
        gap: 8px;
        word-break: break-word;
    }

    .dashboard-main > .table-responsive .table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        flex: 0 0 5.5rem;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        padding-top: 2px;
    }

    .dashboard-main > .table-responsive .table tbody td.actions-cell {
        flex-direction: column;
        align-items: stretch;
        padding-top: 8px !important;
        border-top: 1px solid var(--border-color) !important;
        margin-top: 4px;
        gap: 6px;
    }

    .dashboard-main > .table-responsive .table tbody td.actions-cell::before {
        display: none;
    }

    .dashboard-main > .table-responsive .table tbody td.actions-cell .btn {
        width: 100%;
        justify-content: center;
        min-height: 40px;
    }
}

/* ========================================
   Billing portal mobile
   ======================================== */
@media (max-width: 768px) {
    .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }
}

/* ========================================
   Org admin mobile
   ======================================== */
@media (max-width: 768px) {
    .reset-actions-col {
        min-width: auto;
    }

    .reset-actions-col .input-group {
        flex-wrap: wrap;
    }

    .reset-actions-col input.form-control {
        min-width: 120px;
        width: 100%;
        margin-bottom: 4px;
    }
}

/* ========================================
   Health badges mobile
   ======================================== */
@media (max-width: 768px) {
    .health-inline-badges {
        flex-wrap: wrap;
        gap: 4px;
    }

    .health-badge {
        font-size: 0.7rem;
        padding: 4px 8px;
    }

    .org-health-wrap .hb-row {
        gap: 4px;
    }
}

/* ========================================
   Utility: hide on mobile / show on mobile
   ======================================== */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .show-mobile-only {
        display: none !important;
    }
}

/* ========================================
   Print: hide navigation
   ======================================== */
@media print {
    .navbar-custom,
    .dashboard-sidebar,
    .dashboard-top-bar,
    .sidebar-mobile-overlay {
        display: none !important;
    }

    .dashboard-main {
        padding: 0 !important;
    }
}
