:root {
    --bg-base: #f7f2e8;
    --bg-deep: #efe4d4;
    --surface: #fffaf2;
    --surface-muted: #f4ede2;
    --ink: #1c1a17;
    --muted: #6d655b;
    --accent: #1e5a45;
    --accent-glow: rgba(30, 90, 69, 0.28);
    --accent-soft: rgba(30, 90, 69, 0.12);
    --accent-warm: #c26a4a;
    --accent-warm-soft: rgba(194, 106, 74, 0.18);
    --accent-coral: #b85a40;
    --border: 1px solid rgba(28, 26, 23, 0.08);
    --shadow-sm: 0 8px 22px rgba(28, 26, 23, 0.08);
    --shadow-md: 0 22px 54px rgba(28, 26, 23, 0.12);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --font-heading: 'Instrument Serif', serif;
    --font-ui: 'Manrope', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

body {
    background-color: var(--bg-base);
    color: var(--ink);
    font-family: var(--font-ui);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: inherit;
}

button,
input,
select {
    font-family: inherit;
}

strong {
    font-weight: 600;
}

h1,
h2,
h3 {
    font-family: var(--font-heading);
    font-weight: 400;
}

/* --- Background --- */
.bg-layer {
    position: fixed;
    inset: 0;
    z-index: -2;
    background: linear-gradient(160deg, #faf6ef 0%, #f1e4d6 50%, #f7f1e6 100%);
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.7;
    animation: float 12s ease-in-out infinite alternate;
}

.blob-1 {
    width: 520px;
    height: 520px;
    background: radial-gradient(circle, rgba(30, 90, 69, 0.35), transparent 65%);
    top: -140px;
    left: -120px;
}

.blob-2 {
    width: 560px;
    height: 560px;
    background: radial-gradient(circle, rgba(194, 106, 74, 0.35), transparent 70%);
    bottom: -160px;
    right: -140px;
    animation-delay: -6s;
}

.blob-3 {
    width: 420px;
    height: 420px;
    background: radial-gradient(circle, rgba(184, 90, 64, 0.28), transparent 70%);
    top: 20%;
    right: 15%;
    animation-delay: -3s;
}

.noise-overlay {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(28, 26, 23, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(28, 26, 23, 0.04) 1px, transparent 1px),
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
    background-size: 90px 90px, 90px 90px, 200px 200px;
    opacity: 0.3;
    pointer-events: none;
}

@keyframes float {
    from { transform: translate(0, 0); }
    to { transform: translate(30px, 40px); }
}

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3.5rem 2rem 5rem;
    position: relative;
}

/* --- Hero --- */
.hero {
    margin-bottom: 2.5rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2.5rem;
    align-items: end;
}

.hero-content {
    max-width: 640px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.7rem;
    color: var(--accent);
    margin-bottom: 0.75rem;
    font-weight: 700;
}

h1 {
    font-size: clamp(2.6rem, 4.8vw, 4.6rem);
    line-height: 1.05;
    margin-bottom: 0.9rem;
    color: var(--ink);
}

.subtitle {
    color: var(--muted);
    font-size: 1.05rem;
    max-width: 560px;
}

.highlight {
    color: var(--ink);
    font-weight: 600;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: linear-gradient(120deg, var(--accent-soft), var(--accent-warm-soft));
}

.hero-meta {
    margin-top: 1.6rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.meta-chip {
    background: var(--surface);
    border: var(--border);
    border-radius: 999px;
    padding: 0.35rem 0.9rem;
    font-size: 0.85rem;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    box-shadow: var(--shadow-sm);
}

.dot-indicator {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(30, 90, 69, 0.12);
}

.hero-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
}

.hero-actions .btn {
    justify-content: center;
}

/* --- Buttons --- */
.btn {
    text-decoration: none;
    padding: 0.8rem 1.6rem;
    border-radius: 999px;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    border: 1px solid transparent;
}

.btn:focus-visible,
.duration-pill:focus-visible,
.guest-option:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent), #2a6f57);
    color: #fbf7ef;
    box-shadow: 0 14px 28px rgba(30, 90, 69, 0.24);
}

.btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 36px var(--accent-glow);
}

.btn.ghost {
    background: rgba(255, 255, 255, 0.85);
    color: var(--ink);
    border-color: rgba(28, 26, 23, 0.08);
}

.btn.ghost:hover {
    border-color: rgba(28, 26, 23, 0.2);
    background: rgba(255, 255, 255, 0.98);
}

