/* ── Reset & Tokens ─────────────────────────────────────────── */
:root {
    --bg: #080b12;
    --bg2: #0e1220;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.07);
    --border-focus: rgba(108, 92, 231, 0.5);
    --accent: #6c5ce7;
    --accent-2: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.25);
    --green: #25D366;
    --green-glow: rgba(37, 211, 102, 0.2);
    --text: #f0f0f8;
    --text-2: #8a8aa8;
    --text-3: #5a5a7a;
    --danger: #e55;
    --r-sm: 10px;
    --r-md: 16px;
    --r-lg: 24px;
    --r-xl: 32px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    --trans: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-w: 260px;
    --topbar-h: 60px;
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* ── Ambient blobs ──────────────────────────────────────────── */
.bg-blobs {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.18;
    animation: blobDrift 20s ease-in-out infinite alternate;
}

.blob-1 {
    width: 600px;
    height: 600px;
    background: #6c5ce7;
    top: -200px;
    left: -200px;
    animation-delay: 0s;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: #00b894;
    bottom: -100px;
    right: -100px;
    animation-delay: -7s;
}

.blob-3 {
    width: 300px;
    height: 300px;
    background: #fd79a8;
    top: 40%;
    left: 50%;
    animation-delay: -13s;
}

@keyframes blobDrift {
    from {
        transform: translate(0, 0) scale(1);
    }

    to {
        transform: translate(40px, 60px) scale(1.1);
    }
}

/* ── Login ──────────────────────────────────────────────────── */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 20% 50%, rgba(108, 92, 231, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 30%, rgba(37, 211, 102, 0.08) 0%, transparent 60%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 2.5rem 2.5rem 3rem;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    text-align: center;
    animation: cardIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 1.5rem;
    background: var(--green-glow);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 32px var(--green-glow);
}

.login-logo svg {
    width: 36px;
    height: 36px;
}

.login-card h1 {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 0.4rem;
}

.login-card>p {
    color: var(--text-2);
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.login-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
}

.field-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.4rem;
}

.field-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--trans), box-shadow var(--trans);
}

.field-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-error {
    background: rgba(238, 85, 85, 0.12);
    border: 1px solid rgba(238, 85, 85, 0.3);
    color: #ff7f7f;
    border-radius: var(--r-sm);
    padding: 0.65rem 1rem;
    font-size: 0.85rem;
    text-align: center;
    animation: shake 0.35s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-6px);
    }

    75% {
        transform: translateX(6px);
    }
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    background: linear-gradient(135deg, var(--accent), #8b7cf8);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    font-family: inherit;
    border: none;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all var(--trans);
    box-shadow: 0 4px 20px var(--accent-glow);
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(108, 92, 231, 0.45);
}

.btn-primary:active {
    transform: translateY(0);
}

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

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all var(--trans);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-ghost.small {
    padding: 0.3rem 0.65rem;
    font-size: 0.75rem;
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-2);
    cursor: pointer;
    transition: all var(--trans);
}

.icon-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.icon-btn.danger:hover {
    background: rgba(238, 85, 85, 0.12);
    border-color: rgba(238, 85, 85, 0.3);
    color: var(--danger);
}

/* ── App shell ──────────────────────────────────────────────── */
.app {
    position: relative;
    z-index: 1;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: rgba(8, 11, 18, 0.8);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: -0.3px;
}

.topbar-brand svg {
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    color: var(--text-3);
    pointer-events: none;
}

.search-wrap input {
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    width: 260px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text);
    font-size: 0.875rem;
    font-family: inherit;
    outline: none;
    transition: all var(--trans);
}

.search-wrap input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-count {
    position: absolute;
    right: 0.75rem;
    font-size: 0.72rem;
    color: var(--text-3);
    white-space: nowrap;
}

/* ── Drop zone page ─────────────────────────────────────────── */
.drop-zone-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.drop-zone-card {
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: var(--r-xl);
    padding: 3.5rem 2.5rem;
    text-align: center;
    backdrop-filter: blur(20px);
    transition: all var(--trans);
    cursor: default;
}

.drop-zone-card.dragover,
.drop-zone-card:hover {
    border-color: var(--accent);
    background: rgba(108, 92, 231, 0.06);
    box-shadow: 0 0 40px var(--accent-glow);
    transform: translateY(-4px);
}

.dz-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 1.5rem;
    background: rgba(108, 92, 231, 0.12);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 32px rgba(108, 92, 231, 0.15);
}

.dz-icon svg {
    width: 32px;
    height: 32px;
    color: var(--accent-2);
}

.drop-zone-card h2 {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 0.6rem;
}

