:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #6366f1;
    --dark: #1e293b;
    --gray-900: #0f172a;
    --gray-800: #1e293b;
    --gray-700: #334155;
    --gray-600: #475569;
    --gray-500: #64748b;
    --gray-400: #94a3b8;
    --gray-300: #cbd5e1;
    --gray-200: #e2e8f0;
    --gray-100: #f1f5f9;
    --gray-50: #f8fafc;
    --white: #ffffff;
    --font-mono: 'Fira Code', 'Monaco', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-900);
    min-height: 100vh;
}

/* 主容器 */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--white);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
}

/* 頂部標題欄 */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 1rem 10rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    transition: all 0.3s ease;
}

.status-indicator.connected {
    background: var(--success);
}

/* 聊天區域 */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--gray-50);
}

.chat-messages> :last-child {
    margin-bottom: 1rem;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin: 0 10rem;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--primary);
    color: var(--white);
}

.message.bot .message-avatar {
    background: var(--gray-700);
    color: var(--white);
}

.message-content {
    max-width: 75%;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    line-height: 1.5;
}

/* 用戶訊息保持 pre-wrap 以顯示換行 */
.message.user .message-bubble {
    white-space: pre-wrap;
}

/* Markdown 樣式 */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
    margin: 0.5rem 0;
    font-weight: 600;
}

.message-bubble h1 {
    font-size: 1.25rem;
}

.message-bubble h2 {
    font-size: 1.125rem;
}

.message-bubble h3 {
    font-size: 1rem;
}

.message-bubble h4 {
    font-size: 0.9375rem;
}

.message-bubble p {
    margin: 0.5rem 0;
}

.message-bubble p:first-child {
    margin-top: 0;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble ul,
.message-bubble ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.message-bubble ul {
    list-style-type: disc;
}

.message-bubble ol {
    list-style-type: decimal;
}

.message-bubble li {
    margin: 0.25rem 0;
    display: list-item;
}

.message-bubble ul ul,
.message-bubble ol ol,
.message-bubble ul ol,
.message-bubble ol ul {
    margin: 0.25rem 0;
}

.message-bubble blockquote {
    margin: 0.5rem 0;
    padding: 0.5rem 1rem;
    border-left: 3px solid var(--gray-300);
    background: var(--gray-50);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.message-bubble code {
    background: var(--gray-100);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.875em;
}

.message-bubble pre {
    background: var(--gray-100);
    padding: 0.75rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble strong {
    font-weight: 600;
}

.message-bubble em {
    font-style: italic;
}

.message-bubble a {
    color: var(--primary);
    text-decoration: underline;
}

.message-bubble a:hover {
    color: var(--primary-dark);
}

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
}

.message-bubble th,
.message-bubble td {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--gray-300);
    text-align: left;
}

.message-bubble th {
    background: var(--gray-100);
    font-weight: 600;
}

.message-bubble hr {
    border: none;
    border-top: 1px solid var(--gray-300);
    margin: 1rem 0;
}

.message.user .message-bubble {
    background: var(--primary);
    color: var(--white);
    border-top-right-radius: 4px;
}

.message.bot .message-bubble {
    background: var(--white);
    color: var(--gray-900);
    border: 1px solid var(--gray-200);
    border-top-left-radius: 4px;
}

/* AI 回應中的程式碼樣式調整 */
.message.bot .message-bubble code {
    background: var(--gray-100);
    color: var(--gray-800);
}

.message.bot .message-bubble pre {
    background: var(--gray-900);
    color: var(--gray-100);
}

.message.bot .message-bubble pre code {
    background: none;
    color: var(--gray-100);
}

.message-time {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.message.user .message-time {
    text-align: right;
}

.system-message {
    text-align: center;
    padding: 0.5rem 1rem;
    color: var(--gray-500);
    font-size: 0.875rem;
    font-style: italic;
}

.typing-indicator {
    padding: 1rem;
    display: flex;
    background: var(--gray-50);
    align-items: center;
    gap: 0.5rem;
}

.typing-indicator .message.bot {
    align-items: center;
    margin-bottom: 1rem;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typingAnimation 1.4s infinite;
}

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

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

@keyframes typingAnimation {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.7;
    }

    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* 輸入區域 */
.input-container {
    padding: 1rem 10rem;
    border-top: 1px solid var(--gray-200);
    background: var(--white);
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.input-field {
    flex: 1;
}

.chat-input {
    width: 100%;
    min-height: 44px;
    max-height: 120px;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    resize: none;
    transition: all 0.15s ease;
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-input:disabled {
    background: var(--gray-100);
    cursor: not-allowed;
}

/* 按鈕樣式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    min-width: 80px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-200);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-direction: row;
    align-items: flex-start;
}

.action-buttons .btn {
    height: 47px;
    /* 與 .chat-input 的 min-height 對齊，之後不再跟隨自動增高 */
}

.quick-actions {
    display: flex;
    justify-content: center;
    padding-top: 0.75rem;
}

.quick-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    background: var(--white);
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
}

.quick-btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

#login-btn {
    margin-left: 1rem;
    display: none;
}

/* 登入/登出按鈕視覺：底色與 header 一致（白），hover 時微灰底 */
#login-btn,
#logout-btn {
    color: var(--gray-700);
    text-decoration: none;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    transition: background-color 0.15s ease, color 0.15s ease;
    background: var(--white);
    border: none;
    cursor: pointer;
}

