/* Modern Design System - Smart Exam System */
:root {
    /* Color Palette - High End & Concise */
    --primary-color: #4F46E5; /* Indigo 600 */
    --primary-hover: #4338CA; /* Indigo 700 */
    --secondary-color: #10B981; /* Emerald 500 */
    --accent-color: #F59E0B; /* Amber 500 */
    --danger-color: #EF4444; /* Red 500 */
    
    --bg-body: #F3F4F6; /* Gray 100 */
    --bg-surface: #FFFFFF;
    
    --text-main: #111827; /* Gray 900 */
    --text-muted: #6B7280; /* Gray 500 */
    --text-light: #F9FAFB; /* Gray 50 */
    
    --border-color: #E5E7EB; /* Gray 200 */
    
    /* Spacing & Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px 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);
    
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --header-height: 64px;
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    background-color: var(--bg-body);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: var(--primary-color);
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-hover);
}

ul {
    list-style: none;
}

/* Layout */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 1.5rem;
}

/* Header - Glassmorphism */
header {
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.025em;
}

nav ul {
    display: flex;
    gap: 1.5rem;
}

nav a {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
}

nav a:hover, nav a.active {
    color: var(--primary-color);
}

/* Responsive Navigation for Mobile */
@media (max-width: 768px) {
    header {
        padding: 0 1rem;
    }
    nav ul {
        gap: 1rem;
    }
    nav a {
        font-size: 0.875rem;
    }
}

/* Cards & Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--bg-surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.card h3 {
    margin-bottom: 0.75rem;
    color: var(--text-main);
    font-size: 1.25rem;
}

.card p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    flex-grow: 1;
}

/* Help Button (Circle Question Mark) */
.help-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--secondary-color);
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
    position: relative;
    padding: 0; /* Reset generic button padding */
}

.help-btn:hover {
    background-color: #059669; /* Emerald 600 */
    transform: scale(1.1);
}

.help-btn::after {
    content: "答题解疑";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background-color: #1F2937;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.help-btn:hover::after {
    opacity: 1;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-add, .btn-delete, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-align: center;
}

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

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

.btn-secondary {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-body);
    border-color: var(--text-muted);
    color: var(--text-main);
}

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

.btn-delete:hover {
    background-color: #DC2626; /* Red 600 */
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.9rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: #fff;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Login Page Specific */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--bg-surface);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-container h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

/* Help Button */
.help-btn {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.help-btn:hover {
    background-color: #059669; /* Emerald 600 */
}

/* Exam Practice Page */
.question-card {
    background: var(--bg-surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin: 2rem auto;
    max-width: 800px;
}

.question-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.question-type-badge {
    background-color: #EEF2FF; /* Indigo 50 */
    color: var(--primary-color);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
    margin-right: 0.5rem;
}

.options-list label {
    display: flex;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    background-color: #fff;
}

.options-list label:hover {
    background-color: #F9FAFB;
    border-color: var(--primary-color);
}

.options-list input[type="radio"],
.options-list input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 1rem;
    accent-color: var(--primary-color);
}

/* Progress Bar */
.progress-bar {
    height: 8px;
    background-color: #E5E7EB;
    border-radius: 9999px;
    overflow: hidden;
    margin: 1.5rem auto;
    max-width: 800px;
}

.progress-fill {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.5s ease;
}

/* Timer */
.timer {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 1.5rem;
    color: var(--primary-color);
    text-align: center;
    margin: 1rem 0;
}

/* Chat Interface - Enhanced */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - 40px); /* Adjust for header/padding */
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    max-width: 1000px;
    margin: 20px auto;
    border: 1px solid var(--border-color);
}

.chat-messages {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background-color: #F9FAFB;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    opacity: 0;
    animation: fadeIn 0.3s ease-out forwards;
}

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

