/* Audit Letters Page Styles */

.audit-letters-page {
    max-width: 2500px; /* match the Letters page width */
    margin: 0 auto;
    outline: none;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.page-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-title p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0;
}

.page-actions {
    display: flex;
    gap: 12px;
}

/* Stats Row */
.audit-letters-page .stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border: 1px solid var(--border-primary);
    border-radius: 10px;
    padding: 16px 20px;
}

.stat-card.highlight {
    border-color: var(--color-warning);
    background: var(--color-warning-bg);
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card.highlight .stat-label {
    color: var(--color-warning-text);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-card.highlight .stat-value {
    color: var(--color-warning-text);
}

.stat-subtext {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Status Tabs */
.status-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-primary);
}

.status-tab {
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    position: relative;
    transition: color 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-tab:hover {
    color: var(--text-secondary);
}

.status-tab.active {
    color: var(--text-primary);
}

.status-tab.active::after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--text-primary);
}

.tab-count {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.status-tab.active .tab-count {
    background: var(--text-primary);
    color: white;
}

.tab-count.warning {
    background: var(--color-warning-bg);
    color: var(--color-warning-text);
}

/* Filters Bar */
.filters-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.filters-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-dropdown {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: white;
    border: 1px solid var(--text-faint);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.filter-dropdown i {
    color: var(--text-placeholder);
}

.filter-dropdown select {
    border: none;
    background: transparent;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    outline: none;
}

/* Audit Table */
.audit-table {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--border-primary);
    overflow: hidden;
}

.audit-letters-page .table-header {
    display: grid;
    grid-template-columns: 2fr 1fr 140px 120px 100px 90px;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.audit-letters-page .audit-row {
    display: grid;
    grid-template-columns: 2fr 1fr 140px 120px 100px 90px;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--bg-tertiary);
    align-items: center;
    transition: background 0.15s;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.audit-row:last-child {
    border-bottom: none;
}

.audit-row:hover {
    background: var(--bg-secondary);
}

.audit-row.urgent {
    border-left-color: var(--color-warning);
}

.audit-row.overdue {
    border-left-color: #ef4444;
}

.audit-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.audit-client {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.audit-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.jurisdiction-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

.auditor-cell {
    font-size: 13px;
    color: var(--text-secondary);
}

.auditor-cell .firm {
    font-weight: 500;
}

.auditor-cell .email {
    font-size: 12px;
    color: var(--text-muted);
}

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    width: fit-content;
}

.status-badge .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.intake { background: var(--bg-tertiary); color: var(--text-tertiary); }
.status-badge.collecting { background: var(--color-primary-bg); color: var(--color-info-text); }
.status-badge.drafting { background: #e0e7ff; color: #3730a3; }
.status-badge.review { background: var(--color-warning-bg); color: var(--color-warning-text); }
.status-badge.signing { background: #fce7f3; color: #9d174d; }
.status-badge.complete { background: var(--color-success-bg); color: var(--color-success-text); }

/* Response Progress */
.response-progress {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.progress-bar-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border-primary);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--color-success-light);
    border-radius: 3px;
    transition: width 0.3s;
}

.progress-fill.warning {
    background: var(--color-warning);
}

.progress-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    min-width: 40px;
}

.progress-detail {
    font-size: 11px;
    color: var(--text-muted);
}

/* Due Date */
.due-date {
    font-size: 13px;
    color: var(--text-secondary);
}

.due-date.urgent {
    color: var(--color-warning);
    font-weight: 500;
}

.due-date.overdue {
    color: #ef4444;
    font-weight: 500;
}

.due-date .days {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
}

.due-date.urgent .days,
.due-date.overdue .days {
    color: inherit;
}

/* Pagination */
.table-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-secondary);
}

.pagination-info {
    font-size: 13px;
    color: var(--text-muted);
}

.pagination-info strong {
    color: var(--text-primary);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border-radius: 6px;
    border: 1px solid var(--border-primary);
    background: white;
    color: var(--text-tertiary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.page-btn:hover:not(:disabled) {
    background: var(--bg-secondary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-btn.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: white;
}

.page-ellipsis {
    padding: 0 8px;
    color: var(--text-placeholder);
}

/* Detail Slide-out Panel */
.detail-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.detail-overlay.open {
    opacity: 1;
    visibility: visible;
}

.detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 680px;
    background: white;
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

.detail-panel.open {
    transform: translateX(0);
}

.detail-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.detail-title h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 4px 0;
}

.detail-title p {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0;
}

.close-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.close-btn:hover {
    background: var(--border-primary);
    color: var(--text-secondary);
}

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* Workflow Progress */
.workflow-progress {
    display: flex;
    justify-content: space-between;
    margin-bottom: 28px;
    position: relative;
}

.workflow-progress::before {
    content: "";
    position: absolute;
    top: 14px;
    left: 40px;
    right: 40px;
    height: 2px;
    background: var(--border-primary);
}

.workflow-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.step-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: white;
    border: 2px solid var(--text-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-placeholder);
}

.workflow-step.complete .step-circle {
    background: var(--color-success-light);
    border-color: var(--color-success-light);
    color: white;
}

.workflow-step.current .step-circle {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.step-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
}

.workflow-step.complete .step-label,
.workflow-step.current .step-label {
    color: var(--text-secondary);
}

/* Info Grid */
.info-section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.audit-letters-page .info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.info-item.full-width {
    grid-column: span 2;
}

.info-label {
    font-size: 12px;
    color: var(--text-muted);
}

.info-value {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

.section-divider {
    height: 1px;
    background: var(--border-primary);
    margin: 20px 0;
}

/* Timekeeper Response List */
.timekeeper-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.timekeeper-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.timekeeper-item.responded {
    background: var(--color-success-bg);
}

.timekeeper-item.pending {
    background: var(--color-warning-bg);
}

.timekeeper-item.has-input {
    border-left: 3px solid var(--color-primary);
}

.tk-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--text-faint);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
}

