/**
 * L3 PWA Styles
 * Mobile-first, responsive design with theming support
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ============================================
   CSS CUSTOM PROPERTIES (Theme Variables)
   ============================================ */
:root {
    /* Colors - Overridden by theme system */
    --color-primary: #2F855A;
    --color-primary-dark: #22543D;
    --color-accent: #ECC94B;
    --color-bg: #F0F4F8;
    --color-surface: #FFFFFF;
    --color-text: #2D3748;
    --color-text-muted: #718096;

    /* Radii */
    --radius-card: 12px;
    --radius-button: 999px;

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

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Typography */
    --font-base: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;

    /* Layout */
    --max-width: 600px;
    --header-height: 56px;
    --bottom-nav-height: 64px;
}

/* ============================================
   GLOBAL RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-base);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ============================================
   APP SHELL LAYOUT
   ============================================ */
.app-shell {
    min-height: 100vh;
    max-width: var(--max-width);
    margin: 0 auto;
    background: var(--color-surface);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Header */
.app-header {
    background: var(--color-primary);
    color: white;
    height: var(--header-height);
    padding: 0 var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
    font-size: var(--font-size-lg);
    font-weight: 700;
    letter-spacing: -0.025em;
}

.app-header-back {
    background: none;
    border: none;
    color: white;
    font-size: var(--font-size-xl);
    cursor: pointer;
    padding: var(--spacing-sm);
    margin-left: calc(var(--spacing-sm) * -1);
}

.app-header-actions {
    display: flex;
    gap: var(--spacing-sm);
}

/* Main Content */
.app-main {
    flex: 1;
    padding: var(--spacing-lg);
    padding-bottom: calc(var(--bottom-nav-height) + var(--spacing-lg));
    overflow-y: auto;
}

.app-main.has-bottom-nav {
    padding-bottom: calc(var(--bottom-nav-height) + var(--spacing-lg));
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-width);
    height: var(--bottom-nav-height);
    background: var(--color-surface);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 90;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    text-decoration: none;
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    font-weight: 500;
    transition: color 0.2s;
    cursor: pointer;
    border: none;
    background: none;
}

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

.bottom-nav-icon {
    font-size: var(--font-size-xl);
}

/* ============================================
   COMPONENTS
   ============================================ */

/* Cards */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-card);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.card:last-child {
    margin-bottom: 0;
}

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

.card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text);
}

.card-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: var(--spacing-xs);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    background: var(--color-primary);
    color: white;
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-button);
    text-decoration: none;
    font-weight: 600;
    font-size: var(--font-size-base);
    transition: all 0.2s;
    border: none;
    cursor: pointer;
    width: 100%;
    min-height: 48px;
    margin: 5px auto;
}

.btn:hover, .btn:focus {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn:active {
    transform: translateY(0);
}

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

.btn-secondary:hover {
    background: var(--color-bg);
}

.btn-accent {
    background: var(--color-accent);
    color: var(--color-text);
}

.btn-sm {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    min-height: 36px;
    width: inherit;
}

.btn-md {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
    min-height: 28px;
    width: inherit;
}

.btn-lg {
    padding: var(--spacing-lg) var(--spacing-xl);
    font-size: var(--font-size-lg);
    min-height: 56px;
}

.btn-group {
    display: flex;
    gap: var(--spacing-md);
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    color: var(--color-text);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--spacing-md);
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: calc(var(--radius-card) / 1.5);
    font-family: var(--font-base);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-surface);
    transition: all 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.1);
}

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

.form-help {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: var(--spacing-xs);
}

/* Phone input special styling */
.phone-input {
    font-size: var(--font-size-lg);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-align: center;
    padding: var(--spacing-lg);
}

.phone-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(47, 133, 90, 0.15);
    transform: scale(1.01);
}

/* OTP Box Styling */
.otp-container {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
    margin: var(--spacing-md) 0;
}

.otp-box {
    width: 48px;
    height: 56px;
    text-align: center;
    font-size: var(--font-size-2xl);
    font-weight: 700;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--spacing-sm);
    background: var(--color-surface);
    color: var(--color-text);
    transition: all 0.2s;
}

.otp-box:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.15);
    transform: scale(1.05);
}

.otp-box:not(:placeholder-shown) {
    border-color: var(--color-primary);
    background: rgba(47, 133, 90, 0.05);
}

@media (max-width: 375px) {
    .otp-box {
        width: 42px;
        height: 50px;
        font-size: var(--font-size-xl);
    }

    .otp-container {
        gap: var(--spacing-xs);
    }
}

/* Lists */
.list {
    list-style: none;
}

.list-item {
    padding: var(--spacing-md);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.list-item-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-right: var(--spacing-md);
    background: var(--color-bg);
}

.list-item-content {
    flex: 1;
}

.list-item-title {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.list-item-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-button);
    font-size: var(--font-size-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-success {
    background: #C6F6D5;
    color: #22543D;
}

.badge-warning {
    background: #FED7D7;
    color: #742A2A;
}

.badge-info {
    background: #BEE3F8;
    color: #2C5282;
}

/* Divider */
.divider {
    border: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin: var(--spacing-lg) 0;
}

/* Loading */
.loading {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--color-text-muted);
}

.spinner {
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--spacing-md);
}

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

/* Toast Notifications */
.toast {
    position: fixed;
    top: calc(var(--header-height) + var(--spacing-md));
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(var(--max-width) - var(--spacing-xl));
    width: calc(100% - var(--spacing-xl));
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--color-text);
    color: white;
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translate(-50%, -20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.toast-success { background: #22543D; }
.toast-error { background: #742A2A; }
.toast-warning { background: #975A16; }

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-primary { color: var(--color-primary); }
.text-sm { font-size: var(--font-size-sm); }
.text-lg { font-size: var(--font-size-lg); }

.mt-0 { margin-top: 0; }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }

.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

.hidden { display: none; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 375px) {
    html { font-size: 14px; }
}

@media (min-width: 768px) {
    .app-shell {
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.1);
    }
}

/* ============================================
   PWA SPECIFIC
   ============================================ */
@media (display-mode: standalone) {
    .app-shell {
        box-shadow: none;
    }
}

/* Safe area for notched devices */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--header-height) + env(safe-area-inset-top));
    }

    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    }
}