.message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message.ai {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 1rem 1.25rem;
    border-radius: 1.25rem;
    font-size: 1rem;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

.message.user .message-content {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.ai .message-content {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 0.25rem;
}

.message-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    padding: 0 0.5rem;
}

/* Typing Indicator & Loading */
.typing-indicator::after {
    content: '_';
    animation: blink 1s step-start infinite;
    font-weight: bold;
    color: var(--primary-color);
}

@keyframes blink {
    50% { opacity: 0; }
}

.loading-dots {
    display: flex;
    gap: 4px;
    padding: 0.5rem;
    align-items: center;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.chat-input-area {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: white;
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.chat-input-area textarea {
    flex: 1;
    min-height: 50px;
    max-height: 150px;
    border-radius: 1.5rem;
    padding: 0.875rem 1.25rem;
    resize: none;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    background-color: #F9FAFB;
    transition: all 0.2s;
}

.chat-input-area textarea:focus {
    background-color: white;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.chat-input-area button {
    height: 50px;
    width: 50px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-md);
    transition: transform 0.1s;
}

.chat-input-area button:active {
    transform: scale(0.95);
}

.chat-input-area button svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Admin Specific */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background-color: #1F2937; /* Gray 800 */
    color: white;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1.5rem;
    text-align: center;
    border-bottom: 1px solid #374151;
}

.sidebar-menu {
    flex: 1;
    padding: 1rem 0;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: #9CA3AF; /* Gray 400 */
    transition: all 0.2s;
    font-weight: 500;
}

.sidebar-menu li a:hover, .sidebar-menu li a.active {
    background-color: #111827; /* Gray 900 */
    color: white;
    border-left: 4px solid var(--primary-color);
}

.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background-color: #F3F4F6;
}

/* Tables */
table {
    width: 100%;
    background: white;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    margin-top: 1rem;
}

th, td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #F9FAFB;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background-color: #F9FAFB;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .container {
        padding: 0 1rem;
    }
    
    .question-card {
        padding: 1.5rem;
        margin: 1rem auto;
    }
    
    .chat-input-area {
        padding: 0.75rem;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--bg-surface);
    margin: 5% auto;
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease-out;
}

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

.close {
    color: var(--text-muted);
    float: right;
    font-size: 1.75rem;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close:hover {
    color: var(--text-main);
}

.modal-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.modal-header h3 {
    color: var(--text-main);
    font-size: 1.25rem;
}

.modal-footer {
    text-align: right;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Dynamic Option Rows in Modal */
.options-container {
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius-md);
    background: #F9FAFB;
    margin-bottom: 1rem;
}

.option-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    align-items: center;
}

.option-row input {
    flex: 1;
}

.btn-remove-opt {
    color: var(--danger-color);
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-remove-opt:hover {
    background-color: #FEE2E2; /* Red 100 */
}

.btn-add-opt {
    margin-top: 0.5rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-add-opt:hover {
    background-color: #059669; /* Emerald 600 */
}

/* Toolbar in Admin */
.toolbar {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.toolbar h2 {
    font-size: 1.5rem;
    color: var(--text-main);
}

/* Report Page Specific */
.summary-card {
    background: var(--bg-surface);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 2rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.score-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    margin: 0 auto 1.5rem;
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.3);
}

.detail-item {
    background: var(--bg-surface);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
    border-left: 5px solid var(--border-color);
    border: 1px solid var(--border-color);
    border-left-width: 5px;
    transition: transform 0.2s;
}

.detail-item:hover {
    transform: translateX(4px);
}

.detail-item.correct {
    border-left-color: var(--secondary-color);
}

.detail-item.wrong {
    border-left-color: var(--danger-color);
}

.detail-item h4 {
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
    color: var(--text-main);
}

.answer-info {
    font-size: 0.95rem;
    margin-top: 0.75rem;
    color: var(--text-muted);
    background-color: #F9FAFB;
    padding: 0.75rem;
    border-radius: var(--radius-md);
}

.explanation {
    margin-top: 1rem;
    padding: 1rem;
    background: #EEF2FF; /* Indigo 50 */
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    color: var(--text-main);
    border: 1px solid #E0E7FF;
}

#ai-analysis-card {
    text-align: left;
    border-color: var(--primary-color);
    background-color: #F8FAFC;
}

#ai-analysis-content {
    line-height: 1.7;
    color: var(--text-main);
    white-space: pre-wrap;
    font-size: 1rem;
}