.tk-info {
    flex: 1;
}

.tk-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.tk-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.tk-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
}

.tk-status.responded {
    color: var(--color-success-text);
}

.tk-status.pending {
    color: var(--color-warning-text);
}

.tk-status-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tk-status.responded .tk-status-icon {
    background: var(--color-success-light);
    color: white;
}

.tk-status.pending .tk-status-icon {
    background: var(--color-warning);
    color: white;
}

.tk-hours {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 50px;
    text-align: right;
}

/* Input Card */
.input-card {
    background: white;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
    margin-left: 44px;
}

.input-card-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.input-card-content {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Detail Footer */
.detail-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-left,
.footer-right {
    display: flex;
    gap: 8px;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 300;
}

.modal.show {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 16px;
    width: 720px;
    max-width: 90vw;
    height: 85vh;
    max-height: 85vh;
    overflow: hidden;
    z-index: 301;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Align the New Request modal with the New Letter popup: plain white header band
   (overrides the global blue-gradient .modal-header from app.css) — scoped to this
   modal only so other modals keep the standard blue band. */
.audit-request-modal .modal-header {
    background: var(--bg-primary);
}

/* Icon + title laid out like the New Letter (Generate New Letter) modal header;
   the icon inherits the title color to match it. */
.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--border-primary);
    color: var(--text-secondary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.audit-letters-page .form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: span 2;
}

.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-label .required {
    color: #ef4444;
}

.form-input {
    padding: 10px 12px;
    border: 1px solid var(--text-faint);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-primary);
    transition: all 0.15s;
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* File Upload */
.file-upload {
    border: 2px dashed var(--text-faint);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}

.file-upload:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-bg);
}

.file-upload-icon {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    color: var(--text-muted);
    font-size: 20px;
}

.file-upload-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.file-upload-text span {
    color: var(--color-primary);
    font-weight: 500;
}

.file-upload-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* AI email-processing animation (shown while the dropped email is parsed + read by AI) */
.file-upload.processing {
    border-style: solid;
    border-color: var(--color-primary);
    background: var(--color-primary-bg);
    cursor: default;
    position: relative;
    overflow: hidden;
}

/* A soft highlight sweeping across the drop zone, like a scanner pass over the email. */
.file-upload.processing::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        100deg,
        transparent 30%,
        color-mix(in srgb, var(--color-primary) 14%, transparent) 50%,
        transparent 70%);
    transform: translateX(-100%);
    animation: audit-scan 1.4s ease-in-out infinite;
    pointer-events: none;
}

@keyframes audit-scan {
    to { transform: translateX(100%); }
}

/* The envelope icon pulses with an expanding ring while AI reads it. */
.file-upload-icon.processing {
    background: var(--color-primary-bg);
    color: var(--color-primary);
    animation: audit-pulse 1.4s ease-in-out infinite;
}

@keyframes audit-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-primary) 35%, transparent);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 0 8px color-mix(in srgb, var(--color-primary) 0%, transparent);
    }
}

/* Rolling step text — each new step (keyed on its index) slides + fades in. */
.processing-step {
    display: inline-block;
    animation: audit-step-in 0.4s ease;
}

@keyframes audit-step-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Animated trailing ellipsis on the rolling step text. */
.processing-dots span {
    opacity: 0.2;
    animation: audit-dot 1.2s infinite;
}
.processing-dots span:nth-child(2) { animation-delay: 0.2s; }
.processing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes audit-dot {
    0%, 60%, 100% { opacity: 0.2; }
    30%           { opacity: 1; }
}

/* Respect users who prefer reduced motion — keep the styled state, drop the motion. */
@media (prefers-reduced-motion: reduce) {
    .file-upload.processing::after,
    .file-upload-icon.processing,
    .processing-step,
    .processing-dots span {
        animation: none;
    }
    .processing-dots span { opacity: 1; }
}

/* Buttons — see design-tokens.css for canonical button rules. */

/* Responsive */
@media (max-width: 1200px) {
    .audit-letters-page .stats-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .audit-letters-page .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .audit-letters-page .table-header,
    .audit-letters-page .audit-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .table-header {
        display: none;
    }

    .audit-row {
        padding: 16px;
    }

    .detail-panel {
        width: 100%;
    }

    .modal.show {
        width: 95vw;
    }

    .audit-letters-page .form-row {
        grid-template-columns: 1fr;
    }

    .form-group.full-width {
        grid-column: span 1;
    }
}
