/**
 * Dreamer's Activewear — Sales & Inventory App v2
 * Mobile-first, iPad-optimized, soft premium aesthetic
 */

/* ===========================
   CSS Variables
   =========================== */
:root {
    /* Sage greens */
    --sage: #6B8F71;
    --sage-light: #8B9E7E;
    --sage-dark: #4A6B50;
    --sage-50: #eef4ef;
    --sage-100: #dce8dd;

    /* Cream */
    --cream: #FDFBF7;
    --cream-dark: #F5F0E8;

    /* Blush */
    --blush: #E8C4C0;
    --blush-light: #F5E4E2;

    /* Neutrals */
    --text-primary: #2D3748;
    --text-secondary: #718096;
    --text-light: #A0AEC0;
    --border: #E8E4DE;
    --white: #FFFFFF;

    /* Stock status */
    --stock-good: #059669;
    --stock-low: #D97706;
    --stock-out: #DC2626;
    --stock-good-bg: #D1FAE5;
    --stock-low-bg: #FEF3C7;
    --stock-out-bg: #FEE2E2;

    /* Spacing */
    --topbar-h: 52px;
    --bottomnav-h: 48px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);

    /* Transitions */
    --ease: 0.2s ease;
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--cream);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--sage); text-decoration: none; }
img { max-width: 100%; display: block; }

/* ===========================
   Top Bar
   =========================== */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: var(--shadow-sm);
    z-index: 1000;
}

.topbar__brand {
    font-size: 17px;
    font-weight: 700;
    color: var(--sage-dark);
    letter-spacing: -0.2px;
}

.topbar__brand span {
    color: var(--blush);
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar__btn {
    width: 36px; height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--ease), color var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.topbar__btn:active {
    background: var(--sage-50);
    color: var(--sage);
}

.lang-toggle {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 30px;
    text-align: center;
}

/* ===========================
   Bottom Navigation
   =========================== */
.bottomnav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottomnav-h);
    background: var(--white);
    display: flex;
    align-items: stretch;
    border-top: 1px solid var(--border);
    box-shadow: 0 -1px 4px rgba(0,0,0,0.04);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottomnav__tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 0;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-light);
    font-size: 10px;
    font-weight: 500;
    text-decoration: none;
    position: relative;
    transition: color var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.bottomnav__tab__icon {
    font-size: 20px;
    line-height: 1;
}

.bottomnav__tab.active {
    color: var(--sage);
}

.bottomnav__tab.active::after {
    content: '';
    position: absolute;
    top: 0; left: 25%; right: 25%;
    height: 2px;
    background: var(--sage);
    border-radius: 0 0 2px 2px;
}

.bottomnav__tab:active {
    background: var(--sage-50);
}

/* ===========================
   Main Content
   =========================== */
.main {
    padding-top: var(--topbar-h);
    padding-bottom: calc(var(--bottomnav-h) + var(--bottomnav-h));
    min-height: 100vh;
}

.container {
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
}

/* ===========================
   Page Headers
   =========================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}

.page-header__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--sage-dark);
    letter-spacing: -0.3px;
}

/* ===========================
   Stats Cards
   =========================== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0 16px 16px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.stat-card__value {
    font-size: 26px;
    font-weight: 800;
    color: var(--sage-dark);
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.stat-card__label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

.stat-card--accent .stat-card__value {
    color: var(--sage);
}

.stat-card--blush .stat-card__value {
    color: #c0787a;
}

.stat-card--warn .stat-card__value {
    color: var(--stock-low);
}

/* ===========================
   Large Action Buttons (Home)
   =========================== */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0 16px 16px;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 140px;
    border: none;
    border-radius: var(--radius-xl);
    cursor: pointer;
    text-decoration: none;
    color: var(--white);
    font-size: 15px;
    font-weight: 700;
    box-shadow: var(--shadow-md);
    transition: transform var(--ease), box-shadow var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-sm);
}

.action-btn__emoji {
    font-size: 36px;
    line-height: 1;
}

.action-btn--sale {
    background: linear-gradient(135deg, var(--sage) 0%, var(--sage-dark) 100%);
}

