* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-green: #10b981;
    --primary-green-dark: #059669;
    --primary-green-light: #34d399;
    --secondary-green: #6ee7b7;
    --bg-light: #f0fdf4;
    --bg-white: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5fdf8;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
}

.container {
    width: 100%;
    height: 100vh;
    background: var(--bg-white);
    display: flex;
    flex-direction: column;
}

.layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 280px;
    background: #e8f7ef;
    color: #0f172a;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    border-right: 1px solid #d1e9d9;
}

.sidebar h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.sidebar .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #f5fdf8;
    border: 1px solid #d1e9d9;
    border-radius: 999px;
    font-size: 12px;
    color: #0f172a;
    width: fit-content;
}

.sidebar-section {
    background: #f9fffb;
    border: 1px solid #d1e9d9;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #d1e9d9;
    color: #0f172a;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-item:hover {
    border-color: #10b981;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.08);
}

.sidebar-item.active {
    background: #e6f7ef;
    border-color: #10b981;
    color: #065f46;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    color: #0f172a;
}

.main-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: #ffffff;
}

.main-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
}

.main-header .hint {
    color: #4b5563;
    font-size: 14px;
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 24px 12px;
    gap: 12px;
    overflow: hidden;
}

.two-column {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 16px;
    height: 100%;
}

.full-height {
    height: 100%;
}

.card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-md);
}

.guide {
    background: #e9fbf2;
    border: 1px solid #bbf7d0;
    color: #065f46;
}

.section-title {
    margin: 0 0 8px 0;
    color: #0f172a;
    font-size: 16px;
    font-weight: 700;
}

.domain-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.domain-button {
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #d1e9d9;
    background: #ffffff;
    color: #0f172a;
    cursor: pointer;
    transition: all 0.2s ease;
}

.domain-button:hover {
    border-color: #10b981;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.08);
}

.domain-button.active {
    background: #e6f7ef;
    border-color: #10b981;
    color: #065f46;
}

.list-scroll {
    max-height: calc(100vh - 260px);
    overflow-y: auto;
}

.main-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-green) 0%, var(--primary-green-dark) 100%);
    color: white;
    padding: 24px 32px;
    border-radius: 24px 24px 0 0;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 32px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-5px);
    }
}

.header h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0;
}

.subtitle {
    font-size: 14px;
    opacity: 0.95;
    font-weight: 400;
    margin: 0;
}

/* Domain Selector */
.domain-selector {
    display: none;
}

.domain-selector label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    white-space: nowrap;
}

.domain-selector select {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-primary);
    font-family: inherit;
}

.domain-selector select:hover {
    border-color: var(--primary-green-light);
    background: #fafafa;
}

.domain-selector select:focus {
    outline: none;
    border-color: var(--primary-green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
    background: white;
}

.btn-refresh {
    padding: 10px 14px;
    background: white;
    color: var(--primary-green);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
}

.btn-refresh:hover {
    background: var(--primary-green);
    color: white;
    border-color: var(--primary-green);
    transform: rotate(180deg);
}

.btn-refresh:active {
    transform: rotate(180deg) scale(0.95);
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chat-container::-webkit-scrollbar {
    width: 6px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 72px;
    margin-bottom: 24px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.welcome-message h2 {
    color: var(--text-primary);
    margin-bottom: 12px;
    font-size: 26px;
    font-weight: 600;
}

.welcome-message > p {
    margin-bottom: 16px;
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.example-questions {
    margin-top: 32px;
    padding: 24px;
    background: var(--bg-light);
    border-radius: 16px;
    border: 1px solid var(--border-color);
}

.hint-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.example-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.example-item {
    display: inline-block;
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.example-item:hover {
    border-color: var(--primary-green);
    color: var(--primary-green);
    background: var(--bg-light);
    transform: translateX(4px);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease-in;
    max-width: 80%;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--primary-green) 0%, var(--primary-green-dark) 100%);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--bg-light);
    color: var(--primary-green);
    border: 1.5px solid var(--border-color);
}

.message-content {
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary-green) 0%, var(--primary-green-dark) 100%);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow-md);
}