#login-btn:hover,
#logout-btn:hover {
    background: var(--gray-100);
}

#logout-btn {
    margin-left: 0.25rem;
    display: none;
}

/* 會員姓名純文字樣式 */
#user-name {
    margin-left: 0.5rem;
    color: var(--gray-700);
    font-weight: 500;
}

.job-list {
    margin-top: -32px;
}

.card {
    color: var(--gray-800);
    background-color: #fff;
    border-radius: 12px;
    border: 1px solid var(--blue-100);
    box-shadow: 0 0 1px #21252933, 0 2px 16px #21252914;
    -webkit-backdrop-filter: blur(30px);
    backdrop-filter: blur(30px);
    padding: 16px;
    gap: 8px;
    display: flex;
    flex-direction: column;
    max-width: 327px;
    margin: 16px;
}

.card .job_name {
    color: var(--gray-800);
    font-size: 18px;
    font-weight: 600;
    line-height: 150%;
    margin-bottom: 2px;
}

.card .organ_name {
    color: var(--gray-700);
}

.card .job_city,
.card .salary {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    line-height: 170%;
    color: var(--gray-600);
}

.card .job_city {
    margin-bottom: 2px;
}

.card .icon {
    flex: 0 0 24px;
}

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


/* 響應式設計 */
@media (max-width: 768px) {
    .app-container {
        height: 100vh;
        border-radius: var(--radius);
    }

    .header {
        padding: 0.75rem 1rem;
    }

    .header h1 {
        font-size: 1.125rem;
    }

    .chat-messages {
        padding: 1rem;
    }

    .message {
        margin: 0;
    }

    .input-container {
        padding: 0.75rem 1rem;
    }

    .message-content {
        max-width: 85%;
    }

    .action-buttons {
        flex-direction: row;
    }

    #connection-status {
        display: none;
    }

    #login-btn {
        margin-left: 0;
        padding: 0;
    }

    #user-name {
        display: none !important;
    }
}

/* 自訂捲軸 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--gray-100);
}

::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 3px;
}

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

/* Feedback bar */
.feedback-bar {
    display: inline-flex;
    gap: 6px;
    margin-left: 6px;
}

.feedback-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border: none;
    background: transparent;
    color: var(--gray-500);
    border-radius: 4px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.feedback-btn:hover:not(:disabled) {
    background: var(--gray-100);
    color: var(--gray-700);
}

.feedback-btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.feedback-btn.active {
    color: var(--gray-900);
}

.feedback-btn i {
    font-size: 12px;
}

/* icon 顯示規則：預設空心，hover 或 active 顯示實心 */
.feedback-btn i.solid {
    display: none;
}

.feedback-btn:hover:not(:disabled) i.solid {
    display: inline-block;
}

.feedback-btn:hover:not(:disabled) i.regular {
    display: none;
}

.feedback-btn.active i.solid {
    display: inline-block;
}

.feedback-btn.active i.regular {
    display: none;
}