/**
 * TapriPay - Custom Styles
 * Track who paid at the Tapri. No more chai arguments.
 */

/* ── Variables ─────────────────────────────────────────── */
:root {
    --tp-primary: #e67e22;
    --tp-primary-dark: #d35400;
    --tp-primary-light: #fef5e7;
    --tp-primary-rgb: 230, 126, 34;
    --tp-secondary: #2c3e50;
    --tp-accent: #27ae60;
    --tp-danger: #e74c3c;
    --tp-warning: #f1c40f;
    --tp-info: #3498db;
    --tp-bg: #faf7f2;
    --tp-card: #ffffff;
    --tp-text: #2c3e50;
    --tp-text-muted: #7f8c8d;
    --tp-border: #e8ddd0;
    --tp-radius: 16px;
    --tp-radius-sm: 10px;
    --tp-shadow: 0 2px 12px rgba(0,0,0,0.06);
    --tp-shadow-lg: 0 8px 32px rgba(0,0,0,0.1);
    --tp-transition: 0.25s ease;
}

/* ── Page ─────────────────────────────────────────── */
.tp-page {
    background: var(--tp-bg);
    min-height: 100vh;
}

/* ── Hero Section ─────────────────────────────────────────── */
.tp-hero {
    background: linear-gradient(135deg, #e67e22 0%, #d35400 50%, #c0392b 100%);
    padding: 3rem 0 2rem;
    color: white;
    position: relative;
    overflow: hidden;
}
.tp-hero::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    border-radius: 50%;
}
.tp-hero h1 {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 0.3rem;
}
.tp-hero .tp-tagline {
    opacity: 0.9;
    font-size: 1.05rem;
    font-weight: 400;
}
.tp-hero-emoji {
    font-size: 2.5rem;
    margin-right: 0.5rem;
}

/* ── Group Bar ─────────────────────────────────────────── */
.tp-group-bar {
    background: white;
    border-bottom: 2px solid var(--tp-border);
    padding: 0.75rem 0;
    position: sticky;
    top: 60px;
    z-index: 100;
    box-shadow: var(--tp-shadow);
}
.tp-group-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--tp-secondary);
}
.tp-group-code {
    font-family: 'Courier New', monospace;
    background: var(--tp-primary-light);
    color: var(--tp-primary);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 1px;
    cursor: pointer;
    transition: var(--tp-transition);
}
.tp-group-code:hover {
    background: var(--tp-primary);
    color: white;
}

