* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f9fafb;
    color: #111827;
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* Header */
.header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo-icon {
    width: 32px;
    height: 32px;
    background: #2563eb;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 14px;
}
.logo h1 {
    font-size: 20px;
    font-weight: 700;
    color: #111827;
}
.header-sub {
    font-size: 14px;
    color: #6b7280;
}

/* Main */
.main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* Stats */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
@media (max-width: 640px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
}
.stat-card {
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.stat-clickable {
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.stat-active {
    outline: 2px solid #2563eb;
    outline-offset: -2px;
}
.stat-card p.label { font-size: 14px; color: #6b7280; }
.stat-card p.value { font-size: 24px; font-weight: 700; color: #111827; }
.stat-card .stat-sub { font-size: 12px; color: #9ca3af; margin-top: 2px; }
.stat-card.yellow { background: #fefce8; border-color: #fde68a; }
.stat-card.yellow .label { color: #a16207; }
.stat-card.yellow .value { color: #92400e; }
.stat-card.orange { background: #fff7ed; border-color: #fdba74; }
.stat-card.orange .label { color: #c2410c; }
.stat-card.orange .value { color: #ea580c; }
.stat-card.orange .stat-sub { color: #c2410c; }
.stat-card.red { background: #fef2f2; border-color: #fecaca; }
.stat-card.red .label { color: #b91c1c; }
.stat-card.red .value { color: #991b1b; }

/* Filter buttons */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.filter-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: #4b5563;
    transition: all 0.15s;
}
.filter-btn:hover { background: #f9fafb; }
.filter-btn.active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

/* Table */
.table-wrapper {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    overflow: hidden;
}
.table-wrapper table {
    width: 100%;
    border-collapse: collapse;
}
.table-wrapper thead tr {
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.table-wrapper th {
    text-align: left;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 24px;
}
.table-wrapper th.right { text-align: right; }
.table-wrapper th.center { text-align: center; }
.table-wrapper td {
    padding: 16px 24px;
    font-size: 14px;
    color: #111827;
    border-bottom: 1px solid #f3f4f6;
}
.table-wrapper tr.clickable { cursor: pointer; transition: background 0.15s; }
.table-wrapper tr.clickable:hover { background: #f9fafb; }
.table-wrapper tr.pending-row {
    background: #fefce8;
    border-left: 4px solid #facc15;
}
.td-right { text-align: right; font-family: monospace; }
.td-center { text-align: center; }

/* Source badge */
.source-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    background: #f3f4f6;
    color: #374151;
}

/* Status badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid;
}
.badge-PENDING { background: #fef9c3; color: #92400e; border-color: #fde68a; }
.badge-ACCEPTED { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-REJECTED { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* Duplicate warning */
.duplicate-row { background: #fff7ed !important; border-left: 4px solid #f97316 !important; }
.badge-dupe {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    background: #f97316;
    color: #fff;
    margin-left: 6px;
    vertical-align: middle;
    letter-spacing: 0.5px;
}

/* Action buttons */
.action-btn {
    padding: 6px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    background: transparent;
    transition: background 0.15s;
}
.action-btn.accept { color: #16a34a; }
.action-btn.accept:hover { background: #f0fdf4; }
.action-btn.reject { color: #dc2626; }
.action-btn.reject:hover { background: #fef2f2; }

/* Empty state */
.empty-state {
    padding: 48px;
    text-align: center;
}
.empty-state .icon { font-size: 40px; margin-bottom: 16px; }
.empty-state .title { font-size: 18px; font-weight: 500; color: #4b5563; }
.empty-state .sub { color: #9ca3af; margin-top: 8px; }

/* Loading */
.loading { padding: 48px; text-align: center; color: #6b7280; }

/* ===================== INVOICE DETAIL PAGE ===================== */

.detail-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-outline {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
}
.btn-outline:hover { background: #f9fafb; }
.btn-green { background: #16a34a; color: #fff; }
.btn-green:hover { background: #15803d; }
.btn-red { background: #dc2626; color: #fff; }
.btn-red:hover { background: #b91c1c; }
.btn-blue { background: #2563eb; color: #fff; }
.btn-blue:hover { background: #1d4ed8; }

.back-link {
    color: #6b7280;
    font-size: 14px;
    cursor: pointer;
    background: none;
    border: none;
    transition: color 0.15s;
}
.back-link:hover { color: #374151; }

/* Two column layout */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
}
@media (min-width: 1024px) {
    .detail-grid { grid-template-columns: 1fr 1fr; }
}
.detail-grid.pending-ring {
    border: 2px solid #facc15;
    border-radius: 12px;
    padding: 4px;
}

.card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    padding: 24px;
}
.card h2 {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    margin-bottom: 16px;
}

/* Document preview */
.doc-preview img {
    width: 100%;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}
.doc-preview iframe {
    width: 100%;
    height: 600px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}
.doc-preview-clickable {
    position: relative;
    cursor: pointer;
}
.doc-preview-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.5));
    color: #fff;
    text-align: center;
    padding: 20px 8px 10px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 0 0 8px 8px;
    opacity: 0;
    transition: opacity 0.2s;
}
.doc-preview-clickable:hover .doc-preview-overlay { opacity: 1; }
.doc-placeholder {
    height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border-radius: 8px;
    color: #9ca3af;
}

/* Form */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-row {
    display: grid;
    gap: 16px;
}
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* Line items */
.line-items-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.line-items-header label {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}
.add-item-btn {
    font-size: 14px;
    color: #2563eb;
    background: none;
    border: none;
    cursor: pointer;
}
.add-item-btn:hover { color: #1d4ed8; }

.line-item-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    background: #f9fafb;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
}
.line-item-row .desc { flex: 1; }
.line-item-row .qty { width: 64px; }
.line-item-row .price { width: 96px; }
.line-item-row .amt { width: 96px; }
.line-item-row input {
    width: 100%;
    padding: 4px 8px;
    font-size: 14px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    outline: none;
}
.line-item-row input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.remove-item-btn {
    color: #ef4444;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
}
.remove-item-btn:hover { color: #b91c1c; }

.no-items {
    text-align: center;
    color: #9ca3af;
    padding: 16px;
    font-size: 14px;
}

.save-btn {
    width: 100%;
    padding: 10px;
    margin-top: 16px;
}

/* PAID status */
.badge-PAID { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.stat-card.blue { background: #eff6ff; border-color: #93c5fd; }
.stat-card.blue .label { color: #1d4ed8; }
.stat-card.blue .value { color: #1e40af; }

/* Thumbnail preview in table */
.thumb-cell { width: 60px; padding: 8px 12px !important; }
.thumb-img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.thumb-img:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-color: #3b82f6;
}
.thumb-placeholder {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #9ca3af;
}
.thumb-pdf {
    width: 50px;
    height: 50px;
    border-radius: 6px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #dc2626;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.thumb-pdf:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-color: #dc2626;
}

/* Lightbox overlay */
.lightbox {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: pointer;
    backdrop-filter: blur(4px);
}
.lightbox img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    cursor: default;
}
.lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    background: none;
    border: none;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.lightbox-close:hover { opacity: 1; }

/* Vendor link */
.vendor-link {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}
.vendor-link:hover { text-decoration: underline; }

/* Vendor page */
.vendor-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}
.vendor-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: #111827;
}
.vendor-stats {
    display: flex;
    gap: 24px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.vendor-stat {
    font-size: 14px;
    color: #6b7280;
}
.vendor-stat strong {
    color: #111827;
    font-size: 18px;
    display: block;
}

/* Vendor cards grid */
.vendor-grid {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 16px;
}
@media (min-width: 640px) { .vendor-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .vendor-grid { grid-template-columns: repeat(3, 1fr); } }

.vendor-card {
    display: block;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s, border-color 0.2s;
    cursor: pointer;
}
.vendor-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-color: #3b82f6;
}
.vendor-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.vendor-card-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #2563eb;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}
.vendor-card-name {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
}
.vendor-card-sub {
    font-size: 13px;
    color: #6b7280;
}
.vendor-card-amounts {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.vendor-card-label {
    display: block;
    font-size: 11px;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.vendor-card-value {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    font-family: monospace;
}
.vendor-card-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Paid button */
.btn-paid { background: #2563eb; color: #fff; }
.btn-paid:hover { background: #1d4ed8; }
.action-btn.paid { color: #2563eb; }
.action-btn.paid:hover { background: #eff6ff; }

/* Selected row */
.selected-row { background: #eff6ff !important; }

/* Selection bar (floating bottom) */
.selection-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1e293b;
    color: #fff;
    padding: 12px 24px;
    z-index: 900;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
}
.selection-bar-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}
.modal {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: #111827;
}

/* Responsive overflow */
.overflow-x { overflow-x: auto; }

/* Hide on small screens */
@media (max-width: 640px) {
    .hide-mobile { display: none; }
    .header-inner { padding: 12px 16px; }
    .main { padding: 16px; }
    .table-wrapper th, .table-wrapper td { padding: 10px 12px; }
    .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
    .thumb-cell { display: none; }
}
