/* CalQ AI Mini App — branded light palette, ignores Telegram theme.
   We use our own colors so contrast is guaranteed regardless of
   whether the user runs Telegram in light or dark mode. */

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

html, body {
    min-height: 100vh;
    overflow-x: hidden;
    background: #ffffff;
    color: #1c1c1d;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.4;
}

/* ── Header ────────────────────────────────────────────────────────── */

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #ffffff;
    padding: 12px 16px 8px;
    border-bottom: 1px solid #e5e5ea;
}

.search-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #d1d1d6;
    border-radius: 12px;
    background: #f2f2f7;
    color: #1c1c1d;
    font-size: 16px;
    outline: none;
    -webkit-appearance: none;
}

.search-input::placeholder {
    color: #8e8e93;
}

.search-input:focus {
    background: #ffffff;
    border-color: #2481cc;
    box-shadow: 0 0 0 2px rgba(36, 129, 204, 0.2);
}

/* ── Tabs ──────────────────────────────────────────────────────────── */

.tabs {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    background: #ffffff;
    position: sticky;
    top: 60px;
    z-index: 9;
    border-bottom: 1px solid #e5e5ea;
}

.tab {
    flex: 1;
    padding: 10px 12px;
    border: none;
    background: #f2f2f7;
    color: #6d6d72;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.tab.active {
    background: #2481cc;
    color: #ffffff;
}

/* ── Results list ──────────────────────────────────────────────────── */

.results {
    padding: 12px 16px 24px;
    min-height: 300px;
    background: #ffffff;
}

.result-item {
    background: #ffffff;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: transform 0.1s;
    border: 1px solid #e5e5ea;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.result-item:active {
    transform: scale(0.98);
    background: #f2f2f7;
}

.result-name {
    font-weight: 600;
    font-size: 15px;
    color: #1c1c1d;
    margin-bottom: 4px;
}

.result-brand {
    font-size: 12px;
    color: #8e8e93;
    margin-bottom: 6px;
}

.result-nutrition {
    font-size: 13px;
    color: #6d6d72;
}

.result-nutrition strong {
    color: #1c1c1d;
}

.source-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    background: #f2f2f7;
    color: #6d6d72;
    margin-left: 6px;
}

.empty-state {
    text-align: center;
    color: #8e8e93;
    padding: 40px 20px;
    font-size: 14px;
}

/* ── Loading spinner ───────────────────────────────────────────────── */

.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e5e5ea;
    border-top-color: #2481cc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.hidden {
    display: none !important;
}

/* ── Modal ─────────────────────────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.15s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    width: 100%;
    background: #ffffff;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px max(20px, env(safe-area-inset-bottom));
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.modal-content h3 {
    font-size: 18px;
    margin-bottom: 6px;
    color: #1c1c1d;
}

.modal-nutrition {
    font-size: 13px;
    color: #8e8e93;
    margin-bottom: 16px;
}

.quick-grams {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.g-btn {
    padding: 12px 0;
    border: 1px solid #d1d1d6;
    background: #f2f2f7;
    color: #1c1c1d;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.g-btn.selected {
    background: #2481cc;
    color: #ffffff;
    border-color: #2481cc;
}

.grams-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d1d1d6;
    border-radius: 10px;
    background: #f2f2f7;
    color: #1c1c1d;
    font-size: 16px;
    margin-bottom: 16px;
    outline: none;
    -webkit-appearance: none;
}

.grams-input:focus {
    border-color: #2481cc;
    background: #ffffff;
}

.modal-actions {
    display: flex;
    gap: 8px;
}

.btn-secondary, .btn-primary {
    flex: 1;
    padding: 14px 0;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary {
    background: #f2f2f7;
    color: #1c1c1d;
}

.btn-primary {
    background: #2481cc;
    color: #ffffff;
}

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