/* Tenant Portal Styles */
.pm-tenant-portal {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Modal Overlay */
.pm-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Modal Container */
.pm-modal-container {
    background: white;
    border-radius: 16px;
    max-width: 450px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

@keyframes slideUp {
    from { 
        opacity: 0;
        transform: translateY(30px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

/* Modal Header */
.pm-modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

.pm-modal-header h2 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
}

/* Auth Forms */
.pm-auth-form {
    padding: 30px;
}

.pm-form-group {
    margin-bottom: 20px;
}

.pm-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #2d3748;
    font-size: 14px;
}

.pm-form-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.2s;
    box-sizing: border-box;
}

.pm-form-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.pm-form-group small {
    display: block;
    margin-top: 6px;
    color: #718096;
    font-size: 13px;
}

/* Buttons */
.pm-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
    text-align: center;
}

.pm-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
    padding: 14px;
    font-size: 16px;
}

.pm-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.pm-btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.pm-btn-secondary {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
}

.pm-btn-secondary:hover {
    background: #667eea;
    color: white;
}

.pm-btn-loading {
    opacity: 0.7;
}

/* Modal Footer */
.pm-modal-footer {
    padding: 20px 30px 30px;
    text-align: center;
    background: #f7fafc;
    border-top: 1px solid #e2e8f0;
}

.pm-toggle-link {
    color: #667eea;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: color 0.2s;
}

.pm-toggle-link:hover {
    color: #764ba2;
    text-decoration: underline;
}

/* Messages */
.pm-message {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 0 30px 20px;
    font-size: 14px;
}

.pm-message.pm-error {
    background: #fee;
    color: #c53030;
    border: 1px solid #fc8181;
}

.pm-message.pm-success {
    background: #f0fff4;
    color: #22543d;
    border: 1px solid #9ae6b4;
}

/* Dashboard Styles */
.pm-portal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 40px;
    border-radius: 12px;
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
}

.pm-header-content h1 {
    margin: 0 0 15px;
    font-size: 32px;
    font-weight: 700;
}

.pm-property-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    opacity: 0.95;
}

.pm-icon {
    flex-shrink: 0;
}

/* Stats Cards */
.pm-portal-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.pm-stat-card {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
}

.pm-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.pm-stat-label {
    font-size: 13px;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 8px;
}

.pm-stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #2d3748;
}

.pm-stat-success {
    color: #38a169;
}

.pm-stat-warning {
    color: #d69e2e;
}

/* Portal Section */
.pm-portal-section {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
}

.pm-portal-section h2 {
    margin: 0 0 25px;
    font-size: 24px;
    color: #2d3748;
    font-weight: 700;
}

/* Invoices Table */
.pm-invoices-table-container {
    overflow-x: auto;
}

.pm-invoices-table {
    width: 100%;
    border-collapse: collapse;
}

/* Invoice Link */
.pm-view-invoice {
    color: #667eea;
    text-decoration: none;
    transition: color 0.2s;
    cursor: pointer;
}

.pm-view-invoice:hover {
    color: #764ba2;
    text-decoration: underline;
}

.pm-invoices-table thead {
    background: #f7fafc;
}

.pm-invoices-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: #4a5568;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e2e8f0;
}

.pm-invoices-table td {
    padding: 15px;
    border-bottom: 1px solid #e2e8f0;
    color: #2d3748;
}

.pm-invoices-table tbody tr:hover {
    background: #f7fafc;
}

.pm-invoices-table tbody tr:last-child td {
    border-bottom: none;
}

/* Status Badges */
.pm-status {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pm-status-paid {
    background: #c6f6d5;
    color: #22543d;
}

.pm-status-pending {
    background: #feebc8;
    color: #7c2d12;
}

.pm-status-overdue {
    background: #fed7d7;
    color: #742a2a;
}

/* Empty State */
.pm-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #718096;
}

.pm-empty-icon {
    opacity: 0.3;
    margin-bottom: 20px;
}

