/* ============================================================================
   TIPPA MVP - CSS Design System
   ============================================================================ */

/* CSS Variables */
:root {
    /* Colors */
    --color-primary: #10B981;
    --color-primary-hover: #059669;
    --color-primary-light: #D1FAE5;
    --color-danger: #EF4444;
    --color-warning: #F59E0B;
    --color-success: #10B981;

    /* Neutrals */
    --color-bg: #F9FAFB;
    --color-bg-card: #FFFFFF;
    --color-text: #111827;
    --color-text-muted: #6B7280;
    --color-border: #E5E7EB;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-md: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-xxl: 32px;
}

/* Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ============================================================================
   LAYOUT
   ============================================================================ */

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: var(--space-md);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    background: var(--color-bg-card);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-main {
    flex: 1;
    padding: var(--space-md);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.admin-main {
    max-width: 1200px;
}

/* ============================================================================
   LOGO
   ============================================================================ */

.logo {
    text-align: center;
    margin-bottom: var(--space-lg);
}

/* The real app mark, so the login screen matches the home-screen icon.
   Was a 💵 emoji, which rendered differently on every platform. */
.logo-icon {
    display: block;
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-sm);
    border-radius: var(--radius-md);
}

.logo h1 {
    font-size: var(--font-size-xxl);
    font-weight: 700;
    color: var(--color-primary);
}

.logo-small {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-primary);
}

.tagline {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xl);
}

/* ============================================================================
   LOGIN
   ============================================================================ */

.login-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: var(--space-xl) 0;
}

.login-step {
    animation: fadeIn 0.2s ease;
}

.login-step.hidden {
    display: none;
}

.otp-message {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: var(--space-lg);
}

.otp-input {
    text-align: center;
    font-size: var(--font-size-xl);
    letter-spacing: 8px;
    font-weight: 600;
}

.divider {
    display: flex;
    align-items: center;
    margin: var(--space-xl) 0;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.divider span {
    padding: 0 var(--space-md);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.admin-link {
    display: block;
    text-align: center;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: var(--font-size-sm);
}

.admin-link:hover {
    color: var(--color-primary);
}

/* ============================================================================
   FORMS
   ============================================================================ */

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-bottom: var(--space-xs);
    color: var(--color-text);
}

input[type="text"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="number"] {
    width: 100%;
    padding: var(--space-md);
    font-size: var(--font-size-md);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-card);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.input-with-prefix {
    display: flex;
    align-items: stretch;
}

.input-with-prefix .prefix {
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-right: none;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    color: var(--color-text-muted);
    font-weight: 500;
}

.input-with-prefix input {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    flex: 1;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-md);
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-bg);
    color: var(--color-text);
    border: 2px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--color-text-muted);
}

.btn-link {
    background: transparent;
    color: var(--color-text-muted);
    padding: var(--space-sm) var(--space-md);
}

.btn-link:hover {
    color: var(--color-primary);
}

.btn-small {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
}

.btn-danger {
    background: var(--color-danger);
    color: white;
}

.btn-outline {
    background: transparent;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
}

.btn-outline:hover {
    background: var(--color-primary-light);
}

.actions {
    display: flex;
    gap: var(--space-sm);
}

/* ============================================================================
   CARDS
   ============================================================================ */

