/* ==========================================================================
   AI八字學生系統 - 自定義樣式
   ========================================================================== */

/* 全域樣式 */
:root {
    --primary-color: #6366f1;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: 'Microsoft JhengHei', 'PingFang TC', 'Noto Sans TC', sans-serif;
    background-color: var(--light-bg);
    line-height: 1.6;
}

/* ==========================================================================
   登入頁面樣式
   ========================================================================== */

.login-container {
    min-height: 100vh;
    background: linear-gradient(135deg, #200439 0%, #01041c 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    animation: fadeInUp 0.6s ease-out;
}

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

.login-card h1 {
    font-size: 3rem;
    margin-bottom: 0;
}

.login-card h2 {
    color: var(--primary-color);
    font-weight: 600;
}

.login-card .form-label {
    font-weight: 600;
    color: var(--secondary-color);
}

.login-card .form-select,
.login-card .form-control {
    border-radius: 12px;
    border: 2px solid var(--border-color);
    padding: 12px 16px;
    transition: all 0.3s ease;
}

.login-card .form-select:focus,
.login-card .form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.login-card .btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #8b5cf6 100%);
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.login-card .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ==========================================================================
   師傅個人頁面樣式
   ========================================================================== */

.master-dashboard {
    min-height: 100vh;
    background-color: var(--light-bg);
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.5rem;
}

/* 對話列表樣式 */
.conversation-list {
    max-height: 400px;
    overflow-y: auto;
}

.conversation-item {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
}

.conversation-item:hover {
    background-color: #f1f5f9;
}

.conversation-item.active {
    background-color: rgba(99, 102, 241, 0.1);
    border-left: 4px solid var(--primary-color);
}

/* 對話項目佈局 */
.conversation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-info {
    flex: 1;
}

.conversation-actions {
    opacity: 0;
    transition: opacity 0.3s ease;
    margin-left: 10px;
}

.conversation-item:hover .conversation-actions {
    opacity: 1;
}

.conversation-delete {
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
}

.conversation-delete:hover {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: white !important;
}

.conversation-item h6 {
    margin-bottom: 5px;
    color: var(--secondary-color);
    font-weight: 600;
}

.conversation-item p {
    margin-bottom: 10px;
    font-size: 0.875rem;
}

.conversation-meta {
    display: flex;
    gap: 8px;
}

.conversation-meta .badge {
    font-size: 0.75rem;
}

/* 統計卡片 */
.stat-item h4 {
    font-weight: 700;
    font-size: 1.5rem;
}

.stat-item small {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   聊天界面樣式
   ========================================================================== */

.chat-container {
    height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chat-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #8b5cf6 100%);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
}

.chat-header h4 {
    font-weight: 600;
    margin-bottom: 0;
}

.chat-header small {
    opacity: 0.9;
}

.chat-header .btn {
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

.chat-header .btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

/* 聊天訊息區域 */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #fafbfc;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    margin-bottom: 20px;
    animation: messageSlideIn 0.4s ease-out;
}

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

/* AI學生訊息 */
.ai-message {
    justify-content: flex-start;
}

.ai-message .message-content {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 18px 18px 18px 4px;
    max-width: 80%;
    margin-left: 12px;
}

.ai-message .message-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

/* 師傅訊息 */
.master-message {
    justify-content: flex-end;
}

.master-message .message-content {
    background: linear-gradient(135deg, var(--primary-color) 0%, #8b5cf6 100%);
    color: white;
    border-radius: 18px 18px 4px 18px;
    max-width: 80%;
    margin-right: 12px;
}

.master-message .message-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

/* 訊息內容 */
.message-content {
    padding: 16px 20px;
    box-shadow: var(--shadow);
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.sender-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
}

.message-text {
    line-height: 1.6;
    font-size: 0.95rem;
}

/* Markdown 渲染樣式 */
.message-text strong {
    font-weight: 600;
    color: #2563eb !important;
    background: rgba(37, 99, 235, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
}

.message-text .list-item {
    margin-bottom: 8px;
    padding-left: 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.message-text .list-item .badge {
    font-size: 0.7rem;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-message .message-text {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ai-message .message-text .badge.bg-info {
    background-color: #0dcaf0 !important;
    color: #000;
}

/* 訊息評分樣式 */
.message-rating {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.rating-score {
    font-size: 0.875rem;
    font-weight: 600;
}

.rating-tags {
    display: flex;
    gap: 6px;
}

.rating-tags .badge {
    font-size: 0.7rem;
    padding: 4px 8px;
}

/* ==========================================================================
   輸入區域樣式
   ========================================================================== */

.chat-input-area {
    background: white;
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.input-tools {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.input-tools .btn {
    border-radius: 8px;
    font-size: 0.875rem;
}

.input-group textarea {
    border-radius: 12px 0 0 12px;
    border: 2px solid var(--border-color);
    resize: none;
    transition: all 0.3s ease;
}

.input-group textarea:focus {
    border-color: var(--primary-color);
    box-shadow: none;
}

.input-group .btn {
    border-radius: 0 12px 12px 0;
    border: 2px solid var(--primary-color);
    background: var(--primary-color);
    padding: 12px 20px;
    font-weight: 600;
}

.input-group .btn:disabled {
    background-color: #94a3b8;
    border-color: #94a3b8;
}

.input-status {
    text-align: center;
}

/* ==========================================================================
   評分模態框樣式
   ========================================================================== */

.modal-content {
    border-radius: 16px;
    border: none;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #8b5cf6 100%);
    color: white;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
}

.modal-header .btn-close {
    filter: invert(1);
}

.ai-question-preview {
    background-color: #f8fafc;
    border-radius: 12px;
    padding: 15px;
}

/* 評分星星樣式 */
.rating-stars {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.rating-star {
    border: 2px solid var(--border-color);
    background: white;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.875rem;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 80px;
}

.rating-star:hover {
    border-color: var(--warning-color);
    background-color: rgba(245, 158, 11, 0.1);
    transform: translateY(-2px);
}

.rating-star.selected {
    background: var(--warning-color);
    border-color: var(--warning-color);
    color: white;
}

/* 標籤按鈕樣式 */
.tag-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tag-btn {
    border-radius: 20px;
    font-size: 0.875rem;
    padding: 8px 16px;
    transition: all 0.3s ease;
}

.tag-btn.selected {
    background-color: var(--success-color);
    border-color: var(--success-color);
    color: white;
}

/* ==========================================================================
   Toast 通知樣式
   ========================================================================== */

.toast {
    border-radius: 12px;
    border: none;
    box-shadow: var(--shadow-lg);
}

.toast-header {
    background-color: rgba(99, 102, 241, 0.1);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 12px 12px 0 0;
}

/* ==========================================================================
   響應式設計
   ========================================================================== */

@media (max-width: 768px) {
    .login-card {
        padding: 30px 20px;
        margin: 10px;
    }
    
    .chat-container {
        height: calc(100vh - 80px);
        border-radius: 0;
    }
    
    .chat-header {
        border-radius: 0;
        padding: 15px;
    }
    
    .chat-messages {
        padding: 15px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .rating-stars {
        flex-direction: column;
    }
    
    .rating-star {
        min-width: auto;
    }
    
    .tag-buttons {
        justify-content: center;
    }
    
    .input-tools {
        justify-content: center;
    }
}

@media (max-width: 576px) {
    .login-card h1 {
        font-size: 2rem;
    }
    
    .login-card h2 {
        font-size: 1.5rem;
    }
    
    .message-content {
        max-width: 90%;
        padding: 12px 16px;
    }
    
    .chat-header h4 {
        font-size: 1.2rem;
    }
    
    .conversation-item {
        padding: 12px;
    }
}

/* ==========================================================================
   自定義滾動條
   ========================================================================== */

.chat-messages::-webkit-scrollbar,
.conversation-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.conversation-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.conversation-list::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.conversation-list::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ==========================================================================
   載入動畫
   ========================================================================== */

.spinner-border-sm {
    width: 1rem;
    height: 1rem;
}

/* 打字效果 */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.typing-indicator::after {
    content: '';
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background-color: currentColor;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator::before {
    content: '••';
    animation: typing 1.4s infinite ease-in-out;
    animation-delay: 0.2s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

/* ==========================================================================
   工具提示樣式
   ========================================================================== */

.tooltip {
    font-size: 0.875rem;
}

.tooltip-inner {
    background-color: var(--secondary-color);
    border-radius: 6px;
}

/* ==========================================================================
   按鈕特效
   ========================================================================== */

.btn {
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

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

.btn-success {
    background: var(--success-color);
    border-color: var(--success-color);
}

.btn-warning {
    background: var(--warning-color);
    border-color: var(--warning-color);
}

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

/* ==========================================================================
   評分標籤和移動端優化
   ========================================================================== */

/* 評分標籤按鈕樣式 */
.rating-tag-btn {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    margin: 0.1rem;
    transition: all 0.2s ease;
}

.rating-tag-btn:hover {
    transform: translateY(-1px);
}

.rating-tags-area {
    border-top: 1px solid #dee2e6;
    padding-top: 0.5rem;
}

/* 移動端優化 */
@media (max-width: 768px) {
    .chat-container {
        margin-bottom: 1rem;
        height: calc(100vh - 100px);
    }
    
    .rating-tag-btn {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    
    .chat-header h4 {
        font-size: 1.1rem;
    }
    
    .chat-header small {
        font-size: 0.8rem;
    }
    
    .conversation-list {
        max-height: 300px;
        overflow-y: auto;
    }
    
    /* 移動端時隱藏一些按鈕文字 */
    .btn .d-md-inline {
        display: none !important;
    }
    
    .chat-header .btn-sm {
        padding: 0.25rem 0.5rem;
    }
}

@media (max-width: 576px) {
    .rating-tags-area {
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }
    
    .rating-tags-area .d-flex {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }
    
    .rating-tag-btn {
        flex-shrink: 0;
        white-space: nowrap;
        min-width: auto;
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }
    
    /* 自定義滾動條樣式 */
    .rating-tags-area .d-flex::-webkit-scrollbar {
        height: 4px;
    }
    
    .rating-tags-area .d-flex::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 2px;
    }
    
    .rating-tags-area .d-flex::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 2px;
    }
    
    .rating-tags-area .d-flex::-webkit-scrollbar-thumb:hover {
        background: #a8a8a8;
    }
    
    .chat-header {
        padding: 0.75rem;
    }
    
    .chat-header .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }
    
    .chat-messages {
        height: 250px;
    }
    
    .chat-container {
        height: calc(100vh - 80px);
    }
    
    /* 為文本區域留出更多空間 */
    .chat-input textarea {
        min-height: 80px;
    }
}