/*
 * S3 File Viewer - custom styles (blue and white theme).
 *
 * Bootstrap 5 does most of the work; this file only adds small touches.
 * Keep ALL custom CSS here: inline style="" attributes are blocked by the
 * Content-Security-Policy.
 *
 * Sections:
 *   1. Colours          6. Folder cards       11. Error pages
 *   2. Page + header    7. File table         12. Loading feedback
 *   3. Footer           8. File icons
 *   4. Login page       9. Preview page
 *   5. Breadcrumb      10. Empty states
 */

/* ---------- 1. Colours ---------- */

:root {
    --app-blue: #1a5fb4;
    --app-blue-dark: #134a8e;
    --app-blue-light: #e8f0fb;
    --app-blue-lighter: #f3f7fd;
    --app-border: #dbe5f1;
    --app-text: #1f2d3d;
    --app-text-muted: #5f6f82;

    /* Make Bootstrap's "primary" our blue. */
    --bs-primary: #1a5fb4;
    --bs-primary-rgb: 26, 95, 180;
    --bs-link-color: #1a5fb4;
    --bs-link-color-rgb: 26, 95, 180;
    --bs-link-hover-color: #134a8e;
    --bs-link-hover-color-rgb: 19, 74, 142;
    --bs-body-bg: #f5f8fc;
    --bs-body-color: #1f2d3d;
    --bs-border-radius: 0.5rem;
}

.btn-primary {
    --bs-btn-bg: var(--app-blue);
    --bs-btn-border-color: var(--app-blue);
    --bs-btn-hover-bg: var(--app-blue-dark);
    --bs-btn-hover-border-color: var(--app-blue-dark);
    --bs-btn-active-bg: var(--app-blue-dark);
    --bs-btn-active-border-color: var(--app-blue-dark);
}

.btn-outline-primary {
    --bs-btn-color: var(--app-blue);
    --bs-btn-border-color: var(--app-blue);
    --bs-btn-hover-bg: var(--app-blue);
    --bs-btn-hover-border-color: var(--app-blue);
    --bs-btn-active-bg: var(--app-blue-dark);
    --bs-btn-active-border-color: var(--app-blue-dark);
}

/* Cards and tables are white on the pale-blue page background. */
.card {
    --bs-card-bg: #fff;
}

.table {
    --bs-table-bg: #fff;
}

/* ---------- 2. Page + header ---------- */

.app-header {
    background: #fff;
    border-top: 4px solid var(--app-blue);
    border-bottom: 1px solid var(--app-border);
}

.app-logo {
    height: 40px;
    width: auto;
}

.app-title {
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--app-blue-dark);
}

/* Round badge with the user's initials, e.g. "PS" */
.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--app-blue-light);
    color: var(--app-blue-dark);
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.app-user-email {
    color: var(--app-text-muted);
    font-size: 0.85rem;
}

.user-divider {
    width: 1px;
    height: 2rem;
    background: var(--app-border);
}

/* ---------- 3. Footer ---------- */

.app-footer {
    background: #fff;
    border-top: 1px solid var(--app-border);
    color: var(--app-text-muted);
    font-size: 0.9rem;
}

/* ---------- 4. Login page ---------- */

.login-page {
    background: var(--app-blue-light);
}

.login-card {
    max-width: 440px;
    border: 1px solid var(--app-border);
    border-top: 4px solid var(--app-blue);
    border-radius: 0.75rem;
    box-shadow: 0 0.5rem 1.5rem rgba(19, 74, 142, 0.08);
}

.login-logo {
    height: 88px;
    width: auto;
}

.login-title {
    color: var(--app-blue-dark);
    font-weight: 700;
}

.login-description {
    color: var(--app-text-muted);
    font-size: 1.05rem;
}

.login-error-icon .bi {
    font-size: 2.5rem;
    color: #d98a1c;
}

/* ---------- 5. Breadcrumb ---------- */

.app-breadcrumb {
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 0.5rem;
    padding: 0.65rem 1rem;
}

.app-breadcrumb .breadcrumb {
    margin: 0;
    flex-wrap: wrap;
    font-size: 0.95rem;
}

.app-breadcrumb .breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    color: #9aabbf;
}

.app-breadcrumb a {
    text-decoration: none;
}

.app-breadcrumb a:hover,
.app-breadcrumb a:focus {
    text-decoration: underline;
}

/* The folder you are in: bold, not a link. */
.app-breadcrumb .breadcrumb-item.active {
    color: var(--app-text);
    font-weight: 600;
}

