/* Modern CSS Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-weight: 400;
    font-size: 14px;
}

body {
    min-block-size: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    color: #000000;
    background: #ffffff;
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-inline-size: 100%;
}

input,
button,
textarea,
select {
    font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
    overflow-wrap: break-word;
}

/* Blazor error boundary */
.blazor-error-boundary {
    background: #dc2626;
    padding: 1rem;
    color: white;
    border-radius: 2px;
    margin: 1rem;
}

.blazor-error-boundary::after {
    content: "An error occurred.";
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    body {
        color: #ffffff;
        background: #0d0d0d;
    }
}

/* Hide sidebar toggle buttons on wide screens */
@media (min-width: 1025px) {
    .btn-toggle-sidebar {
        display: none !important;
    }
}
/* Clean Chat UI - Simple Theme System */

:root {
    /* Colors - Light Theme (Default) */
    --apple-blue: #007AFF;
    --apple-blue-hover: #0051D5;
    --bg-main: #e8e9ed;
    --bg-surface: #f5f5f7;
    --bg-input: #f5f5f7;
    --bg-user: linear-gradient(135deg, rgba(0, 122, 255, 0.95) 0%, rgba(88, 86, 214, 0.85) 100%);
    --bg-assistant: #ffffff;
    --bg-menu: #f8f8fa;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --border: rgba(0, 0, 0, 0.15);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.18);
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Colors - Dark Theme */
        --bg-main: #000000;
        --bg-surface: #1c1c1e;
        --bg-input: #1c1c1e;
        --bg-user: linear-gradient(135deg, rgba(10, 132, 255, 0.85) 0%, rgba(94, 92, 230, 0.75) 100%);
        --bg-assistant: #2c2c2e;
        --bg-menu: #2c2c2e;
        --text-primary: #f5f5f7;
        --text-secondary: #98989d;
        --border: rgba(255, 255, 255, 0.1);
        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    }
}

.chat-container {
    display: flex;
    block-size: 100dvh;
    background: var(--bg-main);
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    inline-size: 240px;
    background: var(--bg-surface);
    border-inline-end: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 10;
}

