/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: #1a1a2e;
    background: #f0f2f5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }

/* === Top Bar === */
.topbar {
    background: #1a1a2e;
    color: #fff;
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}
.topbar-brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.topbar-brand:hover { text-decoration: none; }
.nav-logo { height: 32px; width: auto; border-radius: 4px; }
.topbar-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
}
.user-avatar { width: 28px; height: 28px; border-radius: 50%; }
.user-name { color: #ccc; }
.btn-sm {
    padding: 0.25rem 0.65rem;
    font-size: 0.78rem;
    background: rgba(255,255,255,0.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 4px;
    text-decoration: none;
}
.btn-sm:hover { background: rgba(255,255,255,0.22); }

/* === App Layout (sidebar + main) === */
.app-layout {
    display: flex;
    flex: 1;
    min-height: 0;
}

/* === Sidebar === */
.sidebar {
    width: 220px;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    padding: 1rem 0;
    flex-shrink: 0;
    position: sticky;
    top: 52px;
    height: calc(100vh - 52px);
    overflow-y: auto;
}
.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}
.sidebar-menu > li > a {
    display: block;
    padding: 0.6rem 1.25rem;
    color: #374151;
    font-size: 0.9rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background 0.12s, border-color 0.12s;
}
.sidebar-menu > li > a:hover {
    background: #f3f4f6;
    text-decoration: none;
}
.sidebar-menu > li > a.active {
    background: #eff6ff;
    color: #2563eb;
    border-left-color: #2563eb;
    font-weight: 600;
}
.sidebar-menu > li > a.disabled {
    color: #9ca3af;
    cursor: default;
    pointer-events: none;
}

/* === Sidebar Submenu === */
.sidebar-submenu {
    list-style: none;
    padding: 0.25rem 0 0.5rem 0;
    margin: 0;
}
.sidebar-submenu li a {
    display: block;
    padding: 0.35rem 1.25rem 0.35rem 2.25rem;
    color: #6b7280;
    font-size: 0.82rem;
    transition: color 0.12s, background 0.12s;
}
.sidebar-submenu li a:hover {
    color: #2563eb;
    background: #f9fafb;
    text-decoration: none;
}

/* === Main Content === */
.main-content {
    flex: 1;
    padding: 1.5rem 2rem;
    min-width: 0;
    max-width: 1200px;
}

/* === Footer === */
.app-footer {
    padding: 1rem 1.25rem;
    text-align: center;
    color: #9ca3af;
    font-size: 0.82rem;
    border-top: 1px solid #e5e7eb;
}

/* === Alerts === */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error   { background: #fee2e2; color: #991b1b; }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger  { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover  { background: #b91c1c; }
.btn-override { background: #059669; color: #fff; border-color: #059669; }
.btn-override:hover { background: #047857; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* === Page Header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; }

/* === Table === */
.table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.table th, .table td {
    padding: 0.65rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
    font-size: 0.9rem;
}
.table th { background: #f9fafb; font-weight: 600; }
.table tbody tr:hover { background: #f3f4f6; }
.actions { white-space: nowrap; }
.actions .btn-sm { margin-right: 0.25rem; }

/* === Forms === */
.form { max-width: 700px; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.9rem; }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

/* === Detail Card === */
.detail-card {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 1.5rem;
}
.detail-table { width: 100%; }
.detail-table th {
    text-align: left;
    padding: 0.5rem 1rem 0.5rem 0;
    width: 140px;
    color: #6b7280;
    font-weight: 500;
    vertical-align: top;
}
.detail-table td { padding: 0.5rem 0; }
.detail-table code { background: #f3f4f6; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85rem; }

.delete-form { margin-bottom: 1rem; }

/* === Upload Layout (side-by-side preview + form) === */
.upload-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}
.pdf-preview {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    min-height: 600px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.pdf-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 600px;
    color: #9ca3af;
    font-size: 0.95rem;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
}
.pdf-viewer {
    width: 100%;
    min-height: 600px;
    border: none;
    border-radius: 8px;
}
@media (max-width: 900px) {
    .upload-layout {
        grid-template-columns: 1fr;
    }
}

/* === Bulk Import 3-panel layout === */
.bulk-layout {
    display: grid;
    grid-template-columns: 250px 1fr 340px;
    gap: 1rem;
    align-items: start;
}
.file-list-panel {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 0.75rem;
    max-height: 700px;
    overflow-y: auto;
}
.file-list-panel h3 { font-size: 0.95rem; margin-bottom: 0.5rem; }
.file-list { list-style: none; }
.file-item {
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    transition: background 0.12s;
}
.file-item:hover { background: #f3f4f6; }
.file-item.active { background: #dbeafe; font-weight: 600; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; margin-right: 0.5rem; }
.file-size { color: #9ca3af; font-size: 0.78rem; white-space: nowrap; }
.bulk-form-panel {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 1rem;
}
.bulk-form-panel h3 { font-size: 0.95rem; margin-bottom: 0.75rem; }
.bulk-form-panel .form-group { margin-bottom: 0.6rem; }
.bulk-form-panel .form-row { gap: 0.5rem; }
.selected-file-display {
    padding: 0.4rem 0.6rem;
    background: #f3f4f6;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #374151;
}
.folder-item { font-weight: 500; }
.folder-item:hover { background: #e0e7ff; }
.file-icon { margin-right: 0.4rem; font-size: 0.95rem; }
.breadcrumb-bar {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0.5rem;
    white-space: nowrap;
    overflow-x: auto;
}
.breadcrumb-bar a { color: #2563eb; text-decoration: none; }
.breadcrumb-bar a:hover { text-decoration: underline; }
.breadcrumb-bar a:last-child { font-weight: 600; color: #1a1a2e; }
.breadcrumb-sep { color: #9ca3af; margin: 0 0.2rem; }
@media (max-width: 1100px) {
    .bulk-layout {
        grid-template-columns: 1fr;
    }
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    margin: 0.1rem 0.15rem;
    white-space: nowrap;
}
.badge-warning { background: #fee2e2; color: #991b1b; }

/* === Flagged highlights === */
.cell-flagged { background: #fee2e2; }
.form-group-flagged label { color: #991b1b; }
.form-group-flagged input,
.form-group-flagged select,
.form-group-flagged textarea {
    border-color: #f87171;
    background: #fef2f2;
    box-shadow: 0 0 0 2px rgba(248,113,113,0.25);
}

/* === Filter Bar === */
.filter-bar {
    background: #fff;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 1.5rem;
}
.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; min-width: 120px; }
.filter-group label { font-size: 0.78rem; font-weight: 600; color: #6b7280; margin-bottom: 0.2rem; }
.filter-group select,
.filter-group input {
    padding: 0.35rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
}
.filter-actions { flex-direction: row; gap: 0.4rem; align-self: flex-end; }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

/* === Hidden helper === */
.hidden { display: none !important; }

/* === Matrix table === */
.matrix-table { table-layout: auto; width: auto; min-width: 100%; }
.matrix-table th,
.matrix-table td { font-size: 0.78rem; padding: 0.45rem 0.5rem; text-align: right; white-space: nowrap; }
.matrix-table th:first-child,
.matrix-table td:first-child { text-align: left; }
.matrix-table thead th { font-size: 0.72rem; white-space: normal; min-width: 70px; vertical-align: bottom; }
.matrix-table thead th a { color: inherit; text-decoration: none; }
.matrix-table thead th a:hover { text-decoration: underline; }
.matrix-link { color: #2563eb; text-decoration: none; }
.matrix-link:hover { text-decoration: underline; }

/* === Modal === */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

/* === Extraction indicator === */
.btn-primary:disabled {
    opacity: 0.7;
    cursor: wait;
}

/* === Create-Invoice: service form === */
.form-subtitle {
    color: #6b7280;
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}
.section-heading {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}
.input-readonly {
    background: #f3f4f6;
    color: #6b7280;
    cursor: default;
}
.grand-total {
    margin-top: 1.5rem;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: right;
    max-width: 100%;
}

/* === Welcome / Dashboard === */
.welcome-page h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}
.welcome-subtitle {
    color: #6b7280;
    font-size: 1rem;
    margin-bottom: 2rem;
}
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}
.dashboard-card {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: box-shadow 0.15s, transform 0.15s;
    display: block;
    color: inherit;
}
.dashboard-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    transform: translateY(-2px);
    text-decoration: none;
}
.dashboard-card.disabled {
    opacity: 0.5;
    cursor: default;
}
.dashboard-card.disabled:hover {
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transform: none;
}
.card-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}
.dashboard-card h3 {
    font-size: 1.05rem;
    margin-bottom: 0.25rem;
}
.dashboard-card p {
    font-size: 0.82rem;
    color: #6b7280;
    margin: 0;
}
