/* ============================================================
   core/ui.css — shared theme variables & UI components
   Loaded by the launcher and every app (before app styles).
   Telegram theme colors override the variables inline at runtime.
   ============================================================ */

/* ---- Theme variables (defaults; overridden by Telegram theme) ---- */
:root {
    --bg-color: #ffffff;
    --bg-secondary: #f0f2f5;
    --text-color: #1a1a1a;
    --text-secondary: #667085;
    --border-color: #e0e4ea;
    --accent-color: #0088cc;
    --accent-hover: #006da3;
    --accent-soft: rgba(0, 136, 204, 0.12);
    --card-bg: #ffffff;
    --header-bg: #ffffff;
    --input-bg: #ffffff;
    --input-border: #d0d5dd;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    --modal-bg: rgba(0, 0, 0, 0.5);
    --scrollbar-thumb: #c8cdd4;
    --scrollbar-track: transparent;

    /* Chat-specific (single source for the chat app) */
    --user-bubble-bg: #0088cc;
    --user-bubble-text: #ffffff;
    --ai-bubble-bg: #f0f2f5;
    --ai-bubble-text: #1a1a1a;
}

[data-theme="dark"] {
    --bg-color: #12141a;
    --bg-secondary: #1c1f26;
    --text-color: #e4e6ea;
    --text-secondary: #9aa1ad;
    --border-color: #2a2e37;
    --accent-color: #50a9e8;
    --accent-hover: #6db9ef;
    --accent-soft: rgba(80, 169, 232, 0.15);
    --card-bg: #1c1f26;
    --header-bg: #16181e;
    --input-bg: #1c1f26;
    --input-border: #333842;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --scrollbar-thumb: #3a404b;

    --user-bubble-bg: #50a9e8;
    --user-bubble-text: #0b1220;
    --ai-bubble-bg: #1c1f26;
    --ai-bubble-text: #e4e6ea;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body {
    overflow-x: hidden;
}

a {
    color: var(--accent-color);
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, textarea, select {
    font-family: inherit;
    font-size: 15px;
    color: var(--text-color);
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    padding: 10px 12px;
    outline: none;
    width: 100%;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--accent-color);
}

::placeholder {
    color: var(--text-secondary);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

/* ---- App shell (each app page) ---- */
.app-page {
    max-width: 560px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100%;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 20px 0 10px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    transition: opacity 0.15s, transform 0.1s;
    border: none;
}

.btn:active {
    transform: scale(0.97);
}

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

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

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

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

.btn-block {
    width: 100%;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    font-size: 18px;
    flex-shrink: 0;
}

.icon-btn:active {
    transform: scale(0.92);
}

/* ---- Back button (hidden inside Telegram, native BackButton used) ---- */
.back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-color);
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
}

body.in-tg .back-btn {
    display: none;
}

/* ---- Chips / tags ---- */
.chip {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    background: var(--accent-soft);
    color: var(--accent-color);
}

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    background: var(--text-color);
    box-shadow: var(--shadow);
    z-index: 1000;
    animation: toast-in 0.25s ease;
    max-width: 90vw;
    text-align: center;
    direction: rtl;
}

.toast.success { background: var(--success-color); }
.toast.error { background: var(--danger-color); }
.toast.info { background: var(--accent-color); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(12px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Generic modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: var(--card-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.modal-box h3 {
    font-size: 17px;
    margin-bottom: 14px;
}

/* ---- Language switcher ---- */
.lang-switcher {
    display: inline-flex;
    gap: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 3px;
    flex-shrink: 0;
}

.lang-pill {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}

.lang-pill.active {
    background: var(--accent-color);
    color: var(--user-bubble-text);
}

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

.empty-state .empty-icon {
    font-size: 42px;
    margin-bottom: 10px;
}

/* ---- New-version banner (injected by core/tg.js) ---- */
.update-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-color);
    background: var(--accent-soft);
    border-bottom: 1px solid var(--accent-color);
    text-align: center;
}

.update-banner .ub-btn {
    padding: 5px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    color: var(--user-bubble-text);
    background: var(--accent-color);
    border: none;
    cursor: pointer;
}

/* ---- Backup row (notes / bookmarks / shopping) ---- */
.backup-row {
    display: flex;
    gap: 8px;
    margin: 10px 0 18px;
}

.backup-row .btn {
    flex: 1;
    padding: 9px;
    font-size: 12px;
}

/* ---- Version badge (every page; injected by core/tg.js) ---- */
.version-badge {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 2px 8px;
    white-space: nowrap;
    flex-shrink: 0;
    direction: ltr;
    unicode-bidi: embed;
}

.version-badge.updating {
    color: var(--accent-color);
    border-color: var(--accent-color);
}