/* ── Cornucopia — Warm harvest theme, mobile-first ──────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..900;1,9..144,300..900&family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #1c1917;
    --bg-raised: #292524;
    --bg-card: #312e2b;
    --bg-input: #3e3a36;
    --accent: #d4a053;
    --accent-hover: #c2883a;
    --accent-glow: rgba(212, 160, 83, 0.12);
    --text: #fafaf9;
    --text-mid: #d6d3d1;
    --text-dim: #a8a29e;
    --border: rgba(168, 162, 158, 0.15);
    --border-strong: rgba(168, 162, 158, 0.25);
    --success: #a3be8c;
    --danger: #e87878;
    --warning: #ebcb8b;
    --radius: 14px;
    --radius-sm: 10px;
    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Subtle grain texture overlay */
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

/* ── Animations ──────────────────────────────────────────────────────────── */

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

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

@keyframes dotPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

@keyframes shimmer {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

/* ── Login Page ──────────────────────────────────────────────────────────── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: env(safe-area-inset-top, 20px);
    background: radial-gradient(ellipse at 50% 30%, #2a2420 0%, var(--bg) 70%);
}

.login-container {
    width: 100%;
    max-width: 380px;
    animation: fadeUp 0.5s ease-out;
}

.login-header {
    text-align: center;
    margin-bottom: 36px;
}

.login-icon {
    margin-bottom: 4px;
    animation: fadeIn 0.6s ease-out;
}

.login-icon img {
    width: 120px;
    height: 120px;
    object-fit: contain;
    border: none;
    outline: none;
    display: block;
    margin: 0 auto;
}

.login-header h1 {
    font-family: var(--font-display);
    font-size: 34px;
    font-weight: 800;
    font-style: italic;
    color: var(--accent);
    letter-spacing: -0.02em;
    text-shadow: 0 2px 8px rgba(212, 160, 83, 0.15);
}

.subtitle {
    font-family: var(--font-body);
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 6px;
}

.error-banner {
    background: rgba(232, 120, 120, 0.12);
    border: 1px solid rgba(232, 120, 120, 0.3);
    color: var(--danger);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
    text-align: center;
    animation: fadeIn 0.3s ease-out;
}

.member-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 28px;
}

.member-btn {
    background: var(--bg-card);
    border: 2px solid var(--border);
    color: var(--text-mid);
    padding: 18px 14px;
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.member-btn::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, transparent 40%, var(--accent-glow));
    opacity: 0;
    transition: opacity 0.2s;
}

.member-btn:hover::before,
.member-btn.selected::before {
    opacity: 1;
}

.member-btn.selected {
    border-color: var(--accent);
    background: var(--bg-input);
    color: var(--accent);
    box-shadow: var(--shadow-md), 0 0 20px var(--accent-glow);
}

.member-btn:active {
    transform: scale(0.96);
}

.pin-section {
    text-align: center;
    animation: slideUp 0.3s ease-out;
}

.pin-label {
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 18px;
}

.pin-label span {
    color: var(--accent);
    font-family: var(--font-display);
    font-weight: 700;
}

.pin-dots {
    display: flex;
    gap: 18px;
    justify-content: center;
    margin-bottom: 28px;
}

.dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--text-dim);
    transition: all 0.2s ease;
}

.dot.filled {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(212, 160, 83, 0.4);
    animation: dotPop 0.2s ease-out;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 280px;
    margin: 0 auto;
}

.num-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 16px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 22px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.12s ease;
    user-select: none;
    box-shadow: var(--shadow-sm);
}

.num-btn:active {
    background: var(--bg-input);
    transform: scale(0.94);
    box-shadow: none;
}

.num-go {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
    font-family: var(--font-display);
    font-weight: 700;
}

.num-go:active {
    background: var(--accent-hover);
}

/* ── App Layout ──────────────────────────────────────────────────────────── */

.app-container {
    padding: 0 16px 100px 16px;
    padding-top: env(safe-area-inset-top, 16px);
    max-width: 520px;
    margin: 0 auto;
    animation: fadeUp 0.4s ease-out;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 0;
}

.app-header h1 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 800;
    font-style: italic;
    color: var(--accent);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-icon {
    width: 28px;
    height: 28px;
}

.app-header .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-header .user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dim);
}

