:root {
    --bg-main: #f5f7fa;
    --bg-card: #ffffff;
    --surface-border: #e5e7eb;
    
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    
    --primary: #16a34a; /* Nexus Green */
    --primary-hover: #15803d;
    --primary-light: rgba(22, 163, 74, 0.08);
    
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: rgba(239, 68, 68, 0.08);

    --whatsapp: #25D366;
    --whatsapp-hover: #128C7E;
    
    --card-radius: 16px;
    --input-radius: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    
    --transition: all 0.2s ease-in-out;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    padding: 1rem;
    overflow-x: hidden;
    line-height: 1.5;
    /* Prevent iOS rubber banding */
    overscroll-behavior: none;
    /* Prevent iOS home bar overlap */
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

.app-container {
    max-width: 500px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg-main);
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}

/* Header */
.glass-header {
    background: var(--bg-main);
    padding: calc(1rem + env(safe-area-inset-top)) 1rem 1rem 1rem;
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nexus-logo {
    width: 28px;
    height: 28px;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.35rem;
    cursor: pointer;
    transition: var(--transition);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

/* Cards */
.card, .glass-card {
    background: var(--bg-card);
    border: 1px solid var(--surface-border);
    border-radius: var(--card-radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

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

/* Typography */
h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: -0.5rem;
}

/* Inputs */
textarea, input[type="text"], input[type="number"] {
    width: 100%;
    background: #ffffff;
    border: 1px solid var(--surface-border);
    border-radius: var(--input-radius);
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

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

textarea {
    min-height: 120px;
    resize: vertical;
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    outline: none;
    font-weight: 600;
    border-radius: var(--input-radius);
    padding: 12px 20px;
    font-size: 1rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    /* Prevent iOS text selection on long-press */
    -webkit-touch-callout: none;
    user-select: none;
}

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

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

.secondary-btn {
    background: var(--primary-light);
    color: var(--primary);
    width: 100%;
}

.secondary-btn:hover {
    background: rgba(22, 163, 74, 0.15);
}

.danger-btn {
    background: var(--danger-light);
    color: var(--danger);
    width: 100%;
}

.danger-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

.whatsapp-btn {
    background: var(--whatsapp);
    color: white;
    width: 100%;
}

.whatsapp-btn:hover {
    background: var(--whatsapp-hover);
}

/* Bill Specifics */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--surface-border);
    padding-bottom: 0.75rem;
}

.badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.customer-info {
    background: var(--bg-main);
    padding: 1rem;
    border-radius: var(--input-radius);
    font-size: 0.9rem;
    border: 1px solid var(--surface-border);
}

.customer-info p {
    margin-bottom: 0.25rem;
}
.customer-info p:last-child {
    margin-bottom: 0;
}

.instructions-text {
    color: var(--danger);
    font-style: italic;
}

.app-footer {
    text-align: center;
    padding-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.app-footer a {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
}
.app-footer a:hover {
    color: var(--primary);
}

/* Items List */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.items-list::-webkit-scrollbar {
    width: 4px;
}
.items-list::-webkit-scrollbar-thumb {
    background: var(--surface-border);
    border-radius: 4px;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    padding: 0.5rem 0;
    border-bottom: 1px dashed var(--surface-border);
}
.item-row:last-child {
    border-bottom: none;
}

.item-name { font-weight: 500; }
.item-qty { color: var(--text-secondary); text-align: center; }
.item-total { font-weight: 600; text-align: right; }

.remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 0.875rem;
}
.remove-btn:hover {
    color: var(--danger);
}

/* Add Charge */
.add-charge-container {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: 0.5rem;
    background: var(--bg-main);
    padding: 0.75rem;
    border-radius: var(--input-radius);
    border: 1px solid var(--surface-border);
}
.add-charge-container input {
    padding: 0.5rem;
    font-size: 0.85rem;
}
.add-charge-container button {
    padding: 0.5rem 1rem;
}

/* Totals */
.totals-section {
    border-top: 2px solid var(--surface-border);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.total-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.grand-total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 0.5rem;
    border-top: 1px dashed var(--surface-border);
    padding-top: 0.5rem;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
    margin-top: 0.5rem;
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(17, 24, 39, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 0; /* Remove padding to allow full-screen */
}

.modal-content {
    background: var(--bg-main); /* Match main app background */
    width: 100%;
    max-width: 500px; /* Match app container */
    height: 100%; /* Full screen height */
    border-radius: 0; /* Remove rounded corners */
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom)) 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto; /* Enable internal scrolling */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--surface-border);
    padding-bottom: 0.75rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Dashboard Specifics */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.metric-card {
    background: var(--bg-main);
    border: 1px solid var(--surface-border);
    border-radius: var(--input-radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.metric-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}
.metric-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
}
.metric-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.dashboard-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Native CSS Bar Chart */
.chart-container {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px dashed var(--surface-border);
}

.chart-title {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.css-bar-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 120px;
    gap: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--surface-border);
}