/* "Current folder" heading above the listing */
.current-folder-label {
    color: var(--app-text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Search box under "Current folder" */
.folder-search {
    max-width: 640px;
}

.folder-search .input-group-text {
    background: #fff;
    color: var(--app-text-muted);
}

.search-summary {
    font-size: 0.95rem;
}

/* ---------- 6. Folder cards ---------- */

.app-card {
    border: 1px solid var(--app-border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(19, 74, 142, 0.05);
}

.app-card > .card-header {
    background: #fff;
    border-bottom: 1px solid var(--app-border);
    font-weight: 600;
    color: var(--app-blue-dark);
    padding: 0.75rem 1rem;
}

.section-count {
    background: var(--app-blue-light);
    color: var(--app-blue-dark);
    font-weight: 600;
}

.folder-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--app-border);
    border-radius: 0.6rem;
    background: #fff;
    color: var(--app-text);
    text-decoration: none;
    height: 100%;
}

.folder-card:hover,
.folder-card:focus {
    background: var(--app-blue-lighter);
    border-color: var(--app-blue);
    color: var(--app-text);
}

.folder-card:focus-visible {
    outline: 3px solid rgba(26, 95, 180, 0.35);
    outline-offset: 1px;
}

.folder-card .bi {
    font-size: 1.75rem;
    color: #e0a526;          /* classic folder yellow: easy to recognise */
    flex-shrink: 0;
}

.folder-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- 7. File table ---------- */

.file-table {
    margin-bottom: 0;
}

.file-table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--app-text-muted);
    font-weight: 600;
    background: #fafcff;
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
}

.file-table td {
    vertical-align: middle;
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
}

.file-link {
    color: var(--app-text);
    text-decoration: none;
    font-weight: 500;
    word-break: break-word;
}

.file-link:hover,
.file-link:focus {
    color: var(--app-blue);
    text-decoration: underline;
}

.sort-link {
    color: inherit;
    text-decoration: none;
    white-space: nowrap;
}

.sort-link:hover,
.sort-link:focus {
    color: var(--app-blue);
}

/* File extension badge, e.g. "PDF" */
.file-ext {
    background: var(--app-blue-light);
    color: var(--app-blue-dark);
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
}

/* ---------- 8. File icons (one calm colour per kind of file) ---------- */

.file-icon {
    font-size: 1.35rem;
    color: #6b7c93;          /* any other file: grey */
    flex-shrink: 0;
}

.file-icon.bi-file-earmark-pdf { color: #c62828; }
.file-icon.bi-file-earmark-image { color: #2e7d32; }
.file-icon.bi-filetype-json,
.file-icon.bi-file-earmark-code { color: #6a4fb3; }
.file-icon.bi-filetype-csv,
.file-icon.bi-file-earmark-excel { color: #1e7b4a; }
.file-icon.bi-file-earmark-text { color: var(--app-blue); }
.file-icon.bi-file-earmark-word { color: #2b579a; }
.file-icon.bi-file-earmark-ppt { color: #c55a11; }

/* ---------- 9. Preview page ---------- */

.preview-file-name {
    word-break: break-word;
}

/* PDFs and images: a spinner sits BEHIND the file and is covered once it has loaded. */
.preview-loading {
    position: relative;
    min-height: 200px;
}

.preview-loading > .preview-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 0;
    color: var(--app-text-muted);
    text-align: center;
}

.preview-loading > iframe,
.preview-loading > .preview-image-wrap {
    position: relative;
    z-index: 1;
}

.preview-frame {
    display: block;
    width: 100%;
    height: 78vh;
    border: 0;
    background: transparent;
}

.preview-image-wrap {
    min-height: 200px;
}

.preview-image {
    max-height: 78vh;
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #eef1f5 25%, transparent 25%),
        linear-gradient(-45deg, #eef1f5 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #eef1f5 75%),
        linear-gradient(-45deg, transparent 75%, #eef1f5 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    border: 1px solid var(--app-border);
}

.text-preview {
    max-height: 78vh;
    overflow: auto;
    padding: 1rem 1.25rem;
    background: #fbfcfe;
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;       /* wrap long lines instead of scrolling sideways */
    word-break: break-word;
    border-bottom-left-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
}

.csv-preview {
    max-height: 78vh;
    overflow: auto;
}

.csv-preview th {
    position: sticky;            /* headings stay visible while scrolling */
    top: 0;
    background: var(--app-blue-light);
    color: var(--app-blue-dark);
    white-space: nowrap;
}

.csv-preview td {
    font-size: 0.875rem;
    white-space: nowrap;
}

/* ---------- 10. Empty states ---------- */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-state > .bi {
    font-size: 3rem;
    color: #9fb7d6;
}

/* ---------- 11. Error pages ---------- */

.error-card {
    max-width: 620px;
}

.error-alert {
    display: flex;
    gap: 0.9rem;
    align-items: flex-start;
    text-align: left;
}

.error-alert > .bi {
    font-size: 1.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.error-code {
    color: var(--app-text-muted);
    font-size: 0.8rem;
}

/* ---------- 12. Loading feedback ---------- */

/*
 * A thin blue bar at the very top of the window, shown while the next page
 * loads (see public/js/app.js). Hidden the rest of the time.
 */
.page-loading-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 2000;
    overflow: hidden;
    background: var(--app-blue-light);
}

.page-loading-bar::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -40%;
    width: 40%;
    background: var(--app-blue);
    animation: page-loading 1.1s ease-in-out infinite;
}

body.is-loading .page-loading-bar {
    display: block;
}

body.is-loading {
    cursor: progress;
}

@keyframes page-loading {
    from { left: -40%; }
    to { left: 100%; }
}

/* People who ask their computer for less motion get a still bar. */
@media (prefers-reduced-motion: reduce) {
    .page-loading-bar::after {
        animation: none;
        left: 0;
        width: 100%;
    }
}