.balance-card {
    background: linear-gradient(135deg, var(--color-primary) 0%, #059669 100%);
    color: white;
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    text-align: center;
    margin-bottom: var(--space-lg);
    box-shadow: var(--shadow-lg);
}

.balance-label {
    font-size: var(--font-size-sm);
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.balance-amount {
    font-size: 48px;
    font-weight: 700;
    margin: var(--space-sm) 0;
}

.balance-sub {
    font-size: var(--font-size-sm);
    opacity: 0.8;
}

.stat-card {
    background: var(--color-bg-card);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-primary);
    margin-top: var(--space-xs);
}

/* ============================================================================
   SECTIONS
   ============================================================================ */

.section {
    margin-bottom: var(--space-xl);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.section-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

/* ============================================================================
   STATS GRID
   ============================================================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
   DATA LISTS
   ============================================================================ */

.data-list {
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
}

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

.data-row-main {
    flex: 1;
}

.data-row-title {
    font-weight: 500;
}

.data-row-sub {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.data-row-amount {
    font-weight: 600;
    color: var(--color-primary);
}

.data-row-amount.negative {
    color: var(--color-danger);
}


.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.data-table th {
    text-align: left;
    padding: var(--space-md) var(--space-sm);
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
    color: var(--color-text-muted);
}

.data-table td {
    padding: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
}

.data-table td:first-child {
    white-space: nowrap;
    /* Keep date on one line */
    color: var(--color-text-muted);
}

.data-table td:nth-child(4),
/* Amount */
.data-table td:nth-child(5) {
    /* Balance */
    text-align: right;
    font-variant-numeric: tabular-nums;
    /* Monospace numbers */
    white-space: nowrap;
}

.data-table th:nth-child(4),
.data-table th:nth-child(5) {
    text-align: right;
}

.data-empty {
    padding: var(--space-xl);
    text-align: center;
    color: var(--color-text-muted);
}

/* ============================================================================
   REDEMPTION
   ============================================================================ */

.redeem-step {
    animation: fadeIn 0.2s ease;
}

.redeem-step.hidden {
    display: none;
}

.redeem-options {
    margin-top: var(--space-lg);
}

.redeem-options h3 {
    font-size: var(--font-size-md);
    margin-bottom: var(--space-md);
}

.option-tabs {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.tab {
    flex: 1;
    padding: var(--space-md);
    border: 2px solid var(--color-border);
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.tab.active {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.amount-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
}

.amount-option {
    padding: var(--space-md);
    border: 2px solid var(--color-border);
    background: var(--color-bg-card);
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.amount-option:hover {
    border-color: var(--color-text-muted);
}

.amount-option.selected {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.amount-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.success-icon {
    font-size: 64px;
    text-align: center;
    margin-bottom: var(--space-md);
}

/* ============================================================================
   MODALS
   ============================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 400px;
    width: 100%;
    animation: slideUp 0.2s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-muted);
}

.modal-body {
    margin-bottom: var(--space-lg);
}

.modal-actions {
    display: flex;
    gap: var(--space-md);
}

.modal-actions .btn {
    flex: 1;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

#toast-container {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    background: var(--color-text);
    color: white;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    animation: slideUp 0.2s ease;
    box-shadow: var(--shadow-lg);
}

.toast.success {
    background: var(--color-success);
}

.toast.error {
    background: var(--color-danger);
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================================
   UTILITIES
   ============================================================================ */

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--color-text-muted);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

.btn .spinner {
    margin-right: var(--space-sm);
}

/* Activity Modal Styles */
.balance-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    background: var(--color-primary-light);
    border-radius: var(--radius-md);
    font-size: var(--font-size-md);
}

.balance-summary strong {
    font-size: var(--font-size-lg);
    color: var(--color-primary);
}

.activity-list {
    max-height: 300px;
    overflow-y: auto;
}

.activity-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--color-border);
    gap: var(--space-md);
}

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

.activity-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    flex: 1;
}

.activity-description {
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

.activity-date {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

.activity-balance {
    font-size: var(--font-size-xs);
    color: var(--color-primary);
    font-weight: 600;
    white-space: nowrap;
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

/* Mini Table (Recent Activity) */
.mini-table {
    background: var(--color-bg);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.mini-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: var(--space-sm);
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-xs);
}

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

.mini-header {
    background: var(--color-border);
    font-weight: 600;
    color: var(--color-text-muted);
}

.mini-desc {
    color: var(--color-text-muted);
}

.mini-amount {
    text-align: right;
    min-width: 60px;
}

.mini-amount.sent {
    color: var(--color-danger);
}

.mini-amount.received {
    color: var(--color-success);
}

.mini-balance {
    color: var(--color-primary);
    font-weight: 600;
    text-align: right;
    min-width: 60px;
}

.mini-date {
    display: block;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* Filter Tabs */
.filter-tabs {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-xs);
}

/* ============================================================================
   SPEND BALANCE (Airtime & Data Redemption)
   ============================================================================ */

.spend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.btn-spend {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-lg) var(--space-md);
    background: var(--color-bg-card);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.btn-spend:hover:not(:disabled) {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.btn-spend:active:not(:disabled) {
    transform: translateY(0);
}

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

.btn-spend .spend-icon {
    font-size: 32px;
}

.btn-spend .spend-label {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--color-text);
}

.btn-spend.airtime:hover:not(:disabled) {
    border-color: #3B82F6;
    background: #EFF6FF;
}

.btn-spend.data:hover:not(:disabled) {
    border-color: #8B5CF6;
    background: #F5F3FF;
}

/* Bundle grid for data modal */
.bundle-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.btn-bundle {
    padding: var(--space-lg) var(--space-md);
    background: var(--color-bg-card);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.2s;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-bundle:hover:not(:disabled) {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-bundle:active:not(:disabled) {
    transform: translateY(0);
}

.btn-bundle:disabled,
.btn-bundle.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    color: var(--color-text-muted);
}

.form-hint {
    display: block;
    margin-top: var(--space-xs);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}
/* ============================================================================
   INSTALL PROMPT
   Shown by initInstallPrompt() in app.js. Two variants share this markup:
   Android/Chrome gets a working Install button, iOS Safari gets Share -> Add to
   Home Screen instructions, because iOS exposes no install API.
   ============================================================================ */

.install-prompt {
    position: fixed;
    left: var(--space-md);
    right: var(--space-md);
    /* Sits above the iOS home indicator and Android nav bar. */
    bottom: calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
    z-index: 900;

    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-sm) var(--space-md);
    align-items: center;

    padding: var(--space-md);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);

    animation: install-prompt-in 240ms ease-out;
}

.install-prompt[hidden] {
    display: none;
}

@keyframes install-prompt-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .install-prompt { animation: none; }
}

.install-prompt-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
}

.install-prompt-title {
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 var(--space-xs);
}

.install-prompt-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin: 0;
    line-height: 1.4;
}

.install-prompt-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    align-items: center;
}

/* iOS variant: the instructions replace the button, so hide the action. */
.install-prompt.is-ios #install-prompt-action {
    display: none;
}

/* The Share glyph, inlined so the instructions read correctly offline. */
.install-share-glyph {
    display: inline-block;
    font-weight: 600;
    color: var(--color-primary);
}

/* ============================================================================
   OFFLINE BANNER
   Shown by initOfflineIndicator() in app.js while the device reports no
   connection. The app shell still opens from cache — this explains why nothing
   that touches the server will work.
   ============================================================================ */

.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 950;

    padding: var(--space-sm) var(--space-md);
    /* Respects the notch / status bar on installed iOS apps. */
    padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px));

    background: var(--color-warning);
    color: #FFFFFF;
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-align: center;
}

.offline-banner[hidden] {
    display: none;
}

/* ============================================================================
   BUILD STAMP
   Which version a tester is running. Deliberately visible: during the POC the
   first support question is "did you get the update?", and this answers it
   without a screen-share.
   ============================================================================ */

.build-stamp {
    margin-top: var(--space-lg);
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    opacity: 0.7;
}
