/* ==========================================================================
   1. GLOBAL UTILITY THEME (Pure White, Wikipedia/CanLII Precision)
   ========================================================================== */
:root {
    --bg: #ffffff;
    --text-main: #111111;
    --text-muted: #555555;
    --link: #0b57d0;
    --border: #e2e2e2;
    --border-dark: #cccccc;
    --hover-bg: #f8f9fa;
    --tag-bg: #f1f3f4;
    
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-serif: 'Instrument Serif', Georgia, serif;
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-ui);
    max-width: 1120px;
    margin: 20px auto 0 auto;
    padding: 0 24px;
    color: var(--text-main);
    background-color: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    
    /* Glues footer to bottom of viewport on short pages */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Ensure children never shrink in flex column */
.top-nav-bar,
header,
.search-section,
main,
footer {
    width: 100%;
}
/* Top Utility Nav for Homepage */
.top-nav-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 8px 0;
    margin-bottom: 20px;
}

.nav-btn {
    background: none;
    border: none;
    font-family: var(--font-ui);
    font-size: 0.82rem;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0;
}

.nav-btn:hover {
    color: var(--text-main);
}

/* Saved Drawer Styles */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.drawer-overlay.active {
    opacity: 1;
    visibility: visible;
}

.drawer-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    max-width: 360px;
    height: 100%;
    background: #ffffff;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
    padding: 24px;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.drawer-overlay.active .drawer-panel {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.drawer-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.drawer-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
}

.drawer-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 20px 0;
}

.library-item {
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.library-item a {
    color: var(--link);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}

.library-item-del {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 1rem;
}

.library-item-del:hover {
    color: #b91c1c;
}

/* ==========================================================================
   2. HEADER
   ========================================================================== */
header {
    margin-bottom: 32px;
    text-align: center;
}

header h1 {
    font-family: var(--font-serif);
    font-size: 3.2rem;
    font-weight: 400;
    margin: 0 0 6px 0;
    letter-spacing: -0.01em;
    color: var(--text-main);
}

header p {
    font-family: var(--font-ui);
    color: var(--text-muted);
    font-size: 0.95rem;
    margin: 0;
}

/* ==========================================================================
   3. SEARCH & DROPDOWN
   ========================================================================== */
.search-section {
    max-width: 720px;
    width: 100%;
    margin: 0 auto 40px auto;
    position: relative;
}

.search-wrapper {
    position: relative;
    width: 100%;
}

#search-input {
    width: 100%;
    padding: 14px 18px;
    font-size: 1rem;
    font-family: var(--font-ui);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    background: #ffffff;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.15s ease;
}

#search-input:focus {
    border-color: var(--text-main);
}

.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: #ffffff;
    border: 1px solid var(--border-dark);
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    display: none;
    z-index: 500;
    max-height: 380px;
    overflow-y: auto;
}

.search-dropdown.active {
    display: block;
}

.dropdown-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    text-decoration: none;
    display: block;
    transition: background-color 0.1s ease;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background-color: var(--hover-bg);
}

.dropdown-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--link);
    margin-bottom: 2px;
}

.dropdown-meta {
    font-family: var(--font-ui);
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* Filters */
.filter-row {
    display: flex;
    justify-content: flex-start;
    gap: 8px;
    margin-top: 12px;
}

.filter-btn {
    background: transparent;
    border: 1px solid var(--border);
    padding: 5px 12px;
    font-size: 0.8rem;
    font-family: var(--font-ui);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
}

.filter-btn.active {
    background: var(--text-main);
    border-color: var(--text-main);
    color: #ffffff;
}

.filter-btn:hover:not(.active) {
    border-color: var(--text-main);
    color: var(--text-main);
}

/* ==========================================================================
   4. AUTHORITIES LEDGER
   ========================================================================== */
.ledger-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid var(--text-main);
    padding-bottom: 8px;
    margin-bottom: 0;
}

.ledger-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.01em;
}

.count-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-ui);
}

.table-container {
    width: 100%;
    overflow-x: auto;
}

.authorities-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.authorities-table th {
    padding: 10px 12px;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.authorities-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.authorities-table tbody tr:hover {
    background-color: var(--hover-bg);
}

.col-date {
    width: 110px;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.col-title {
    width: auto;
}

.col-title a {
    color: var(--link);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
}

.col-title a:hover {
    text-decoration: underline;
}

.table-citation {
    display: block;
    font-family: var(--font-ui);
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.col-type {
    width: 90px;
    text-align: right;
}

.type-pill {
    font-size: 0.72rem;
    background: var(--tag-bg);
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

/* ==========================================================================
   5. FOOTER & MODAL
   ========================================================================== */
/* Main pushes footer to the bottom */
main {
    flex: 1 0 auto;
}

/* Footer sits cleanly at the bottom */
footer {
    max-width: 1120px;
    margin-top: auto; /* Pushes to bottom */
    margin-bottom: 24px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
}

.link-btn {
    background: none;
    border: none;
    color: var(--link);
    text-decoration: underline;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: #ffffff;
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.modal-card h3 {
    margin: 0 0 4px 0;
    font-size: 1.15rem;
}

.modal-card p {
    margin: 0 0 16px 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.form-group input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.88rem;
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    outline: none;
}

.file-drop-zone {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 10px 14px;
    background: #fafafa;
    border: 1px dashed var(--border-dark);
    border-radius: 4px;
    cursor: pointer;
}

.file-drop-zone input[type="file"] {
    display: none;
}

.file-drop-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

.modal-actions button {
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.82rem;
    cursor: pointer;
}

#modal-cancel {
    background: #ffffff;
    border: 1px solid var(--border);
}

#modal-submit-btn {
    background: var(--text-main);
    border: 1px solid var(--text-main);
    color: #ffffff;
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #111111;
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.82rem;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 1100;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   MOBILE RESPONSIVE TABLE (Phones under 768px)
   ========================================================================== */
@media (max-width: 768px) {
    body {
        padding: 0 16px;
        margin: 16px auto 40px auto;
    }

    header h1 {
        font-size: 2.2rem;
    }

    .authorities-table thead {
        display: none;
    }

    .authorities-table, 
    .authorities-table tbody, 
    .authorities-table tr {
        display: block;
        width: 100%;
    }

    .authorities-table tr {
        padding: 14px 0;
        border-bottom: 1px solid var(--border);
        position: relative;
    }

    .authorities-table td {
        display: block;
        padding: 0;
        border: none;
    }

    .col-type {
        position: absolute;
        top: 14px;
        right: 0;
        text-align: right;
    }

    .col-title {
        padding-right: 60px;
        margin-bottom: 4px;
    }

    .col-title a {
        font-size: 1rem;
        line-height: 1.35;
    }

    .table-citation {
        font-size: 0.82rem;
        margin-top: 4px;
        line-height: 1.4;
    }

    .col-date {
        font-size: 0.75rem;
        margin-top: 6px;
        color: var(--text-muted);
    }
}