/* ── Samal Water Mini App ── */

:root {
    --samal-red: #e63932;
    --samal-red-dark: #c4302a;
    --samal-red-light: #ff5c55;
    --bg-primary: #f5f5f5;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --border: #e8e8e8;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 16px;
    --radius-sm: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding-bottom: 100px;
    overscroll-behavior: none;
}

/* ── Header ── */

.header {
    background: linear-gradient(135deg, var(--samal-red), var(--samal-red-dark));
    color: white;
    padding: 20px 16px 24px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.header-sub {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 4px;
    font-weight: 400;
}

/* ── Tabs ── */

.tabs {
    display: flex;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 99;
}

.tab {
    flex: 1;
    padding: 14px 0;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.tab.active {
    color: var(--samal-red);
    border-bottom-color: var(--samal-red);
}

.tab .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--samal-red);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    padding: 0 5px;
    margin-left: 4px;
    vertical-align: middle;
}

/* ── Product Grid ── */

.products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 12px;
}

.product-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.15s;
}

.product-card:active {
    transform: scale(0.97);
}

.product-img-wrap {
    width: 100%;
    aspect-ratio: 1;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    position: relative;
}

.product-img-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.product-img-placeholder {
    font-size: 48px;
    opacity: 0.3;
}

.product-volume-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--samal-red);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 8px;
}

.product-info {
    padding: 12px;
}

.product-name {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.product-price {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
}

.product-price-suffix {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.btn-add {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--samal-red);
    color: white;
    font-size: 22px;
    font-weight: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}

.btn-add:active {
    background: var(--samal-red-dark);
}

/* ── Cart quantity control (in product card) ── */

.qty-control {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--samal-red);
    border-radius: 18px;
    overflow: hidden;
    height: 36px;
}

.qty-btn {
    width: 32px;
    height: 36px;
    border: none;
    background: transparent;
    color: white;
    font-size: 18px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-btn:active {
    background: rgba(0,0,0,0.15);
}

.qty-value {
    color: white;
    font-size: 14px;
    font-weight: 700;
    min-width: 24px;
    text-align: center;
}

/* ── Cart Page ── */

.cart-page {
    padding: 12px;
}

.cart-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.cart-empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.cart-empty-text {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.cart-empty-sub {
    font-size: 13px;
}

.cart-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
}

.cart-item-img {
    width: 60px;
    height: 60px;
    border-radius: 10px;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 6px;
}

.cart-item-img img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.cart-item-info {
    flex: 1;
    min-width: 0;
}

.cart-item-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-volume {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.cart-item-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cart-item-price {
    font-size: 15px;
    font-weight: 700;
}

.cart-item-controls {
    display: flex;
    align-items: center;
    gap: 0;
    background: #f0f0f0;
    border-radius: 14px;
    overflow: hidden;
    height: 28px;
}

.cart-ctrl-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.cart-ctrl-btn:active {
    background: #e0e0e0;
}

.cart-ctrl-btn.delete {
    color: var(--samal-red);
}

.cart-ctrl-qty {
    font-size: 14px;
    font-weight: 700;
    min-width: 24px;
    text-align: center;
}

/* ── Cart Summary ── */

.cart-summary {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 12px;
    box-shadow: var(--shadow);
}

.cart-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.cart-summary-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.cart-summary-value {
    font-size: 14px;
    font-weight: 600;
}

.cart-summary-total {
    border-top: 1px solid var(--border);
    margin-top: 8px;
    padding-top: 12px;
}

.cart-summary-total .cart-summary-label {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.cart-summary-total .cart-summary-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--samal-red);
}

/* ── Checkout Form ── */

.checkout-page {
    padding: 12px;
}

.form-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.form-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group:last-child {
    margin-bottom: 0;
}

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

.form-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: var(--bg-primary);
}

.form-input:focus {
    border-color: var(--samal-red);
}

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

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

/* ── Success Page ── */

.success-page {
    padding: 40px 20px;
    text-align: center;
}

.success-icon {
    font-size: 72px;
    margin-bottom: 20px;
}

.success-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.success-text {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 24px;
}

.kaspi-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    text-align: left;
    margin-bottom: 16px;
}

.kaspi-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--samal-red);
}

.kaspi-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.kaspi-label {
    font-size: 13px;
    color: var(--text-muted);
}

.kaspi-value {
    font-size: 14px;
    font-weight: 600;
}

/* ── Loading ── */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--samal-red);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ── Page transitions ── */

.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

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

/* ── Toast notifications ── */

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    z-index: 200;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ── Telegram theme ── */

body.tg-theme-dark {
    --bg-primary: #1a1a1a;
    --bg-card: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --text-muted: #777777;
    --border: #3a3a3a;
}