/* ── Navigation Tabs ─────────────────────────────────────────── */
.tp-nav {
    display: flex;
    gap: 0;
    background: white;
    border-bottom: 2px solid var(--tp-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.tp-nav::-webkit-scrollbar { display: none; }
.tp-nav-item {
    flex: 1;
    min-width: fit-content;
    text-align: center;
    padding: 0.85rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--tp-text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: var(--tp-transition);
    white-space: nowrap;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}
.tp-nav-item i {
    font-size: 1.1rem;
}
.tp-nav-item:hover {
    color: var(--tp-primary);
    background: var(--tp-primary-light);
}
.tp-nav-item.active {
    color: var(--tp-primary);
    border-bottom-color: var(--tp-primary);
    background: var(--tp-primary-light);
}

/* ── Tab Content ─────────────────────────────────────────── */
.tp-tab-content {
    display: none;
    padding: 1.25rem;
    max-width: 700px;
    margin: 0 auto;
}
.tp-tab-content.active {
    display: block;
    animation: tpFadeIn 0.3s ease;
}
@keyframes tpFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Cards ─────────────────────────────────────────── */
.tp-card {
    background: var(--tp-card);
    border-radius: var(--tp-radius);
    box-shadow: var(--tp-shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid var(--tp-border);
    transition: var(--tp-transition);
}
.tp-card:hover {
    box-shadow: var(--tp-shadow-lg);
}
.tp-card-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--tp-secondary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.tp-card-title i {
    color: var(--tp-primary);
}

/* ── Form Elements ─────────────────────────────────────────── */
.tp-form-group {
    margin-bottom: 1.25rem;
}
.tp-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--tp-secondary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.tp-label .tp-step {
    background: var(--tp-primary);
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
}
.tp-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--tp-border);
    border-radius: var(--tp-radius-sm);
    font-size: 1rem;
    color: var(--tp-text);
    background: white;
    transition: var(--tp-transition);
    outline: none;
}
.tp-input:focus {
    border-color: var(--tp-primary);
    box-shadow: 0 0 0 3px rgba(var(--tp-primary-rgb), 0.15);
}
.tp-input::placeholder {
    color: #bdc3c7;
}
select.tp-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237f8c8d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

/* ── Member Checkboxes ─────────────────────────────────────────── */
.tp-member-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 0.5rem;
}
.tp-member-check {
    position: relative;
}
.tp-member-check input[type="checkbox"],
.tp-member-check input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.tp-member-check label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--tp-border);
    border-radius: var(--tp-radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--tp-transition);
    background: white;
    user-select: none;
}
.tp-member-check label::before {
    content: '';
    width: 18px;
    height: 18px;
    border: 2px solid #ccc;
    border-radius: 4px;
    flex-shrink: 0;
    transition: var(--tp-transition);
}
.tp-member-check input[type="radio"] + label::before {
    border-radius: 50%;
}
.tp-member-check input:checked + label {
    border-color: var(--tp-primary);
    background: var(--tp-primary-light);
    color: var(--tp-primary-dark);
}
.tp-member-check input:checked + label::before {
    background: var(--tp-primary);
    border-color: var(--tp-primary);
    box-shadow: inset 0 0 0 2px white;
}

