/* ==============================
   LOAN VIEW STYLES
   (Zoho Day Mode)
============================== */

/* Layout */
.loan-container {
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 60px;
}

/* Header Section with Actions */
/* Header Section with Actions */
.view-header,
.loan-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Center alignment looks cleaner if height is consistent */
    margin-bottom: 24px;
    background: transparent;
    /* Removed card bg */
    /* White/Card bg */
    padding: 0;
    /* Removed padding to use full width efficiently */
    /* Spacious padding */
    border-radius: var(--radius- lg);
    border: none;
    box-shadow: none;
    /* Subtle lift */
    flex-wrap: wrap;
    gap: 20px;
    animation: fadeIn 0.4s ease-out;
}

.view-header-left h2,
.loan-title h3 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.view-header-left p,
.loan-subtitle {
    display: block;
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 6px;
    font-weight: 500;
}

.view-header-right,
.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Ensure status badge inside title aligns well */
.loan-title .status-badge {
    margin-left: 0;
    /* Reset margin if wrapped */
    vertical-align: middle;
}

/* Responsive Actions */
@media (max-width: 768px) {

    .view-header,
    .loan-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 16px;
    }

    .view-header-right,
    .header-actions {
        width: 100%;
        flex-direction: column;
    }

    .view-header-right .btn,
    .header-actions .btn {
        width: 100%;
        justify-content: center;
    }
}


/* Status Banner */
.status-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    border: 1px solid transparent;
}

.status-banner.active {
    background-color: #dcfce7;
    border-color: #bbf7d0;
    color: #166534;
}

.status-banner.closed {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.status-banner.overdue {
    background-color: #fee2e2;
    border-color: #fecaca;
    color: #991b1b;
}

/* Status Badges (Matches Dashboard) */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-left: 12px;
}

.status-active {
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.status-closed {
    background-color: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-border);
}


/* Summary Grid (Key Details) */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.summary-item {
    background: var(--bg-card);
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}

.summary-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.summary-label {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.summary-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.summary-value.highlight {
    color: var(--primary);
}

/* Section Cards (Customer, Items, Documents) */
.section-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    margin-bottom: 24px;
    overflow: hidden;
}

.section-header {
    background: #ffffff;
    border-bottom: 1px solid #f1f5f9;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.section-body {
    padding: 20px;
}

/* Items Table inside Card - reuse .view-table from base.css */

/* Image Gallery */
.image-gallery {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.gallery-item {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition);
}

.gallery-item:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px) scale(1.03);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Responsive */
@media (max-width: 1024px) {
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .view-header-right {
        width: 100%;
        flex-direction: column;
    }

    .view-header-right .btn {
        width: 100%;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }
}

/* ==============================
   VIEW PAGE SPECIFIC STYLES
   (Matches loan_view.html structure)
============================== */

.view-container {
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 60px;
}

/* Info Grid System */
.info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* 4 Columns for density like Zoho */
    gap: 24px;
    width: 100%;
}

.info-item {
    margin-bottom: 4px;
}

.info-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
    display: block;
}

.info-value {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-word;
}

.info-value-large {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
}

.info-value-danger {
    font-size: 14px;
    font-weight: 600;
    color: var(--error-text);
}

.info-value-warn {
    font-size: 14px;
    font-weight: 600;
    color: var(--warning-text);
}

/* Customer Photo */
.customer-photo-thumb {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

/* Images inside tables */
.gallery-img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.gallery-img:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-sm);
}

/* Responsive Grid */
@media (max-width: 1024px) {
    .info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .info-grid {
        grid-template-columns: 1fr;
    }
}

/* ==============================
   EDIT LOAN SPECIFIC STYLES
============================== */
.edit-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.split-layout {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}

.edit-side {
    flex: 1.5;
    min-width: 0;
    background: #f9fafb;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid #f1f5f9;
}

.view-side {
    flex: 1;
    position: sticky;
    top: 80px;
    min-width: 0;
    background: #ffffff;
    border-radius: 8px;
    transition: all 0.3s ease;
    z-index: 10;
}

/* Sticky state enhancement (requires JS for exact 'stuck' detection, but we provide base class) */
.view-side.stuck .summary-card {
    box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.12);
    border-color: var(--primary-light);
}

