:root {
    --primary-text-color: #424242;
    --button-fill-color: #00008b;
    --bg: #ffffff;
    --panel: #ffffff;
    --muted: #6b7280;
    --border: #e5e7eb;
    --ring: #3b82f6;
    --text: #111827;
    --text-dim: #6b7280;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
}

html,
body,
#root {
    height: 100%;
}

/* Prevent page-level scrolling; only chat messages area should scroll */
html,
body {
    overflow: hidden;
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, Helvetica, Arial;
    color: var(--text);
    background: var(--bg);
}

.app {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100dvh;
    min-height: 0;
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.brand .title {
    font-weight: 600;
}

.actions {
    display: flex;
    gap: 8px;
}

.list {
    overflow: auto;
}

.item {
    padding: 10px;
    border-radius: 10px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
    cursor: pointer;
}

.item:hover {
    background: var(--gray-50);
}

.item.active {
    background: var(--gray-100);
    border: 1px solid var(--border);
}

.item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-actions {
    display: flex;
    gap: 6px;
}

.chat {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

.chat__title {
    font-weight: 600;
}

.messages {
    overflow: auto;
    padding: 16px;
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.bubble {
    max-width: min(720px, 90%);
    padding: 10px 12px;
    border-radius: 12px;
    margin-bottom: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
    color: var(--text);
}

.message-row {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 8px;
    align-items: start;
}

.message-row.user {
    justify-content: end;
    grid-template-columns: auto auto;
}

.message-row.assistant {
    grid-template-columns: auto 1fr;
}

.message-row .meta {
    margin-bottom: 0;
}

/* Nudge the user label above the top-left corner of the bubble */
.message-row.user .meta {
    align-self: start;
    transform: translateY(-15px);
}

.message-actions {
    grid-column: 2 / 3;
    display: flex;
    gap: 8px;
}

/* Icon-only buttons for actions; remove hover animations and prevent clipping */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--primary-text-color);
    cursor: pointer;
}

.icon-btn i {
    font-size: 18px;
    line-height: 1;
    display: inline-block;
}

.icon-btn:hover,
.icon-btn:focus,
.icon-btn:active {
    background: transparent;
    box-shadow: none;
    outline: none;
    transform: none;
}

/* Ensure horizontal layout doesn’t wrap/cut icons on smaller viewports */
.message-actions { flex-wrap: nowrap; }

.edit-textarea {
    width: 100%;
    min-width: 240px;
    min-height: 60px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    font: inherit;
    color: var(--text);
    background: #fff;
}

.edit-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

/* Copy toast next to Copy button */
.action-with-label {
    position: relative;
    display: inline-block;
}

.action-with-toast { display:none; }

/* Hover label under icon buttons */
.hover-label {
    position: absolute;
    left: 50%;
    top: calc(100% + 4px);
    transform: translate(-50%, 4px);
    background: var(--text);
    color: #fff;
    font-size: 11px;
    padding: 3px 6px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease, transform 150ms ease;
    z-index: 1;
}

.action-with-label:hover .hover-label {
    opacity: 1;
    transform: translate(-50%, 0);
}

.bubble.user {
    background: var(--gray-100);
    border: 1px solid var(--border);
    margin-left: auto;
    width: fit-content;
}

.bubble.assistant {
    background: transparent;
}

.bubble.typing {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
}

.typing-dots {
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-dim);
    animation: blink 1s infinite ease-in-out;
}

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

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

@keyframes blink {

    0%,
    80%,
    100% {
        opacity: 0.2;
    }

    40% {
        opacity: 1;
    }
}

.meta {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--panel);
}

.textarea {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    min-height: 44px;
    resize: none;
}

button {
    cursor: pointer;
}

/* Hero (empty state) */
.messages.hero-mode {
    display: grid;
    place-items: center;
}

.hero {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
}

.hero__inner {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    text-align: center;
    max-width: 720px;
    padding: 24px;
}

.hero__title {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
}

.hero__composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    width: min(720px, 90vw);
}

/* Transitions for entering chat from hero */
.hero-fade-out {
    animation: heroFade 240ms ease forwards;
}

@keyframes heroFade {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

.composer-hidden {
    opacity: 0;
    transform: translateY(16px);
    pointer-events: none;
}

.messages:not(.hero-mode)+.composer {
    transition: transform 260ms ease, opacity 260ms ease;
}

.composer-enter {
    opacity: 1 !important;
    transform: translateY(0) !important;
    pointer-events: auto;
}

md-filled-button {
    /* Material Web button overrides*/
    --md-filled-button-container-color: var(--button-fill-color);
    --md-filled-button-label-text-color: #ffffff;
    /* Fallback primary token used by some states */
    --md-sys-color-primary: var(--button-fill-color);
}

/* Use primary text color throughout chat UI */
.chat,
.chat .bubble,
.chat .meta,
.chat .chat__title,
.chat #typing,
.chat .messages {
    color: var(--primary-text-color) !important;
}
