/* ============================================================
   Copilot AI — Main Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
    --brand:       #0078D4;
    --brand-dark:  #005A9E;
    --brand-light: #EBF3FB;
    --accent:      #7B61FF;
    --accent-light:#F3F0FF;
    --bg:          #F5F6FA;
    --surface:     #FFFFFF;
    --sidebar-bg:  #FAFBFC;
    --border:      #E5E8EF;
    --text:        #1A1D23;
    --text-muted:  #6B7280;
    --text-light:  #9CA3AF;
    --user-bubble: linear-gradient(135deg, #0078D4 0%, #1E90FF 100%);
    --ai-bubble:   #FFFFFF;
    --shadow-sm:   0 1px 4px rgba(0,0,0,.06);
    --shadow-md:   0 4px 16px rgba(0,0,0,.08);
    --shadow-lg:   0 8px 32px rgba(0,0,0,.12);
    --radius:      12px;
    --radius-sm:   8px;
    --radius-lg:   20px;
    --sidebar-w:   280px;
    --header-h:    60px;
    --transition:  .2s ease;
}

html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow: hidden;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

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

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--transition);
    z-index: 100;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    margin-bottom: 14px;
}

.brand-icon {
    width: 34px; height: 34px;
    background: var(--user-bubble);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,120,212,.35);
}

.brand-name { font-size: 1.1rem; font-weight: 700; color: var(--brand); }

.btn-new-chat {
    width: 100%;
    padding: 10px 14px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    display: flex; align-items: center; gap: 8px;
    justify-content: center;
    transition: background var(--transition), transform .1s;
}
.btn-new-chat:hover  { background: var(--brand-dark); }
.btn-new-chat:active { transform: scale(.98); }

.sidebar-nav {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.nav-tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition);
    display: flex; align-items: center; justify-content: center; gap: 5px;
}
.nav-tab.active { color: var(--brand); border-bottom: 2px solid var(--brand); }
.nav-tab:hover:not(.active) { color: var(--text); }

.sidebar-content { flex: 1; overflow-y: auto; padding: 8px; }

.section-label {
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 10px 8px 6px;
}

/* Conversation item */
.conv-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex; align-items: center; gap: 10px;
    transition: background var(--transition);
    position: relative;
    group: true;
}
.conv-item:hover { background: var(--border); }
.conv-item.active { background: var(--brand-light); }
.conv-item.active .conv-title { color: var(--brand); }