.action-btn--restock {
    background: linear-gradient(135deg, #5B7C8E 0%, #3D5A6E 100%);
}

.action-btn--products {
    background: linear-gradient(135deg, var(--blush) 0%, #C89590 100%);
    color: #5a3030;
}

.action-btn--reports {
    background: linear-gradient(135deg, #8B8B8B 0%, #6B6B6B 100%);
}

/* ===========================
   Product Cards
   =========================== */
.product-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 12px;
    display: flex;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 10px;
    transition: box-shadow var(--ease);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.product-card:active {
    box-shadow: var(--shadow-md);
}

.product-card__photo {
    width: 80px; height: 80px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    background: var(--cream-dark);
}

.product-card__photo img {
    width: 100%; height: 100%;
    object-fit: cover;
}

.product-card__info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.product-card__name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-card__price {
    font-size: 14px;
    color: var(--sage);
    font-weight: 600;
}

.product-card__stock {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    width: fit-content;
}

.stock-badge--good { background: var(--stock-good-bg); color: var(--stock-good); }
.stock-badge--low { background: var(--stock-low-bg); color: var(--stock-low); }
.stock-badge--out { background: var(--stock-out-bg); color: var(--stock-out); }

/* ===========================
   Expandable Sections
   =========================== */
.expand-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 6px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.expand-toggle .arrow {
    transition: transform var(--ease);
    font-size: 10px;
}

.expand-toggle.open .arrow {
    transform: rotate(180deg);
}

.expand-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.expand-content.open {
    max-height: 1000px;
}

/* ===========================
   Sales History List Items
   =========================== */
.sale-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--white);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    border: 1px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}

.sale-item__thumb {
    width: 48px; height: 48px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    background: var(--cream-dark);
}

.sale-item__thumb img {
    width: 100%; height: 100%;
    object-fit: cover;
}

.sale-item__info {
    flex: 1;
    min-width: 0;
}

.sale-item__product {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.sale-item__detail {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sale-item__price {
    text-align: right;
    font-size: 14px;
    font-weight: 700;
    color: var(--sage-dark);
    flex-shrink: 0;
}

.sale-item__channel {
    font-size: 10px;
    color: var(--text-light);
    margin-top: 2px;
}

/* ===========================
   Forms
   =========================== */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.3px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px; /* prevents iOS zoom */
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--text-primary);
    transition: border-color var(--ease), box-shadow var(--ease);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(107, 143, 113, 0.15);
}

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

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

select.form-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23718096' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

/* ===========================
   Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: opacity var(--ease), transform var(--ease);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
}

.btn:active {
    opacity: 0.85;
    transform: scale(0.98);
}

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

.btn--secondary {
    background: var(--cream-dark);
    color: var(--text-primary);
    border: 1.5px solid var(--border);
}

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

.btn--sm {
    padding: 8px 14px;
    font-size: 14px;
    width: auto;
}

/* ===========================
   Variant Pills
   =========================== */
.pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: var(--white);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--ease);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.pill:active,
.pill.active {
    background: var(--sage);
    color: var(--white);
    border-color: var(--sage);
}

.pill--size {
    min-width: 44px;
    justify-content: center;
}

.pill--color {
    min-width: 44px;
    justify-content: center;
}

.pill--disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ===========================
   Channel & Period Selector Pills
   =========================== */
