/* =========================================================
   Archery Score Aggregator — styles.css
   Mobile-first, no external fonts, CSS custom properties
   ========================================================= */

/* ----- Custom Properties ----- */
:root {
    --color-bg:          #f8f9fa;
    --color-surface:     #ffffff;
    --color-border:      #dee2e6;
    --color-text:        #212529;
    --color-text-muted:  #6c757d;
    --color-nav-bg:      #1a2332;
    --color-nav-text:    #ffffff;
    --color-nav-link:    #e0e7ef;
    --color-accent:      #2563eb;
    --color-accent-text: #ffffff;

    --color-filter-bg:       #e9ecef;
    --color-filter-hover:    #ced4da;
    --color-filter-active-bg:#2563eb;
    --color-filter-active-fg:#ffffff;

    --color-row-alt:    #f2f5f8;
    --color-row-hover:  #dce8f8;

    --color-pct-high-bg:  #d1fae5;
    --color-pct-high-fg:  #065f46;
    --color-pct-mid-bg:   #fef3c7;
    --color-pct-mid-fg:   #92400e;
    --color-pct-low-bg:   #fee2e2;
    --color-pct-low-fg:   #991b1b;

    --font-stack: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
                  Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans",
                  "Helvetica Neue", sans-serif;

    --max-width: 960px;
    --radius:    4px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
}

/* ----- Reset / Base ----- */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-stack);
    line-height: 1.5;
}

/* ----- Layout Container ----- */
.container {
    width: 100%;
    max-width: var(--max-width);
    margin-inline: auto;
    padding-inline: 1rem;
}

/* ----- Navigation Bar ----- */
.navbar {
    background: var(--color-nav-bg);
    padding: .75rem 0;
    box-shadow: var(--shadow-sm);
}

.nav-brand {
    color: var(--color-nav-text);
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: .02em;
}

.nav-brand:hover {
    color: var(--color-nav-link);
}

/* ----- Main Content Area ----- */
main.container {
    padding-top: 1.5rem;
    padding-bottom: 2rem;
}

/* ----- Footer ----- */
.footer {
    border-top: 1px solid var(--color-border);
    padding: 1rem 0;
    color: var(--color-text-muted);
    font-size: .85rem;
}

.footer p {
    margin: 0;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
}

.bmc-wrap {
    transform: scale(.6);
    transform-origin: right center;
    flex-shrink: 0;
}

/* ----- Page Header ----- */
.page-header {
    margin-bottom: 1.25rem;
}

.page-header h1 {
    margin: 0 0 .25rem;
    font-size: 1.75rem;
}

.page-header .subtitle {
    margin: .25rem 0 0;
    color: var(--color-text-muted);
    font-size: 1rem;
}

.page-header .meta {
    margin: .25rem 0 0;
    color: var(--color-text-muted);
    font-size: .9rem;
}

/* ----- Back Link ----- */
.back-link {
    margin: 0 0 .5rem;
    font-size: .9rem;
}

.back-link a {
    color: var(--color-accent);
    text-decoration: none;
}

.back-link a:hover {
    text-decoration: underline;
}

/* ----- Archer Search ----- */
.search-wrap {
    margin-bottom: 1.25rem;
}