/* --- Data Section Cards (For Tables) --- */
.history-section,
.data-card {
    background: #ffffff;
    border: 1px solid #f1f5f9;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.data-header {
    background: #ffffff;
    border-bottom: 1px solid #f1f5f9;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.data-header h4 {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Finance Table Refinement */
.finance-table {
    width: 100%;
    border-collapse: collapse;
}

.finance-table th {
    background: #f8fafc;
    padding: 10px 20px;
    text-align: left;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid #f1f5f9;
}

.finance-table td {
    padding: 12px 20px;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid #f8fafc;
    transition: background 0.2s;
}

/* Zebra Striping */
.finance-table tbody tr:nth-child(even) td {
    background: #fafbfc;
}

.finance-table tbody tr:hover td {
    background: #f1f5f9;
}

.finance-table .amount-cell {
    font-family: var(--font-number);
    font-weight: 700;
    color: var(--text-primary);
}

.finance-table .positive {
    color: #166534;
}

.finance-table .negative {
    color: #991b1b;
}

.finance-table .pending {
    color: #92400e;
}


/* Edit Form Grids */
.field-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.field-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.field-group {
    margin-bottom: 20px;
}

.field-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.field-group input,
.field-group textarea {
    border: 1px solid #e2e8f0;
    background: #ffffff;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 14px;
    width: 100%;
    transition: all 0.2s;
}

.field-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}


/* Pledge/Adjustment Table in Edit Mode */
.adj-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
    /* Spaced rows */
}

.adj-table th {
    text-align: left;
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    padding: 0 10px 8px;
}

.adj-table td {
    padding: 0 4px;
    vertical-align: middle;
}

.adj-table input {
    background: #ffffff;
    border: 1px solid var(--border-color);
    height: 38px;
    /* Consistent height */
    width: 100%;
    padding: 0 10px;
    border-radius: var(--radius-sm);
}

.f-control-sm {
    background: #ffffff;
    border: 1px solid var(--border-color);
    height: 32px;
    width: 100%;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: all 0.2s;
}

.f-control-sm:focus {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
    outline: none;
}


/* Add Row Button */
.btn-add-row {
    background: var(--bg-hover);
    color: var(--primary);
    border: 2px dashed var(--border-color);
    padding: 12px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--transition);
}

.btn-add-row:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: scale(1.01);
}

.btn-remove-row {
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    transition: var(--transition);
}

.btn-remove-row:hover {
    color: var(--error-text);
    background: var(--error-bg);
    border-radius: 4px;
}

/* Total Section */
.total-section {
    margin-top: 24px;
    padding: 16px;
    background: #f8fafc;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
    border: 1px solid var(--border-color);
}

.total-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.total-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Mirroring View Side Styles (Summary Card) */
.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.summary-header-dark {
    background: #1e293b;
    /* Dark header for contrast in view side */
    color: white;
    padding: 16px 20px;
}

.summary-header-dark h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.view-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 20px;
}

.view-item {
    margin-bottom: 12px;
}

.view-label-sm {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 4px;
}

.view-value-lg {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

.view-value-lg.high {
    color: var(--primary);
    font-weight: 600;
}

@media (max-width: 1024px) {
    .split-layout {
        flex-direction: column;
    }

    .view-side {
        position: static;
        width: 100%;
    }
}

/* --- Fixed Loan Action Footer --- */
.view-container {
    padding-bottom: 120px;
    /* Space for the fixed footer */
}

.view-action-footer {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    height: 80px;
    background: white;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    z-index: 1050;
    transition: left var(--transition-slow);
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.footer-loan-info h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.footer-loan-info .status-badge {
    margin-left: 0 !important;
    margin-top: 4px;
}

.footer-actions {
    display: flex;
    gap: 12px;
}

/* Button Variants for Footer */
.btn-footer {
    padding: 10px 24px;
    font-weight: 600;
    font-size: 13px;
    border-radius: var(--radius-pill);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-f-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.15);
}

.btn-f-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.2);
}

.btn-f-secondary {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.btn-f-secondary:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.btn-f-warning {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
}

.btn-f-warning:hover {
    background: #fef3c7;
    border-color: #fcd34d;
}

.btn-f-danger {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.btn-f-danger:hover {
    background: #fee2e2;
    border-color: #fca5a5;
}

/* Responsive Footer */
@media (max-width: 768px) {
    .view-action-footer {
        left: 0;
        height: auto;
        padding: 16px;
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .footer-left {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .footer-actions {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }

    .btn-footer {
        width: 100%;
        justify-content: center;
    }

    .view-container {
        padding-bottom: 240px;
        /* More space for stacked buttons */
    }
}

/* Document Icon Previews */
.doc-icon-preview {
    height: 32px;
    width: 32px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 800;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.doc-icon-preview span {
    margin-top: -2px;
}

.pdf-icon {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.word-icon {
    background: #eff6ff;
    color: #1e40af;
    border-color: #bfdbfe;
}

.receipt-icon {
    background: #ecfdf5;
    color: #059669;
    border-color: #10b981;
}

.doc-icon-preview:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}