@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

/* ── DESIGN TOKENS ─────────────────────────────────────── */
:root {
    --ink: #111827;
    --ink-2: #1f2937;
    --ink-3: #374151;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --surface-3: #f3f4f6;
    --muted: #6b7280;
    --muted-2: #9ca3af;
    --border: #e5e7eb;
    --border-2: #d1d5db;

    --accent: #5b4fff;
    --accent-2: #7c6fff;
    --accent-3: #a78bfa;
    --accent-glow: rgba(91, 79, 255, 0.18);
    --accent-bg: rgba(91, 79, 255, 0.07);

    --green: #059669;
    --green-bg: rgba(5, 150, 105, 0.08);
    --red: #dc2626;
    --amber: #d97706;

    --font-display: 'DM Sans', sans-serif;
    --font-body: 'DM Sans', sans-serif;
    --font-mono: 'DM Mono', monospace;

    --r-xs: 4px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 20px;
    --r-2xl: 24px;
    --r-full: 999px;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-out: cubic-bezier(0, 0, 0.2, 1);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.10), 0 4px 8px rgba(0, 0, 0, 0.04);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--surface-2);
    color: var(--ink);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── LAYOUT ────────────────────────────────────────────── */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s var(--ease);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.04);
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border: none;
    border-radius: var(--r-md);
    color: white;
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    box-shadow: 0 2px 8px rgba(91, 79, 255, 0.2);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(91, 79, 255, 0.3);
}

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

.new-chat-btn svg {
    flex-shrink: 0;
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-history-item {
    padding: 10px 12px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all 0.2s var(--ease);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--ink-2);
    position: relative;
}

.chat-history-item:hover {
    background: var(--surface-3);
    color: var(--ink);
}

.chat-history-item.active {
    background: linear-gradient(135deg, rgba(91, 79, 255, 0.15), rgba(124, 111, 255, 0.1));
    color: var(--accent);
    border-left: 3px solid var(--accent);
    padding-left: 9px;
    font-weight: 600;
}

.chat-history-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface);
    min-width: 0;
}

/* ── TOPBAR ────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    z-index: 20;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.topbar-center {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    justify-content: center;
    min-width: 0;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: var(--r-sm);
    padding: 10px 16px;
    border: none;
    border-radius: var(--r-md);
    background: var(--surface-3);
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: fit-content;
    box-shadow: var(--shadow-xs);
    letter-spacing: 0.3px;
}

.action-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.action-btn.leave-btn {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(99, 102, 241, 0.1));
    color: var(--accent);
    border: 1.5px solid rgba(91, 79, 255, 0.3);
}

.action-btn.leave-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(99, 102, 241, 0.2));
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(91, 79, 255, 0.2);
}

.action-btn.wfh-btn {
    background: linear-gradient(135deg, rgba(3, 169, 244, 0.1), rgba(0, 172, 193, 0.1));
    color: #0369a1;
    border: 1.5px solid rgba(3, 169, 244, 0.3);
}

.action-btn.wfh-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(3, 169, 244, 0.2), rgba(0, 172, 193, 0.2));
    border-color: #0369a1;
    box-shadow: 0 4px 16px rgba(3, 169, 244, 0.2);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f3f4f6;
    color: #9ca3af;
    border: 1px solid #e5e7eb;
    transform: none !important;
    box-shadow: none;
}

.action-btn:disabled:hover {
    background-color: #f3f4f6 !important;
    transform: none !important;
    box-shadow: none !important;
}

.action-btn svg {
    transition: transform 0.2s var(--ease);
}

.action-btn:hover svg {
    transform: scale(1.1);
}

.balance-status {
    display: flex;
    gap: 12px;
    padding: 10px 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.7), rgba(249, 250, 251, 0.9));
    border-radius: var(--r-lg);
    border: 1.5px solid var(--border);
    font-size: 12px;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.balance-status.hidden {
    display: none !important;
}

.balance-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    border-right: 1px solid var(--border);
}

.balance-item:last-child {
    border-right: none;
    padding-right: 0;
}

.balance-label {
    font-weight: 600;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

.balance-value {
    font-weight: 700;
    padding: 3px 8px;
    border-radius: var(--r-sm);
    transition: all 0.2s var(--ease);
    position: relative;
    font-size: 13px;
    display: inline-block;
    min-width: 25px;
    text-align: center;
}

.balance-value:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.balance-value.available {
    color: white;
    background: linear-gradient(135deg, #059669, #10b981);
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
}

.balance-value.unavailable {
    color: white;
    background: linear-gradient(135deg, #dc2626, #ef4444);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s var(--ease);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--surface-3);
    color: var(--ink);
    border-color: var(--border-2);
}

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

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--green);
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--green-bg);
    animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.2);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(5, 150, 105, 0.1);
    }
}

.status-text {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.topbar-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--ink);
    letter-spacing: -0.025em;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s var(--ease);
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--surface-3);
    color: var(--ink);
    border-color: var(--border-2);
}

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

/* ── CATEGORY BAR ──────────────────────────────────────── */
.category-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow-x: hidden;
    justify-content: center;
    flex-wrap: wrap;
}