.btn.small {
    padding: 0.6rem 1.1rem;
    font-size: 0.85rem;
}

#refresh-btn.is-loading {
    pointer-events: none;
    opacity: 0.7;
}

#refresh-btn.is-loading .btn-icon {
    animation: spin 1s linear infinite;
}

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

/* --- Stats --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--surface);
    border: var(--border);
    padding: 1.4rem;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-card.accent {
    border-color: rgba(30, 90, 69, 0.25);
    background: linear-gradient(135deg, rgba(30, 90, 69, 0.08), rgba(194, 106, 74, 0.16));
}

.stat-label {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.18em;
}

.stat-value {
    font-size: 2.4rem;
    font-weight: 500;
}

/* --- Dashboard Layout --- */
.dashboard {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-areas: "main rail";
    gap: 2rem;
    align-items: start;
}

.dashboard-main {
    grid-area: main;
}

.dashboard-rail {
    grid-area: rail;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* --- Loader --- */
.loader-panel {
    background: var(--surface);
    border: var(--border);
    border-radius: var(--radius-md);
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow-sm);
    display: none;
}

.loader-panel.is-visible {
    display: block;
    animation: fadeIn 0.3s ease;
}

.loader-content {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.refresh-label {
    font-weight: 700;
    color: var(--ink);
}

.refresh-status {
    color: var(--muted);
    font-size: 0.9rem;
}

.progress-track {
    height: 6px;
    background: rgba(28, 26, 23, 0.08);
    border-radius: 999px;
    margin-top: 0.6rem;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-warm));
    width: 0%;
    transition: width 0.2s;
}

.progress-bar.run {
    width: 35%;
    animation: progress-indeterminate 1.4s ease-in-out infinite;
}

.progress-bar.done {
    width: 100% !important;
    transition: width 0.3s ease;
    animation: none;
    transform: none;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(420%); }
}

/* --- Filters --- */
.filters-panel {
    background: var(--surface);
    border: var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.panel-header {
    margin-bottom: 1rem;
}

.panel-header h3 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.panel-subtitle {
    color: var(--muted);
    font-size: 0.9rem;
}

.filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
    align-items: end;
}

.filter-group label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--muted);
    margin-bottom: 0.45rem;
}

.filter-group select,
.filter-group input {
    width: 100%;
    background: var(--surface-muted);
    border: 1px solid rgba(28, 26, 23, 0.12);
    border-radius: var(--radius-sm);
    color: var(--ink);
    padding: 0.65rem 0.75rem;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-group input::placeholder {
    color: rgba(109, 101, 91, 0.7);
}

.filter-group select:focus,
.filter-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(30, 90, 69, 0.12);
}

.filter-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    flex-wrap: wrap;
}

/* --- Booking Preview --- */
.booking-preview {
    background: var(--surface);
    border: var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
}

.preview-title {
    max-width: 520px;
}

.preview-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.preview-header h3 {
    font-size: 1.6rem;
    margin-bottom: 0.35rem;
}

.preview-subtitle {
    color: var(--muted);
    font-size: 0.95rem;
}

.preview-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-top: 1.2rem;
}

.detail-item {
    background: var(--surface-muted);
    border: 1px solid rgba(28, 26, 23, 0.08);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
}

.detail-label {
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
    margin-bottom: 0.4rem;
}

.detail-value {
    font-weight: 600;
}

.invoice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.invoice-card {
    background: var(--surface);
    border: 1px solid rgba(28, 26, 23, 0.08);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
}

.invoice-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.invoice-amount {
    color: var(--accent);
    font-weight: 700;
}

.preview-empty {
    margin-top: 1rem;
    color: var(--muted);
    font-size: 0.9rem;
}

/* --- Schedule Feed --- */
.schedule-feed {
    display: grid;
    gap: 1.8rem;
}

.day-group {
    padding: 1.2rem;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(28, 26, 23, 0.08);
    background: rgba(255, 250, 242, 0.85);
    box-shadow: var(--shadow-sm);
    animation: rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
    transform: translateY(20px);
}

.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0 0.2rem;
}

.day-header h2 {
    font-size: 1.5rem;
}

.slot-count-badge {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 0.25rem 0.8rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.slots-list {
    display: grid;
    gap: 0.75rem;
}

.slot-item {
    background: var(--surface);
    border: 1px solid rgba(28, 26, 23, 0.1);
    padding: 1rem;
    border-radius: var(--radius-md);
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr) auto;
    gap: 1.2rem;
    align-items: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.slot-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
    border-color: rgba(30, 90, 69, 0.35);
}