/* ── Buttons ─────────────────────────────────────────── */
.tp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: var(--tp-radius-sm);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--tp-transition);
    text-decoration: none;
}
.tp-btn-primary {
    background: linear-gradient(135deg, var(--tp-primary), var(--tp-primary-dark));
    color: white;
    box-shadow: 0 4px 12px rgba(var(--tp-primary-rgb), 0.3);
}
.tp-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(var(--tp-primary-rgb), 0.4);
}
.tp-btn-primary:active {
    transform: translateY(0);
}
.tp-btn-success {
    background: linear-gradient(135deg, #27ae60, #219a52);
    color: white;
}
.tp-btn-danger {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
}
.tp-btn-outline {
    background: white;
    border: 2px solid var(--tp-border);
    color: var(--tp-text);
}
.tp-btn-outline:hover {
    border-color: var(--tp-primary);
    color: var(--tp-primary);
}
.tp-btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}
.tp-btn-block {
    width: 100%;
}
.tp-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ── Leaderboard ─────────────────────────────────────────── */
.tp-leaderboard-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: white;
    border-radius: var(--tp-radius);
    border: 1px solid var(--tp-border);
    margin-bottom: 0.6rem;
    transition: var(--tp-transition);
    gap: 0.75rem;
}
.tp-leaderboard-item:hover {
    box-shadow: var(--tp-shadow-lg);
    transform: translateX(4px);
}
.tp-rank {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.tp-rank-1 { background: linear-gradient(135deg, #FFD700, #FFA500); color: white; }
.tp-rank-2 { background: linear-gradient(135deg, #C0C0C0, #A0A0A0); color: white; }
.tp-rank-3 { background: linear-gradient(135deg, #CD7F32, #B8690E); color: white; }
.tp-rank-default { background: #f0f0f0; color: #666; }

.tp-lb-info {
    flex: 1;
    min-width: 0;
}
.tp-lb-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--tp-secondary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.tp-lb-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    font-weight: 600;
    white-space: nowrap;
}
.tp-lb-stats {
    display: flex;
    gap: 1rem;
    margin-top: 0.3rem;
    font-size: 0.78rem;
    color: var(--tp-text-muted);
}
.tp-lb-balance {
    font-weight: 800;
    font-size: 1rem;
    white-space: nowrap;
}
.tp-balance-positive { color: var(--tp-accent); }
.tp-balance-negative { color: var(--tp-danger); }
.tp-balance-zero { color: var(--tp-text-muted); }

/* ── Next Payer Card ─────────────────────────────────────────── */
.tp-next-payer {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border: 2px solid #ffb74d;
    border-radius: var(--tp-radius);
    padding: 1.25rem;
    text-align: center;
    margin-bottom: 1rem;
}
.tp-next-payer-name {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--tp-primary-dark);
    margin: 0.5rem 0;
}
.tp-next-payer-label {
    font-size: 0.85rem;
    color: var(--tp-text-muted);
    font-weight: 600;
}

/* ── Dashboard Stats ─────────────────────────────────────────── */
.tp-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.tp-stat-card {
    background: white;
    border-radius: var(--tp-radius);
    padding: 1rem;
    text-align: center;
    border: 1px solid var(--tp-border);
    transition: var(--tp-transition);
}
.tp-stat-card:hover {
    box-shadow: var(--tp-shadow);
}
.tp-stat-icon {
    font-size: 1.5rem;
    margin-bottom: 0.3rem;
}
.tp-stat-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--tp-secondary);
    line-height: 1.2;
}
.tp-stat-label {
    font-size: 0.75rem;
    color: var(--tp-text-muted);
    font-weight: 500;
    margin-top: 0.1rem;
}

/* ── History ─────────────────────────────────────────── */
.tp-history-item {
    background: white;
    border-radius: var(--tp-radius);
    border: 1px solid var(--tp-border);
    padding: 1rem;
    margin-bottom: 0.6rem;
    transition: var(--tp-transition);
}
.tp-history-item:hover {
    box-shadow: var(--tp-shadow);
}
.tp-history-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}
.tp-history-item-type {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--tp-secondary);
}
.tp-history-amount {
    font-weight: 800;
    font-size: 1.05rem;
    color: var(--tp-primary);
}
.tp-history-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.78rem;
    color: var(--tp-text-muted);
}
.tp-history-meta i {
    margin-right: 0.25rem;
}
.tp-history-members {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.5rem;
}
.tp-history-member-tag {
    font-size: 0.7rem;
    background: #f0f0f0;
    color: #555;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-weight: 500;
}
.tp-history-member-tag.payer {
    background: var(--tp-primary-light);
    color: var(--tp-primary-dark);
    font-weight: 700;
}

/* ── Members Management ─────────────────────────────────────────── */
.tp-member-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: white;
    border-radius: var(--tp-radius-sm);
    border: 1px solid var(--tp-border);
    margin-bottom: 0.5rem;
}
.tp-member-name {
    font-weight: 600;
    font-size: 0.9rem;
}
.tp-member-inactive {
    opacity: 0.5;
    text-decoration: line-through;
}
.tp-member-actions {
    display: flex;
    gap: 0.3rem;
}

/* ── Toast Notification ─────────────────────────────────────────── */
.tp-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--tp-secondary);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: var(--tp-radius);
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 10000;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: var(--tp-shadow-lg);
    max-width: 90%;
    text-align: center;
}
.tp-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.tp-toast.success { background: #27ae60; }
.tp-toast.error { background: #e74c3c; }

/* ── Welcome / Create/Join Screen ─────────────────────────────────────────── */
.tp-welcome {
    max-width: 480px;
    margin: 2rem auto;
    padding: 0 1rem;
}
.tp-welcome-card {
    background: white;
    border-radius: var(--tp-radius);
    box-shadow: var(--tp-shadow-lg);
    padding: 2rem;
    text-align: center;
}
.tp-welcome-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}
.tp-welcome-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--tp-secondary);
    margin-bottom: 0.5rem;
}
.tp-welcome-subtitle {
    color: var(--tp-text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}
.tp-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--tp-text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}
.tp-divider::before,
.tp-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--tp-border);
}
.tp-divider span {
    padding: 0 1rem;
}

