/* Dark UI palette inspired by the provided screenshot */
:root {
    --bg: #0b1220;
    --panel: #0f172a;
    --panel-2: #101b34;
    --text: #e5e7eb;
    --muted: #9aa7bf;
    --border: #22304a;

    --blue-1: #1e4fb4;
    --blue-2: #183b86;
    --teal: #1dd6b6;
    --teal-2: #16b39a;
    --purple: #7c3aed;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
        "Segoe UI Emoji";
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    position: relative;
}

/* Keep the backdrop as a single fixed layer (prevents tiling/seams as content height changes) */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(1200px 600px at 20% -10%, rgba(30, 79, 180, 0.35), transparent 60%),
        radial-gradient(900px 500px at 90% 10%, rgba(29, 214, 182, 0.18), transparent 55%),
        var(--bg);
    background-repeat: no-repeat;
}

.container {
    width: min(1280px, 96vw);
    margin: 18px auto 40px;
}

/* Global search bar: sticky below topbar, hides when user scrolls down */
.search-bar-wrap {
    position: sticky;
    top: 54px; /* below topbar */
    z-index: 40;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(11, 18, 32, 0.97));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 0;
    transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}

.search-bar-wrap.is-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: min(900px, 92vw);
    margin: 0 auto;
    padding: 0 16px;
}

.search-bar__label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    font-weight: 700;
    white-space: nowrap;
}

.search-bar__input {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(3, 6, 14, 0.4);
    color: var(--text);
    font-size: 15px;
    outline: none;
}

.search-bar__input::placeholder {
    color: var(--muted);
}

.search-bar__input:focus {
    border-color: rgba(29, 214, 182, 0.6);
    box-shadow: 0 0 0 3px rgba(29, 214, 182, 0.15);
}

.search-bar__btn {
    cursor: pointer;
    padding: 12px 20px;
    border-radius: 12px;
    border: 1px solid rgba(29, 214, 182, 0.5);
    background: rgba(29, 214, 182, 0.15);
    color: var(--text);
    font-weight: 700;
    white-space: nowrap;
}

.search-bar__btn:hover {
    background: rgba(29, 214, 182, 0.25);
    border-color: rgba(29, 214, 182, 0.7);
}

/* Main layout: table left, filters sidebar right */
.main-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    margin-top: 14px;
}

.main-content {
    flex: 1;
    min-width: 0;
}

/* Filters sidebar: right, slides to narrow strip when collapsed so table expands */
.filters-sidebar {
    flex-shrink: 0;
    width: 260px;
    position: sticky;
    top: 80px;
    overflow: hidden;
    transition: width 0.3s ease-out;
}

.filters-sidebar.filters-sidebar--collapsed {
    width: 44px;
}

.filters-sidebar__toggle {
    width: 100%;
    min-width: 44px;
    cursor: pointer;
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    white-space: nowrap;
    transition: padding 0.2s ease, border-radius 0.2s ease;
}

.filters-sidebar.filters-sidebar--collapsed .filters-sidebar__toggle {
    justify-content: center;
    padding: 12px 8px;
    border-radius: 10px 0 0 10px;
}

.filters-sidebar__toggle-icon {
    display: none;
    width: 20px;
    height: 20px;
    color: currentColor;
}

.filters-sidebar.filters-sidebar--collapsed .filters-sidebar__toggle .filters-sidebar__toggle-text {
    display: none;
}

.filters-sidebar.filters-sidebar--collapsed .filters-sidebar__toggle .filters-sidebar__toggle-icon {
    display: block;
}

.filters-sidebar.filters-sidebar--collapsed .filters-sidebar__toggle::after {
    content: none;
}

.filters-sidebar__toggle:hover {
    border-color: rgba(29, 214, 182, 0.4);
    background: rgba(29, 214, 182, 0.08);
}

.filters-sidebar__toggle::after {
    content: "▼";
    font-size: 10px;
    opacity: 0.8;
    transition: transform 0.2s ease;
}

.filters-sidebar.filters-sidebar--collapsed .filters-sidebar__toggle::after {
    transform: none;
}

.filters-sidebar__panel {
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(15, 23, 42, 0.55);
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    transition: opacity 0.2s ease;
    white-space: nowrap;
}

.filters-sidebar.filters-sidebar--collapsed .filters-sidebar__panel {
    opacity: 0;
    visibility: hidden;
    position: absolute;
    pointer-events: none;
}