.pm-empty-state p {
    margin: 0;
    font-size: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .pm-modal-container {
        max-width: 100%;
        margin: 0;
        border-radius: 0;
    }
    
    .pm-portal-header {
        flex-direction: column;
        gap: 20px;
        padding: 25px 20px;
    }
    
    .pm-header-content h1 {
        font-size: 24px;
    }
    
    .pm-property-info {
        font-size: 14px;
    }
    
    .pm-portal-stats {
        grid-template-columns: 1fr;
    }
    
    .pm-portal-section {
        padding: 20px;
    }
    
    /* Make table responsive */
    .pm-invoices-table {
        display: block;
    }
    
    .pm-invoices-table thead {
        display: none;
    }
    
    .pm-invoices-table tbody {
        display: block;
    }
    
    .pm-invoices-table tr {
        display: block;
        margin-bottom: 20px;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        overflow: hidden;
    }
    
    .pm-invoices-table td {
        display: flex;
        justify-content: space-between;
        padding: 12px 15px;
        border-bottom: 1px solid #f7fafc;
    }
    
    .pm-invoices-table td:before {
        content: attr(data-label);
        font-weight: 600;
        color: #4a5568;
        font-size: 13px;
        text-transform: uppercase;
    }
    
    .pm-invoices-table td:last-child {
        border-bottom: none;
    }
}

@media (max-width: 480px) {
    .pm-modal-header {
        padding: 25px 20px;
    }
    
    .pm-modal-header h2 {
        font-size: 24px;
    }
    
    .pm-auth-form {
        padding: 25px 20px;
    }
    
    .pm-modal-footer {
        padding: 15px 20px 25px;
    }
    
    .pm-stat-value {
        font-size: 24px;
    }
}

/* Invoice Modal */
.pm-invoice-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pm-invoice-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 1;
}