.chart-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
}

.chart-bar {
    width: 100%;
    max-width: 30px;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    transition: height 0.5s ease-out;
    min-height: 2px;
}

.chart-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 5px;
    text-align: center;
}

.chart-tooltip {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

/* CRM Segment Badges */
.crm-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-left: 5px;
}
.badge-regular { background: #dcfce7; color: #166534; }
.badge-risk { background: #fee2e2; color: #991b1b; }
.badge-onetime { background: #f3f4f6; color: #4b5563; }
.badge-new { background: #dbeafe; color: #1e40af; }

/* New vs Repeat Split Bar */
.split-bar-container {
    width: 100%;
    height: 12px;
    background: var(--surface-border);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    margin-top: 10px;
    margin-bottom: 5px;
}
.split-bar-repeat {
    background: var(--primary);
    height: 100%;
    transition: width 0.5s ease-out;
}
.split-bar-new {
    background: #3b82f6; /* Blue for new */
    height: 100%;
    transition: width 0.5s ease-out;
}
.split-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.crm-row {
    transition: background 0.2s;
    cursor: pointer;
}
.crm-row:hover {
    background: rgba(0,0,0,0.02);
}

/* License Lock Screen */
.license-lock {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-body);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}
.license-lock-card {
    background: var(--bg-card);
    border: 1px solid var(--surface-border);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    max-width: 360px;
    width: 100%;
    text-align: center;
}

/* ==========================================
   Guided Tour / Onboarding Walkthrough
   ========================================== */
.tour-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: transparent;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

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

.tour-spotlight {
    position: absolute;
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10001;
    pointer-events: none;
}

.tour-tooltip {
    position: absolute;
    z-index: 10002;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 20px 22px 16px;
    width: 300px;
    max-width: calc(100vw - 32px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: tourPop 0.35s ease;
}

@keyframes tourPop {
    0% { opacity: 0; transform: scale(0.9) translateY(8px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.tour-tooltip-step {
    display: inline-block;
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.tour-tooltip h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    line-height: 1.3;
}

.tour-tooltip p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin-bottom: 14px;
}

.tour-tooltip-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.tour-dots {
    display: flex;
    gap: 5px;
}

.tour-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--surface-border);
    transition: all 0.3s ease;
}

.tour-dot.active {
    background: var(--primary);
    width: 18px;
    border-radius: 4px;
}

.tour-btn-skip {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: var(--transition);
}

.tour-btn-skip:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.tour-btn-next {
    background: var(--primary);
    color: white;
    border: none;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 5px;
}

.tour-btn-next:hover {
    background: var(--primary-hover);
}

/* Welcome screen (first step) */
.tour-welcome {
    position: fixed;
    z-index: 10002;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border-radius: 20px;
    box-shadow: 0 25px 80px rgba(0,0,0,0.35);
    padding: 30px 28px 24px;
    width: 320px;
    max-width: calc(100vw - 32px);
    text-align: center;
    animation: tourPop 0.4s ease;
}

.tour-welcome-icon {
    font-size: 2.8rem;
    margin-bottom: 12px;
}

.tour-welcome h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.tour-welcome p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.tour-welcome .tour-btn-next {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 0.9rem;
}