.chip-group {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.chip-group::-webkit-scrollbar {
    display: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: var(--white);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.chip.active {
    background: var(--sage);
    color: var(--white);
    border-color: var(--sage);
}

.chip:active {
    transform: scale(0.96);
}

/* ===========================
   Quantity Stepper
   =========================== */
.qty-stepper {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--white);
}

.qty-stepper__btn {
    width: 40px; height: 40px;
    border: none;
    background: var(--cream-dark);
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.qty-stepper__btn:active {
    background: var(--sage-100);
}

.qty-stepper__btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.qty-stepper__value {
    width: 50px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    border: none;
    background: transparent;
    padding: 0;
    -moz-appearance: textfield;
}

.qty-stepper__value::-webkit-outer-spin-button,
.qty-stepper__value::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

/* ===========================
   Pin Input (Login)
   =========================== */
.pin-container {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 32px 0;
}

.pin-dot {
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--white);
    transition: all var(--ease);
}

.pin-dot.filled {
    background: var(--sage);
    border-color: var(--sage);
}

.pin-dot.error {
    background: var(--stock-out);
    border-color: var(--stock-out);
}

.pin-keypad {
    display: grid;
    grid-template-columns: repeat(3, 76px);
    gap: 12px;
    justify-content: center;
    margin-top: 24px;
}

.pin-key {
    width: 76px; height: 76px;
    border: none;
    border-radius: 50%;
    background: var(--white);
    font-size: 28px;
    font-weight: 300;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: all var(--ease);
    -webkit-tap-highlight-color: transparent;
}

.pin-key:active {
    background: var(--sage-100);
    transform: scale(0.95);
}

.pin-key--empty {
    background: transparent;
    box-shadow: none;
    cursor: default;
}

.pin-key--delete {
    font-size: 20px;
}

/* ===========================
   Toast Notifications
   =========================== */
.toast {
    position: fixed;
    bottom: calc(var(--bottomnav-h) + 16px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 600;
    color: var(--white);
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: calc(100vw - 32px);
    text-align: center;
}

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

.toast--success { background: #059669; }
.toast--error { background: var(--stock-out); }
.toast--info { background: var(--sage); }

/* ===========================
   Card Container
   =========================== */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 12px;
}

.card__title {
    font-size: 16px;
    font-weight: 700;
    color: var(--sage-dark);
    margin-bottom: 12px;
}

/* ===========================
   Top Sellers List
   =========================== */
.top-seller-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

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

.top-seller-rank {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--sage-100);
    color: var(--sage-dark);
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.top-seller-rank.gold { background: #FEF3C7; color: #B45309; }
.top-seller-rank.silver { background: #F1F5F9; color: #64748B; }
.top-seller-rank.bronze { background: #FED7AA; color: #C2410C; }

.top-seller__info { flex: 1; }
.top-seller__name { font-size: 14px; font-weight: 600; }
.top-seller__qty { font-size: 12px; color: var(--text-secondary); }
.top-seller__rev { font-size: 14px; font-weight: 700; color: var(--sage); }

/* ===========================
   Section Spacing
   =========================== */
.section {
    margin-bottom: 20px;
}

.section__title {
    font-size: 15px;
    font-weight: 700;
    color: var(--sage-dark);
    margin-bottom: 10px;
    padding-left: 4px;
}

/* ===========================
   Loading Spinner
   =========================== */
.spinner {
    width: 24px; height: 24px;
    border: 2.5px solid var(--sage-100);
    border-top-color: var(--sage);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 24px auto;
}

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

/* ===========================
   Empty State
   =========================== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.empty-state__icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state__text {
    font-size: 14px;
    font-weight: 500;
}

/* ===========================
   Login Page
   =========================== */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
    background: linear-gradient(180deg, var(--cream) 0%, var(--sage-50) 100%);
}

.login-logo {
    font-size: 28px;
    font-weight: 800;
    color: var(--sage-dark);
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.login-logo span { color: var(--blush); }

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* ===========================
   Search Bar
   =========================== */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--white);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
}

.search-bar__icon {
    font-size: 16px;
    color: var(--text-light);
}

.search-bar__input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    background: transparent;
    color: var(--text-primary);
}

.search-bar__input::placeholder {
    color: var(--text-light);
}

/* ===========================
   Divider
   =========================== */
.divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

/* ===========================
   iPad + Desktop
   =========================== */
@media (min-width: 768px) {
    .main {
        padding-bottom: calc(var(--bottomnav-h) + 16px);
    }

    .container {
        max-width: 720px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .action-grid {
        max-width: 500px;
        margin: 0 auto;
    }

    .bottomnav {
        max-width: 500px;
        left: 50%;
        transform: translateX(-50%);
        margin-bottom: 12px;
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-lg);
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 900px;
    }
}

/* ===========================
   Print
   =========================== */
@media print {
    .topbar, .bottomnav, .toast { display: none !important; }
    .main { padding: 0 !important; }
    body { background: white !important; }
}

/* FAB */
.fab {
    position: fixed;
    bottom: calc(var(--bottomnav-h) + 20px);
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--sage);
    color: white;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    text-decoration: none;
    z-index: 50;
    transition: transform var(--ease);
}
.fab:active { transform: scale(0.92); }

/* Topbar language toggle */
.topbar__lang {
    width: auto;
    min-width: 28px;
    font-size: 12px;
    font-weight: 700;
}
.topbar__lang.active {
    background: var(--sage);
    color: white !important;
    border-radius: 100px;
}

/* Sale expanded detail */
.sale-detail.expanded { display: block !important; }
