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

/* ─── Theme Variables ───────────────────────────────────────── */
:root {
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

/* Light theme */
[data-theme="light"] {
    --bg:            #f2f2f7;
    --surface:       #ffffff;
    --surface-2:     #f7f7f7;
    --border:        rgba(0, 0, 0, 0.07);
    --text-primary:  #1c1c1e;
    --text-secondary:#6d6d72;
    --text-tertiary: #aeaeb2;
    --accent:        #007aff;
    --accent-soft:   rgba(0, 122, 255, 0.12);
    --danger:        #ff3b30;
    --danger-soft:   rgba(255, 59, 48, 0.10);
    --shadow-sm:     0 1px 4px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
    --shadow-md:     0 4px 24px rgba(0,0,0,0.08);
    --overlay:       rgba(0,0,0,0.35);
}

/* Dark theme */
[data-theme="dark"] {
    --bg:            #0e0e12;
    --surface:       #1c1c22;
    --surface-2:     #252529;
    --border:        rgba(255, 255, 255, 0.07);
    --text-primary:  #f2f2f7;
    --text-secondary:#98989e;
    --text-tertiary: #8e8e93;
    --accent:        #0a84ff;
    --accent-soft:   rgba(10, 132, 255, 0.18);
    --danger:        #ff453a;
    --danger-soft:   rgba(255, 69, 58, 0.15);
    --shadow-sm:     0 1px 4px rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.25);
    --shadow-md:     0 4px 24px rgba(0,0,0,0.5);
    --overlay:       rgba(0,0,0,0.6);
}

/* Ensure placeholders are always readable in dark mode */
[data-theme="dark"] .composer-input::placeholder,
[data-theme="dark"] .search-input::placeholder,
[data-theme="dark"] .ask-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

/* ─── Body ───────────────────────────────────────────────────── */
html { height: 100%; }

body {
    font-family: var(--font);
    background-color: var(--bg);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition), color var(--transition);
    overflow-x: hidden;
}

#app {
    max-width: 640px;
    margin: 0 auto;
    padding: 0 0 80px;
}

/* ─── Header ─────────────────────────────────────────────────── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    transition: background-color var(--transition);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #30d158);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}

.header-info { overflow: hidden; }

.header-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color var(--transition);
}

.header-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
    transition: color var(--transition);
}

/* Theme toggle button */
.theme-toggle {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    transition: background var(--transition), color var(--transition), transform var(--transition);
}
.theme-toggle:active { transform: scale(0.92); }

/* ─── Composer ───────────────────────────────────────────────── */
.composer-wrap {
    padding: 0 16px 12px;
}

.composer {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.composer:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

.composer-input {
    display: block;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 400;
    line-height: 1.6;
    padding: 14px 16px 8px;
    resize: none;
    outline: none;
    min-height: 52px;
    max-height: 200px;
    overflow-y: auto;
    transition: color var(--transition);
}

.composer-input::placeholder { color: var(--text-tertiary); }

.composer-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px 8px 16px;
}

.char-count {
    font-size: 12px;
    color: var(--text-tertiary);
    transition: color var(--transition);
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--transition), opacity var(--transition), background var(--transition);
    flex-shrink: 0;
}
.send-btn:hover { opacity: 0.88; }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.4; cursor: default; }

/* ─── Search ─────────────────────────────────────────────────── */
.search-wrap {
    padding: 0 16px 16px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0 12px;
    height: 42px;
    transition: border-color var(--transition), background var(--transition);
}

.search-box:focus-within {
    border-color: var(--accent);
}

.search-icon { color: var(--text-tertiary); flex-shrink: 0; }

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: color var(--transition);
}
.search-input::placeholder { color: var(--text-tertiary); }

.search-clear {
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 50%;
    transition: color var(--transition), background var(--transition);
}
.search-clear:hover { color: var(--text-primary); background: var(--surface-2); }

/* ─── Notes List ─────────────────────────────────────────────── */
.main {
    padding: 0 16px;
}

#notes-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ─── Note Card ──────────────────────────────────────────────── */
.note-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: default;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition), background var(--transition);
    animation: card-in 0.25s cubic-bezier(0.4, 0, 0.2, 1) both;
    position: relative;
    overflow: hidden;
}

.note-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

/* Swipe-to-reveal left accent line */
.note-card::before {
    content: '';
    position: absolute;
    left: 0; top: 12px; bottom: 12px;
    width: 3px;
    border-radius: 2px;
    background: var(--accent);
    opacity: 0;
    transition: opacity var(--transition);
}
.note-card:hover::before { opacity: 1; }

