:root {
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --bg: #f3f4f8;
    --surface: #ffffff;
    --text: #1c1c1e;
    --text-muted: #636366;
    --border: #e5e5ea;
    --radius: 14px;
    --radius-lg: 18px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    --accent: #007aff;
    --accent-hover: #0056d6;
    --accent-alt: #34c759;
    --accent-alt-hover: #2fa74d;
    --danger: #ff3b30;
    --success: #34c759;
    --max-width: 980px;
    color-scheme: light;
}

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

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

body.theme-fastysolo {
    --page-accent: var(--accent-alt);
    --page-accent-hover: var(--accent-alt-hover);
}

body.theme-beap,
body.theme-home {
    --page-accent: var(--accent);
    --page-accent-hover: var(--accent-hover);
}

.page-wrap {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px 40px;
}

/* Site navigation */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.site-nav {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.site-nav__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1rem;
}

.site-nav__brand img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
}

.site-nav__links {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.site-nav__links a {
    text-decoration: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 8px 14px;
    border-radius: 999px;
    transition: background 0.15s, color 0.15s;
}

.site-nav__links a:hover {
    background: #eef0f5;
    color: var(--text);
}

.site-nav__links a.is-active {
    background: var(--page-accent, var(--accent));
    color: #fff;
}

/* Page hero */
.page-hero {
    text-align: center;
    padding: 28px 0 8px;
}

.page-hero h1 {
    margin: 0 0 8px;
    font-size: 1.75rem;
}

.page-hero p {
    margin: 0;
    color: var(--text-muted);
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

.page-hero .logo-lg {
    width: 88px;
    height: 88px;
    margin-bottom: 12px;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.card h2,
.card h3 {
    margin-top: 0;
}

.is-hidden {
    display: none !important;
}

.card.is-hidden {
    display: none;
}

.card.fade-in {
    animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Home option cards */
.options-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.option-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.option-card--fasty {
    border-top: 4px solid var(--accent-alt);
}

.option-card--beap {
    border-top: 4px solid var(--accent);
}

.option-card h2 {
    margin: 0;
    font-size: 1.25rem;
}

.option-card p {
    margin: 0;
    color: var(--text-muted);
    flex: 1;
}

.option-card__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    min-height: 44px;
}

.btn:focus-visible {
    outline: 2px solid var(--page-accent, var(--accent));
    outline-offset: 2px;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--page-accent, var(--accent));
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--page-accent-hover, var(--accent-hover));
}

.btn-secondary {
    background: #eef0f5;
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background: #e2e5ec;
}

.btn-alt {
    background: var(--accent-alt);
    color: #fff;
}

.btn-alt:hover:not(:disabled) {
    background: var(--accent-alt-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--page-accent, var(--accent));
    border: 1px solid var(--border);
}

/* Sync code form */
.sync-card h2 {
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.sync-card .hint {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin: 0 0 16px;
    text-align: center;
}

.sync-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
    max-width: 420px;
    margin: 0 auto;
}

.sync-form__row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.sync-input {
    flex: 1;
    min-width: 160px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 1.1rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: #fafbfc;
}

.sync-input:focus {
    outline: none;
    border-color: var(--page-accent, var(--accent));
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

body.theme-fastysolo .sync-input:focus {
    box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.2);
}

.sync-form__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.sync-form__actions .btn {
    flex: 1;
    min-width: 120px;
}

/* Messages */
.message {
    text-align: center;
    margin-top: 14px;
    padding: 12px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
}

.message:empty {
    display: none;
}

.message--error {
    background: #ffeceb;
    color: var(--danger);
}

.message--success {
    background: #e8f8ed;
    color: #1d7a36;
}

.message--empty {
    background: #f5f5f7;
    color: var(--text-muted);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.stat-item {
    text-align: center;
    padding: 16px;
    background: linear-gradient(135deg, #f4f6fb, #eceef4);
    border-radius: var(--radius);
}

.stat-item--hero {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.12), rgba(0, 122, 255, 0.04));
}

body.theme-fastysolo .stat-item--hero {
    background: linear-gradient(135deg, rgba(52, 199, 89, 0.15), rgba(52, 199, 89, 0.04));
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--page-accent, var(--accent));
}

.stat-item--hero .stat-value {
    font-size: 2.2rem;
}

.stat-label {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.sync-info {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 12px 0 0;
}

/* Tables */
.table-wrap,
.table-container {
    overflow-x: auto;
    max-height: 420px;
    overflow-y: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-top: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th,
td {
    padding: 11px 12px;
    text-align: center;
    border-bottom: 1px solid #f0f0f2;
    font-size: 0.92rem;
}

th {
    background: #f7f8fc;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

tbody tr:nth-child(even) {
    background: #fafbfc;
}

/* Charts */
.chart-card canvas {
    max-width: 100%;
}

canvas.chart-canvas {
    display: block;
    max-width: 100%;
    border-radius: var(--radius);
    background: var(--surface);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* Filters */
.filter-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 10px 16px;
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    margin: 0;
}

.filter-btn.active {
    background: var(--page-accent, var(--accent));
    color: #fff;
    border-color: var(--page-accent, var(--accent));
}

.filter-btn:focus-visible {
    outline: 2px solid var(--page-accent, var(--accent));
    outline-offset: 2px;
}

/* Loading overlay */
#loadingOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

#loadingOverlay.is-visible {
    display: flex;
}

.loader {
    width: 52px;
    height: 52px;
    border: 5px solid #f3f3f3;
    border-top-color: var(--page-accent, var(--accent));
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1500;
    padding: 20px;
}

.modal-overlay.is-visible {
    display: flex;
}

.modal-content {
    background: var(--surface);
    padding: 24px;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 0.9rem;
}

.modal-content input,
.modal-content textarea {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 1rem;
}

.modal-content textarea {
    min-height: 100px;
    resize: vertical;
}

.modal-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner.is-visible {
    display: inline-block;
}

/* Package selection modal */
#selectionModal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
    width: min(500px, 92vw);
    max-height: 80vh;
    display: none;
    flex-direction: column;
    z-index: 1600;
}

#selectionModal.is-visible {
    display: flex;
}

#selectionModal h2 {
    padding: 20px 20px 0;
    text-align: center;
    margin: 0;
    font-size: 1.1rem;
}

#packageList {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px;
}

.package-option {
    padding: 14px;
    margin: 10px 0;
    background: #f4f6fb;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background 0.15s;
}

.package-option:hover {
    background: #e8ecf8;
}

#selectionModal .btn {
    margin: 16px auto 20px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1550;
    display: none;
}

.modal-backdrop.is-visible {
    display: block;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: min(420px, calc(100% - 32px));
}

.toast {
    padding: 14px 18px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    animation: toastIn 0.3s ease;
    pointer-events: auto;
}

.toast--success {
    background: #1d7a36;
    color: #fff;
}

.toast--error {
    background: #c41e12;
    color: #fff;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.site-footer {
    text-align: center;
    padding: 24px 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.site-footer a {
    color: var(--page-accent, var(--accent));
    text-decoration: none;
    font-weight: 600;
}

.btn-edit {
    padding: 6px 12px;
    min-height: 36px;
    font-size: 0.85rem;
    border-radius: 8px;
}

.table-actions {
    white-space: nowrap;
}

@media (max-width: 600px) {
    .sync-form__row {
        flex-direction: column;
    }

    .sync-form__actions .btn {
        width: 100%;
    }

    .site-nav {
        flex-direction: column;
        align-items: stretch;
    }

    .site-nav__links {
        justify-content: center;
    }
}
