/* Download Portal theme.
 *
 * Layered on top of Bootstrap 5.3 rather than replacing it: only tokens,
 * surfaces and a few components are restyled, so the existing markup and the
 * built-in dark mode keep working.
 */

:root {
    --portal-radius: 14px;
    --portal-radius-sm: 10px;
    --portal-surface: #ffffff;
    --portal-canvas: #f5f6f8;
    --portal-border: rgba(16, 24, 40, .09);
    --portal-ring: rgba(16, 24, 40, .06);
    --portal-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .18);
    --portal-shadow-lift: 0 2px 4px rgba(16, 24, 40, .05), 0 16px 32px -16px rgba(16, 24, 40, .26);
    --portal-accent: var(--bs-primary);
    --portal-muted: #667085;
}

[data-bs-theme="dark"] {
    --portal-surface: #171a21;
    --portal-canvas: #0f1116;
    --portal-border: rgba(255, 255, 255, .09);
    --portal-ring: rgba(255, 255, 255, .05);
    --portal-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
    --portal-shadow-lift: 0 2px 4px rgba(0, 0, 0, .45), 0 18px 36px -18px rgba(0, 0, 0, .75);
    --portal-muted: #98a2b3;
}

/* ---------------------------------------------------------------- Base --- */

body {
    min-height: 100vh;
    background: var(--portal-canvas);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.bg-body-tertiary {
    background: var(--portal-canvas) !important;
}

h1, h2, h3, h4, h5, h6, .display-6 {
    letter-spacing: -.018em;
}

.display-6 {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.text-body-secondary {
    color: var(--portal-muted) !important;
}

/* ------------------------------------------------------------- Navbar --- */

.navbar.bg-primary {
    background: linear-gradient(100deg,
        var(--bs-primary) 0%,
        color-mix(in srgb, var(--bs-primary) 82%, #000) 100%) !important;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, var(--portal-shadow);
    padding-block: .7rem;
}

[data-bs-theme="dark"] .navbar.bg-primary {
    --bs-bg-opacity: 1;
    background: linear-gradient(100deg, #1c2230 0%, #141821 100%) !important;
}

.navbar-brand.fw-semibold {
    font-weight: 650 !important;
    letter-spacing: -.02em;
}

.navbar .btn {
    border-radius: 999px;
    font-weight: 500;
    padding-inline: .85rem;
}

.navbar .btn-outline-light {
    border-color: rgba(255, 255, 255, .28);
}

.navbar .btn-outline-light:hover {
    background: rgba(255, 255, 255, .16);
    border-color: rgba(255, 255, 255, .4);
}

.navbar .badge {
    border-radius: 999px;
    font-weight: 500;
    padding: .4em .75em;
}

/* -------------------------------------------------------------- Cards --- */

.card {
    border-radius: var(--portal-radius);
    border: 1px solid var(--portal-border);
    background: var(--portal-surface);
    box-shadow: var(--portal-shadow);
    transition: box-shadow .18s ease, transform .18s ease;
}

.card.shadow-sm {
    box-shadow: var(--portal-shadow) !important;
}

[data-bs-theme="dark"] .shadow-sm {
    box-shadow: var(--portal-shadow) !important;
}

.card-header {
    border-bottom: 1px solid var(--portal-border);
    background: transparent !important;
    border-top-left-radius: var(--portal-radius) !important;
    border-top-right-radius: var(--portal-radius) !important;
    font-weight: 600;
}

.card-footer {
    border-top: 1px solid var(--portal-border);
    background: transparent !important;
}

/* Summary tiles: quieter label, prominent figure. */
.card-body > .text-uppercase.small.fw-semibold {
    letter-spacing: .07em;
    font-size: .69rem;
    color: var(--portal-muted) !important;
}

/* ------------------------------------------------------------ Buttons --- */

.btn {
    border-radius: var(--portal-radius-sm);
    font-weight: 500;
    transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    box-shadow: 0 1px 2px rgba(16, 24, 40, .12);
}

.btn-sm {
    border-radius: 8px;
}

/* ------------------------------------------------------- File listing --- */

.list-group-item {
    border-color: var(--portal-border);
    background: transparent;
    padding: .85rem 1.1rem;
    transition: background-color .14s ease;
}

.list-group-item:hover {
    background: color-mix(in srgb, var(--bs-primary) 5%, transparent);
}

.list-group-flush > .list-group-item:first-child {
    border-top-left-radius: var(--portal-radius);
    border-top-right-radius: var(--portal-radius);
}

.list-group-flush > .list-group-item:last-child {
    border-bottom-left-radius: var(--portal-radius);
    border-bottom-right-radius: var(--portal-radius);
}

.file-link {
    color: var(--bs-body-color);
    font-weight: 500;
}

.file-link:hover {
    color: var(--portal-accent);
}

/* Type chip: the file extension as a small square, in place of an emoji. */
.entry-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--portal-radius-sm);
    background: color-mix(in srgb, var(--bs-body-color) 6%, transparent);
    border: 1px solid var(--portal-border);
    color: var(--portal-muted);
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    overflow: hidden;
}

.entry-chip-media {
    background: color-mix(in srgb, var(--bs-primary) 12%, transparent);
    border-color: color-mix(in srgb, var(--bs-primary) 22%, transparent);
    color: color-mix(in srgb, var(--bs-primary) 80%, var(--bs-body-color));
}

.entry-chip-folder {
    background: color-mix(in srgb, var(--bs-warning) 16%, transparent);
    border-color: color-mix(in srgb, var(--bs-warning) 26%, transparent);
    color: color-mix(in srgb, var(--bs-warning) 62%, var(--bs-body-color));
}

/* Lets long filenames truncate instead of forcing the row wider. */
.min-w-0 {
    min-width: 0;
}

/* Dense listing: more files visible without scrolling. */
.list-dense .list-group-item {
    padding: .45rem .85rem;
    line-height: 1.35;
}

.list-dense .entry-chip {
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 7px;
    font-size: .55rem;
}

.list-dense .entry-chip svg {
    width: 15px;
    height: 15px;
}

.list-dense .btn-sm {
    --bs-btn-padding-y: .15rem;
    --bs-btn-padding-x: .5rem;
    --bs-btn-font-size: .78rem;
}

.list-dense .entry-meta {
    font-size: .78rem;
}

/* Below the button row the metadata would collide, so let it wrap away. */
@media (max-width: 575.98px) {
    .list-dense .entry-meta {
        margin-left: 0 !important;
        width: 100%;
    }
}

/* ------------------------------------------------------------- Tables --- */

.table {
    --bs-table-border-color: var(--portal-border);
}

.table th {
    white-space: nowrap;
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--portal-muted);
}

.table > thead > tr > th {
    border-bottom: 1px solid var(--portal-border);
    padding-block: .8rem;
}

.table > tbody > tr > td {
    padding-block: .8rem;
    vertical-align: middle;
}

.table-hover > tbody > tr:hover > * {
    --bs-table-accent-bg: color-mix(in srgb, var(--bs-primary) 4%, transparent);
    background-color: color-mix(in srgb, var(--bs-primary) 4%, transparent);
}

.table td .fw-semibold {
    font-weight: 600;
}

/* Keep numeric columns readable when they line up vertically. */
.table td:nth-child(2),
.table td:nth-child(3),
.table td:nth-child(4),
.table td:nth-child(5) {
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ Badges --- */

.badge {
    border-radius: 7px;
    font-weight: 500;
    letter-spacing: .01em;
    padding: .38em .6em;
}

.text-bg-success {
    background: color-mix(in srgb, var(--bs-success) 15%, transparent) !important;
    color: color-mix(in srgb, var(--bs-success) 78%, var(--bs-body-color)) !important;
}

.text-bg-warning {
    background: color-mix(in srgb, var(--bs-warning) 20%, transparent) !important;
    color: color-mix(in srgb, var(--bs-warning) 68%, var(--bs-body-color)) !important;
}

.text-bg-danger {
    background: color-mix(in srgb, var(--bs-danger) 15%, transparent) !important;
    color: color-mix(in srgb, var(--bs-danger) 80%, var(--bs-body-color)) !important;
}

.text-bg-info {
    background: color-mix(in srgb, var(--bs-info) 18%, transparent) !important;
    color: color-mix(in srgb, var(--bs-info) 72%, var(--bs-body-color)) !important;
}

.text-bg-secondary,
.text-bg-dark {
    background: color-mix(in srgb, var(--bs-body-color) 9%, transparent) !important;
    color: var(--portal-muted) !important;
}

/* Keep the navbar's status pills legible against the gradient. */
.navbar .text-bg-success,
.navbar .text-bg-warning,
.navbar .text-bg-info {
    background: rgba(255, 255, 255, .18) !important;
    color: #fff !important;
}

/* ------------------------------------------------------------- Forms --- */

.form-label {
    font-size: .8rem;
    font-weight: 550;
    color: var(--portal-muted);
    margin-bottom: .3rem;
}

.form-control,
.form-select {
    border-radius: var(--portal-radius-sm);
    border-color: var(--portal-border);
    padding: .5rem .7rem;
    transition: border-color .14s ease, box-shadow .14s ease;
}

/* A select draws its caret as a background image on the right, so the right
   padding above has to leave room for it -- otherwise the value sits underneath
   the arrow. Bootstrap reserves 2.25rem; keep that and only restyle the rest. */
.form-select {
    padding-right: 2.25rem;
    background-position: right .7rem center;
}

.form-control:focus,
.form-select:focus {
    border-color: color-mix(in srgb, var(--bs-primary) 55%, transparent);
    box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--bs-primary) 14%, transparent);
}

/* --------------------------------------------------------- Breadcrumb --- */

.breadcrumb {
    background: transparent;
    padding: 0;
    margin-bottom: 1rem;
    font-size: .92rem;
}

.breadcrumb-item a {
    color: var(--portal-muted);
    text-decoration: none;
}

.breadcrumb-item a:hover {
    color: var(--portal-accent);
    text-decoration: underline;
}

/* --------------------------------------------------------------- Misc --- */

.alert {
    border-radius: var(--portal-radius);
    border: 1px solid var(--portal-border);
}

.progress {
    border-radius: 999px;
    height: .5rem;
    background: color-mix(in srgb, var(--bs-body-color) 8%, transparent);
}

.pagination .page-link {
    border-radius: 8px;
    margin-inline: 1px;
    border-color: transparent;
    color: var(--bs-body-color);
}

.pagination .page-item.active .page-link {
    background: var(--bs-primary);
    border-color: var(--bs-primary);
}

.theme-toggle {
    min-width: 5.5rem;
}

/* ------------------------------------------------- Navbar sync widget --- */

.sync-widget {
    position: relative;
}

.sync-chip {
    cursor: default;
    user-select: none;
}

.sync-chip:focus-visible {
    outline: 2px solid rgba(255, 255, 255, .8);
    outline-offset: 2px;
}

.sync-detail {
    position: absolute;
    top: calc(100% + .5rem);
    right: 0;
    z-index: 1040;
    min-width: 15rem;
    padding: .7rem .85rem;
    border-radius: var(--portal-radius-sm);
    border: 1px solid var(--portal-border);
    background: var(--portal-surface);
    color: var(--bs-body-color);
    font-size: .82rem;
    line-height: 1.6;
    /* Hidden by default; opacity rather than display so it can transition and
       still be reachable by assistive technology when revealed. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-.25rem);
    transition: opacity .12s ease, transform .12s ease, visibility .12s;
}

/* Revealed on hover, and on keyboard focus anywhere inside the widget. */
.sync-widget:hover .sync-detail,
.sync-widget:focus-within .sync-detail {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

@media (max-width: 575.98px) {
    .sync-detail {
        right: auto;
        left: 0;
    }
}

/* Respect a reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
    .btn,
    .card,
    .list-group-item,
    .form-control,
    .form-select {
        transition: none;
    }
}