.conv-icon { color: var(--text-muted); font-size: .9rem; flex-shrink: 0; }
.conv-info { flex: 1; min-width: 0; }
.conv-title { font-size: .85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time  { font-size: .72rem; color: var(--text-muted); }

.conv-delete {
    background: none; border: none; color: var(--text-light); cursor: pointer;
    padding: 2px 4px; border-radius: 4px; font-size: .8rem;
    opacity: 0; transition: opacity var(--transition), color var(--transition);
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { color: #EF4444; }

/* Saved item */
.saved-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    margin-bottom: 6px;
    cursor: default;
}
.saved-item-title { font-size: .82rem; font-weight: 500; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item-date  { font-size: .72rem; color: var(--text-muted); }
.saved-item-actions { display: flex; gap: 6px; margin-top: 8px; }

.btn-icon-sm {
    background: none; border: 1px solid var(--border); color: var(--text-muted);
    border-radius: 5px; padding: 3px 8px; font-size: .75rem; cursor: pointer;
    transition: all var(--transition);
    display: flex; align-items: center; gap: 4px;
}
.btn-icon-sm:hover { border-color: var(--brand); color: var(--brand); }
.btn-icon-sm.danger:hover { border-color: #EF4444; color: #EF4444; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 30px 16px;
    color: var(--text-muted);
    font-size: .85rem;
}
.empty-state i { font-size: 2rem; margin-bottom: 8px; display: block; opacity: .4; }

/* ── Main Content ────────────────────────────────────────────── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ── Top Bar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 20px;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.topbar-title {
    font-size: 1rem; font-weight: 600;
    flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

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

.btn-topbar {
    background: none; border: 1px solid var(--border); color: var(--text-muted);
    border-radius: var(--radius-sm); padding: 6px 14px; font-size: .82rem;
    font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 6px;
    transition: all var(--transition);
}
.btn-topbar:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }

.hamburger {
    display: none;
    background: none; border: none; font-size: 1.1rem; color: var(--text-muted);
    cursor: pointer; padding: 6px;
}

/* ── Chat Area ───────────────────────────────────────────────── */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Welcome Screen */
.welcome {
    max-width: 680px;
    margin: auto;
    text-align: center;
    padding: 40px 20px;
    animation: fadeInUp .4s ease;
}

.welcome-icon {
    width: 72px; height: 72px;
    background: var(--user-bubble);
    border-radius: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 2rem; color: #fff;
    margin-bottom: 20px;
    box-shadow: 0 8px 24px rgba(0,120,212,.3);
}

.welcome h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 10px; }
.welcome h1 span { background: var(--user-bubble); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.welcome p { color: var(--text-muted); font-size: .95rem; margin-bottom: 32px; }

.example-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    text-align: left;
    margin-bottom: 32px;
}

.example-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex; align-items: flex-start; gap: 10px;
}
.example-card:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.example-card i { color: var(--brand); font-size: 1rem; margin-top: 2px; flex-shrink: 0; }
.example-card-text { font-size: .85rem; font-weight: 500; color: var(--text); }
.example-card-sub  { font-size: .77rem; color: var(--text-muted); margin-top: 2px; }

/* Templates */
.templates-row {
    display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 16px;
}
.template-chip {
    padding: 7px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: .8rem; font-weight: 500; color: var(--text-muted);
    cursor: pointer; transition: all var(--transition);
    display: flex; align-items: center; gap: 5px;
}
.template-chip:hover { background: var(--brand-light); border-color: var(--brand); color: var(--brand); }

/* Messages */
.messages-wrap { max-width: 780px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 20px; }

.msg { display: flex; gap: 12px; animation: fadeInUp .3s ease; }
.msg.user { flex-direction: row-reverse; }

.msg-avatar {
    width: 34px; height: 34px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem; flex-shrink: 0; align-self: flex-end;
}
.msg.user .msg-avatar    { background: var(--user-bubble); color: #fff; }
.msg.assistant .msg-avatar { background: linear-gradient(135deg,#7B61FF,#A78BFA); color: #fff; }

.msg-body { max-width: 75%; display: flex; flex-direction: column; gap: 4px; }
.msg.user .msg-body { align-items: flex-end; }

.msg-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: .9rem;
    line-height: 1.65;
    position: relative;
}
.msg.user .msg-bubble {
    background: var(--user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* Markdown inside AI bubble */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { font-size: 1em; font-weight: 600; margin: .5em 0 .3em; }
.msg-bubble p  { margin: .25em 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 1.4em; margin: .3em 0; }
.msg-bubble li { margin: .2em 0; }
.msg-bubble code {
    background: rgba(0,0,0,.07); padding: 1px 5px; border-radius: 4px;
    font-family: 'Consolas', monospace; font-size: .85em;
}
.msg-bubble pre {
    background: #1E1E2E; color: #CDD6F4; border-radius: var(--radius-sm);
    padding: 12px 16px; overflow-x: auto; margin: .5em 0; font-size: .82em;
}
.msg-bubble pre code { background: none; padding: 0; color: inherit; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; }

.msg-actions {
    display: flex; gap: 6px; opacity: 0;
    transition: opacity var(--transition);
}
.msg:hover .msg-actions { opacity: 1; }

.msg-time { font-size: .7rem; color: var(--text-light); }

.action-btn {
    background: none; border: 1px solid var(--border); color: var(--text-muted);
    border-radius: 5px; padding: 3px 8px; font-size: .73rem; cursor: pointer;
    transition: all var(--transition); display: flex; align-items: center; gap: 4px;
}
.action-btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }

/* Typing indicator */
.typing-indicator {
    display: flex; gap: 12px; align-items: flex-end;
    animation: fadeInUp .3s ease;
}
.typing-bubble {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); border-bottom-left-radius: 4px;
    padding: 14px 20px; display: flex; gap: 5px; align-items: center;
    box-shadow: var(--shadow-sm);
}
.dot {
    width: 7px; height: 7px; background: var(--brand);
    border-radius: 50%; animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }

/* ── Input Area ──────────────────────────────────────────────── */
.input-area {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 16px 24px 20px;
    flex-shrink: 0;
}

.input-wrapper {
    max-width: 780px;
    margin: 0 auto;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex; align-items: flex-end; gap: 8px;
    padding: 10px 10px 10px 16px;
    transition: border-color var(--transition), box-shadow var(--transition);
    box-shadow: var(--shadow-sm);
}
.input-wrapper:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(0,120,212,.12);
}

.chat-input {
    flex: 1; border: none; outline: none; resize: none;
    font-family: inherit; font-size: .9rem; line-height: 1.5;
    background: transparent; color: var(--text);
    min-height: 22px; max-height: 160px; overflow-y: auto;
}
.chat-input::placeholder { color: var(--text-light); }

.input-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

.btn-send {
    width: 38px; height: 38px;
    background: var(--brand);
    color: #fff; border: none; border-radius: 10px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: .95rem; transition: background var(--transition), transform .1s;
    flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--brand-dark); }
.btn-send:active  { transform: scale(.93); }
.btn-send:disabled { background: var(--border); cursor: not-allowed; }

.input-hint {
    max-width: 780px; margin: 6px auto 0;
    font-size: .73rem; color: var(--text-light); text-align: center;
}

/* ── Notifications ───────────────────────────────────────────── */
.toast-container {
    position: fixed; bottom: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.toast {
    background: var(--text); color: #fff;
    padding: 10px 16px; border-radius: var(--radius-sm);
    font-size: .85rem; box-shadow: var(--shadow-lg);
    animation: slideInRight .3s ease;
    display: flex; align-items: center; gap: 8px;
}
.toast.success { background: #10B981; }
.toast.error   { background: #EF4444; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
    display: flex; align-items: center; justify-content: center;
    z-index: 500; opacity: 0; pointer-events: none;
    transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
    background: var(--surface); border-radius: var(--radius);
    padding: 28px; max-width: 500px; width: 90%;
    box-shadow: var(--shadow-lg); transform: scale(.95);
    transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: scale(1); }
.modal h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.modal p  { color: var(--text-muted); font-size: .88rem; margin-bottom: 20px; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; }
.btn-modal { padding: 8px 20px; border-radius: var(--radius-sm); font-size: .88rem; font-weight: 500; cursor: pointer; transition: all var(--transition); border: 1px solid var(--border); }
.btn-modal.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-modal.primary:hover { background: var(--brand-dark); }
.btn-modal.danger  { background: #EF4444; color: #fff; border-color: #EF4444; }
.btn-modal.danger:hover { background: #DC2626; }
.btn-modal:not(.primary):not(.danger):hover { background: var(--bg); }

/* ── Saved Response Full View (modal) ───────────────────────── */
.saved-full { max-width: 640px; width: 95%; }
.saved-full .q { font-weight: 600; font-size: .88rem; color: var(--brand); margin-bottom: 8px; }
.saved-full .a { font-size: .88rem; color: var(--text); background: var(--bg); border-radius: var(--radius-sm); padding: 12px; max-height: 300px; overflow-y: auto; white-space: pre-wrap; }

/* ── Sidebar overlay (mobile) ────────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 99;
}

/* ── Keyframes ───────────────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-6px); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --sidebar-w: 270px; }

    .sidebar {
        position: fixed; top: 0; left: 0; height: 100%;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop { display: block; }
    .hamburger { display: block; }

    .chat-area { padding: 16px; }
    .input-area { padding: 12px 16px 16px; }
    .example-grid { grid-template-columns: 1fr; }

    .msg-body { max-width: 88%; }
    .topbar-actions .btn-topbar span { display: none; }
}

@media (max-width: 480px) {
    .welcome h1 { font-size: 1.4rem; }
    .templates-row { gap: 6px; }
    .template-chip { font-size: .75rem; padding: 6px 10px; }
}