.message.assistant .message-content {
    background: var(--bg-light);
    color: var(--text-primary);
    border: 1.5px solid var(--border-color);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-content p {
    margin: 0 0 8px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 12px;
}

.message.user .message-sources {
    border-top-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

.message.assistant .message-sources {
    color: var(--text-secondary);
}

.message-sources strong {
    display: block;
    margin-bottom: 6px;
    color: var(--text-primary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.source-link {
    display: inline-block;
    color: var(--primary-green);
    text-decoration: none;
    margin-right: 12px;
    margin-top: 6px;
    padding: 4px 8px;
    background: white;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
    font-size: 11px;
}

.message.user .source-link {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

.source-link:hover {
    background: var(--primary-green);
    color: white;
    border-color: var(--primary-green);
    transform: translateY(-1px);
}

.message.user .source-link:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Loading Indicator */
.loading {
    display: flex;
    gap: 6px;
    padding: 14px 18px;
    align-items: center;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-green);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.input-area {
    padding: 20px 32px;
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 24px 24px;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--bg-light);
    padding: 8px;
    border-radius: 16px;
    border: 1.5px solid var(--border-color);
    transition: all 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-green);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
    background: white;
}

#question-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    background: transparent;
    color: var(--text-primary);
    line-height: 1.5;
}

#question-input::placeholder {
    color: var(--text-light);
}

#question-input:focus {
    outline: none;
}

#question-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--primary-green);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-green-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-send:active:not(:disabled) {
    transform: translateY(0);
}

.btn-send:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.send-icon {
    font-size: 18px;
}

.input-footer {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-light);
}

.api-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

.api-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-light);
    animation: pulse 2s infinite;
}

.api-status.connected::before {
    background: var(--primary-green);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.api-status.error::before {
    background: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.1);
    }
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
        border: none;
    }

    .header {
        border-radius: 0;
        padding: 20px 24px;
    }

    .header h1 {
        font-size: 24px;
    }

    .domain-selector {
        padding: 16px 24px;
    }

    .chat-container {
        padding: 16px 20px;
    }

    .input-area {
        padding: 16px 20px;
    }

    .message {
        max-width: 85%;
    }

    .welcome-message {
        padding: 40px 16px;
    }

    .welcome-icon {
        font-size: 56px;
    }

}

/* Library layout */
.library-layout {
    display: flex;
    height: 100vh;
    background: #f5fdf8;
    color: #0f172a;
}

.library-sidebar {
    width: 260px;
    background: #e8f7ef;
    border-right: 1px solid #d1e9d9;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.library-sidebar h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #0f172a;
}

.library-tabs {
    display: flex;
    gap: 8px;
}

.library-tab {
    flex: 1;
    padding: 10px 12px;
    text-align: center;
    border-radius: 10px;
    border: 1px solid #d1e9d9;
    background: #ffffff;
    color: #0f172a;
    cursor: pointer;
    transition: all 0.2s ease;
}

.library-tab.active {
    background: #e6f7ef;
    border-color: #10b981;
    color: #065f46;
}

.library-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.library-item {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #d1e9d9;
    background: #ffffff;
    color: #0f172a;
    cursor: pointer;
    transition: all 0.2s ease;
}

.library-item:hover {
    border-color: #10b981;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.08);
}

.library-item.active {
    background: #e6f7ef;
    border-color: #10b981;
    color: #065f46;
}

.library-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 16px;
    padding: 16px;
    background: #f5fdf8;
}

.doc-list {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.doc-list-scroll {
    flex: 1;
    overflow-y: auto;
    margin-top: 12px;
}

.doc-item {
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    color: #0f172a;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 8px;
}

.doc-item:hover {
    border-color: #10b981;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.08);
}

.doc-item.active {
    background: #e6f7ef;
    border-color: #10b981;
    color: #065f46;
}

.doc-detail {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 16px;
    overflow: auto;
}

.benefit-badges {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
    margin-top: 6px;
}

.benefit-badge {
    background: #e6f7ef;
    border: 1px solid #bbf7d0;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
    color: #065f46;
    line-height: 1.5;
}