.search-wrap form {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.search-input {
    flex: 1 1 180px;
    min-width: 0;
    max-width: 320px;
    padding: .6rem 1rem;
    font-size: 1rem;
    font-family: var(--font-stack);
    color: var(--color-text);
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.search-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

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

.search-btn {
    padding: .6rem 1.25rem;
    font-size: 1rem;
    font-family: var(--font-stack);
    color: #fff;
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
}

.search-btn:hover {
    opacity: .88;
}

.search-clear-btn {
    padding: .6rem 1rem;
    font-size: 1rem;
    font-family: var(--font-stack);
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    text-decoration: none;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.search-clear-btn:hover {
    background: var(--color-filter-bg);
    color: var(--color-text);
    border-color: #adb5bd;
}

/* ----- Discipline Filter Bar ----- */
.filter-bar {
    display: flex;
    gap: .5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.filter-btn {
    display: inline-block;
    padding: .35rem .85rem;
    border-radius: var(--radius);
    background: var(--color-filter-bg);
    color: var(--color-text);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    border: 1px solid var(--color-border);
    transition: background .15s, border-color .15s;
}

.filter-btn:hover {
    background: var(--color-filter-hover);
    border-color: #adb5bd;
}

.filter-btn.active {
    background: var(--color-filter-active-bg);
    color: var(--color-filter-active-fg);
    border-color: var(--color-filter-active-bg);
}

/* ----- Tables ----- */
.table-wrap {
    overflow-x: auto;          /* horizontal scroll on small screens */
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    font-size: .9rem;
}

thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

thead tr {
    background: var(--color-nav-bg);
    color: var(--color-nav-text);
}

thead th {
    padding: .65rem .85rem;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    border-bottom: 2px solid var(--color-border);
}

tbody tr:nth-child(even) {
    background: var(--color-row-alt);
}

tbody tr {
    cursor: pointer;
}

tbody tr:hover {
    background: var(--color-row-hover);
}

tbody td {
    padding: .55rem .85rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

/* ----- Sortable Column Headers ----- */
thead th:has(.sort-link) {
    padding: 0;          /* reset — padding lives on the inner .sort-link */
}

.sort-link {
    display: block;
    padding: .65rem .85rem;
    color: #fff;         /* explicit white — overrides browser default link blue */
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}

.sort-link:hover {
    color: #fff;
    background: rgba(255,255,255,.1);
}

.sort-link.sort-active {
    color: #fff;
    background: rgba(255,255,255,.08);
}

.sort-arrow {
    font-size: .75em;
    margin-left: .25em;
}

.sort-arrow-inactive {
    opacity: .35;
}

/* ----- Archer Name Links in Table ----- */
.archer-link {
    color: inherit;
    text-decoration: none;
    font-weight: 500;
}

.archer-link:hover {
    text-decoration: underline;
}

/* ----- Score Percentage Colouring ----- */
td.pct-high {
    background: var(--color-pct-high-bg);
    color: var(--color-pct-high-fg);
    font-weight: 600;
}

td.pct-mid {
    background: var(--color-pct-mid-bg);
    color: var(--color-pct-mid-fg);
    font-weight: 600;
}

td.pct-low {
    background: var(--color-pct-low-bg);
    color: var(--color-pct-low-fg);
    font-weight: 600;
}

/* ----- Elimination Round Rows ----- */
tr.elim-row td {
    background: #f0f4f8;
    color: var(--color-text-muted);
    font-style: italic;
}

.elim-category {
    display: block;
    font-size: .8rem;
    font-style: normal;
    color: var(--color-text-muted);
    margin-top: .1rem;
}

.elim-link-cell {
    font-style: normal;
}

.elim-link {
    color: var(--color-accent);
    text-decoration: none;
    font-size: .85rem;
    font-style: normal;
}

.elim-link:hover {
    text-decoration: underline;
}

.elim-placement {
    font-weight: 600;
    font-style: normal;
    color: var(--color-text);
}

/* ----- Pagination Bar ----- */
.pagination-bar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-top: .75rem;
    font-size: .9rem;
}

.pg-btn {
    padding: .3rem .75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-filter-bg);
    color: var(--color-text);
    cursor: pointer;
    font-size: .85rem;
}

.pg-btn:hover:not(:disabled) {
    background: var(--color-filter-hover);
}

.pg-btn:disabled {
    opacity: .4;
    cursor: default;
}

.pg-label {
    color: var(--color-text-muted);
}

/* ----- Results Link ----- */
.results-link {
    color: var(--color-accent);
    text-decoration: none;
    font-size: .9rem;
}

.results-link:hover {
    text-decoration: underline;
}

/* ----- Round Breakdown & Chart Sections ----- */
.stats-section,
.chart-section {
    margin-bottom: 2rem;
}

.stats-heading {
    margin: 0 0 .75rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--color-text);
}

.stat-event-cell {
    font-size: .85rem;
}

.stat-event-name {
    display: block;
}

.stat-event-date {
    display: block;
    color: var(--color-text-muted);
    font-size: .8rem;
}

.chart-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    max-height: 360px;
}

.chart-wrap canvas {
    max-height: 320px;
}

/* ----- Empty State ----- */
.empty-state {
    text-align: center;
    color: var(--color-text-muted);
    padding: 2.5rem 1rem;
    font-size: 1.05rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

/* ----- Responsive: larger screens ----- */
@media (min-width: 600px) {
    .page-header h1 {
        font-size: 2rem;
    }
}

/* ----- Loading Bar ----- */
#loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: #2563eb;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
}
#loading-bar.loading {
    opacity: 1;
    animation: loading-bar-progress 8s cubic-bezier(.1, .05, .1, 1) forwards;
}
@keyframes loading-bar-progress {
    0%   { width: 0%; }
    30%  { width: 55%; }
    70%  { width: 80%; }
    100% { width: 92%; }
}
body.is-loading .sort-link,
body.is-loading a.pg-btn,
body.is-loading .filter-btn,
body.is-loading .search-btn,
body.is-loading .search-clear-btn {
    opacity: .45;
    pointer-events: none;
    cursor: default;
}
body.is-loading .search-input {
    pointer-events: none;
    opacity: .65;
}
body.is-loading tbody tr {
    pointer-events: none;
}