.filters {
    margin: 14px 0 14px;
}

.filters__form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(15, 23, 42, 0.55);
    border-radius: 14px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.filters-sidebar .filters__form {
    flex-direction: column;
    align-items: stretch;
}

.filters-sidebar .filters__actions {
    margin-left: 0;
}

.field {
    display: grid;
    gap: 6px;
    min-width: 180px;
}

.field__label {
    font-size: 12px;
    color: rgba(229, 231, 235, 0.78);
    letter-spacing: 0.3px;
    text-transform: uppercase;
    font-weight: 700;
}

.field__control {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(3, 6, 14, 0.35);
    color: rgba(229, 231, 235, 0.92);
    outline: none;
}

/* Do not use appearance:none on type=date — it removes the calendar control in Chromium */
.field__control:not(.field__control--date) {
    appearance: none;
}

.field__control:focus {
    border-color: rgba(29, 214, 182, 0.65);
    box-shadow: 0 0 0 3px rgba(29, 214, 182, 0.14);
}

/* Native calendar glyph is dark; invert so it reads as light on the dark field */
.field__control--date::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 1;
    padding: 6px;
    margin-left: 4px;
    filter: invert(1) brightness(1.15);
}

.field__control--date::-webkit-calendar-picker-indicator:hover {
    filter: invert(1) brightness(1.4);
}

.filters__actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-left: auto;
}

.btn {
    cursor: pointer;
    border: 1px solid rgba(29, 214, 182, 0.45);
    background: rgba(29, 214, 182, 0.14);
    color: rgba(229, 231, 235, 0.95);
    font-weight: 800;
    padding: 10px 14px;
    border-radius: 999px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    border-color: rgba(29, 214, 182, 0.8);
    box-shadow: 0 0 0 3px rgba(29, 214, 182, 0.14);
    background: rgba(29, 214, 182, 0.18);
}

.btn--ghost {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(15, 23, 42, 0.25);
}

.btn--ghost:hover {
    border-color: rgba(124, 58, 237, 0.40);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.14);
    background: rgba(124, 58, 237, 0.16);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(90deg, rgba(30, 79, 180, 0.95), rgba(24, 59, 134, 0.9));
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
}

.topbar__title {
    font-weight: 700;
    letter-spacing: 0.2px;
}

.topbar__meta {
    color: rgba(229, 231, 235, 0.85);
    font-size: 13px;
    margin-top: 2px;
}

.topbar__right {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
}

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    background: rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(6px);
}

.pill:hover {
    border-color: rgba(29, 214, 182, 0.45);
    box-shadow: 0 0 0 3px rgba(29, 214, 182, 0.15);
}

.table-wrap {
    background: linear-gradient(180deg, rgba(16, 27, 52, 0.9), rgba(15, 23, 42, 0.92));
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

table.results-table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    position: sticky;
    top: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(6px);
    color: rgba(229, 231, 235, 0.92);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sortable-th {
    white-space: nowrap;
}

a.th-sort {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

a.th-sort:hover {
    color: var(--teal);
}

.sort-indicator {
    font-size: 12px;
    color: var(--teal);
}

.sortable-th .sort-arrow {
    margin-left: 4px;
}

.sort-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    font-size: 14px;
    color: var(--muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
}

.sort-arrow:hover {
    color: var(--teal);
    background: rgba(29, 214, 182, 0.15);
}

th, td {
    padding: 12px 12px;
    text-align: left;
    vertical-align: top;
}

tbody tr {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(10, 16, 31, 0.12);
}

tbody tr:nth-child(2n) {
    background: rgba(16, 27, 52, 0.25);
}

tbody tr:hover {
    background: rgba(29, 214, 182, 0.08);
}

td.title-cell {
    font-weight: 600;
    color: rgba(229, 231, 235, 0.96);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    color: rgba(229, 231, 235, 0.86);
    font-size: 13px;
}

.link {
    color: var(--teal);
    font-weight: 700;
    text-decoration: none;
}

.link:hover {
    color: #7ff7e6;
    text-decoration: underline;
}

button.pdf-btn {
    cursor: pointer;
    border: 1px solid rgba(29, 214, 182, 0.45);
    background: rgba(29, 214, 182, 0.12);
    color: rgba(229, 231, 235, 0.95);
    font-weight: 700;
    padding: 8px 12px;
    border-radius: 999px;
}

button.pdf-btn:hover {
    border-color: rgba(29, 214, 182, 0.8);
    box-shadow: 0 0 0 3px rgba(29, 214, 182, 0.14);
    background: rgba(29, 214, 182, 0.18);
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background: rgba(3, 6, 14, 0.72);
    backdrop-filter: blur(4px);
}
.modal-content {
    background: linear-gradient(180deg, rgba(16, 27, 52, 0.96), rgba(15, 23, 42, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 14px;
    margin: 6vh auto;
    padding: 18px 18px 10px;
    width: min(920px, 92vw);
    max-height: 86vh;
    overflow: auto;
    box-shadow: 0 18px 64px rgba(0, 0, 0, 0.55);
}
#close {
    float: right;
    cursor: pointer;
    font-size: 24px;
    color: rgba(229, 231, 235, 0.85);
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

#close:hover {
    background: rgba(124, 58, 237, 0.18);
    color: rgba(229, 231, 235, 0.98);
}

#modal-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

#modal-table th {
    text-align: left;
    color: rgba(229, 231, 235, 0.9);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
    padding: 10px 10px;
}

#modal-table td {
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    padding: 10px 10px;
    color: rgba(229, 231, 235, 0.9);
}

#modal-table pre {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(3, 6, 14, 0.35);
    color: rgba(229, 231, 235, 0.9);
}

