:root {
    --bg: #646464;
    --card: whitesmoke;
    --text: #222222;
    --muted: #666666;
    --accent: #d8c3a5;
    --accent-hover: #cdb08a;
    --border: #d7d7d7;
    --danger-bg: #f8d7da;
    --danger-text: #842029;
    --info-bg: #e7f1ff;
    --info-text: #0b5394;
    --success-bg: #e6f4ea;
    --success-text: #1e6b36;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
}

* {
    box-sizing: border-box;
}

h1 {
    margin-top: 10px;
}

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

body {
    min-height: 100vh;
}

/* =========================
   Layout
   ========================= */

.app-main {
    min-height: calc(100vh - 60px);
    padding: 16px;
}

body.has-bottom-nav .app-main {
    padding-bottom: calc(90px + env(safe-area-inset-bottom));
}

.content-shell {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
}

.auth-shell {
    min-height: calc(100vh - 60px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* =========================
   Cards
   ========================= */

.card {
    background: var(--card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.auth-card {
    width: 100%;
    max-width: 460px;
    padding: 32px 28px;
}

.page-card {
    width: 100%;
    padding: 26px 24px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    background: var(--card);
}

.centered-card {
    max-width: 720px;
    margin: 0 auto;
}

.metric-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px 18px;
}

.metric-card-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-card-label {
    font-size: 0.9rem;
    color: var(--muted);
}

.metric-card-value {
    font-size: 1.15rem;
    font-weight: 700;
}

/* =========================
   Typography / Blocks
   ========================= */

.brand-block {
    margin-bottom: 28px;
}

.brand-block h1 {
    margin: 0 0 8px;
    font-size: clamp(1.8rem, 5vw, 3rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.05;
}

.brand-block p {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
    font-size: 1rem;
}

.section-title {
    margin: 18px 0 12px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

.payment-status-cell {
    min-width: 220px;
}

.payment-status-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* =========================
   Forms
   ========================= */

.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.95rem;
    font-weight: 600;
}

.form-group input,
.select-field {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-size: 1rem;
    background: #ffffff;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.select-field:focus {
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 4px rgba(216, 195, 165, 0.35);
}

.select-field {
    appearance: none;
    -webkit-appearance: none;
}

/* =========================
   Buttons
   ========================= */

.btn {
    border: none;
    border-radius: 999px;
    padding: 14px 18px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease, background 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--accent);
    color: #2f241b;
    text-decoration: none;
    padding: 16px 18px;
    font-size: 1.05rem;
    letter-spacing: 0.01em;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0,0,0,0.12);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: #2f241b;
    border: 1px solid var(--border);
    text-decoration: none;
}

.btn-secondary:hover {
    background: #f3f3f3;
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.85rem;
}


.event-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
    margin-bottom: 18px;
}

.rule-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.rule-actions .btn {
    flex: 1 1 180px;
}

.btn-danger {
    background: #f8d7da;
    color: #842029;
    border: 1px solid #f1b8bf;
}

.btn-danger:hover {
    background: #f1c2c7;
}

/* =========================
   Alerts / Placeholders
   ========================= */

.alert {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--danger-bg);
    color: var(--danger-text);
    font-size: 0.95rem;
    font-weight: 600;
}

.info-alert {
    margin-bottom: 18px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--info-bg);
    color: var(--info-text);
    font-size: 0.95rem;
    font-weight: 600;
}

.form-placeholder {
    padding: 18px;
    border-radius: var(--radius-md);
    background: #ffffff;
    border: 1px solid var(--border);
    text-align: center;
    color: var(--muted);
}

/* =========================
   Footer Links in Auth
   ========================= */

.auth-footer {
    margin-top: 18px;
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
}

.auth-footer a {
    color: #2f241b;
    font-weight: 700;
    text-decoration: none;
    margin-left: 6px;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* =========================
   Tables
   ========================= */

.table-wrap {
    width: 100%;
    overflow-x: auto;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: #f3f3f3;
    font-weight: 700;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.balance-positive {
    color: #1e6b36;
    font-weight: 700;
}

.balance-negative {
    color: #842029;
    font-weight: 700;
}

.balance-neutral {
    color: #666666;
    font-weight: 600;
}

/* =========================
   Invite / Copy Box
   ========================= */

.invite-box {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.invite-box label {
    font-size: 0.95rem;
    font-weight: 600;
}

.invite-box input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-size: 0.95rem;
    background: #ffffff;
}

/* =========================
   Account / Event Cards
   ========================= */

.account-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.account-card-link {
    text-decoration: none;
    color: inherit;
}

.account-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 16px;
    transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.account-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
    border-color: var(--accent-hover);
}

.account-card h3 {
    margin: 0 0 6px;
    font-size: 1rem;
    line-height: 1.15;
}

.account-card p {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.account-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    max-width: 42%;
}

.event-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px 18px;
}

