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

:root {
    --sidebar-width: 260px;
    --chat-width: 500px;
    --black: #1a1a1a;
    --ink: #222222;
    --dark: #333333;
    --mid: #555555;
    --muted: #777777;
    --subtle: #999999;
    --border: #d4d4d4;
    --line: #e5e5e5;
    --soft: #f5f5f5;
    --offwhite: #fafafa;
    --white: #ffffff;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md: 0 4px 14px rgba(0,0,0,0.07);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.10);
    --shadow-xl: 0 20px 60px rgba(0,0,0,0.12);
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    color: var(--ink);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--soft);
}

h1, h2, h3, h4,
.brand-title,
.chat-title {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 800;
    letter-spacing: -0.02em;
}

button, a, input, select, textarea {
    font: inherit;
}

/* — Glass card — */
.glass {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    transition: box-shadow var(--transition), transform var(--transition);
}

.glass:hover {
    box-shadow: var(--shadow-md);
}

/* — Top bar — */
.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 28;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.5rem;
    background: rgba(255,255,255,0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.hamburger-button,
.sidebar-close,
.icon-button,
.chat-toggle {
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--black);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.hamburger-button:hover,
.sidebar-close:hover,
.icon-button:hover {
    background: var(--soft);
    border-color: var(--subtle);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.hamburger-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
}

.hamburger-lines,
.hamburger-lines::before,
.hamburger-lines::after {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--black);
    content: "";
    border-radius: 2px;
    transition: all var(--transition);
}

.hamburger-lines {
    position: relative;
}
.hamburger-lines::before {
    position: absolute;
    top: -6px;
}
.hamburger-lines::after {
    position: absolute;
    top: 6px;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-title {
    font-weight: 800;
    color: var(--black);
    font-size: 1.05rem;
}

.topbar-section {
    color: var(--muted);
    font-size: 0.85rem;
    padding: 0.25rem 0.65rem;
    background: var(--soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-full);
    font-weight: 600;
}

/* — Sidebar — */
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    z-index: 45;
    display: flex;
    flex-direction: column;
    background: var(--black);
    color: var(--white);
    transform: translateX(-100%);
    transition: transform 280ms cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
    box-shadow: var(--shadow-xl);
}

.app-sidebar.open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1.15rem;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    background: var(--white);
    color: var(--black);
    font-weight: 900;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.brand-title, .brand-subtitle {
    display: block;
}

.brand-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.brand-subtitle {
    color: rgba(255,255,255,0.5);
    font-size: 0.76rem;
    font-weight: 400;
}

.sidebar-close {
    margin-left: auto;
    width: 34px;
    height: 34px;
    color: var(--white);
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
}

.sidebar-close:hover {
    background: rgba(255,255,255,0.2) !important;
    border-color: rgba(255,255,255,0.35) !important;
}

.sidebar-nav {
    padding: 0.8rem;
    display: grid;
    gap: 0.25rem;
}

.sidebar-nav a {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    padding: 0.72rem 0.95rem;
    border: 1px solid transparent;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: all 200ms ease;
    position: relative;
    overflow: hidden;
}

.sidebar-nav a::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 60%;
    background: var(--white);
    border-radius: 0 3px 3px 0;
    transition: width 200ms ease;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: var(--white);
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.08);
    transform: translateX(4px);
}

.sidebar-nav a.active::before,
.sidebar-nav a:hover::before {
    width: 3px;
}

/* — Main content — */
.app-main {
    min-height: 100vh;
    padding: 5.5rem 1.5rem 1.5rem;
    transition: none;
}

.app-main.chat-closed {
    margin-right: 0;
}

/* — Chat Panel (floating, does NOT push content) — */
.chat-panel {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 30;
    width: calc(var(--chat-width) - 1rem);
    height: min(780px, calc(100vh - 2rem));
    display: flex;
    flex-direction: column;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    transition: transform 280ms cubic-bezier(0.4,0,0.2,1),
                opacity 280ms cubic-bezier(0.4,0,0.2,1);
    overflow: hidden;
}

.chat-panel.closed {
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
}

.chat-header {
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1.1rem;
    color: var(--black);
    background: var(--white);
    border-bottom: 1px solid var(--line);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.chat-title {
    font-weight: 700;
    line-height: 1.15;
    font-size: 1.1rem;
    color: var(--black);
}

.chat-subtitle {
    margin-top: 0.15rem;
    color: var(--muted);
    font-size: 0.76rem;
}

.chat-header-actions {
    display: flex;
    gap: 0.35rem;
}

.icon-button {
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
}

.chat-history {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    padding: 1rem;
    background: var(--offwhite);
}

.chat-message {
    display: flex;
    animation: messageSlideIn 300ms cubic-bezier(0.4,0,0.2,1);
}

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

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

.chat-message.ai {
    justify-content: flex-start;
}

.chat-bubble {
    max-width: 88%;
    border: 1px solid var(--line);
    padding: 0.75rem 0.9rem;
    font-size: 0.86rem;
    line-height: 1.55;
    background: var(--white);
    border-radius: var(--radius-md);
    transition: box-shadow var(--transition);
}

.chat-bubble:hover {
    box-shadow: var(--shadow-sm);
}

.chat-message.user .chat-bubble {
    background: var(--black);
    color: var(--white);
    border-color: transparent;
    border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
}

.chat-message.ai .chat-bubble {
    color: var(--ink);
    border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 4px;
}

.chat-bubble h1,
.chat-bubble h2,
.chat-bubble h3 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0.2rem 0 0.5rem;
}