/* ----- Donation Chat Bubble ----- */
#donate-bubble {
    position: fixed;
    bottom: 1.25rem;
    left: 1.25rem;
    max-width: 270px;
    width: calc(100vw - 2.5rem);
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 14px 14px 14px 4px;
    box-shadow: 0 4px 18px rgba(0,0,0,.14);
    overflow: hidden;
    z-index: 1000;
    opacity: 0;
    transform: translateY(12px) scale(.97);
    transition: opacity .35s ease, transform .35s ease;
    pointer-events: none;
}
#donate-bubble.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
#donate-bubble.hidden {
    display: none;
}
#donate-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #2563eb;
    color: #fff;
    padding: .55rem .75rem .55rem 1rem;
    font-weight: 700;
    font-size: .92rem;
    letter-spacing: .01em;
}
#donate-close {
    background: none;
    border: none;
    font-size: 1.15rem;
    line-height: 1;
    color: rgba(255,255,255,.75);
    cursor: pointer;
    padding: 0 .1rem;
    flex-shrink: 0;
}
#donate-close:hover { color: #fff; }
#donate-body {
    background: #fefce8;
    padding: .85rem 1rem;
}
#donate-link {
    display: block;
    text-decoration: none;
    color: inherit;
}
#donate-link:hover #donate-text {
    text-decoration: underline;
}
.donate-dots {
    display: flex;
    gap: 5px;
    margin-bottom: .5rem;
    height: 10px;
    align-items: center;
}
.donate-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #92400e;
    opacity: .45;
    animation: donate-dot-bounce .9s infinite ease-in-out;
}
.donate-dots span:nth-child(2) { animation-delay: .15s; }
.donate-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes donate-dot-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: .4; }
    40%            { transform: translateY(-5px); opacity: 1; }
}
#donate-text {
    margin: 0;
    font-size: .88rem;
    line-height: 1.5;
    color: #212529;
    min-height: 1.3em;
    white-space: pre-wrap;
}
#donate-text.typing::after {
    content: '|';
    animation: donate-caret .6s steps(1) infinite;
    color: #2563eb;
    margin-left: 1px;
}
@keyframes donate-caret {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}
@media (max-width: 400px) {
    #donate-bubble {
        bottom: .75rem;
        left: .75rem;
        right: .75rem;
        width: auto;
        max-width: none;
    }
}