.slot-time-box {
    background: linear-gradient(135deg, rgba(30, 90, 69, 0.12), rgba(194, 106, 74, 0.2));
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    text-align: center;
}

.slot-time-box .time {
    font-weight: 700;
    color: var(--ink);
    font-size: 1.05rem;
}

.slot-details {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.slot-court {
    font-weight: 600;
    font-size: 1.05rem;
}

.slot-meta {
    font-size: 0.8rem;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.meta-pill {
    background: rgba(28, 26, 23, 0.04);
    border: 1px solid rgba(28, 26, 23, 0.08);
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.slot-durations {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.duration-label {
    font-size: 0.72rem;
    color: var(--muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.duration-pill {
    border: 1px solid rgba(28, 26, 23, 0.2);
    border-radius: 999px;
    padding: 0.2rem 0.65rem;
    font-size: 0.75rem;
    color: var(--ink);
    background: transparent;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.duration-pill:hover {
    border-color: var(--accent);
    background: var(--accent);
    color: #fbf7ef;
}

.duration-pill[data-loading="1"] {
    opacity: 0.6;
    pointer-events: none;
}

.guest-option {
    padding: 0.5rem;
    background: var(--surface-muted);
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.9rem;
    border: 1px solid rgba(28, 26, 23, 0.08);
    text-align: left;
}

.guest-option:hover {
    border-color: rgba(30, 90, 69, 0.35);
    background: #fff6ea;
}

.slot-action {
    display: flex;
    justify-content: flex-end;
}

.status-pill {
    color: var(--accent);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    border: 1px solid rgba(30, 90, 69, 0.35);
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    background: var(--accent-soft);
}

/* --- Footer --- */
.footer {
    margin-top: 4rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.footer a {
    color: inherit;
}

/* --- Empty States --- */
.empty-state {
    text-align: center;
    padding: 3.5rem 1.5rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px dashed rgba(28, 26, 23, 0.18);
    box-shadow: var(--shadow-sm);
}

.empty-state h3 {
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--muted);
}

/* --- Login --- */
.login-page .login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
}

.login-page .login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-md);
    animation: rise 0.6s ease;
}

.login-page h1 {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
}

.login-page .login-error {
    margin-top: 1rem;
    background: rgba(194, 106, 74, 0.14);
    border: 1px solid rgba(194, 106, 74, 0.35);
    color: #5b2d22;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.login-page .login-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.login-page .login-form label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--muted);
}

.login-page .login-form input {
    background: var(--surface-muted);
    border: 1px solid rgba(28, 26, 23, 0.12);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    color: var(--ink);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-page .login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(30, 90, 69, 0.12);
}

.login-page .login-form .btn {
    margin-top: 0.75rem;
    justify-content: center;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .container {
        padding: 3rem 1.5rem 4rem;
    }

    .hero {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .hero-actions {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .dashboard {
        grid-template-columns: 1fr;
        grid-template-areas: "rail" "main";
    }
}

@media (max-width: 720px) {
    h1 {
        font-size: clamp(2.2rem, 8vw, 3.2rem);
    }

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

    .slot-item {
        grid-template-columns: 1fr;
        align-items: flex-start;
    }

    .slot-time-box {
        width: 100%;
        text-align: left;
    }

    .slot-action {
        justify-content: flex-start;
    }

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

    body.preview-active .dashboard-main {
        padding-bottom: clamp(14rem, 42vh, 24rem);
    }

    .booking-preview.booking-preview--active {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 900;
        margin: 0;
        border-radius: 16px 16px 0 0;
        max-height: 45vh;
        overflow: auto;
        padding-bottom: calc(1.2rem + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -18px 40px rgba(28, 26, 23, 0.22);
    }
}

/* --- Modal & Loading UX --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(28, 26, 23, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

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

.modal-card {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.4);
    width: 90%;
    max-width: 480px;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: center;
}

.modal-overlay.active .modal-card {
    transform: translateY(0);
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--accent-soft);
    border-bottom-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: rotation 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.modal-title {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--ink);
}

.modal-desc {
    color: var(--muted);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.modal-invoice-list {
    background: var(--surface-muted);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin: 1rem 0 2rem;
    text-align: left;
}

.modal-invoice-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
    font-size: 0.9rem;
}

.modal-invoice-row:last-child {
    border-bottom: none;
}

.modal-invoice-total {
    display: flex;
    justify-content: space-between;
    margin-top: 0.8rem;
    padding-top: 0.8rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--accent);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}