.chat-bubble ul,
.chat-bubble ol {
    padding-left: 1.15rem;
    margin: 0.35rem 0;
}

.chat-bubble p {
    margin: 0.35rem 0;
}

.chat-bubble code {
    background: var(--soft);
    color: var(--black);
    padding: 0.15rem 0.3rem;
    border-radius: 4px;
    font-size: 0.82em;
}

/* — Agentic action buttons — */
.agent-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.65rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--line);
}

.agent-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--soft);
    color: var(--black);
    font-size: 0.78rem;
    font-weight: 650;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.agent-action-btn:hover {
    background: var(--black);
    color: var(--white);
    border-color: var(--black);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.agent-action-btn.yes {
    background: var(--black);
    border-color: var(--black);
    color: var(--white);
}

.agent-action-btn.yes:hover {
    background: var(--dark);
    border-color: var(--dark);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.agent-action-btn.no {
    background: var(--white);
    border-color: var(--border);
    color: var(--muted);
}

.agent-action-btn.no:hover {
    background: var(--soft);
    color: var(--black);
    border-color: var(--subtle);
}

/* — Typing indicator — */
.typing-bubble {
    display: flex;
    align-items: center;
    gap: 0.28rem;
    min-height: 2.4rem;
}

.typing-dot {
    width: 0.46rem;
    height: 0.46rem;
    border-radius: var(--radius-full);
    background: var(--dark);
    animation: typing 1.4s infinite ease-in-out both;
}

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

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.35); opacity: 0.35; }
    40% { transform: scale(1); opacity: 1; }
}

/* — Prompt suggestions — */
.prompt-suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    padding: 0.7rem;
    background: var(--white);
    border-top: 1px solid var(--line);
}

.prompt-suggestions button {
    min-height: 2.35rem;
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--black);
    padding: 0.5rem 0.6rem;
    text-align: left;
    font-size: 0.74rem;
    font-weight: 650;
    line-height: 1.25;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.prompt-suggestions button:hover {
    border-color: var(--black);
    background: var(--soft);
    transform: translateY(-1px);
}

/* — Chat composer — */
.chat-composer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--line);
    background: var(--white);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.chat-composer input {
    min-width: 0;
    flex: 1;
    border: 1px solid var(--line);
    padding: 0.72rem 0.85rem;
    font-size: 0.86rem;
    outline: none;
    border-radius: var(--radius-md);
    transition: all var(--transition);
    background: var(--soft);
}

.chat-composer input:focus {
    border-color: var(--dark);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
    background: var(--white);
}

.chat-composer button,
.dialog-actions button {
    border: none;
    background: var(--black);
    color: var(--white);
    font-weight: 700;
    padding: 0.72rem 1rem;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition);
}

.chat-composer button:hover,
.dialog-actions button:hover {
    background: var(--dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

/* — Chat toggle FAB — */
.chat-toggle {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 25;
    width: 3.6rem;
    height: 3.6rem;
    background: var(--black);
    color: var(--white);
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    font-weight: 900;
    font-size: 0.85rem;
    border: none;
    border-radius: var(--radius-full);
    transition: all var(--transition);
}

.chat-toggle:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.hidden {
    display: none !important;
}

/* — Override Tailwind rounded classes — */
.rounded-lg  { border-radius: var(--radius-lg) !important; }
.rounded-md  { border-radius: var(--radius-md) !important; }
.rounded-full { border-radius: var(--radius-full) !important; }
.rounded-2xl { border-radius: var(--radius-xl) !important; }
.rounded-xl  { border-radius: var(--radius-lg) !important; }

/* — Tailwind bg-slate-950 overrides (monochrome) — */
[class*="bg-slate-950"] {
    background: var(--black) !important;
    color: var(--white) !important;
    border-radius: var(--radius-sm) !important;
}

[class*="hover\\:bg-slate"]:hover {
    background: var(--dark) !important;
}

[class*="text-slate-950"] {
    color: var(--black) !important;
}

/* — Danger / delete buttons — */
.btn-danger {
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--dark);
    font-weight: 700;
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.btn-danger:hover {
    background: var(--black);
    color: var(--white);
    border-color: var(--black);
}

/* — Charts — */
canvas {
    filter: none;
}

/* — Custom scrollbar — */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--subtle);
}

/* — Responsive — */
@media (max-width: 1180px) {
    :root {
        --chat-width: 400px;
    }
}

@media (max-width: 920px) {
    .app-topbar {
        right: 0;
    }

    .app-main,
    .app-main.chat-closed {
        margin-right: 0;
        padding: 5rem 1rem 1rem;
    }

    .chat-panel {
        width: min(100vw - 1.5rem, 420px);
        height: min(700px, calc(100vh - 5rem));
        right: 0.75rem;
        bottom: 0.75rem;
    }
}

@media (max-width: 560px) {
    .topbar-section {
        display: none;
    }

    .chat-panel {
        inset: auto 0 0 0;
        width: 100vw;
        height: calc(100vh - 4rem);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

    .prompt-suggestions {
        grid-template-columns: 1fr;
    }

    .chat-bubble {
        max-width: 94%;
    }
}
