/* ========================================
   Partner Dashboard - Mobile Responsive Styles
   Version: 0.7.4
   ======================================== */

/* ========================================
   Base Styles (Mobile First - 0-767px)
   ======================================== */

/* Main wrapper - ensures proper spacing and max-width */
.pd-wrap {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 1rem;
    box-sizing: border-box;
}

/* Desktop: break out of theme's content column and use full viewport width (same technique as IG Dashboard; !important overrides theme) */
@media (min-width: 769px) {
    .pd-wrap {
        width: 100vw !important;
        max-width: 100vw !important;
        position: relative !important;
        left: 50% !important;
        margin-left: -50vw !important;
        margin-right: 0 !important;
        padding-left: 24px !important;
        padding-right: 24px !important;
        box-sizing: border-box !important;
    }
}

/* Email filter banner (when "View transactions" from upcoming renewals); theme-aware via --color-* */
.pd-email-filter-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 10px 14px;
    background: var(--color-surface, #f0f4f8);
    border: 1px solid var(--color-border, #c5d0e0);
    border-radius: 6px;
}

.pd-email-filter-banner .pd-email-filter-label {
    font-weight: 600;
    color: var(--color-text, #333);
}

.pd-email-filter-banner .pd-email-filter-value {
    color: var(--color-text, #1a1a1a);
}

/* Show all: same look as Export CSV (solid accent, contrast text) */
.pd-email-filter-banner .pd-filter-clear {
    margin-left: 0;
    width: auto;
    padding: 6px 14px;
    font-size: 14px;
    min-height: 36px;
    background: var(--color-accent, #0073aa);
    color: var(--color-accent-contrast, #fff);
    border: 1px solid var(--color-accent, #0073aa);
}

.pd-email-filter-banner .pd-filter-clear:hover {
    background: var(--color-accent-hover, #005d87);
    border-color: var(--color-accent-hover, #005d87);
    color: var(--color-accent-contrast, #fff);
}

.pd-upcoming-renewals .pd-renewal-view-link:hover {
    text-decoration: underline;
}

/* Portal page wrapper */
.pd-portal {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 1rem;
    box-sizing: border-box;
}

/* Portal list styling */
.pd-portal ul {
    margin: 0;
    padding-left: 1.5rem;
}

.pd-portal li {
    margin-bottom: 0.75rem;
}

.pd-portal a {
    font-size: 1rem;
    padding: 0.5rem 0;
    display: inline-block;
    min-height: 44px; /* Touch-friendly */
    line-height: 1.5;
}

/* ========================================
   Filter Forms
   ======================================== */

.pd-filters {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.pd-filter-group {
    margin-bottom: 1rem;
}

.pd-filter-group:last-child {
    margin-bottom: 0;
}

.pd-filters label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #333;
    font-size: 0.9rem;
}

.pd-filter-input {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem; /* Prevents zoom on iOS */
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    box-sizing: border-box;
    min-height: 44px; /* Touch-friendly */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.pd-filter-input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.1);
}

/* Select arrow styling */
.pd-filter-input[type="select"],
select.pd-filter-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

.pd-filter-custom-dates {
    display: none; /* Hidden by default, shown via JS */
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #ddd;
    flex-direction: column;
    gap: 1rem;
}

.pd-button {
    width: 100%;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: #0073aa;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    min-height: 44px; /* Touch-friendly */
    transition: background-color 0.2s ease;
    box-sizing: border-box;
}

.pd-button:hover {
    background: #005a87;
}

.pd-button:active {
    background: #004a6f;
}

.pd-filter-submit {
    margin-top: 1rem;
}

/* ========================================
   Pagination
   ======================================== */

.pd-pagination {
    margin: 1.5rem 0 0 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
}

.pd-pagination-info {
    color: #555;
    font-size: 0.95rem;
    text-align: center;
    order: 1;
}

.pd-pagination-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    order: 2;
}

.pd-pagination-btn {
    display: inline-block;
    padding: 0.75rem 1.25rem;
    min-height: 44px; /* Touch-friendly */
    min-width: 100px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-decoration: none;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 500;
    color: #333;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pd-pagination-btn:hover {
    background: #f5f5f5;
    border-color: #bbb;
    color: #000;
}

.pd-pagination-btn:active {
    background: #e8e8e8;
}

.pd-pagination-btn-disabled {
    border-color: #eee;
    color: #aaa;
    background: #fafafa;
    cursor: not-allowed;
}

.pd-pagination-btn-disabled:hover {
    background: #fafafa;
    border-color: #eee;
    color: #aaa;
}

.pd-pagination-count {
    color: #666;
    font-size: 0.9rem;
    text-align: center;
    order: 3;
}

/* ========================================
   Export Controls
   ======================================== */

.pd-export-controls {
    margin: 0 0 1rem 0;
}

.pd-button-export {
    width: 100%;
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
}

.pd-button-export:hover {
    background: #135e96;
    border-color: #135e96;
    color: #fff;
}

.pd-button-export:active {
    background: #0a4b78;
    border-color: #0a4b78;
}

/* ========================================
   View Toggle
   ======================================== */

.pd-view-toggle {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #ddd;
}

.pd-view-toggle-link {
    display: inline-block;
    padding: 0.625rem 1rem;
    min-height: 44px; /* Touch-friendly */
    line-height: 1.5;
    color: #2271b1;
    text-decoration: none;
    font-weight: 500;
    border: 1px solid #2271b1;
    border-radius: 4px;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.pd-view-toggle-link:hover {
    background: #2271b1;
    color: #fff;
}

/* ========================================
   Metadata Notes
   ======================================== */

.pd-metadata-note {
    margin-bottom: 0.75rem;
    color: #555;
    font-size: 0.95rem;
    line-height: 1.5;
}

.pd-metadata-range {
    color: #666;
    font-size: 0.9rem;
}

.pd-metadata-warning {
    margin-bottom: 0.5rem;
    color: #a00;
    font-size: 0.9rem;
    line-height: 1.5;
    padding: 0.5rem;
    background: #fff5f5;
    border-left: 3px solid #a00;
    border-radius: 3px;
}

/* ========================================
   Rank Distribution Summary
   ======================================== */

.pd-rank-summary {
    margin: 0.75rem 0 1rem 0;
    padding: 1rem;
    border: 1px solid #eee;
    background: #fafafa;
    border-radius: 6px;
    color: #333;
    font-size: 0.95rem;
    line-height: 1.6;
}

.pd-rank-summary-empty {
    color: #555;
}

.pd-rank-summary strong {
    font-weight: 600;
    color: #333;
}

.pd-rank-items {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.pd-rank-item {
    display: inline-block;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* ========================================
   Admin Data Management Forms
   ======================================== */

/* Target forms within the admin data management page */
.wrap form {
    margin-bottom: 2rem;
    padding: 1rem;
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.pd-admin-form-group {
    margin-bottom: 1rem;
}

.pd-admin-form-group:last-of-type {
    margin-bottom: 0;
}

.wrap form .pd-admin-input,
.wrap form select.pd-admin-input,
.wrap form input[type="month"].pd-admin-input {
    width: 100%;
    max-width: 100%;
    padding: 0.75rem;
    font-size: 1rem; /* Prevents zoom on iOS */
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    box-sizing: border-box;
    min-height: 44px; /* Touch-friendly */
}

.wrap form label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #333;
    font-size: 0.9rem;
}

.wrap form .button,
.wrap form input[type="submit"] {
    width: 100%;
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    min-height: 44px; /* Touch-friendly */
    margin-top: 1rem;
}

/* ========================================
   Responsive Tables
   ======================================== */

/* Table wrapper */
.pd-table-wrapper {
    width: 100%;
    overflow-x: auto;
    margin: 1rem 0;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Mobile: Card Layout (0-767px) */
@media (max-width: 767px) {
    .pd-table-wrapper {
        overflow-x: visible; /* No horizontal scroll on mobile */
    }
    
    .pd-table {
        width: 100%;
        border-collapse: collapse;
    }
    
    /* Hide table header on mobile */
    .pd-table thead {
        display: none;
    }
    
    /* Convert table rows to cards */
    .pd-table tbody,
    .pd-table tr {
        display: block;
        width: 100%;
    }
    
    .pd-table tr {
        margin-bottom: 1rem;
        border: 1px solid #ddd;
        border-radius: 6px;
        padding: 0;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    /* Convert table cells to block elements */
    .pd-table td {
        display: block;
        width: 100%;
        padding: 0.75rem 1rem;
        border: none;
        border-bottom: 1px solid #eee;
        text-align: left !important;
        box-sizing: border-box;
    }
    
    /* Remove border from last cell in each row */
    .pd-table tr td:last-child {
        border-bottom: none;
    }
    
    /* Add label before each cell content */
    .pd-table td::before {
        content: attr(data-label);
        font-weight: 600;
        display: block;
        margin-bottom: 0.25rem;
        color: #555;
        font-size: 0.875rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    /* Special handling for empty cells or cells without labels */
    .pd-table td:empty::before,
    .pd-table td[data-label=""]::before {
        display: none;
    }
    
    /* Preserve background colors from inline styles */
    .pd-table tr[style*="background"] {
        /* Inline styles will still apply */
    }
}

/* ========================================
   Tablet Styles (768px - 1023px)
   ======================================== */

@media (min-width: 768px) {
    .pd-wrap {
        padding: 1.5rem;
    }
    
    .pd-portal {
        padding: 1.5rem;
    }
    
    /* Tablet: Filter forms - horizontal layout */
    .pd-filters {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        align-items: flex-end;
        padding: 1.25rem;
    }
    
    .pd-filter-group {
        margin-bottom: 0;
        flex: 1 1 auto;
        min-width: 150px;
    }
    
    .pd-filter-custom-dates {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        width: 100%;
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid #ddd;
    }
    
    .pd-filter-custom-dates .pd-filter-group {
        flex: 1 1 200px;
    }
    
    .pd-filter-submit {
        margin-top: 0;
        flex: 0 0 auto;
    }
    
    .pd-button {
        width: auto;
        min-width: 140px;
    }
    
    /* Tablet: Pagination - horizontal layout */
    .pd-pagination {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
    }
    
    .pd-pagination-info {
        order: 1;
        text-align: left;
        margin: 0;
    }
    
    .pd-pagination-buttons {
        order: 2;
        margin: 0;
    }
    
    .pd-pagination-count {
        order: 3;
        text-align: right;
        margin: 0;
    }
    
    .pd-pagination-btn {
        min-width: 90px;
        padding: 0.625rem 1rem;
        min-height: 40px;
    }
    
    /* Tablet: Export controls */
    .pd-button-export {
        width: auto;
        min-width: 140px;
    }
    
    /* Tablet: View toggle */
    .pd-view-toggle-link {
        min-height: 40px;
        padding: 0.5rem 1rem;
    }
    
    /* Tablet: Rank summary */
    .pd-rank-items {
        gap: 1rem;
    }
    
    /* Tablet: Admin forms */
    .wrap form {
        display: flex;
        flex-wrap: wrap;
        gap: 1rem;
        align-items: flex-end;
    }
    
    .pd-admin-form-group {
        flex: 1 1 200px;
        margin-bottom: 0;
    }
    
    .wrap form .pd-admin-input,
    .wrap form select.pd-admin-input,
    .wrap form input[type="month"].pd-admin-input {
        width: 100%;
    }
    
    .wrap form .button,
    .wrap form input[type="submit"] {
        width: auto;
        min-width: 160px;
        margin-top: 0;
        flex: 0 0 auto;
    }
    
    /* Tablet: Show table normally but allow horizontal scroll if needed */
    .pd-table-wrapper {
        overflow-x: auto;
    }
    
    .pd-table {
        display: table;
        width: 100%;
        border-collapse: collapse;
    }
    
    .pd-table thead {
        display: table-header-group;
    }
    
    .pd-table tbody {
        display: table-row-group;
    }
    
    .pd-table tr {
        display: table-row;
    }
    
    .pd-table td,
    .pd-table th {
        display: table-cell;
        padding: 10px;
        border: 1px solid #ddd;
    }
    
    /* Hide mobile labels on tablet+ */
    .pd-table td::before {
        display: none;
    }
}

/* ========================================
   Desktop Styles (1024px+)
   ======================================== */

@media (min-width: 1024px) {
    .pd-wrap {
        padding: 2rem;
        max-width: 1400px;
        margin: 0 auto;
    }
    
    .pd-portal {
        padding: 2rem;
        max-width: 800px;
        margin: 0 auto;
    }
    
    /* Desktop: Filter forms - optimized horizontal layout */
    .pd-filters {
        padding: 1.5rem;
    }
    
    .pd-filter-group {
        min-width: 180px;
    }
    
    .pd-filter-input {
        font-size: 0.95rem;
        padding: 0.625rem 0.75rem;
        min-height: 40px;
    }
    
    .pd-button {
        padding: 0.75rem 2rem;
        min-height: 40px;
    }
    
    /* Desktop: Pagination - optimized spacing */
    .pd-pagination {
        gap: 1.5rem;
    }
    
    .pd-pagination-btn {
        padding: 0.625rem 1.25rem;
        min-height: 38px;
        font-size: 0.9rem;
    }
    
    /* Desktop: Export controls */
    .pd-button-export {
        width: auto;
        padding: 0.75rem 1.5rem;
        min-height: 40px;
    }
    
    /* Desktop: View toggle */
    .pd-view-toggle-link {
        min-height: 38px;
        padding: 0.5rem 1.25rem;
        font-size: 0.95rem;
    }
    
    /* Desktop: Metadata notes */
    .pd-metadata-note {
        font-size: 1rem;
    }
    
    /* Desktop: Rank summary */
    .pd-rank-summary {
        font-size: 1rem;
    }
    
    .pd-rank-item {
        font-size: 0.95rem;
        padding: 0.625rem 1rem;
    }
    
    /* Desktop: Admin forms */
    .wrap form .pd-admin-input,
    .wrap form select.pd-admin-input,
    .wrap form input[type="month"].pd-admin-input {
        width: auto;
        min-width: 200px;
        padding: 0.625rem 0.75rem;
        min-height: 40px;
        font-size: 0.95rem;
    }
    
    .wrap form .button,
    .wrap form input[type="submit"] {
        width: auto;
        padding: 0.75rem 1.5rem;
        min-height: 40px;
    }
    
    /* Desktop: Full table layout */
    .pd-table-wrapper {
        overflow-x: visible;
    }
    
    .pd-table {
        display: table;
        width: 100%;
        border-collapse: collapse;
    }
    
    .pd-table thead {
        display: table-header-group;
    }
    
    .pd-table tbody {
        display: table-row-group;
    }
    
    .pd-table tr {
        display: table-row;
    }
    
    .pd-table td,
    .pd-table th {
        display: table-cell;
        padding: 10px;
        border: 1px solid #ddd;
    }
    
    /* Hide mobile labels on desktop */
    .pd-table td::before {
        display: none;
    }
}
