* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--background);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
    min-height: 100vh;
}

/* ----------------------------------------
   Topbar
---------------------------------------- */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 20px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-size: 22px;
    font-weight: 650;
}

.navigation {
    display: flex;
    align-items: center;
    gap: 6px;
}

.navigation a {
    padding: 8px 11px;
    border-radius: 7px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
}

.navigation a:hover {
    background: var(--surface-hover);
    color: var(--text-secondary);
}

.navigation a.active {
    background: var(--surface-hover);
    color: var(--text);
}

/* ----------------------------------------
   Main
---------------------------------------- */

main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 28px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 650;
}

.page-header p {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

/* ----------------------------------------
   Panels
---------------------------------------- */

.section {
    margin-bottom: 24px;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.section-header h2 {
    margin: 0;
    font-size: 18px;
}

.section-header p {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

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

.cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.card {
    padding: 20px;
    background: var(--surface-secondary);
    border: 1px solid var(--border-secondary);
    border-radius: 10px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}

.card h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 650;
}

.file-name {
    display: block;
    margin-top: 5px;
    color: var(--text-muted);
    font-family: monospace;
    font-size: 12px;
}

.description {
    margin: 0 0 16px;
    color: var(--text-muted-strong);
    font-size: 13px;
    line-height: 1.5;
}

/* ----------------------------------------
   Status badges
---------------------------------------- */

.status-badge {
    flex-shrink: 0;
    padding: 4px 8px;
    border-radius: 5px;
    background: var(--border);
    color: var(--text-muted);
    font-size: 11px;
}

.status-badge.available {
    background: var(--success-surface);
    color: var(--success);
}

.status-badge.missing {
    background: var(--error-surface);
    color: var(--error);
}

/* ----------------------------------------
   File selection
---------------------------------------- */

.file-input {
    display: block;
    padding: 13px;
    border: 1px dashed var(--border-input);
    border-radius: 7px;
    background: var(--input-background);
    color: var(--text-secondary);
    text-align: center;
    cursor: pointer;
    font-size: 13px;
}

.file-input:hover {
    background: var(--surface-hover);
    border-color: var(--border-input);
}

.file-input input {
    display: none;
}

.selected-file {
    min-height: 18px;
    margin: 9px 0 14px;
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

button {
    padding: 9px 12px;
    border: 1px solid var(--border-input);
    border-radius: 7px;
    background: var(--surface-hover);
    color: var(--text-strong);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--border);
    border-color: var(--border-input);
}

button:disabled {
    opacity: 0.45;
    cursor: default;
}

.button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--surface);
}

.button.primary:hover:not(:disabled) {
    background: var(--text-strong);
    border-color: var(--text-strong);
}

.button.secondary {
    background: var(--surface-hover);
    color: var(--text-secondary);
}

/* ----------------------------------------
   Operation result
---------------------------------------- */

.operation-result {
    min-height: 18px;
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
}

.operation-result.success {
    color: var(--success);
}

.operation-result.error {
    color: var(--error);
}

/* ----------------------------------------
   TCGdex
---------------------------------------- */

.tcgdex-card {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.tcgdex-info {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

.tcgdex-current {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.label {
    color: var(--text-muted);
    font-size: 12px;
}

.tcgdex-current code {
    width: fit-content;
    font-size: 13px;
}

.repository-status {
    padding: 10px 12px;
    border: 1px solid var(--border-secondary);
    border-radius: 7px;
    background: var(--surface-secondary);
    color: var(--text-muted);
    font-size: 12px;
}

.repository-status.success {
    background: var(--success-surface);
    border-color: #244b32;
    color: var(--success);
}

.repository-status.error {
    background: var(--error-surface);
    border-color: #522323;
    color: var(--error);
}

/* ----------------------------------------
   Database statistics
---------------------------------------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.stat-card {
    padding: 18px;
    background: var(--surface-secondary);
    border: 1px solid var(--border-secondary);
    border-radius: 10px;
}

.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
}

.stat-card strong {
    display: block;
    margin-top: 6px;
    color: var(--text-strong);
    font-size: 26px;
    font-weight: 650;
}

/* ----------------------------------------
   Responsive
---------------------------------------- */

@media (max-width: 900px) {
    .cards {
        grid-template-columns: 1fr;
    }

    .tcgdex-info {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 700px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

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

    .page-header {
        align-items: flex-start;
        flex-direction: column;
    }

    main {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.source-link {
    color: #88b9ff;
    text-underline-offset: 3px;
}

.source-link:hover {
    color: #bad6ff;
}

.manual-upload-label { margin-top: 18px; margin-bottom: 8px; }

/* Native details panels support mouse, touch and keyboard navigation. */
.section.collapsible-section { padding: 0; }
.section-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 22px;
    cursor: pointer;
    list-style: none;
    border-radius: 16px;
}
.section-summary::-webkit-details-marker { display: none; }
.section-summary::after { content: "+"; color: var(--accent); font-size: 24px; line-height: 1; }
.collapsible-section[open] > .section-summary::after { content: "−"; }
.section-summary:hover { background: var(--surface-hover); }
.section-summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.section-summary h2 { margin: 0; font-size: 18px; }
.section-content { padding: 0 22px 22px; }
.import-timestamp { margin: 0 0 16px; color: var(--text-muted); font-size: 13px; }
.import-timestamp time { color: var(--text); font-variant-numeric: tabular-nums; }
.tcgdex-card > .import-timestamp { margin-bottom: 0; }
