/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --background: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --success: #10b981;
    --error: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

/* Login Screen */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-box {
    background: var(--surface);
    padding: 3rem 2.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

.login-box h1 {
    font-size: 2rem;
    margin-bottom: 2rem;
    text-align: center;
    color: var(--primary-color);
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.875rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: all 0.2s;
}

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

.btn-primary {
    width: 100%;
    padding: 0.875rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--background);
    border-color: var(--secondary-color);
}

.error-message {
    color: var(--error);
    font-size: 0.875rem;
    margin-top: 1rem;
    text-align: center;
}

/* Dashboard */
.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.dashboard-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.4rem 0.6rem;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.btn-icon:hover {
    background: var(--background);
    border-color: var(--primary-color);
}

.btn-icon.active {
    background: #eff6ff;
    border-color: var(--primary-color);
}

/* Navigation Tabs */
.nav-tabs {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    padding: 0 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.tab-btn {
    padding: 1rem 1.5rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Tab Content */
.tab-content {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.panel-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.count-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 600;
}

/* Thread List */
.thread-list {
    background: var(--surface);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.thread-item {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.thread-item:last-child {
    border-bottom: none;
}

.thread-item:hover {
    background: var(--background);
}

.thread-item.unread {
    background: #eef2ff;
    border-left: 3px solid var(--primary-color);
}

.thread-item.unread:hover {
    background: #e0e7ff;
}

.thread-item.unread .thread-user,
.thread-item.unread .thread-preview {
    font-weight: 600;
    color: var(--text-primary);
}

.thread-avatar {
    width: 48px;
    height: 48px;
    border-radius: 0.5rem;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    overflow: visible;
    position: relative;
}

.thread-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0.5rem;
}

.unread-dot {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border: 2px solid var(--surface);
    border-radius: 50%;
    z-index: 1;
}

.thread-content {
    flex: 1;
    min-width: 0;
}

.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.25rem;
}

.thread-user {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.thread-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.thread-car {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.thread-preview {
    font-size: 0.875rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Thread Detail View */
.thread-detail-view {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
}

.detail-header {
    background: var(--surface);
    border-radius: 0.75rem 0.75rem 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    padding: 1.25rem;
}

.btn-back {
    background: transparent;
    border: none;
    color: var(--primary-color);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-back:hover {
    color: var(--primary-hover);
}

.thread-info h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.thread-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Thread Detail Stats Strip */
.thread-detail-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.4rem 0.75rem;
}

.stat-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.125rem;
}

.stat-value {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Messages List */
.messages-list {
    flex: 1;
    overflow-y: auto;
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Inline message list inside agreement Messages sub-tab */
.ag-msg-list {
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-item {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.message-item.admin {
    align-self: flex-end;
}

.message-item.user {
    align-self: flex-start;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.message-bubble {
    padding: 0.875rem 1rem;
    border-radius: 1rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.message-item.admin .message-bubble {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message-item.user .message-bubble {
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.25rem;
}

.message-attachment {
    margin-top: 0.5rem;
    max-width: 100%;
}

.message-attachment img {
    max-width: 100%;
    max-height: 400px;
    border-radius: 0.5rem;
    object-fit: contain;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.5rem;
    color: inherit;
    text-decoration: none;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.message-item.user .attachment-link {
    background: rgba(0, 0, 0, 0.05);
    border-color: var(--border);
    color: var(--primary-color);
}

.attachment-link:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.message-item.user .attachment-link:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* Message Input */
.message-input-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 0 0.75rem 0.75rem;
    padding: 1.25rem;
}

.message-input-container textarea {
    width: 100%;
    padding: 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 0.75rem;
    transition: all 0.2s;
}

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

.input-actions {
    display: flex;
    justify-content: flex-end;
}

.input-actions .btn-primary {
    width: auto;
    padding: 0.75rem 2rem;
}

/* Agreements Tab — Status Filter Pills */
.status-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.status-filter {
    padding: 0.4rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.status-filter:hover {
    border-color: var(--secondary-color);
    color: var(--text-primary);
}

.status-filter.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.status-filter.active .filter-count {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Non-"All" pills get their status color on hover when not active */
.status-filter[style]:not(.active):hover {
    border-color: var(--status-color);
    color: var(--status-color);
}

.status-filter.empty {
    opacity: 0.45;
}

.filter-count {
    background: var(--background);
    color: var(--text-secondary);
    padding: 0.05rem 0.45rem;
    border-radius: 0.75rem;
    font-size: 0.7rem;
    font-weight: 600;
}

/* Agreements Tab — Card List */
.agreement-list {
    background: var(--surface);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.agreement-item {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    cursor: pointer;
}

.agreement-item:last-child {
    border-bottom: none;
}

.agreement-item:hover {
    background: var(--background);
}

/* Agreement card — header row: name + status badge */
.agreement-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}

.agreement-user {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.agreement-status-badge {
    font-size: 0.725rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 0.375rem;
    white-space: nowrap;
}

/* Agreement card — car line */
.agreement-car {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

/* Agreement card — financial summary row */
.agreement-financials {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.3rem;
}

.agreement-financial {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-primary);
}

.agreement-sep {
    font-size: 0.75rem;
    color: var(--border);
    margin: 0 0.15rem;
}

/* Agreement card — dates row */
.agreement-dates {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Agreement Detail View — Header */
.agreement-detail-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.agreement-detail-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.agreement-detail-title h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.agreement-detail-car {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

/* Agreement Detail View — Sub-tabs */
.ag-tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    background: var(--surface);
    border-radius: 0.75rem 0.75rem 0 0;
    border: 1px solid var(--border);
    padding: 0.5rem 0.5rem 0;
}

.ag-tab-btn {
    padding: 0.6rem 1rem;
    background: transparent;
    border: none;
    border-radius: 0.5rem 0.5rem 0 0;
    color: var(--text-secondary);
    font-size: 0.825rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.ag-tab-btn:hover {
    color: var(--text-primary);
    background: var(--background);
}

.ag-tab-btn.active {
    color: var(--primary-color);
    background: var(--background);
    font-weight: 600;
    border-bottom: 2px solid var(--primary-color);
}

/* Agreement Detail View — Tab Content */
.ag-tab-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 0.75rem 0.75rem;
    padding: 1.5rem;
}

.ag-tab-pane {
    display: none;
}

.ag-tab-pane.active {
    display: block;
}

/* Detail sections — shared layout for all sub-tabs */
.detail-section {
    margin-bottom: 1.5rem;
}

.detail-section:last-child {
    margin-bottom: 0;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    font-size: 0.825rem;
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
    margin-right: 1rem;
}

.detail-value {
    font-size: 0.825rem;
    color: var(--text-primary);
    text-align: right;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.detail-description {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1rem;
}

/* Inline badges */
.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 0.3rem;
}

.badge-verified {
    color: var(--success);
    background: #d1fae5;
}

.badge-pending {
    color: #d97706;
    background: #fef3c7;
}

.badge-approved {
    color: var(--success);
    background: #d1fae5;
}

.badge-completed {
    color: var(--success);
    background: #d1fae5;
}

.badge-immobilized {
    color: #b91c1c;
    background: #fee2e2;
}

.badge-repo_initiated {
    color: #92400e;
    background: #fef3c7;
}

.badge-needs_service {
    color: #1d4ed8;
    background: #dbeafe;
}

.badge-none {
    color: #64748b;
    background: transparent;
    border: 1px dashed #cbd5e1;
}

.collections-hold-trigger {
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
}

.collections-hold-trigger:hover {
    opacity: 0.75;
    transform: scale(1.03);
}

/* Doc links */
.doc-link {
    color: var(--primary-color);
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.15s;
}

.doc-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Insurance image preview */
.doc-preview {
    margin-top: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--background);
}

.doc-preview img {
    width: 100%;
    max-height: 350px;
    object-fit: contain;
}

/* Empty-state placeholder */
.empty-state {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 1.5rem 0;
    text-align: center;
}

/* "Open Message Thread" button */
.btn-open-thread {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1.25rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-open-thread:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* Payment rows */
.payment-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0.75rem;
    background: var(--background);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
}

.payment-row:last-child {
    margin-bottom: 0;
}

.payment-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.payment-type {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-primary);
}

.payment-meta {
    font-size: 0.725rem;
    color: var(--text-secondary);
}

.payment-late {
    color: var(--error);
    font-weight: 600;
}

.payment-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.payment-amount {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-capture-downpayment {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: white;
    background-color: #7c3aed;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-capture-downpayment:hover:not(:disabled) {
    background-color: #6d28d9;
}

.btn-capture-downpayment:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Approve & Sign section */
.approve-section {
    background: #fefce8;
    border: 1px solid #fde047;
    border-radius: 0.625rem;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.approve-header .section-title {
    margin-bottom: 0.75rem;
    border-bottom-color: #fde047;
}

.sign-action-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
}

.btn-sign {
    padding: 0.6rem 1.35rem;
    background: #16a34a;
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-sign:hover {
    background: #15803d;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-sign:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.sign-feedback {
    font-size: 0.8rem;
}

.sign-feedback-success {
    color: var(--success);
}

.sign-feedback-error {
    color: var(--error);
}

/* Insurance status toggle */
.ins-status-toggle {
    display: flex;
    gap: 0.4rem;
}

.ins-status-btn {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.775rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.ins-status-btn:hover {
    border-color: var(--secondary-color);
    color: var(--text-primary);
}

.ins-status-btn[data-status="pending"].active {
    background: #fef3c7;
    border-color: #d97706;
    color: #d97706;
}

.ins-status-btn[data-status="verified"].active {
    background: #d1fae5;
    border-color: #059669;
    color: #059669;
}

.ins-status-btn[data-status="expired"].active {
    background: #fee2e2;
    border-color: #dc2626;
    color: #dc2626;
}

/* Insurance text / date inputs */
.ins-input {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.825rem;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color 0.15s;
}

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

.ins-input[type="text"] {
    width: 200px;
}

/* Insurance detail header — title + save button on one line */
.ins-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ins-detail-header .section-title {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

/* Insurance save row (sits inside the header) */
.ins-save-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-ins-save {
    padding: 0.55rem 1.25rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.825rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-ins-save:hover {
    background: var(--primary-hover);
}

.btn-ins-save:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
}

/* Insurance save feedback */
.ins-feedback {
    font-size: 0.8rem;
}

.ins-feedback-success {
    color: var(--success);
}

.ins-feedback-error {
    color: var(--error);
}

/* Agreement status change row */
.ag-status-change-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #e2e8f0;
}

.ag-status-select {
    flex: 1;
    max-width: 280px;
    padding: 0.5rem 0.65rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    font-size: 0.825rem;
    background: white;
    color: #334155;
    cursor: pointer;
    appearance: auto;
}

.ag-status-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn-ag-status {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.825rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-ag-status:hover {
    background: var(--primary-hover);
}

.btn-ag-status:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
}

.ag-status-feedback {
    font-size: 0.8rem;
}

.ag-status-feedback-error {
    color: var(--error);
}

/* Confirmation modal */
.confirm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.confirm-modal {
    background: white;
    border-radius: 0.75rem;
    padding: 1.75rem;
    width: 90%;
    max-width: 420px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.tracker-modal {
    max-width: 500px;
}

.confirm-modal-title {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
}

.confirm-modal-message {
    margin: 0 0 1.25rem;
    font-size: 0.875rem;
    color: #475569;
    line-height: 1.5;
}

.confirm-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
}

.btn-modal-cancel {
    padding: 0.5rem 1.1rem;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    font-size: 0.825rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-modal-cancel:hover {
    background: #e2e8f0;
}

.btn-modal-confirm {
    padding: 0.5rem 1.1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.825rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-modal-confirm:hover {
    background: var(--primary-hover);
}

.btn-modal-confirm:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
}

/* License edit section */
.license-edit-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.license-edit-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.license-edit-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 52px;
}

.license-edit-select {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    font-size: 0.825rem;
    background: white;
    color: var(--text-primary);
    cursor: pointer;
    min-width: 140px;
}

.license-edit-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.license-edit-date {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    font-size: 0.825rem;
    color: var(--text-primary);
    min-width: 150px;
}

.license-edit-date:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.license-edit-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

/* Notes section */
.notes-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.note-item {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.note-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.note-date {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.note-content {
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Tracker list */
.tracker-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tracker-item {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.tracker-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.tracker-brand {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tracker-position {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: #f1f5f9;
    padding: 0.2rem 0.5rem;
    border-radius: 0.3rem;
}

.tracker-item-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.8rem;
}

.tracker-label {
    color: var(--text-secondary);
    font-weight: 600;
}

.tracker-value {
    color: var(--text-primary);
    font-family: monospace;
}

/* Tracker form */
.tracker-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tracker-form-row {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.tracker-form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.tracker-form-input {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    font-size: 0.825rem;
    color: var(--text-primary);
    transition: all 0.15s;
}

.tracker-form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Manually Add Payment modal — leg cards, calculated stats, split summary */
.mp-leg-card {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 1rem;
    margin-bottom: 0.85rem;
}

.mp-leg-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 0.85rem;
}

.mp-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.mp-calc-row {
    display: flex;
    gap: 0.6rem;
}

.mp-stat-box {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    padding: 0.5rem 0.65rem;
    min-width: 0;
}

.mp-stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mp-stat-value {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.mp-id-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
}

.mp-split-summary {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.85rem 1rem;
    margin-bottom: 0.85rem;
}

.mp-split-total {
    font-size: 0.85rem;
    font-weight: 700;
    margin-top: 0.5rem;
    color: var(--text-secondary);
}

.mp-split-total.mp-match {
    color: var(--success);
}

.mp-split-total.mp-mismatch {
    color: var(--error);
}

.tracker-form-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

/* Ledger table */
.ledger-table-wrap {
    max-height: 340px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.ledger-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.825rem;
}

.ledger-table thead {
    position: sticky;
    top: 0;
    background: var(--background);
    z-index: 1;
}

.ledger-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.ledger-table td {
    padding: 0.55rem 0.75rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.ledger-row:last-child td {
    border-bottom: none;
}

.ledger-row:hover {
    background: #f8fafc;
}

.ledger-row-late td {
    color: var(--error);
}

.ledger-week {
    font-weight: 600;
    color: var(--text-secondary);
}

.ledger-amount {
    font-weight: 700;
}

.ledger-due {
    white-space: nowrap;
}

.ledger-rescheduled {
    color: #d97706;
    font-size: 0.8rem;
    margin-left: 0.3rem;
    cursor: default;
}

.ledger-paid {
    color: var(--text-secondary);
}

.badge-due {
    color: #d97706;
    background: #fef3c7;
}

.badge-paid {
    color: var(--success);
    background: #d1fae5;
}

.badge-late {
    color: var(--error);
    background: #fef2f2;
}

/* Ledger edit button */
.ledger-due {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ledger-due-text {
    flex: 1;
}

.ledger-edit-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    opacity: 0.6;
    transition: opacity 0.15s, transform 0.15s;
}

.ledger-edit-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Textarea for tracker form */
.tracker-form-textarea {
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    font-size: 0.825rem;
    color: var(--text-primary);
    font-family: inherit;
    resize: vertical;
    transition: all 0.15s;
}

.tracker-form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        padding: 1rem;
    }

    .tab-content {
        padding: 1rem;
    }

    .nav-tabs {
        padding: 0 1rem;
    }

    .message-item {
        max-width: 85%;
    }

    .thread-detail-view {
        height: calc(100vh - 160px);
    }

    /* Agreement sub-tabs: horizontal scroll on mobile */
    .ag-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        padding: 0.5rem 0.25rem 0;
        gap: 0.15rem;
    }

    .ag-tabs::-webkit-scrollbar {
        display: none; /* Chrome / Safari / Edge */
    }

    .ag-tab-btn {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }

    .ag-tab-content {
        padding: 1rem;
    }
}

/* ─────────────────────────────────────────────
   PAYMENTS TAB
   ───────────────────────────────────────────── */

.payments-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.summary-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.summary-card h3 {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0 0 0.5rem 0;
    font-weight: 500;
}

.summary-card .value {
    font-size: 1.875rem;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.summary-card .amount-paid .value {
    color: #10b981;
}

.summary-card .amount-due .value {
    color: #f59e0b;
}

.summary-card .overdue-count .value {
    color: #ef4444;
}

.payments-section {
    margin-bottom: 2rem;
}

.payments-section h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #111827;
    margin: 0 0 1rem 0;
}

.payments-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.payments-table thead {
    background: #f9fafb;
}

.payments-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #e5e7eb;
}

.payments-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.875rem;
    color: #374151;
}

.payments-table tbody tr:hover {
    background: #f9fafb;
}

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

.amount-paid {
    color: #10b981 !important;
    font-weight: 600;
}

.amount-due {
    color: #f59e0b !important;
    font-weight: 600;
}

.amount-overdue {
    color: #ef4444 !important;
    font-weight: 600;
}

.overdue-badge {
    background: #fee2e2;
    color: #991b1b;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    display: inline-block;
    text-align: center;
}

.overdue-row {
    background: #fef2f2 !important;
}

.days-overdue {
    color: #dc2626;
    font-weight: 600;
}

.no-data {
    padding: 2rem;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
}

@media (max-width: 768px) {
    .payments-summary {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .summary-card .value {
        font-size: 1.5rem;
    }
    
    .payments-table {
        font-size: 0.75rem;
    }
    
    .payments-table th,
    .payments-table td {
        padding: 0.5rem;
    }
}

/* Additional Payments Table Styling */
.payments-table td:nth-child(2),
.payments-table th:nth-child(2) {
    font-weight: 600;
}

.payments-table td:nth-child(3) {
    font-family: monospace;
    font-size: 0.8rem;
}

.payments-table td:nth-child(4) {
    color: #6b7280;
    font-size: 0.85rem;
}

@media (max-width: 768px) {
    .payments-table td:nth-child(3),
    .payments-table th:nth-child(3) {
        display: none;
    }
}