.drop-zone-card p {
    color: var(--text-2);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.drop-zone-card code {
    font-family: monospace;
    background: rgba(255, 255, 255, 0.07);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.drop-zone-card .btn-primary {
    width: auto;
    margin: 0 auto;
}

.dz-note {
    margin-top: 1.5rem;
    font-size: 0.8rem;
    color: var(--text-3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.dz-note::before {
    content: "🔒";
}

/* ── Viewer layout ──────────────────────────────────────────── */
.viewer {
    flex: 1;
    display: flex;
    height: calc(100vh - var(--topbar-h));
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: calc(100vh - var(--topbar-h));
    background: rgba(8, 11, 18, 0.6);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.chat-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    overflow: hidden;
    flex: 1;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #25D366, #128C7E);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 0 16px var(--green-glow);
}

.chat-info {
    overflow: hidden;
}

.chat-name {
    font-weight: 700;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-stats {
    font-size: 0.72rem;
    color: var(--text-3);
    margin-top: 1px;
}

.sidebar-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 0.75rem 0;
    gap: 0.25rem;
}

.nav-tab {
    flex: 1;
    padding: 0.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-2);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--trans);
    border-radius: var(--r-sm) var(--r-sm) 0 0;
}

.nav-tab:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.nav-tab.active {
    color: var(--accent-2);
    border-bottom-color: var(--accent);
}

.tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.tab-content.hidden {
    display: none;
}

/* Scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(108, 92, 231, 0.4) transparent;
}

::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(108, 92, 231, 0.4);
    border-radius: 999px;
}

/* ── Timeline tree ──────────────────────────────────────────── */
.timeline-tree {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tree-year {}

.tree-year-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text);
    transition: background var(--trans);
    user-select: none;
}

.tree-year-label:hover {
    background: var(--surface-hover);
}

.tree-caret {
    font-size: 0.65rem;
    color: var(--text-3);
    transition: transform var(--trans);
}

.tree-year-label.open .tree-caret {
    transform: rotate(90deg);
}

.tree-months {
    display: none;
    flex-direction: column;
    gap: 1px;
    padding-left: 1rem;
}

.tree-months.open {
    display: flex;
}

.tree-month-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-2);
    transition: background var(--trans);
    user-select: none;
}

.tree-month-label:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.tree-month-label.open .tree-caret {
    transform: rotate(90deg);
}

.tree-dates {
    display: none;
    flex-direction: column;
    padding-left: 1rem;
}

.tree-dates.open {
    display: flex;
}

.tree-date-row {
    display: flex;
    align-items: center;
    border-radius: var(--r-sm);
    transition: background var(--trans);
}

.tree-date-row:hover {
    background: var(--surface-hover);
}

.tree-date-label {
    flex: 1;
    padding: 0.25rem 0.4rem;
    cursor: pointer;
    font-size: 0.76rem;
    color: var(--text-3);
    transition: color var(--trans);
}

.tree-date-label:hover {
    color: var(--accent-2);
}

.star-btn {
    background: none;
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    color: var(--text-3);
    transition: all var(--trans);
    flex-shrink: 0;
}

.star-btn:hover {
    color: #ffd700;
    transform: scale(1.2);
}

.star-btn.active {
    color: #ffd700;
}

/* ── Bookmarks ──────────────────────────────────────────────── */
.bookmarks-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bookmark-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--r-sm);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    transition: all var(--trans);
}

.bookmark-item:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateX(2px);
}

.bookmark-item::before {
    content: "📌";
    flex-shrink: 0;
}

.empty-hint {
    font-size: 0.78rem;
    color: var(--text-3);
    line-height: 1.6;
    padding: 0.5rem;
}

/* ── Chat pane ──────────────────────────────────────────────── */
.chat-pane {
    flex: 1;
    overflow: hidden;
}

.chat-bg {
    height: 100%;
    background-color: #0d1117;
    background-image:
        radial-gradient(ellipse at 0% 0%, rgba(37, 211, 102, 0.04) 0%, transparent 50%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.015'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    overflow-y: auto;
    padding: 1rem 4.5rem;
}

.chat-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ── Message bubbles ────────────────────────────────────────── */
.chat-date-pill {
    align-self: center;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.5);
    padding: 0.3rem 0.9rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 500;
    margin: 0.75rem 0;
    letter-spacing: 0.02em;
}

.message {
    max-width: 70%;
    padding: 0.55rem 0.85rem 1.4rem;
    border-radius: 12px;
    position: relative;
    font-size: 0.92rem;
    line-height: 1.5;
    word-break: break-word;
    animation: msgIn 0.15s ease both;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.received {
    align-self: flex-start;
    background: #202c33;
    color: #e9edef;
    border-top-left-radius: 2px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.message.received.consecutive {
    border-top-left-radius: 12px;
}

.message.sent {
    align-self: flex-end;
    background: #005c4b;
    color: #e9edef;
    border-top-right-radius: 2px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.message.sent.consecutive {
    border-top-right-radius: 12px;
}

.message.highlight {
    outline: 2px solid var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
}

.sender-name {
    font-weight: 700;
    font-size: 0.78rem;
    color: #53bdeb;
    margin-bottom: 0.2rem;
}

.message-text {
    white-space: pre-wrap;
}

.message-time {
    position: absolute;
    bottom: 0.28rem;
    right: 0.6rem;
    font-size: 0.67rem;
    color: rgba(233, 237, 239, 0.5);
}

/* ── Loading ─────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(8, 11, 18, 0.85);
    backdrop-filter: blur(8px);
}

.loader-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 2.5rem 3rem;
    text-align: center;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(108, 92, 231, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loader-text {
    font-size: 0.9rem;
    color: var(--text-2);
}

.hidden {
    display: none !important;
}

/* ── Animations for page transitions ──────────────────────────── */
.viewer {
    animation: fadeIn 0.3s ease both;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ── Search highlights ──────────────────────────────────────── */
mark {
    background: rgba(255, 214, 0, 0.35);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}