.category-bar::-webkit-scrollbar {
    display: none;
}

.bar-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--r-full);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-3);
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s var(--ease);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.2px;
}

.bar-pill::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(91, 79, 255, 0.2) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.bar-pill:active::before {
    opacity: 1;
}

.bar-pill:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
    color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(91, 79, 255, 0.18);
}

.bar-pill:active {
    transform: scale(0.98);
}

.bar-pill.active {
    background: linear-gradient(135deg, #5b4fff, #7c6fff);
    border-color: transparent;
    color: white;
    box-shadow: 0 4px 16px rgba(91, 79, 255, 0.35);
}

.bar-pill.active:hover {
    box-shadow: 0 6px 18px rgba(91, 79, 255, 0.45);
}

.bar-pill.active .bar-icon {
    animation: iconPop 0.4s var(--spring) both;
}

.bar-icon {
    font-size: 1rem;
    line-height: 1;
    display: block;
    flex-shrink: 0;
    transition: transform 0.25s var(--spring);
}

.bar-pill:hover .bar-icon {
    transform: scale(1.2) translateY(-1px);
}

@keyframes iconPop {
    0% {
        transform: scale(1) rotate(0deg);
    }

    45% {
        transform: scale(1.4) rotate(-8deg);
    }

    70% {
        transform: scale(0.92) rotate(4deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

/* ── CHAT AREA ─────────────────────────────────────────── */
.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    background: linear-gradient(135deg, #fafbfc 0%, #f5f6f8 100%);
    min-height: 0;
}

.chat-area::-webkit-scrollbar {
    width: 4px;
}

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: 2px;
}

/* ── WELCOME SCREEN ────────────────────────────────────── */
.welcome-screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    overflow-y: auto;
    animation: fadeUp 0.5s var(--ease-out) both;
    z-index: 5;
    background: var(--surface-2);
}

.welcome-screen.hidden {
    display: none !important;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.welcome-glow {
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(91, 79, 255, 0.07) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    border-radius: 50%;
}

.welcome-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    max-width: 640px;
    width: 100%;
    position: relative;
}

.welcome-avatar {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    opacity: 0.18;
    animation: spin-slow 8s linear infinite;
}

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

.avatar-emoji {
    font-size: 1.8rem;
    z-index: 1;
    color: var(--accent);
    position: relative;
}

.welcome-heading {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 3.5vw, 2rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--ink);
    text-align: center;
    line-height: 1.3;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-sub {
    font-size: 0.9rem;
    color: var(--muted);
    text-align: center;
    margin-top: -12px;
    font-weight: 400;
}

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
}

.cat-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 14px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--r-lg);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-3);
    transition: all 0.25s var(--ease);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.cat-pill:hover {
    border-color: var(--accent-3);
    background: var(--accent-bg);
    color: var(--accent);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(91, 79, 255, 0.15);
}

.cat-pill:active {
    transform: translateY(-1px);
}

.cat-pill.active {
    background: linear-gradient(135deg, #5b4fff, #7c6fff);
    border-color: transparent;
    color: white;
    box-shadow: 0 6px 24px rgba(91, 79, 255, 0.35);
    transform: translateY(-2px);
}

.cat-pill.active:hover {
    box-shadow: 0 8px 28px rgba(91, 79, 255, 0.45);
    transform: translateY(-3px);
}

.cat-pill.active .cat-icon {
    animation: iconPop 0.4s var(--spring) both;
}

.cat-icon {
    font-size: 1.5rem;
    transition: transform 0.25s var(--spring);
    display: block;
    line-height: 1;
}

.cat-pill:hover .cat-icon {
    transform: scale(1.2) translateY(-2px);
}

.active-mode-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--muted);
}

