/**
 * Installationskollen – Responsive Overrides for Orders (orders2.html)
 * Modulär responsiv CSS för surfplatta och mobil.
 * RÖR INTE DESKTOP (> 1024px) – Alla regler är inkapslade i @media queries.
 */

/* ==========================================================================
   1. SURFPLATTA (Tablet: 768px – 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
    .top-navbar {
        padding: 0 16px;
    }

    .brand-heading {
        font-size: 0.98rem;
    }

    .nav-links-group {
        gap: 3px;
        padding: 3px 6px;
    }

    .nav-link-btn {
        font-size: 0.80rem;
        padding: 6px 12px;
        gap: 5px;
    }

    .orders-container {
        padding: 10px 16px 35px !important;
    }

    .filter-card {
        padding: 16px 18px;
    }

    #orders-table thead th {
        padding: 11px 10px;
        font-size: 0.72rem;
    }

    #orders-table tbody td {
        padding: 9px 10px;
        font-size: 0.84rem;
    }

    #editOrderModal .modal-dialog {
        width: 94vw;
        max-width: 94vw;
    }
}


/* ==========================================================================
   2. MOBIL & MINDRE SURFPLATTOR (Max-width: 767px)
   ========================================================================== */
@media (max-width: 767px) {

    /* --- Förhindra oönskad auto-zoom i iOS Safari på formulärfält --- */
    input[type="text"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* --- Toppmeny Mobil --- */
    .top-navbar {
        height: 50px;
        padding: 0 10px;
        background: rgba(15, 23, 42, 0.94);
    }

    .nav-brand-wrap {
        gap: 6px;
    }

    .brand-heading {
        font-size: 0.90rem;
        gap: 6px;
    }

    .brand-heading i {
        font-size: 1rem;
    }

    .nav-center-wrap {
        position: static;
        transform: none;
        margin-left: auto;
    }

    .nav-links-group {
        padding: 2px 4px;
        gap: 2px;
        border-radius: 20px;
        background: rgba(0, 0, 0, 0.5);
    }

    .nav-link-btn {
        padding: 6px 8px;
        font-size: 0.76rem;
        gap: 4px;
        border-radius: 16px;
    }

    /* I mobilen visar vi ikonen och endast texten för AKTIV sida ("Ordrar") */
    .nav-link-btn span {
        display: none !important;
    }

    .nav-link-btn.active span {
        display: inline-block !important;
        font-size: 0.74rem;
    }

    .nav-right-spacer {
        display: none !important;
    }

    /* --- Sidinnehåll & Marginaler --- */
    body {
        padding-top: 62px;
        padding-bottom: 16px;
    }

    .orders-container {
        padding: 6px 8px 24px !important;
    }

    /* Page Header */
    .page-header-icon {
        width: 38px;
        height: 38px;
        border-radius: 10px;
        font-size: 1.1rem;
    }

    h2.fw-bold.text-white {
        font-size: 1.25rem !important;
    }

    /* --- Filter Card Mobil --- */
    .filter-card {
        padding: 12px 10px;
        border-radius: 14px;
        margin-bottom: 10px !important;
    }

    /* --- Mobil filterbar (sök + filterknapp, kollapsbara parametrar) --- */
    .filter-mobile-bar {
        display: flex !important;
        flex-direction: column;
        gap: 8px;
        margin-bottom: 2px;
    }

    .filter-mobile-search .form-control,
    .filter-mobile-search .input-group-text {
        min-height: 44px;
    }

    .filter-mobile-row {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .filter-toggle-btn {
        flex: 1;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        min-height: 44px;
        padding: 8px 14px;
        border-radius: 12px;
        border: 1px solid #cbd5e1;
        background: #f8fafc;
        color: #0f172a;
        font-size: 0.86rem;
        font-weight: 700;
        cursor: pointer;
    }

    .filter-toggle-btn:active {
        transform: scale(0.98);
    }

    .filter-card.filters-open .filter-toggle-btn {
        background: #0284c7;
        border-color: #0284c7;
        color: #ffffff;
    }

    .filter-count-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 22px;
        height: 22px;
        padding: 0 6px;
        border-radius: 11px;
        background: #dc2626;
        color: #ffffff;
        font-size: 0.72rem;
        font-weight: 800;
    }

    .filter-card.filters-open .filter-count-badge {
        background: rgba(255, 255, 255, 0.28);
    }

    .filter-chevron {
        margin-left: auto;
        font-size: 0.75rem;
        opacity: 0.7;
    }

    .filter-mobile-count {
        font-size: 0.72rem;
        color: #64748b;
        font-weight: 600;
        white-space: nowrap;
    }

    /* Kollaps: parametrarna dolda tills användaren fäller ut (desktop påverkas ej) */
    .filter-collapsible {
        display: none;
    }

    .filter-card.filters-open .filter-collapsible {
        display: block;
    }

    .filter-card.filters-open .filter-mobile-bar {
        margin-bottom: 10px;
    }

    /* Periodval: horisontell scroll istället för 9 rader wrap */
    .filter-card .d-flex.flex-wrap.align-items-center.justify-content-between {
        flex-wrap: nowrap !important;
        flex-direction: column;
        align-items: stretch !important;
    }

    .preset-pills-group {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 8px;
        padding: 4px 2px 8px;
        margin: 0 -2px;
    }

    .preset-pills-group::-webkit-scrollbar {
        display: none;
    }

    .preset-pill {
        flex-shrink: 0;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 8px 14px;
        font-size: 0.82rem;
    }

    /* Datumläges-växlaren: full bredd, stora touchytor */
    #date-mode-toggle {
        width: 100%;
    }

    #date-mode-toggle .btn {
        flex: 1;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .filter-card .bg-light.p-1.px-2.rounded-pill {
        width: 100%;
        border-radius: 12px !important;
    }

    .filter-card .row.g-3 {
        --bs-gutter-y: 0.6rem;
        --bs-gutter-x: 0.5rem;
    }

    /* Sökfältet tar full bredd överst */
    .filter-card .col-lg-3.col-md-4 {
        width: 100% !important;
    }

    /* Filterfälten fördelas i bekväm 2-kolumns grid */
    .filter-card .col-lg-2.col-md-3,
    .filter-card .col-lg-2.col-md-3.col-sm-6 {
        width: 50% !important;
    }

    /* Antal rader och Excel-knapp */
    .filter-card .col-lg-1.col-md-2.col-sm-4 {
        width: 35% !important;
    }

    .filter-card .col-lg-2.col-md-3.col-sm-8 {
        width: 65% !important;
    }

    .filter-card .btn-primary,
    .filter-card .btn-danger {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
        min-height: 40px;
    }

    /* Statusbar i botten av filterkortet – staplad, stora switchar */
    .filter-card .border-top {
        margin-top: 8px !important;
        padding-top: 8px !important;
        gap: 8px;
        flex-direction: column;
        align-items: stretch !important;
    }

    .filter-card .border-top .d-flex.flex-wrap {
        gap: 4px 16px !important;
    }

    .filter-card .form-check.form-switch {
        min-height: 44px;
        align-items: center;
    }

    .filter-card .form-check-input[type="checkbox"] {
        width: 2.6em !important;
        height: 1.5em !important;
    }

    .filter-card .d-flex.align-items-center.gap-2:last-child {
        justify-content: space-between;
        width: 100%;
    }

    /* Sök + selects: minst 44px höjd för touch */
    .filter-card .form-control,
    .filter-card .form-select {
        min-height: 44px;
    }

    .filter-card .input-group .input-group-text {
        min-height: 44px;
    }

    .form-check-switch {
        font-size: 0.85rem;
    }

    #showing-count {
        font-size: 0.72rem;
        padding: 4px 8px;
    }

    #toggle-version-btn {
        display: none !important; /* Dölj versionsknappen på mobil för att spara utrymme */
    }

    /* --- Tabellkort döljs på mobil – kortvy tar över --- */
    .table-card {
        display: none !important;
    }

    /* --- Mobil kortvy (renderMobileCards) --- */
    .orders-cards-toolbar {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        margin: 2px 2px 8px;
        color: #cbd5e1;
        font-size: 0.76rem;
    }

    .orders-cards-select-all {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        color: #e2e8f0;
        font-weight: 600;
        font-size: 0.80rem;
        cursor: pointer;
        min-height: 44px;
        padding: 6px 4px;
        margin: 0;
    }

    .orders-cards-select-all .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin: 0;
        cursor: pointer;
    }

    .orders-cards-hint {
        color: #94a3b8;
        font-size: 0.72rem;
        white-space: nowrap;
    }

    .orders-cards {
        display: flex !important;
        flex-direction: column;
        gap: 10px;
        padding-bottom: 12px;
    }

    .order-card {
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 14px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
        padding: 12px 12px 10px;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .order-card.is-completed {
        opacity: 0.92;
        border-left: 4px solid #10b981;
    }

    .order-card.has-missing {
        border-left: 4px solid #f59e0b;
    }

    .order-card-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .order-card-top-actions {
        display: flex;
        align-items: center;
        gap: 6px;
        margin-left: auto;
    }

    .order-card-check {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
        margin: 0;
        cursor: pointer;
    }

    .order-card-check .form-check-input {
        width: 1.3rem;
        height: 1.3rem;
        margin: 0;
        cursor: pointer;
    }

    .order-card-address {
        font-size: 1.02rem;
        font-weight: 700;
        color: #0f172a;
        line-height: 1.3;
        cursor: pointer;
        padding: 6px 4px;
        margin: 0 -4px;
        border-radius: 8px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .order-card-address:active {
        background: #f1f5f9;
    }

    .order-card-customer {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px 12px;
        font-size: 0.86rem;
        color: #334155;
    }

    .order-card-phone {
        color: #0284c7;
        font-weight: 700;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        padding: 4px 8px;
        margin: -4px -8px;
        border-radius: 8px;
    }

    .order-card-service {
        font-size: 0.86rem;
        line-height: 1.4;
        color: #0f172a;
        background: #f8fafc;
        border: 1px solid #f1f5f9;
        border-radius: 8px;
        padding: 7px 9px;
    }

    .order-card-backrep {
        font-size: 0.68rem;
        vertical-align: middle;
    }

    .order-card-meta {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px 10px;
        font-size: 0.78rem;
        color: #64748b;
    }

    .order-card-meta-item {
        display: inline-flex;
        align-items: center;
        white-space: nowrap;
    }

    .order-card-missing {
        display: inline-flex;
        align-items: center;
        font-size: 0.76rem;
        font-weight: 700;
        color: #b45309;
        background: #fef3c7;
        border: 1px solid #fde68a;
        border-radius: 8px;
        padding: 6px 9px;
        line-height: 1.3;
    }

    .order-card-bottom {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        gap: 10px;
        border-top: 1px solid #f1f5f9;
        padding-top: 8px;
    }

    .order-card-ordernr,
    .order-card-price {
        display: flex;
        flex-direction: column;
        gap: 4px;
        min-width: 0;
    }

    .order-card-price {
        align-items: flex-end;
        text-align: right;
    }

    .order-card-label {
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: #94a3b8;
    }

    .order-card-ordernr .bb-order-input {
        min-width: 0;
        width: 100%;
        max-width: 170px;
        min-height: 44px;
    }

    .order-card-actions {
        display: flex;
        gap: 8px;
        margin-top: 2px;
    }

    .order-card-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        min-height: 44px;
        border-radius: 10px;
        font-size: 0.86rem;
        font-weight: 700;
        border: 1px solid transparent;
        cursor: pointer;
        text-decoration: none;
        transition: transform 0.1s ease, background-color 0.15s ease;
    }

    .order-card-btn:active {
        transform: scale(0.97);
    }

    .order-card-btn-edit {
        flex: 1;
        background: #f0f9ff;
        color: #0284c7;
        border-color: #bae6fd;
        padding: 0 14px;
    }

    .order-card-btn-edit.has-missing {
        background: #fef2f2;
        color: #dc2626;
        border-color: #fecaca;
    }

    .order-card-btn-call {
        flex: 1;
        background: #ecfdf5;
        color: #15803d;
        border-color: #bbf7d0;
        padding: 0 14px;
    }

    .order-card-btn-delete {
        width: 48px;
        flex-shrink: 0;
        background: #fef2f2;
        color: #ef4444;
        border-color: #fee2e2;
    }

    .order-card-empty {
        align-items: center;
        text-align: center;
        color: #64748b;
        font-size: 0.88rem;
        padding: 32px 16px;
    }

    /* Kompakt padding i tabellceller */
    #orders-table thead th {
        padding: 9px 8px;
        font-size: 0.68rem;
    }

    #orders-table tbody td {
        padding: 8px 8px;
        font-size: 0.80rem;
    }

    /* Touch-anpassade åtgärdsknappar */
    .btn-action-icon {
        width: 34px;
        height: 34px;
        font-size: 0.85rem;
        border-radius: 8px;
    }

    .btn-toggle-completion {
        font-size: 1.35rem;
        padding: 4px;
    }

    .badge-service-date {
        font-size: 0.74rem;
        padding: 3px 7px;
    }

    .bb-order-input {
        padding: 5px 6px !important;
        font-size: 0.82rem !important;
        min-width: 90px;
    }

    /* --- REDIGERINGSMODAL (Edit Order Modal) MOBIL --- */
    #editOrderModal .modal-dialog {
        width: calc(100vw - 12px) !important;
        max-width: calc(100vw - 12px) !important;
        margin: 6px auto !important;
    }

    #editOrderModal .modal-content {
        max-height: calc(100dvh - 12px) !important;
        max-height: calc(100vh - 12px) !important;
        border-radius: 14px;
    }

    #editOrderModal .modal-header {
        padding: 8px 12px;
    }

    #editOrderModal .modal-title {
        font-size: 1rem;
    }

    .modal-header-icon {
        width: 32px;
        height: 32px;
        font-size: 0.95rem;
    }

    #editOrderModal .modal-body {
        padding: 8px 8px;
        -webkit-overflow-scrolling: touch;
    }

    .edit-card {
        padding: 8px 10px;
        border-radius: 10px;
        margin-bottom: 6px;
    }

    /* Form inputs i modalen */
    .edit-card .form-control,
    .edit-card .form-select {
        height: 34px;
        padding: 4px 8px;
        font-size: 16px !important;
    }

    /* Ekonomi & tidsmätare - 2x2 grid */
    .edit-metric-box {
        padding: 4px 4px;
    }

    .edit-metric-box input {
        font-size: 0.95rem;
    }

    /* Street View & Google Maps anpassas i höjd på mobil */
    #edit-streetview-wrapper {
        min-height: 145px !important;
        height: 155px !important;
    }

    #edit-map-wrapper {
        min-height: 145px !important;
        height: 155px !important;
    }

    #edit-view-mode-group .btn-view-mode {
        padding: 4px 6px;
        font-size: 0.70rem;
    }

    #editOrderModal .modal-footer {
        padding: 8px 12px;
    }

    .sync-status-pill {
        font-size: 0.68rem;
        padding: 2px 6px;
    }

    .btn-modal-save {
        padding: 8px 14px;
        font-size: 0.82rem;
    }

    .btn-modal-cancel {
        padding: 8px 10px;
        font-size: 0.80rem;
    }

    /* --- Sub-modal Artiklar (#editItemsModal) & Backrep (#resolveBackrepModal) --- */
    #editItemsModal .modal-dialog,
    #resolveBackrepModal .modal-dialog {
        width: calc(100vw - 12px) !important;
        max-width: calc(100vw - 12px) !important;
        margin: 6px auto !important;
    }

    #editItemsModal .modal-content,
    #resolveBackrepModal .modal-content {
        max-height: calc(100dvh - 12px) !important;
        max-height: calc(100vh - 12px) !important;
        border-radius: 14px;
    }

    #edit-items-container {
        max-height: 48vh !important;
        min-height: 180px !important;
    }

    .item-row {
        padding: 8px 10px !important;
    }
}


/* ==========================================================================
   3. EXTRA SMÅ SKÄRMAR (Max-width: 400px)
   ========================================================================== */
@media (max-width: 400px) {
    .brand-heading span {
        display: none !important;
    }

    .top-navbar {
        padding: 0 8px;
    }

    .filter-card .col-lg-2.col-md-3,
    .filter-card .col-lg-2.col-md-3.col-sm-6 {
        width: 100% !important;
    }

    .filter-card .col-lg-1.col-md-2.col-sm-4 {
        width: 40% !important;
    }

    .filter-card .col-lg-2.col-md-3.col-sm-8 {
        width: 60% !important;
    }
}