.note-content {
    font-size: 14.5px;
    line-height: 1.65;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
    margin-bottom: 12px;
    transition: color var(--transition);
}

/* Limit note preview to 6 lines when collapsed */
.note-content.collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.expand-btn {
    font-size: 12px;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-bottom: 10px;
    font-family: var(--font);
    font-weight: 500;
    display: block;
}

.note-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.note-date {
    font-size: 11.5px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color var(--transition);
}

.note-date svg { flex-shrink: 0; }

.delete-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 12px;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    transition: color var(--transition), background var(--transition);
}
.delete-btn:hover {
    color: var(--danger);
    background: var(--danger-soft);
}

/* ─── Empty State ────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--surface);
    border: 1.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    color: var(--text-tertiary);
    box-shadow: var(--shadow-sm);
}

.empty-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.empty-sub {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 260px;
    margin: 0 auto;
    line-height: 1.5;
}

/* ─── Loading Spinner ────────────────────────────────────────── */
.loading-state {
    display: flex;
    justify-content: center;
    padding: 48px 0;
}

.spinner {
    width: 26px;
    height: 26px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* ─── Delete Dialog / Overlay ────────────────────────────────── */
.overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    animation: fade-in 0.2s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.confirm-dialog {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
    animation: slide-up 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.confirm-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.confirm-sub {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.confirm-actions {
    display: flex;
    gap: 10px;
}

.btn-cancel, .btn-confirm-delete {
    flex: 1;
    height: 46px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--transition), transform var(--transition);
}
.btn-cancel:active, .btn-confirm-delete:active { transform: scale(0.97); }

.btn-cancel {
    background: var(--surface-2);
    color: var(--text-primary);
    border: 1.5px solid var(--border);
}

.btn-confirm-delete {
    background: var(--danger);
    color: #fff;
}

.btn-confirm-delete:hover { opacity: 0.88; }

/* ─── Toast ──────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--text-primary);
    color: var(--bg);
    font-size: 13.5px;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: 100px;
    z-index: 200;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
}

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

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

/* ─── Selection ──────────────────────────────────────────────── */
::selection { background: var(--accent-soft); color: var(--accent); }

/* ─── Note action buttons ────────────────────────────────────── */
.note-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1.5px solid var(--border);
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font);
    font-weight: 500;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 100px;
    transition: color var(--transition), background var(--transition),
                border-color var(--transition), transform var(--transition);
    white-space: nowrap;
}
.action-btn:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}
.action-btn:active { transform: scale(0.95); }
.action-btn:disabled {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}
.action-btn.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ─── Supplements ────────────────────────────────────────────── */
.supplements-list {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.supplement-block {
    border-top: 1.5px solid var(--border);
    padding-top: 12px;
    animation: card-in 0.25s ease both;
}

.supplement-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.supplement-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 3px 8px;
    border-radius: 100px;
    border: 1.5px solid;
}

.supplement-label.summary {
    color: #30d158;
    border-color: rgba(48, 209, 88, 0.3);
    background: rgba(48, 209, 88, 0.08);
}

.supplement-label.qa {
    color: #bf5af2;
    border-color: rgba(191, 90, 242, 0.3);
    background: rgba(191, 90, 242, 0.08);
}

.supplement-question {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
    font-style: italic;
}

.supplement-content {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── Ask question inline input ──────────────────────────────── */
.ask-input-wrap {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: card-in 0.2s ease both;
}

.ask-input {
    flex: 1;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    padding: 9px 12px;
    outline: none;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color var(--transition), background var(--transition);
    line-height: 1.5;
}
.ask-input::placeholder { color: var(--text-tertiary); }
.ask-input:focus {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.ask-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform var(--transition), opacity var(--transition);
}
.ask-send-btn:hover { opacity: 0.85; }
.ask-send-btn:active { transform: scale(0.92); }
.ask-send-btn:disabled { opacity: 0.4; cursor: default; }

/* ─── Demo mode blur overlay on composer/search ─────────────── */
.demo-mode .composer,
.demo-mode .search-wrap {
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
}

/* ─── Telegram-only banner ───────────────────────────────────── */
.tg-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1.5px solid var(--border);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.10);
    animation: slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tg-banner-inner {
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.tg-banner-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    color: #2CA5E0;
    fill: #2CA5E0;
}

.tg-banner-text {
    flex: 1;
    min-width: 0;
}

.tg-banner-text strong {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.tg-banner-text span {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.tg-banner-close {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--surface-2);
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color var(--transition), background var(--transition);
}
.tg-banner-close:hover { color: var(--text-primary); background: var(--border); }