.mode-label {
    font-weight: 400;
}

.mode-chip {
    background: var(--accent-bg);
    color: var(--accent);
    border: 1px solid rgba(91, 79, 255, 0.18);
    border-radius: var(--r-full);
    padding: 3px 12px;
    font-size: 0.78rem;
    font-weight: 600;
}

/* ── CHAT MESSAGES ─────────────────────────────────────── */
.chat-history {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 780px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px 8px;
    flex: 1;
}

/* Message row wrapper for alignment control */
.message-row {
    display: flex;
    width: 100%;
    animation: msgIn 0.28s var(--ease-out) both;
}

.message-row.user {
    justify-content: flex-end;
}

.message-row.assistant {
    justify-content: flex-start;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }

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

.message {
    max-width: min(72%, 560px);
    min-width: 80px;
    padding: 12px 18px;
    border-radius: var(--r-xl);
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    width: fit-content;
    animation: msgIn 0.3s var(--ease-out) both;
}

.message.user {
    background: linear-gradient(135deg, #5b4fff, #7c6fff);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: 0 4px 16px rgba(91, 79, 255, 0.28);
}

.message.user a {
    color: #e0d5ff;
    text-decoration: underline;
}

.message.assistant {
    background: var(--surface);
    color: var(--ink);
    border: 1.5px solid var(--border);
    border-bottom-left-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

/* Small avatar indicator for assistant */
.message-row.assistant {
    gap: 8px;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, #5b4fff, #7c6fff);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: white;
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 2px;
    box-shadow: 0 4px 12px rgba(91, 79, 255, 0.28);
    font-weight: 600;
}

/* Timestamp label */
.msg-time {
    font-size: 0.68rem;
    color: var(--muted-2);
    margin-top: 3px;
    padding: 0 4px;
}

.message-row.user .msg-time {
    text-align: right;
}

.message-row.assistant .msg-time {
    text-align: left;
    margin-left: 36px;
}

.msg-content-wrap {
    display: flex;
    flex-direction: column;
    max-width: min(72%, 560px);
    min-width: 120px;
    width: fit-content;
}

.message-row.user .msg-content-wrap {
    align-items: flex-end;
}

.message-row.assistant .msg-content-wrap {
    align-items: flex-start;
}

/* ── OPTION BUTTONS ────────────────────────────────────── */
.options-row {
    display: flex;
    width: 100%;
    justify-content: flex-start;
    padding: 0 20px 0 calc(20px + 36px);
    max-width: 780px;
    margin: 0 auto;
    animation: msgIn 0.28s var(--ease-out) 0.05s both;
}

.options-container {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding-top: 4px;
    padding-bottom: 12px;
}

.option-btn {
    padding: 10px 18px;
    border-radius: var(--r-full);
    border: none;
    background: var(--surface);
    color: var(--ink-3);
    font-family: var(--font-body);
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.option-btn:hover {
    background: var(--accent);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(91, 79, 255, 0.3);
}

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

.option-btn.primary-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    box-shadow: 0 4px 12px rgba(91, 79, 255, 0.28);
}

.option-btn.primary-btn:hover {
    box-shadow: 0 6px 16px rgba(91, 79, 255, 0.4);
}

.option-btn.secondary-btn {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
}

.option-btn.secondary-btn:hover {
    background: var(--surface-3);
    color: var(--ink-3);
    border-color: var(--border-2);
    transform: none;
    box-shadow: none;
}

/* ── DATE & FILE PICKERS ───────────────────────────────── */
.date-picker-input,
.file-picker-input {
    padding: 9px 14px;
    border: 1.5px solid var(--border-2);
    border-radius: var(--r-md);
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--ink);
    background: var(--surface);
    transition: all 0.18s var(--ease);
    outline: none;
    min-width: 0;
}

.date-picker-input:focus,
.file-picker-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── INPUT DOCK ────────────────────────────────────────── */
.input-dock {
    padding: 12px 20px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 24px;
    padding: 8px 8px 8px 20px;
    transition: all 0.2s var(--ease);
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    min-width: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.input-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow), 0 2px 8px rgba(0, 0, 0, 0.04);
    background: var(--surface);
}

#chatInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--ink);
    padding: 10px 0;
    min-width: 0;
}

#chatInput::placeholder {
    color: var(--muted-2);
    font-weight: 400;
}