.logout-btn {
    background: none;
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.logout-btn:hover {
    border-color: var(--text-dim);
    color: var(--text);
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.tab-bar {
    display: flex;
    gap: 4px;
    background: var(--bg-raised);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 22px;
    overflow-x: auto;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 11px 8px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
    position: relative;
}

.tab-btn.active {
    background: var(--bg-input);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.25s ease-out;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 14px;
}

/* ── Balance Cards ───────────────────────────────────────────────────────── */

.balance-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    animation: slideUp 0.3s ease-out both;
}

.balance-card:nth-child(1) { animation-delay: 0s; }
.balance-card:nth-child(2) { animation-delay: 0.06s; }
.balance-card:nth-child(3) { animation-delay: 0.12s; }
.balance-card:nth-child(4) { animation-delay: 0.18s; }

.balance-info {
    flex: 1;
}

.balance-names {
    font-size: 15px;
    font-weight: 600;
}

.balance-names .owe-arrow {
    color: var(--text-dim);
    margin: 0 8px;
    font-size: 11px;
    vertical-align: 1px;
}

.balance-amount {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    color: var(--warning);
    margin-top: 4px;
    letter-spacing: -0.02em;
}

.balance-amount.you-owe {
    color: var(--danger);
}

.balance-amount.owed-to-you {
    color: var(--success);
}

.settle-btn {
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 14px;
    white-space: nowrap;
    transition: all 0.15s;
    box-shadow: 0 2px 6px rgba(212, 160, 83, 0.2);
}

.settle-btn:active {
    background: var(--accent-hover);
    transform: scale(0.96);
}

.no-balances {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 16px;
    font-size: 15px;
    font-style: italic;
}

/* ── Form Elements ───────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 7px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.form-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 13px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
    color: #666;
}

.submit-btn {
    width: 100%;
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 15px;
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
    box-shadow: 0 3px 10px rgba(212, 160, 83, 0.2);
    letter-spacing: -0.01em;
}

.submit-btn:hover {
    box-shadow: 0 4px 16px rgba(212, 160, 83, 0.3);
}

.submit-btn:active {
    background: var(--accent-hover);
    transform: scale(0.98);
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

/* ── Purchase History ────────────────────────────────────────────────────── */

.purchase-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    animation: fadeIn 0.3s ease-out both;
}

.purchase-item:nth-child(1) { animation-delay: 0s; }
.purchase-item:nth-child(2) { animation-delay: 0.04s; }
.purchase-item:nth-child(3) { animation-delay: 0.08s; }
.purchase-item:nth-child(4) { animation-delay: 0.12s; }
.purchase-item:nth-child(5) { animation-delay: 0.16s; }

.purchase-item:last-child {
    border-bottom: none;
}

.purchase-meta {
    flex: 1;
}

.purchase-buyer {
    font-weight: 600;
    font-size: 15px;
}

.purchase-location {
    color: var(--text-dim);
    font-size: 13px;
    margin-top: 3px;
}

.purchase-date {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 3px;
    font-weight: 500;
}

.purchase-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.purchase-amount {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
}

.purchase-item.voided {
    opacity: 0.45;
}

.purchase-item.voided .purchase-buyer,
.purchase-item.voided .purchase-location,
.purchase-item.voided .purchase-amount {
    text-decoration: line-through;
}

.void-label {
    color: var(--danger);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-left: 6px;
}

.void-purchase-btn {
    background: none;
    border: 1px solid rgba(232, 120, 120, 0.3);
    color: var(--danger);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
    opacity: 0.6;
}

.void-purchase-btn:hover {
    opacity: 1;
    border-color: var(--danger);
    background: rgba(232, 120, 120, 0.08);
}

.void-purchase-btn:active {
    background: rgba(232, 120, 120, 0.18);
    transform: scale(0.96);
}

/* ── Admin ───────────────────────────────────────────────────────────────── */

.member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

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

.member-name {
    flex: 1;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 16px;
}

.member-pct {
    font-size: 15px;
    color: var(--accent);
    font-weight: 600;
    min-width: 50px;
    text-align: right;
}

.pct-input {
    width: 72px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 15px;
    text-align: right;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.pct-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.remove-btn {
    background: none;
    border: 1px solid rgba(232, 120, 120, 0.3);
    color: var(--danger);
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.remove-btn:hover {
    border-color: var(--danger);
    background: rgba(232, 120, 120, 0.08);
}

.remove-btn:active {
    background: rgba(232, 120, 120, 0.18);
}

.pct-total {
    text-align: right;
    font-family: var(--font-display);
    font-size: 15px;
    padding: 12px 0;
    font-weight: 700;
}

.pct-total.valid {
    color: var(--success);
}

.pct-total.invalid {
    color: var(--danger);
}

.section-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 22px 0;
}

.add-member-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.add-member-form .form-group {
    flex: 1;
    margin-bottom: 0;
}

.add-member-form .submit-btn {
    width: auto;
    padding: 13px 18px;
    flex-shrink: 0;
    font-size: 15px;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    color: var(--text);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(8px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    border-color: rgba(163, 190, 140, 0.4);
    color: var(--success);
}

.toast.error {
    border-color: rgba(232, 120, 120, 0.4);
    color: var(--danger);
}

/* ── Settle Modal ────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

.modal {
    background: var(--bg-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.25s ease-out;
}

.modal h3 {
    font-family: var(--font-display);
    font-size: 20px;
    margin-bottom: 16px;
    color: var(--accent);
    font-weight: 800;
}

.modal p {
    color: var(--text-mid);
    font-size: 14px;
    line-height: 1.5;
}

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

.modal-actions button {
    flex: 1;
    padding: 13px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-cancel {
    background: none;
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
}

.btn-cancel:hover {
    border-color: var(--text-dim);
    color: var(--text);
}

.btn-confirm {
    background: var(--accent);
    border: none;
    color: var(--bg);
    box-shadow: 0 2px 8px rgba(212, 160, 83, 0.2);
}

.btn-confirm:active {
    background: var(--accent-hover);
    transform: scale(0.97);
}

/* ── Change PIN section ──────────────────────────────────────────────────── */

.change-pin-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.change-pin-form .form-group {
    flex: 1;
    margin-bottom: 0;
}

.change-pin-form .submit-btn {
    width: auto;
    padding: 13px 18px;
    font-size: 15px;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}

/* ── Selection ───────────────────────────────────────────────────────────── */

::selection {
    background: rgba(212, 160, 83, 0.3);
    color: var(--text);
}