/* Auth pages */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.auth-card {
    width: min(400px, 92vw);
    padding: 28px;
    background: linear-gradient(180deg, rgba(16, 27, 52, 0.9), rgba(15, 23, 42, 0.92));
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.auth-title {
    margin: 0 0 8px;
    font-size: 24px;
    font-weight: 700;
}

.auth-subtitle {
    margin: 0 0 20px;
    font-size: 14px;
    color: var(--muted);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-actions {
    margin-top: 8px;
}

.auth-links {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-messages {
    margin-bottom: 16px;
}

.auth-message {
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 14px;
}

.auth-message--error {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.auth-message--success {
    background: rgba(29, 214, 182, 0.15);
    border: 1px solid rgba(29, 214, 182, 0.4);
    color: var(--teal);
}

.password-requirements {
    margin: 8px 0 0;
    padding: 0;
    list-style: none;
    font-size: 12px;
    color: var(--muted);
}

.password-requirements li {
    padding: 2px 0;
}

.password-requirements li.met {
    color: var(--teal);
}

.password-requirements li.met::before {
    content: "✓ ";
}

.field__hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #fca5a5;
}

/* User badge and logout */
.user-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.4);
    font-size: 13px;
}

.role-pill {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.role-pill--admin {
    background: rgba(124, 58, 237, 0.3);
    border: 1px solid rgba(124, 58, 237, 0.5);
}

.role-pill--editor {
    background: rgba(29, 214, 182, 0.2);
    border: 1px solid rgba(29, 214, 182, 0.4);
}

.role-pill--viewer {
    background: rgba(154, 167, 191, 0.2);
    border: 1px solid rgba(154, 167, 191, 0.4);
}

/* Admin add-user section */
.admin-add-user {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(16, 27, 52, 0.6), rgba(15, 23, 42, 0.7));
}

.admin-add-user__form {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    align-items: end;
}

.admin-add-user__form .field {
    margin: 0;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    cursor: help;
    position: relative;
}

.info-icon:hover {
    color: var(--teal);
    background: rgba(29, 214, 182, 0.2);
}

.info-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    white-space: pre-line;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
    z-index: 100;
    min-width: 200px;
}

.info-icon:hover::after {
    opacity: 1;
    visibility: visible;
}

.admin-add-user__form .btn {
    align-self: end;
}

.btn--danger {
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.btn--danger:hover {
    border-color: rgba(239, 68, 68, 0.8);
    background: rgba(239, 68, 68, 0.25);
}

/* Loading bar */
.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 9999;
    background: rgba(29, 214, 182, 0.2);
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.loading-bar.is-active {
    opacity: 1;
}

.loading-bar.is-active::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 30%;
    background: var(--teal);
    animation: loading-bar 1.2s ease-in-out infinite;
}

@keyframes loading-bar {
    0% { left: -30%; }
    100% { left: 100%; }
}