#chatInput:focus {
    outline: none;
}

#chatInput::selection {
    background: rgba(91, 79, 255, 0.2);
    color: var(--ink);
}

.send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #5b4fff, #7c6fff);
    border: none;
    border-radius: var(--r-lg);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s var(--ease);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(91, 79, 255, 0.32);
}

.send-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(91, 79, 255, 0.4);
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.send-btn svg {
    transition: transform 0.2s var(--ease);
}

.send-btn:hover svg {
    transform: rotate(15deg);
}

.input-footer-hint {
    font-size: 0.7rem;
    color: var(--muted-2);
    text-align: center;
    margin-top: 10px;
    font-weight: 400;
    letter-spacing: 0.2px;
}

/* ── LOADING OVERLAY ───────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 25, 0.65);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.loading-overlay.hidden {
    display: none !important;
}

.loader-ring {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin-bottom: 14px;
    position: relative;
}

.loader-ring::after {
    content: '';
    width: 38px;
    height: 38px;
    border: 3px solid transparent;
    border-top-color: var(--accent);
    border-right-color: rgba(91, 79, 255, 0.4);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    position: absolute;
}

/* Remove the old 4-div loader approach to prevent scroll arrow glitch */
.loader-ring div {
    display: none;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.88rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}

/* ── TOAST ─────────────────────────────────────────────── */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #1f2937;
    border-left: 4px solid var(--red);
    color: white;
    padding: 14px 18px;
    border-radius: var(--r-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 360px;
    font-size: 0.875rem;
    animation: slideInRight 0.3s var(--ease-out) both;
    line-height: 1.5;
}

.toast.success {
    border-left-color: var(--green);
}

.toast.hidden {
    display: none !important;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

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

.toast-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.error-message,
.success-message {
    flex: 1;
    line-height: 1.4;
    min-width: 0;
}

.error-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 0.9rem;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-xs);
    transition: all 0.15s;
    flex-shrink: 0;
}

.error-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: white;
}

/* ── UTILITY ───────────────────────────────────────────── */
.hidden {
    display: none !important;
}

/* ── TYPING INDICATOR ──────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--r-xl);
    border-bottom-left-radius: 8px;
    width: fit-content;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.typing-dot {
    width: 7px;
    height: 7px;
    background: var(--muted-2);
    border-radius: 50%;
    animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* ── CHAT DATE SEPARATOR ───────────────────────────────── */
.date-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted-2);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    padding: 16px 0;
}

.date-sep::before,
.date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, var(--border), transparent);
}

/* ── RESPONSIVE ────────────────────────────────────────── */
@media (max-width: 768px) {
    .topbar {
        padding: 14px 16px;
        gap: 10px;
    }

    .balance-status {
        display: none !important;
    }

    .action-btn {
        padding: 8px 12px;
        font-size: 0.75rem;
        gap: 4px;
    }

    .action-btn span {
        display: none;
    }

    .send-btn {
        width: 36px;
        height: 36px;
    }

    .msg-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .message {
        max-width: min(85%, 420px);
        font-size: 0.875rem;
    }

    .cat-pill {
        padding: 14px 12px;
        gap: 6px;
        font-size: 0.75rem;
    }

    .cat-icon {
        font-size: 1.3rem;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        max-width: 280px;
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .topbar {
        padding: 12px 14px;
        gap: 8px;
    }

    .topbar-left {
        gap: 4px;
    }

    .topbar-center {
        gap: 6px;
        order: 3;
        width: 100%;
        flex: 1 1 100%;
    }

    .topbar-right {
        order: 4;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
    }

    .action-btn {
        padding: 6px 10px;
        font-size: 0.7rem;
        gap: 3px;
        min-width: 40px;
    }

    .send-btn {
        width: 36px;
        height: 36px;
    }

    .message {
        max-width: 86%;
        min-width: 70px;
        font-size: 0.85rem;
    }

    .msg-content-wrap {
        max-width: 86%;
    }

    .msg-avatar {
        width: 26px;
        height: 26px;
    }

    .input-dock {
        padding: 12px 12px 14px;
    }

    .input-wrap {
        padding: 6px 6px 6px 16px;
        gap: 8px;
    }

    #chatInput {
        font-size: 0.85rem;
    }

    .input-footer-hint {
        font-size: 0.6rem;
    }

    .cat-pill {
        padding: 12px 10px;
        font-size: 0.7rem;
        gap: 5px;
    }

    .cat-icon {
        font-size: 1.2rem;
    }

    .toast {
        right: 12px;
        left: 12px;
        max-width: none;
        font-size: 0.8rem;
    }

    .welcome-heading {
        font-size: clamp(1.1rem, 2.5vw, 1.4rem);
    }
}