.pm-invoice-modal-content {
    position: relative;
    background: white;
    border-radius: 12px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 2;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

/* Modal Header with Buttons */
.pm-invoice-modal-header {
    position: sticky;
    top: 0;
    background: white;
    padding: 15px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    border-radius: 12px 12px 0 0;
}

.pm-btn-print {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.pm-btn-print:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.pm-btn-print svg {
    width: 16px;
    height: 16px;
}

.pm-invoice-modal-close {
    background: #f7fafc;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
    color: #4a5568;
    flex-shrink: 0;
}

.pm-invoice-modal-close:hover {
    background: #e2e8f0;
    color: #2d3748;
}

#pm-invoice-modal-body {
    padding: 40px;
}

/* Invoice View Styles */
.pm-invoice-view {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.pm-invoice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 40px;
    padding-bottom: 30px;
    border-bottom: 2px solid #e2e8f0;
}

.pm-invoice-logo h1 {
    margin: 0 0 10px;
    font-size: 24px;
    color: #2d3748;
}

.pm-invoice-logo p {
    margin: 5px 0;
    color: #718096;
    font-size: 14px;
}

.pm-invoice-meta {
    text-align: right;
}

.pm-invoice-meta h2 {
    margin: 0 0 15px;
    font-size: 28px;
    color: #667eea;
    font-weight: 700;
}

.pm-invoice-meta p {
    margin: 8px 0;
    color: #4a5568;
    font-size: 14px;
}

.pm-invoice-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.pm-invoice-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

.pm-invoice-section h3 {
    margin: 0 0 15px;
    font-size: 14px;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.pm-invoice-section p {
    margin: 5px 0;
    color: #2d3748;
    font-size: 14px;
}

.pm-invoice-items {
    margin-bottom: 40px;
}

.pm-invoice-table {
    width: 100%;
    border-collapse: collapse;
}

.pm-invoice-table thead {
    background: #f7fafc;
}

.pm-invoice-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: #4a5568;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e2e8f0;
}

.pm-invoice-table td {
    padding: 15px;
    color: #2d3748;
    font-size: 14px;
    border-bottom: 1px solid #e2e8f0;
}

.pm-invoice-amount {
    text-align: right;
    font-weight: 600;
}

.pm-invoice-table tfoot td {
    padding: 20px 15px;
    font-size: 18px;
    border-top: 2px solid #2d3748;
    border-bottom: none;
}

.pm-invoice-total {
    text-align: right;
    color: #667eea;
}

.pm-invoice-footer {
    padding: 25px;
    background: #f7fafc;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.pm-invoice-footer p {
    margin: 5px 0;
    color: #4a5568;
    font-size: 14px;
}

.pm-invoice-paid {
    background: #f0fff4;
    border-left-color: #38a169;
    text-align: center;
}

.pm-paid-stamp {
    font-size: 48px;
    font-weight: 900;
    color: #38a169;
    margin: 20px 0;
    text-transform: uppercase;
    letter-spacing: 5px;
    opacity: 0.3;
}

.pm-loading {
    text-align: center;
    padding: 40px;
    color: #718096;
    font-size: 16px;
}

.pm-error {
    padding: 20px;
    background: #fee;
    color: #c53030;
    border-radius: 8px;
    border: 1px solid #fc8181;
    text-align: center;
}

/* Responsive Invoice Modal */
@media (max-width: 768px) {
    .pm-invoice-modal-content {
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
    }
    
    #pm-invoice-modal-body {
        padding: 20px;
    }
    
    .pm-invoice-header {
        flex-direction: column;
        gap: 20px;
    }
    
    .pm-invoice-meta {
        text-align: left;
    }
    
    .pm-invoice-details {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .pm-invoice-table {
        font-size: 13px;
    }
    
    .pm-invoice-table th,
    .pm-invoice-table td {
        padding: 10px;
    }
}

/* Print Styles */
@media print {
    /* Page settings */
    @page {
        size: letter portrait;
        margin: 0.5in;
    }
    
    /* Reset body */
    body {
        margin: 0 !important;
        padding: 0 !important;
        color: #000 !important;
        background: white !important;
    }
    
    html, body {
        height: auto !important;
        overflow: visible !important;
    }
    
    /* Hide everything except invoice modal */
    body > *:not(.pm-invoice-modal) {
        display: none !important;
    }
    
    .pm-tenant-portal > *:not(.pm-invoice-modal) {
        display: none !important;
    }
    
    /* Hide modal UI elements */
    .pm-invoice-modal-overlay,
    .pm-invoice-modal-header {
        display: none !important;
    }
    
    /* Show and position modal */
    .pm-invoice-modal {
        display: block !important;
        position: relative !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        z-index: 1 !important;
    }
    
    /* Show modal content */
    .pm-invoice-modal-content {
        display: block !important;
        position: relative !important;
        max-width: 100% !important;
        width: 100% !important;
        max-height: none !important;
        height: auto !important;
        overflow: visible !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
    }
    
    /* Show modal body */
    #pm-invoice-modal-body {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        background: white !important;
    }
    
    /* Show invoice view */
    .pm-invoice-view {
        display: block !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        font-size: 11pt !important;
        background: white !important;
        color: #000 !important;
    }
    
    /* Show all invoice sections */
    .pm-invoice-header,
    .pm-invoice-logo,
    .pm-invoice-meta,
    .pm-invoice-details,
    .pm-invoice-section,
    .pm-invoice-items,
    .pm-invoice-table,
    .pm-invoice-footer {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Compact header */
    .pm-invoice-header {
        display: flex !important;
        justify-content: space-between !important;
        page-break-after: avoid;
        page-break-inside: avoid;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 2px solid #333;
    }
    
    .pm-invoice-logo h1 {
        font-size: 18pt;
        margin: 0 0 5px 0;
        color: #000 !important;
    }
    
    .pm-invoice-logo p {
        font-size: 9pt;
        margin: 2px 0;
        line-height: 1.3;
        color: #000 !important;
    }
    
    .pm-invoice-meta {
        text-align: right;
    }
    
    .pm-invoice-meta h2 {
        font-size: 20pt;
        margin: 0 0 8px 0;
        color: #000 !important;
    }
    
    .pm-invoice-meta p {
        font-size: 9pt;
        margin: 3px 0;
        line-height: 1.3;
        color: #000 !important;
    }
    
    /* Compact details section */
    .pm-invoice-details {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        page-break-inside: avoid;
        page-break-after: avoid;
        margin-bottom: 15px;
        gap: 20px;
    }
    
    .pm-invoice-section h3 {
        font-size: 10pt;
        margin: 0 0 5px 0;
        color: #000 !important;
    }
    
    .pm-invoice-section p {
        font-size: 9pt;
        margin: 2px 0;
        line-height: 1.3;
        color: #000 !important;
    }
    
    /* Compact items table */
    .pm-invoice-items {
        page-break-inside: avoid;
        page-break-after: avoid;
        margin-bottom: 15px;
    }
    
    .pm-invoice-table {
        display: table !important;
        width: 100%;
        border-collapse: collapse;
    }
    
    .pm-invoice-table thead {
        display: table-header-group !important;
        background: #f0f0f0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        page-break-after: avoid;
    }
    
    .pm-invoice-table thead tr {
        display: table-row !important;
    }
    
    .pm-invoice-table th {
        display: table-cell !important;
        padding: 8px 10px;
        font-size: 9pt;
        border-bottom: 2px solid #333;
        color: #000 !important;
    }
    
    .pm-invoice-table tbody {
        display: table-row-group !important;
        page-break-inside: avoid;
    }
    
    .pm-invoice-table tbody tr {
        display: table-row !important;
    }
    
    .pm-invoice-table td {
        display: table-cell !important;
        padding: 8px 10px;
        font-size: 10pt;
        border-bottom: 1px solid #ddd;
        color: #000 !important;
    }
    
    .pm-invoice-table td small {
        font-size: 8pt;
        color: #666 !important;
    }
    
    .pm-invoice-table tfoot {
        display: table-footer-group !important;
        page-break-inside: avoid;
        page-break-before: avoid;
    }
    
    .pm-invoice-table tfoot tr {
        display: table-row !important;
    }
    
    .pm-invoice-table tfoot td {
        display: table-cell !important;
        padding: 10px;
        font-size: 14pt;
        border-top: 2px solid #333;
        border-bottom: none;
        color: #000 !important;
    }
    
    /* Compact footer */
    .pm-invoice-footer {
        page-break-inside: avoid;
        page-break-before: avoid;
        margin-top: 15px;
        padding: 10px 15px;
        background: #f9f9f9 !important;
        border-left: 3px solid #667eea;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .pm-invoice-footer p {
        margin: 3px 0;
        font-size: 9pt;
        line-height: 1.4;
        color: #000 !important;
    }
    
    /* Compact PAID stamp */
    .pm-invoice-paid {
        background: #f0fff4 !important;
        border-left-color: #38a169;
        padding: 15px;
    }
    
    .pm-paid-stamp {
        font-size: 32pt;
        margin: 10px 0;
        line-height: 1;
        letter-spacing: 8px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color: #38a169 !important;
        opacity: 0.3;
    }
    
    /* Ensure colors print correctly */
    .pm-invoice-status {
        display: inline-block !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color-adjust: exact;
        padding: 3px 8px;
        font-size: 8pt;
        border-radius: 8px;
    }
    
    .pm-status-paid {
        background: #c6f6d5 !important;
        color: #22543d !important;
    }
    
    .pm-status-pending {
        background: #feebc8 !important;
        color: #7c2d12 !important;
    }
    
    .pm-status-overdue {
        background: #fed7d7 !important;
        color: #742a2a !important;
    }
    
    /* Remove effects */
    * {
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    /* Links */
    a {
        text-decoration: none;
        color: inherit !important;
    }
    
    /* Make amount column stand out */
    .pm-invoice-amount {
        font-weight: bold;
        text-align: right;
    }
    
    .pm-invoice-total {
        font-size: 16pt !important;
        font-weight: bold;
        text-align: right;
    }
    
    /* Show strong and other inline elements */
    strong, b {
        display: inline !important;
        font-weight: bold;
    }
    
    span, small {
        display: inline !important;
    }
    
    br {
        display: block !important;
    }
}