/* Mobile entity-list card system.
   The list views (quotes/jobs/invoices/clients) render each row as a card on
   mobile. This file owns: the .mobile-card-* header/body layout, the desktop
   .entity-id-pill mirror, the <=767px table->card transformation, and the
   per-row actions dropdown. Loaded after Bootstrap (see base.html). */

/* Mobile card styles */
.mobile-card-view {
    padding: 0 15px;
}

/* Mobile card header — [ID] [client rows]. The ID column width and the
   column gap are declared here once; the below-address description reaches
   back under the ID column by referencing the same two values. */
.mobile-card-header-main {
    --mobile-card-id-width: 50px;
    --mobile-card-gap: 0.75rem;
    display: flex;
    gap: var(--mobile-card-gap);
    align-items: flex-start;
}

.mobile-card-amount {
    font-size: 0.8rem;
    white-space: nowrap;
}

.mobile-card-eye {
    margin-left: auto;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mobile-card-eye .bi {
    font-size: 1.2rem;
}

.mobile-card-id {
    display: flex;
    flex-direction: column;
    min-width: var(--mobile-card-id-width);
    flex-shrink: 0;
}

.mobile-card-id .entity-type {
    font-size: 0.7rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}

.mobile-card-id .entity-num {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c3e50;
    line-height: 1.2;
}

/* Desktop entity ID pill — mirrors the mobile .mobile-card-id layout
   and tint so the "#" column on entity list tables carries the same
   themed highlight users see on mobile cards. */
.entity-id-pill {
    display: inline-flex;
    flex-direction: column;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    line-height: 1;
}

.entity-id-pill .entity-type {
    font-size: 0.7rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}

.entity-id-pill .entity-num {
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c3e50;
    line-height: 1.2;
    margin-top: 2px;
}

.entity-id-quotes {
    background: color-mix(in srgb, var(--entity-color-quotes) 15%, transparent);
}

.entity-id-jobs {
    background: color-mix(in srgb, var(--entity-color-jobs) 15%, transparent);
}

.entity-id-invoices {
    background: color-mix(in srgb, var(--entity-color-invoices) 15%, transparent);
}

.entity-id-clients {
    background: color-mix(in srgb, var(--entity-color-clients) 15%, transparent);
}

.mobile-card-client {
    flex: 1;
    min-width: 0; /* Allow text truncation */
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.mobile-card-line-name {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.mobile-card-name {
    flex: 1;
    min-width: 0;
}

.mobile-card-meta-top {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
    flex-shrink: 0;
    max-width: 8rem;
}

/* Price sits in the top-right column directly under the status badge (moved out
   of the floated action stack so it no longer drops to the address line on
   two-line names). The margin gives it a little air below the badge. */
.mobile-card-meta-top .mobile-card-amount {
    margin-top: 0.2rem;
}

.mobile-card-status-badge {
    flex: 0 0 auto;
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-card-status-badge .custom-status {
    display: block;
    font-size: 0.85em;
    margin-top: 2px;
    pointer-events: none;
    white-space: normal;
}

.mobile-card-client-details > br:first-child {
    display: none;
}

.mobile-card-line-address {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    min-width: 0;
}

.mobile-card-action-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
    flex-shrink: 0;
    margin-left: auto;
}

.mobile-card-client-details {
    flex: 1;
    min-width: 0;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* Address sits in the same dark text as the client name, not muted. The address
   is the only <small class="text-muted"> inside the details (phone/email are
   spans, the amount lives in the action stack), so it is the one element this
   darkens. !important overrides Bootstrap's .text-muted utility. */
.mobile-card-client-details small.text-muted {
    color: var(--text-primary) !important;
}

/* Client name: wrap normally (multi-word names break across lines), break an
   over-long unspaced token (e.g. HappyPath1777389274126) so it can't side-scroll
   the viewport, then clamp to two lines with an ellipsis. overflow-wrap:anywhere
   (not break-word) is required so the long token also shrinks the min-content
   width — otherwise the table stays wide and scrolls. */
.mobile-card-name strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    line-height: 1.15;
}

.mobile-card-description {
    color: var(--text-muted);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    line-height: 1.4;
    max-height: calc(1.4em * 3);
    overflow-wrap: anywhere;
}

.mobile-card-description--below-address {
    margin-left: calc(-1 * (var(--mobile-card-id-width) + var(--mobile-card-gap)));
    width: calc(100% + var(--mobile-card-id-width) + var(--mobile-card-gap));
}

/* Address + description card: the action stack (amount + eye) floats right
   inside a block-flow container so both the address and the description wrap
   AROUND the eye. Lines level with the eye stop short of it; once the text
   clears the eye's bottom it runs on to the card edge. flow-root keeps the
   float contained so the eye/amount keep their top-right position and nothing
   escapes into neighbouring rows. */
.mobile-card-flow {
    display: flow-root;
}

.mobile-card-flow .mobile-card-action-stack {
    float: right;
    margin-left: var(--mobile-card-gap);
}

/* Clamp the description to 3 wrapped lines with a clean trailing ellipsis.
   The clamp (-webkit-box + -webkit-line-clamp:3 + overflow:hidden) is inherited
   from the base .mobile-card-description rule; here we only keep the top gap.
   overflow:hidden makes this a block formatting context, so the description
   clears BELOW the floated action stack rather than wrapping around the eye —
   the accepted trade-off for line-based truncation (tr.expanded unclamps it). */
.mobile-card-flow .mobile-card-description {
    margin-top: 0.6rem;
}

.mobile-card {
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

.mobile-card:active {
    transform: scale(0.98);
}

.mobile-card-header .card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.detail-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #6c757d;
}

.detail-row i {
    width: 16px;
    text-align: center;
    color: var(--primary-color);
}

.mobile-card-stats .stat-number {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
}

.mobile-card-stats .stat-label {
    font-size: 0.75rem;
    color: #6c757d;
    text-transform: uppercase;
}

.mobile-card-actions .btn {
    min-height: 44px; /* Touch target compliance */
    font-size: 0.9rem;
}

/* Ensure proper spacing for touch */
.mobile-card-actions .btn-group .btn {
    border-radius: 0;
}

.mobile-card-actions .btn-group .btn:first-child {
    border-radius: 6px 0 0 6px;
}

.mobile-card-actions .btn-group .btn:last-child {
    border-radius: 0 6px 6px 0;
}

/* Mobile table adjustments */
@media (max-width: 767px) {
    /* Transform tables into card list on mobile */
    .table-responsive {
        overflow: visible;
        border: none;
    }

    /* Admin tables: card view on mobile — hide non-essential cells */
    .container-fluid .table-responsive td.d-none.d-md-table-cell {
        display: none !important;
    }

    .table-responsive table {
        border: 0;
    }

    .table-responsive thead {
        display: none; /* Hide table headers on mobile */
    }

    .table-responsive tbody {
        display: block;
    }

    .table-responsive tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        background: var(--card-bg);
        padding: 1rem;
        cursor: pointer;
        transition: box-shadow 0.3s ease, min-height 0.3s ease;
        position: relative;
        min-height: 80px;
    }

    .table-responsive tr.expanded {
        box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    }

    .table-responsive td {
        display: block;
        text-align: left;
        padding: 0.5rem 0;
        border: none;
        position: relative;
    }

    /* First cell (ID) has no top padding */
    .table-responsive td:first-child {
        padding-top: 0;
    }

    /* Last visible cell before actions has reduced bottom padding */
    .table-responsive td:not(.table-actions):last-of-type {
        padding-bottom: 0.25rem;
    }

    /* Expanded: unclamp mobile descriptions and clear the action overlay. */
    tr.expanded .mobile-card-description {
        -webkit-line-clamp: unset;
        max-height: none;
        overflow: visible;
        padding-right: 145px;
    }

    /* Content extends full width - buttons overlay on top */
    .table-responsive tr td:not(.table-actions) {
        padding-right: 0;
    }

    /* Hide old mobile dropdown toggle */
    .table-responsive tr .mobile-actions-toggle,
    .table-responsive tr .mobile-actions-dropdown {
        display: none !important;
    }

    /* Mobile action buttons (Call, Email) - icon only when collapsed */
    .btn-mobile-action {
        font-size: 0; /* Hide text when collapsed */
    }

    .btn-mobile-action .bi {
        font-size: 1rem;
    }

    /* Show text when expanded */
    tr.expanded .btn-mobile-action {
        font-size: 0.75rem;
    }

    tr.expanded .btn-mobile-action .bi {
        margin-right: 0.25rem;
    }

    /* Actions container — absolute overlay top-right. When collapsed it shows
       nothing for quotes/jobs/invoices (the eye now lives in the header aside);
       for clients it shows the Call/Email quick buttons. When expanded it holds
       the full action stack. Pinned to the top: the card grows downward to fit. */
    .table-actions {
        position: absolute !important;
        top: 0.5rem;
        right: 0.5rem;
        width: auto;
        height: auto;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 0.5rem;
        z-index: 10;
        pointer-events: auto; /* Buttons are clickable */
    }

    /* Collapsed: the header aside owns the View "eye", so hide the actions-cell
       copy. Expanded: it rejoins the action stack (top, above Edit) and picks up
       the pill styling from `tr.expanded .table-actions .btn` below. */
    .table-actions .btn-view {
        display: none !important;
    }

    tr.expanded .table-actions .btn-view {
        display: flex !important;
    }

    /* Hide desktop inline buttons by default */
    .table-actions .d-none.d-md-inline {
        display: none;
    }

    /* Show desktop actions on mobile when expanded */
    tr.expanded .table-actions .d-none.d-md-inline {
        display: flex !important;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
        align-items: stretch;
    }

    /* Stack action buttons vertically when expanded - show text */
    tr.expanded .table-actions .d-none.d-md-inline .btn,
    tr.expanded .table-actions .d-none.d-md-inline form {
        display: block;
        width: auto;
        min-width: 120px;
        opacity: 0;
        transform: translateX(20px);
        animation: slideIn 0.3s ease forwards;
    }

    /* Stagger animation for each button */
    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(1) {
        animation-delay: 0s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(2) {
        animation-delay: 0.05s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(3) {
        animation-delay: 0.1s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(4) {
        animation-delay: 0.15s;
    }

    tr.expanded .table-actions .d-none.d-md-inline > *:nth-child(5) {
        animation-delay: 0.2s;
    }

    @keyframes slideIn {
        from {
            opacity: 0;
            transform: translateX(20px);
        }
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    tr.expanded .table-actions .btn {
        min-height: 44px;
        width: auto;
        min-width: 120px;
        text-align: left;
        font-size: 0.875rem; /* Show text */
        padding: 0.5rem 1rem;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        display: flex;
        align-items: center;
        justify-content: flex-start;
        white-space: nowrap;
    }

    /* Show icons with text */
    tr.expanded .table-actions .btn .bi {
        margin-right: 0.5rem;
        font-size: 1rem;
    }

    /* Status badge adjustments for card view */
    .status-badge {
        max-width: 100%;
        word-wrap: break-word;
        line-height: 1.2;
        padding: 0.5rem 0.75rem;
        text-align: center;
        display: inline-block;
    }

    .status-badge[data-short="true"] {
        white-space: nowrap;
    }

    .status-badge:not([data-short]) {
        white-space: normal;
    }

    /* Client info styling in card */
    .table td small {
        font-size: 0.85rem;
        line-height: 1.3;
        color: #6c757d;
    }


    /* The eye, price, and status badge are rendered in the mobile card header
       (see _mobile_card_header.html) and laid out by flow (.mobile-card above).
       The old :has()-driven top:Nrem lookup table that positioned an absolutely
       placed eye/price per (has-price x has-custom-status) combo is gone — flow
       layout computes those positions now. */
}

/* Mobile dropdown menu for actions */
.mobile-actions-dropdown {
    position: absolute;
    left: 0;
    top: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 9999;
    min-width: 180px;
    display: none;
    overflow: hidden;
    margin-top: 4px;
}

.mobile-actions-dropdown.show {
    display: block;
}

.mobile-actions-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    /* Large touch target — easy to hit with big fingers. */
    padding: 15px 18px;
    color: var(--text-primary);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 1rem;
    transition: background-color 0.2s ease;
}

.mobile-actions-dropdown .dropdown-item:hover {
    background-color: var(--bg-secondary);
}

.mobile-actions-dropdown .dropdown-item i {
    margin-right: 8px;
    width: 16px;
}

/* Flush divider — a crisp line directly between two items, no floating gap. */
.mobile-actions-dropdown .dropdown-divider {
    height: 0;
    margin: 0;
    border-top: 1px solid var(--border-color);
}