@media (max-width: 1024px) {
    .sidebar {
        position: absolute;
        inset-block: 0;
        inset-inline-start: 0;
        box-shadow: var(--shadow-lg);
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-block-end: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.btn-new-chat {
    inline-size: 100%;
    padding: 10px 14px;
    background: var(--bg-user);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-new-chat:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.sessions-list {
    margin-block-start: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-menu);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.session-item:hover {
    background: var(--bg-surface);
    border-color: var(--apple-blue);
    transform: translateX(4px);
}

.session-item.active {
    background: var(--apple-blue) !important;
    color: white !important;
    border-color: transparent !important;
}

.session-item.active:hover {
    background: var(--apple-blue-hover) !important;
    transform: translateX(4px);
}

.session-info {
    flex: 1;
    min-inline-size: 0;
}

.session-title {
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-date {
    font-size: 10px;
    opacity: 0.7;
    margin-block-start: 2px;
}

.btn-delete {
    padding: 6px;
    background: rgba(255, 59, 48, 0.1);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-delete:hover {
    background: rgba(255, 59, 48, 0.2);
    transform: scale(1.1);
}

/* Chat Main */
.chat {
    flex: 1;
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: var(--bg-main);
    position: relative;
    overflow: hidden;
}

.chat::before {
    content: '';
    position: absolute;
    inset: -50%;
    background: radial-gradient(circle at 30% 20%, rgba(0, 122, 255, 0.04) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(88, 86, 214, 0.03) 0%, transparent 50%);
    animation: floatBackground 20s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes floatBackground {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(3%, -3%) rotate(1deg); }
    66% { transform: translate(-3%, 3%) rotate(-1deg); }
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--bg-surface);
    border-block-end: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 5;
}

.btn-icon {
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary);
}

.btn-icon:hover {
    background: var(--bg-assistant);
    border-color: var(--apple-blue);
    transform: translateY(-2px);
}

.btn-icon-sm {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    color: var(--text-primary);
}

.btn-icon-sm:hover {
    background: var(--bg-assistant);
    border-color: var(--apple-blue);
}

.dropdown-menu {
    position: absolute;
    inset-block-start: 100%;
    inset-inline-start: 0;
    margin-block-start: 4px;
    background: var(--bg-menu);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 100;
    backdrop-filter: blur(20px);
}

.dropdown-menu button {
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: 6px;
    text-align: start;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: all 0.2s;
}

.dropdown-menu button:hover {
    background: var(--bg-assistant);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    max-inline-size: 500px;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    transition: all 0.2s;
}

.search-box:focus-within {
    border-color: var(--apple-blue);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.search-box input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: var(--text-primary);
}

.search-box input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.search-count {
    font-size: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.spacer {
    flex: 1;
}

/* Messages */
.messages {
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: text;
    position: relative;
    z-index: 1;
}

.messages::-webkit-scrollbar {
    inline-size: 8px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 122, 255, 0.3);
    background-clip: padding-box;
    box-shadow: 0 0 8px rgba(0, 122, 255, 0.2);
}

.message {
    max-inline-size: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    letter-spacing: -0.01em;
    animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-block-end: 24px;
}

.message.user {
    background: var(--bg-user);
    color: white;
    margin-inline-start: auto;
    box-shadow: var(--shadow-md), 0 0 20px rgba(0, 122, 255, 0.1);
    backdrop-filter: blur(20px);
    position: relative;
    overflow: hidden;
    transform-origin: right center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message.user .message-actions {
    inset-inline-start: auto;
    inset-inline-end: 0;
}

.message.user::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
}

.message.user:hover {
    box-shadow: var(--shadow-lg), 0 0 30px rgba(0, 122, 255, 0.2);
}

.message.assistant {
    background: var(--bg-assistant);
    color: var(--text-primary);
    margin-inline-end: auto;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
    transform-origin: left center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message.assistant:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(0, 122, 255, 0.15);
}

.message-content {
    flex: 1;
}

.message-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 9px;
    opacity: 0.6;
    margin-block-start: 4px;
}

.timestamp {
    font-weight: 500;
}

.edited {
    font-style: italic;
}

.message-actions {
    position: absolute;
    inset-block-end: -20px;
    inset-inline-start: 0;
    display: flex;
    gap: 6px;
    animation: fadeIn 0.2s;
    z-index: 10;
}

.btn-action {
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.message.user .btn-action {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-action:hover {
    background: rgba(0, 122, 255, 0.1);
    border-color: var(--apple-blue);
    transform: translateY(-2px);
}

.message.user .btn-action:hover {
    background: rgba(255, 255, 255, 0.25);
}

.edit-textarea {
    inline-size: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 15px;
    background: var(--bg-surface);
    color: var(--text-primary);
    resize: vertical;
    min-block-size: 80px;
}

.edit-textarea:focus {
    outline: none;
    border-color: var(--apple-blue);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

/* Search Highlighting */
.search-match {
    outline: 2px solid rgba(255, 193, 7, 0.3);
    outline-offset: 2px;
}

.search-highlight {
    outline: 3px solid #ffc107;
    outline-offset: 2px;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { outline-color: #ffc107; }
    50% { outline-color: rgba(255, 193, 7, 0.5); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.typing {
    display: flex;
    gap: 5px;
    padding-block: 6px;
}

.typing span {
    inline-size: 8px;
    block-size: 8px;
    background: var(--apple-blue);
    border-radius: 50%;
    animation: typingBounce 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    box-shadow: 0 0 8px rgba(0, 122, 255, 0.3);
}

.typing span:nth-child(2) {
    animation-delay: 0.16s;
}

.typing span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0) scale(1);
        opacity: 0.6;
        box-shadow: 0 0 8px rgba(0, 122, 255, 0.3);
    }
    30% {
        transform: translateY(-6px) scale(1.2);
        opacity: 1;
        box-shadow: 0 0 16px rgba(0, 122, 255, 0.6);
    }
}

/* Input */
.input {
    background: var(--bg-input);
    padding: 12px 16px 10px;
    backdrop-filter: blur(20px) saturate(180%);
    border-block-start: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 2;
}

.error {
    background: linear-gradient(135deg, #ff3b30 0%, #ff2d55 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    margin-block-end: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
    animation: errorShake 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.version {
    text-align: center;
    font-size: 9px;
    color: var(--text-secondary);
    margin-block-start: 8px;
    opacity: 0.5;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.version:hover {
    opacity: 0.8;
    transform: translateY(-1px);
}

.input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.input-group textarea {
    flex: 1;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 14px;
    font-family: inherit;
    font-size: 14px;
    letter-spacing: -0.01em;
    resize: none;
    min-block-size: 44px;
    max-block-size: 180px;
    background: var(--bg-assistant);
    color: var(--text-primary);
    line-height: 1.47;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-group textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.input-group textarea:focus {
    outline: none;
    border-color: var(--apple-blue);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.1), 0 4px 16px rgba(0, 122, 255, 0.15);
    transform: translateY(-1px);
}

.input-group textarea:disabled {
    background: var(--bg-assistant);
    cursor: not-allowed;
    opacity: 0.5;
}

.input-group button {
    padding: 0;
    background: var(--apple-blue);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    inline-size: 44px;
    block-size: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.25);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.input-group button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.input-group button:hover:not(:disabled) {
    transform: scale(1.05) translateY(-1px);
    box-shadow: var(--shadow-lg), 0 0 40px rgba(0, 122, 255, 0.2);
}

.input-group button:hover:not(:disabled)::before {
    opacity: 1;
}

.input-group button:active:not(:disabled) {
    transform: scale(0.95);
}

.input-group button:disabled {
    background: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.4;
    transform: scale(1);
    box-shadow: var(--shadow-sm);
}

/* Markdown Styling */
.message p {
    margin-block: 0;
    padding: 0;
}

.message > *:first-child {
    margin-block-start: 0 !important;
}

.message > *:last-child {
    margin-block-end: 0 !important;
}

.message code {
    background: rgba(0, 0, 0, 0.06);
    color: #ff3b30;
    padding: 3px 6px;
    border-radius: 6px;
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.message code:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.message pre {
    background: #1d1d1f;
    padding: 16px 18px;
    border-radius: 12px;
    overflow-x: auto;
    margin-block: 12px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.message pre:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: rgba(0, 122, 255, 0.2);
}

.message pre code {
    background: none;
    padding: 0;
    color: #f5f5f7;
    font-weight: 400;
}

.message pre code:hover {
    background: none;
    transform: none;
}

.message ul, .message ol {
    margin-block: 10px;
    padding-inline-start: 28px;
}

.message li {
    margin-block: 6px;
}

.message blockquote {
    border-inline-start: 3px solid var(--apple-blue);
    padding-inline-start: 16px;
    margin-inline: 0;
    margin-block: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

.message h1, .message h2, .message h3, .message h4, .message h5, .message h6 {
    margin-block: 12px 8px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.message h1 { font-size: 24px; }
.message h2 { font-size: 20px; }
.message h3 { font-size: 17px; }
.message h4 { font-size: 15px; }

.message a {
    color: var(--apple-blue);
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: inline-block;
}

.message a::after {
    content: '';
    position: absolute;
    inset-inline: 0;
    inset-block-end: -2px;
    block-size: 2px;
    background: var(--apple-blue);
    transform: scaleX(0);
    transform-origin: right;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message a:hover {
    color: var(--apple-blue-hover);
    transform: translateY(-1px);
}

.message a:hover::after {
    transform: scaleX(1);
    transform-origin: left;
}

.message.user code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-weight: 600;
}

.message.user pre {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

.message.user a {
    color: white;
    text-decoration: underline;
}