/* ── CREDENTIALS MODAL ─────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 25, 0.8);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 10001;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 20px 16px;
    padding-top: 60px;
}

.modal.hidden {
    display: none !important;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--r-2xl);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
    max-width: 520px;
    width: 100%;
    overflow: hidden;
    animation: modalIn 0.3s var(--spring) both;
    border-left: 5px solid var(--red);
}

.modal-content.modal-message {
    max-width: 520px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }

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

.modal-body {
    padding: 32px 28px;
    text-align: center;
}

.error-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--red);
    line-height: 1.8;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.error-text::before {
    content: '⚠';
    font-size: 1.4rem;
    flex-shrink: 0;
    display: inline-block;
}

/* ── TYPING INDICATOR ──────────────────────────────── */
.typing-message {
    max-width: 100px !important;
    padding: 12px 14px !important;
    background: var(--surface-2) !important;
}

.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    height: 12px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
    display: inline-block;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-8px);
    }
}

/* Enhanced Balance Modal Styles */
.balance-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s var(--ease);
}

.balance-modal {
    background: var(--surface);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    animation: slideUp 0.3s var(--spring);
    border: 1px solid var(--border);
}

.balance-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--r-lg) var(--r-xl);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.balance-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: var(--r-sm);
}

.balance-modal-header .close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--muted);
    cursor: pointer;
    padding: var(--r-xs);
    border-radius: var(--r-sm);
    transition: all 0.2s var(--ease);
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.balance-modal-header .close-btn:hover {
    background: var(--surface-3);
    color: var(--ink);
}

.balance-modal-content {
    padding: var(--r-xl);
}

.balance-summary {
    display: flex;
    flex-direction: column;
    gap: var(--r-lg);
}

.balance-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--r-md);
    border-radius: var(--r-md);
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: all 0.2s var(--ease);
}

.balance-item.available {
    background: rgba(5, 150, 105, 0.08);
    border-color: rgba(5, 150, 105, 0.2);
}

.balance-item.unavailable {
    background: rgba(220, 38, 38, 0.08);
    border-color: rgba(220, 38, 38, 0.2);
}

.balance-label {
    font-weight: 500;
    color: var(--ink-2);
}

.balance-status {
    font-weight: 600;
    padding: var(--r-xs) var(--r-md);
    border-radius: var(--r-full);
    font-size: 0.875rem;
}

.balance-item.available .balance-status {
    background: var(--green);
    color: white;
}

.balance-item.unavailable .balance-status {
    background: var(--red);
    color: white;
}

.balance-details {
    display: flex;
    flex-direction: column;
    gap: var(--r-sm);
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--r-sm) 0;
    border-bottom: 1px solid var(--border);
}

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

.detail-label {
    font-weight: 500;
    color: var(--ink-2);
    font-size: 0.9rem;
}

.detail-value {
    font-weight: 600;
    color: var(--ink);
    font-size: 0.95rem;
}

.detail-value.remaining-days {
    color: var(--green);
    font-size: 1.1rem;
    font-weight: 700;
}

.balance-modal-footer {
    padding: var(--r-lg) var(--r-xl);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    display: flex;
    justify-content: center;
}

.calendar-btn {
    display: flex;
    align-items: center;
    gap: var(--r-sm);
    padding: var(--r-md) var(--r-lg);
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--r-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease);
    font-size: 0.9rem;
}

.calendar-btn:hover {
    background: var(--accent-2);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

/* Modal Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

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

/* Responsive Design for Modal */
@media (max-width: 768px) {
    .balance-modal {
        width: 95%;
        margin: var(--r-md);
    }

    .balance-modal-header,
    .balance-modal-content,
    .balance-modal-footer {
        padding: var(--r-md);
    }

    .balance-status {
        font-size: 0.8rem;
    }

    .detail-value {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .modal {
        padding: 12px;
        padding-top: 40px;
    }

    .modal-content {
        max-width: 100%;
    }

    .modal-body {
        padding: 30px 20px;
    }

    .error-text {
        font-size: 1rem;
    }
}