/* ============================================
   Living Invoices - Main Styles
   Institutional, clean, grandma-friendly
   ============================================ */

/* ============ CSS VARIABLES ============ */
:root {
    /* Colors - Institutional (matching Keystone) */
    --primary: #1a365d;
    --primary-dark: #14284a;
    --primary-light: #2d4a7c;
    --secondary: #1a365d;
    
    /* Status colors */
    --success: #276749;
    --success-light: #c6f6d5;
    --danger: #c53030;
    --danger-light: #fed7d7;
    --warning: #b7791f;
    --warning-light: #fefcbf;
    
    /* Neutrals */
    --dark: #1a202c;
    --gray: #4a5568;
    --gray-light: #718096;
    --light-gray: #e2e8f0;
    --lighter-gray: #f1f5f9;
    --white: #ffffff;
    --bg: #f7fafc;
    
    /* Kaspa accent (used sparingly) */
    --kaspa: #49EACB;
    --kaspa-dark: #40C9A2;
    
    /* Safe areas for mobile */
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    
    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    /* Font */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Consolas', monospace;
}

/* ============ RESET & BASE ============ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--dark);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
}

img {
    max-width: 100%;
    height: auto;
}

/* ============ TYPOGRAPHY ============ */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--dark);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

p {
    margin-bottom: 1rem;
}

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

.text-small {
    font-size: 0.875rem;
}

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

/* ============ APP LAYOUT ============ */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Hide all sections by default */
.section {
    display: none;
}

.section.active {
    display: block;
}

/* ============ WELCOME / AUTH SECTION ============ */
.welcome-section {
    min-height: 100vh;
    width: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.welcome-section.active {
    display: flex;
}

.welcome-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.welcome-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 1.5rem;
}

.welcome-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.welcome-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    color: var(--gray);
    margin-bottom: 2rem;
    font-size: 1rem;
}

.welcome-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--gray-light);
    font-size: 0.875rem;
}

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

.welcome-divider span {
    padding: 0 1rem;
}

/* Auth buttons */
.auth-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.auth-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--light-gray);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--dark);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.auth-btn:hover {
    border-color: var(--primary);
    background: var(--lighter-gray);
}

.auth-btn:active {
    transform: scale(0.98);
}

.auth-btn svg,
.auth-btn img {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* Wallet auth buttons group */
.wallet-buttons {
    display: flex;
    gap: 0.75rem;
}

.wallet-buttons .auth-btn {
    flex: 1;
    padding: 0.875rem 0.5rem;
    font-size: 0.875rem;
}

.wallet-buttons .auth-btn svg,
.wallet-buttons .auth-btn img {
    width: 20px;
    height: 20px;
}

/* Primary auth button (Keystone) */
.auth-btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--white);
}

.auth-btn.primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* Google button specific */
.auth-btn.google {
    background: var(--white);
}

.welcome-footer {
    margin-top: 2rem;
    font-size: 0.8125rem;
    color: var(--gray-light);
}

.welcome-footer a {
    color: var(--gray);
}

.welcome-footer a:hover {
    color: var(--primary);
}

/* ============ MAIN APP LAYOUT (after login) ============ */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--white);
    border-right: 1px solid var(--light-gray);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--light-gray);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.sidebar-logo img {
    width: 36px;
    height: 36px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.5rem;
    color: var(--gray);
    font-weight: 500;
    transition: all var(--transition-fast);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 0.9375rem;
}

.nav-item:hover {
    background: var(--lighter-gray);
    color: var(--dark);
}

.nav-item.active {
    background: var(--primary);
    color: var(--white);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--light-gray);
}

/* Main content area */
.main-content {
    flex: 1;
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top bar */
.top-bar {
    background: var(--white);
    border-bottom: 1px solid var(--light-gray);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-bar-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--dark);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.user-menu:hover {
    background: var(--lighter-gray);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
    object-fit: cover;
}

.user-name {
    font-weight: 500;
    color: var(--dark);
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--white);
    border: 1px solid var(--light-gray);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    overflow: hidden;
}

.user-menu-dropdown.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--dark);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--lighter-gray);
}

.dropdown-item.danger {
    color: var(--danger);
}

/* Page content */
.page-content {
    flex: 1;
    padding: 2rem;
}

/* Pages - show/hide */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

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

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

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

.btn-secondary {
    background: var(--lighter-gray);
    color: var(--dark);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--light-gray);
}

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

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

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

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

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-block {
    width: 100%;
}

/* ============ FORMS ============ */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark);
    font-size: 0.9375rem;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--light-gray);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color var(--transition-fast);
    background: var(--white);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-input::placeholder {
    color: var(--gray-light);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--gray-light);
    margin-top: 0.375rem;
}

.form-error {
    font-size: 0.8125rem;
    color: var(--danger);
    margin-top: 0.375rem;
}

/* ============ CARDS ============ */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--light-gray);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--dark);
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--light-gray);
    background: var(--lighter-gray);
}

/* ============ STATS CARDS ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark);
}

.stat-value.success {
    color: var(--success);
}

.stat-value.warning {
    color: var(--warning);
}

/* ============ TABLES ============ */
.table-container {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--light-gray);
}

.table th {
    font-weight: 600;
    color: var(--gray);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.table tbody tr:hover {
    background: var(--lighter-gray);
}

/* ============ BADGES ============ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.badge-draft {
    background: var(--lighter-gray);
    color: var(--gray);
}

.badge-pending {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-paid {
    background: var(--success-light);
    color: var(--success);
}

.badge-overdue {
    background: var(--danger-light);
    color: var(--danger);
}

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--gray);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    color: var(--dark);
    margin-bottom: 0.5rem;
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* ============ LOADING ============ */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--light-gray);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============ TOAST NOTIFICATIONS ============ */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    background: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 280px;
    max-width: 400px;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

/* ============ MOBILE RESPONSIVE ============ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .top-bar {
        padding: 1rem;
    }
    
    .page-content {
        padding: 1rem;
    }
    
    .welcome-card {
        padding: 2rem 1.5rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    /* Mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: none;
        background: none;
        cursor: pointer;
        color: var(--dark);
    }
}

@media (min-width: 769px) {
    .mobile-menu-toggle {
        display: none;
    }
    
    .mobile-overlay {
        display: none !important;
    }
}

/* Mobile overlay */
.mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.mobile-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* ============ UTILITIES ============ */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