/* =========================
   Pills
   ========================= */

.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 8px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    background: #ececec;
    color: #333333;
}

.pill-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.pill-muted {
    background: #efefef;
    color: #666666;
}

/* =========================
   Topbar
   ========================= */

.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    min-height: 56px;
    padding: env(safe-area-inset-top) 14px 0 14px;

    background: rgba(36, 36, 36, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);

    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.topbar-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.topbar-logout-form {
    margin: 0;
}

.topbar-right .topbar-pill,
.topbar-right .topbar-pill:visited,
.topbar-right .topbar-pill:hover,
.topbar-right .topbar-pill:active,
.topbar-right .topbar-pill:focus {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    appearance: none;
    -webkit-appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.12);
    outline: none;
    box-shadow: none;

    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;

    padding: 8px 12px;
    min-height: 34px;
    border-radius: 999px;
    cursor: pointer;

    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.topbar-right .topbar-pill:hover,
.topbar-right .topbar-pill:focus {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.18);
}

.topbar-right .topbar-pill:active {
    transform: translateY(0);
    background: rgba(255, 255, 255, 0.18);
}

/* =========================
   Collapsible Section
   ========================= */

.collapse-card {
    margin-bottom: 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: #ffffff;
    overflow: hidden;
}

.collapse-card summary {
    list-style: none;
    cursor: pointer;
    padding: 16px 18px;
    font-weight: 700;
    user-select: none;
}

.collapse-card summary::-webkit-details-marker {
    display: none;
}

.collapse-card[open] summary {
    border-bottom: 1px solid var(--border);
}

.collapse-form {
    padding: 18px;
}

/* =========================
   Bottom Navigation
   ========================= */

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;

    display: flex;
    align-items: stretch;
    justify-content: space-around;
    gap: 6px;

    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(245, 245, 245, 0.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);

    border-top: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
}

.bottom-nav-item {
    flex: 1 1 0;
    min-width: 0;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;

    text-decoration: none;
    color: #2f241b;

    padding: 8px 4px;
    border-radius: 16px;
    transition: background 0.2s ease, transform 0.15s ease;
}

.bottom-nav-item:hover,
.bottom-nav-item:active {
    background: rgba(216, 195, 165, 0.22);
}

.bottom-nav-item.is-active {
    background: rgba(216, 195, 165, 0.35);
}

.bottom-nav-item.is-active .bottom-nav-label,
.bottom-nav-item.is-active .bottom-nav-icon {
    font-weight: 800;
}

.bottom-nav-icon {
    display: block;
    font-size: 1.1rem;
    line-height: 1;
}

.bottom-nav-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.1;
}

/* =========================
   Inline Action Link
   ========================= */

.inline-action-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(216, 195, 165, 0.28);
    color: #2f241b;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.2s ease;
}

.inline-action-link:hover {
    background: rgba(216, 195, 165, 0.42);
}

/* =========================
   Mobile
   ========================= */

@media (max-width: 768px) {
    .app-main {
        padding: 14px 12px;
    }

    body.has-bottom-nav .app-main {
        padding-bottom: calc(92px + env(safe-area-inset-bottom));
    }

    .page-card,
    .auth-card {
        padding: 18px 14px;
        border-radius: 22px;
    }

    .brand-block h1 {
        font-size: 1.55rem;
    }

    .brand-block p {
        font-size: 0.98rem;
    }

    .home-actions {
        gap: 10px;
    }

    .btn {
        padding: 14px 16px;
        font-size: 0.98rem;
    }

    .account-card {
        align-items: flex-start;
        flex-direction: column;
    }

    .account-meta {
        justify-content: flex-start;
        max-width: 100%;
    }

    .topbar-right {
        min-width: 60px;
    }

    .topbar-right .topbar-pill,
    .topbar-right .topbar-pill:visited,
    .topbar-right .topbar-pill:hover,
    .topbar-right .topbar-pill:active,
    .topbar-right .topbar-pill:focus {
        font-size: 0.78rem;
        padding: 7px 10px;
        min-height: 32px;
    }
}