/* ── Share Button ─────────────────────────────────────────── */
.tp-share-btn {
    background: #25D366;
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: var(--tp-radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--tp-transition);
}
.tp-share-btn:hover {
    background: #128C7E;
    color: white;
}

/* ── Loading Spinner ─────────────────────────────────────────── */
.tp-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: tpSpin 0.6s linear infinite;
}
@keyframes tpSpin {
    to { transform: rotate(360deg); }
}

/* ── Empty State ─────────────────────────────────────────── */
.tp-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--tp-text-muted);
}
.tp-empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}
.tp-empty-text {
    font-size: 0.95rem;
    font-weight: 500;
}

/* ── Select All / Deselect ─────────────────────────────────────────── */
.tp-select-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.tp-link-btn {
    background: none;
    border: none;
    color: var(--tp-primary);
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    transition: var(--tp-transition);
}
.tp-link-btn:hover {
    background: var(--tp-primary-light);
}

/* ── Recent Groups ─────────────────────────────────────────── */
.tp-recent-groups {
    margin-top: 1.5rem;
}
.tp-recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.8rem;
    background: #f8f9fa;
    border-radius: var(--tp-radius-sm);
    margin-bottom: 0.4rem;
    cursor: pointer;
    transition: var(--tp-transition);
}
.tp-recent-item:hover {
    background: var(--tp-primary-light);
}
.tp-recent-item-name {
    font-weight: 600;
    font-size: 0.85rem;
}
.tp-recent-item-code {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--tp-text-muted);
}

/* ── Chart Container ─────────────────────────────────────────── */
.tp-chart-container {
    background: white;
    border-radius: var(--tp-radius);
    border: 1px solid var(--tp-border);
    padding: 1rem;
    margin-bottom: 1rem;
}

/* ── Delete button ─────────────────────────────────────────── */
.tp-delete-session {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    padding: 0.2rem;
    transition: var(--tp-transition);
    font-size: 0.85rem;
}
.tp-delete-session:hover {
    color: var(--tp-danger);
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 576px) {
    .tp-hero { padding: 2rem 0 1.5rem; }
    .tp-hero h1 { font-size: 1.6rem; }
    .tp-hero-emoji { font-size: 2rem; }
    .tp-tab-content { padding: 1rem 0.75rem; }
    .tp-group-bar { position: relative; top: 0; z-index: 10; padding: 0.5rem 0; }
    .tp-group-bar .container-fluid { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
    .tp-group-name { font-size: 0.85rem; max-width: 90px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: middle; }
    .tp-group-code { font-size: 0.75rem; padding: 0.2rem 0.4rem; }
    .tp-share-btn { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
    .tp-member-grid { grid-template-columns: repeat(2, 1fr); }
    .tp-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .tp-lb-stats { gap: 0.5rem; }
    .tp-leaderboard-item { padding: 0.8rem; }
    .tp-stat-value { font-size: 1.2rem; }
    .tp-nav-item { padding: 0.7rem 0.6rem; font-size: 0.75rem; }
    .tp-member-item { padding: 0.6rem 0.5rem; }
    .tp-member-name { font-size: 0.85rem; }
    .tp-member-actions { gap: 0.2rem; }
    .tp-member-actions .tp-btn { padding: 0.3rem 0.5rem; font-size: 0.75rem; }
}

/* ── Footer Fix ─────────────────────────────────────────── */
#tp-footer {
    position: relative;
    z-index: 1;
    background: #1e293b;
    margin-top: 3rem;
    clear: both;
}

/* Ensure footer doesn't overlap content */
.tp-app-container {
    padding-bottom: 2rem;
    position: relative;
    z-index: 2;
    background: #fff;
}

/* Fix any potential fixed positioning in footer */
#tp-footer .tb-footer {
    position: relative !important;
}

/* ── Confetti Animation ─────────────────────────────────────────── */
@keyframes tpConfetti {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(-100px) rotate(720deg); opacity: 0; }
}
.tp-confetti-piece {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: tpConfetti 1s ease-out forwards;
    pointer-events: none;
    z-index: 10001;
}
