/* Base styles */
:root {
    --primary: #374151;
    --primary-dark: #1f2937;
    --primary-hover: #4b5563;
    --secondary: #6b7280;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --bg: #f9fafb;
    --bg-white: #ffffff;
    --text: #111827;
    --text-light: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --radius: 8px;

    /* Consistent color scheme */
    --color-primary: #374151;
    --color-primary-hover: #1f2937;
    --color-surface: #f3f4f6;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-muted: #6b7280;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Landing page */
.landing {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.landing-header {
    text-align: center;
    margin-bottom: 30px;
}

.landing-header h1 {
    color: var(--primary);
    font-size: 2rem;
}

.landing-header .subtitle {
    color: var(--text-light);
}

.course-info {
    text-align: center;
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 30px;
}

.course-info h2 {
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.course-info .semester {
    color: var(--text-light);
}

.info-section {
    margin-bottom: 25px;
}

.info-section h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: var(--text);
}

.info-section ul {
    padding-left: 20px;
}

.info-section li {
    margin-bottom: 8px;
}

.contact {
    background: var(--bg);
    padding: 20px;
    border-radius: var(--radius);
}

.consent-form {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    margin-bottom: 20px;
}

.checkbox-label input {
    margin-top: 4px;
}

button, .btn {
    display: inline-block;
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

button:hover, .btn:hover {
    background: var(--primary-dark);
}

button:disabled {
    background: var(--secondary);
    cursor: not-allowed;
}

button.secondary, .btn.secondary {
    background: var(--secondary);
}

button.secondary:hover, .btn.secondary:hover {
    background: #475569;
}

/* Message box */
.message-box {
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
}

.message-box.warning {
    background: #fef3c7;
    border: 1px solid var(--warning);
}

.message-box .period {
    margin-top: 15px;
    color: var(--text-light);
}

/* Chat */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px); /* Account for container padding */
    max-height: calc(100dvh - 40px);
    max-width: 900px;
    margin: 0 auto;
    background: var(--bg-white);
    overflow: hidden;
}

@supports (height: 100dvh) {
    .chat-container {
        height: calc(100dvh - 40px);
    }
}

.chat-header {
    padding: 12px 16px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
    color: white;
}

.chat-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    font-size: 1rem;
    font-weight: 500;
    margin: 0;
}

.end-btn-header {
    background: transparent;
    color: rgba(255,255,255,0.9);
    border: 1px solid rgba(255,255,255,0.5);
    padding: 6px 16px;
    font-size: 0.85rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.end-btn-header:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.8);
    color: white;
}

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    animation: messageSlideIn 0.3s ease-out;
}

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

.message.assistant {
    align-items: flex-start;
}

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

.message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    white-space: pre-wrap;
}

.message.assistant .message-content {
    background: var(--bg);
    border-bottom-left-radius: 4px;
}

.message.user .message-content {
    background: #374151;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.system-error {
    align-items: center;
}

.message.system-error .message-content {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    max-width: 90%;
    text-align: center;
}

.message.token-limit-notice {
    align-items: center;
}

.message.token-limit-notice .message-content {
    background: #fefce8;
    border: 1px solid #fde047;
    color: #713f12;
    max-width: 90%;
    text-align: center;
    padding: 16px 20px;
}

.message.token-limit-notice .message-content strong {
    color: #92400e;
}

/* Message timestamps */
.message-timestamp {
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 4px;
    padding: 0 4px;
}

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

/* Typing indicator dots */
.typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}

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

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

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

/* Typing status text (shown during retry) */
.typing-status {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

@keyframes typingPulse {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Loading dots for buttons */
.loading-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background-color: currentColor;
    border-radius: 50%;
    animation: typingPulse 1.4s ease-in-out infinite;
}

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

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

button.loading {
    cursor: wait;
        transform: scale(1);
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .message {
        animation: none;
    }
    .typing-dots span {
        animation: none;
        opacity: 0.6;
    }
}

.pii-warning {
    padding: 10px 20px;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.9rem;
    flex-shrink: 0;
    text-align: center;
}

.chat-form {
    padding: 15px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-group {
    display: flex;
    gap: 10px;
}

.input-group textarea {
    flex: 1;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    min-height: 50px;
    max-height: 200px;
    overflow-y: hidden;
}

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

.chat-actions {
    padding: 10px 20px;
    text-align: center;
    background: var(--bg);
    flex-shrink: 0;
}

.end-hint {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 6px;
}

/* Chat readonly state (after bot ends conversation) */
.chat-readonly-notice {
    padding: 16px 20px;
    background: #f3f4f6;
    border-top: 1px solid var(--border);
    text-align: center;
    flex-shrink: 0;
}

.chat-readonly-notice p {
    margin: 0 0 12px 0;
    color: var(--text-light);
    font-size: 0.9rem;
}

.chat-readonly-notice button {
    background: #374151;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.chat-readonly-notice button:hover {
    background: #1f2937;
}

/* Thanks page */
.thanks {
    text-align: center;
    padding: 40px;
}

.thanks-header h1 {
    color: var(--success);
    margin-bottom: 30px;
}

.summary-section {
    text-align: left;
    background: var(--bg);
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 30px;
}

.summary-section h2 {
    font-size: 1.1rem;
    margin-bottom: 15px;
}

.summary-content {
    white-space: pre-wrap;
}

.thanks-message {
    color: var(--text-light);
    margin-bottom: 15px;
}

.thanks-hint {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 30px;
}

.thanks-hint a {
    color: var(--primary);
}

/* Error page */
.error-page {
    text-align: center;
    padding: 60px 20px;
}

.error-page h1 {
    color: var(--error);
    margin-bottom: 20px;
}

/* Admin */
.admin {
    padding: 20px;
}

.admin-header {
    margin-bottom: 30px;
}

.admin-header h1 {
    color: var(--primary);
    margin-bottom: 15px;
}

.admin-nav {
    display: flex;
    gap: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.admin-nav a {
    color: var(--text-light);
    text-decoration: none;
    padding: 5px 0;
}

.admin-nav a:hover,
.admin-nav a.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
}

.stat-label {
    color: var(--text-light);
    font-size: 0.9rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.data-table th,
.data-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg);
    font-weight: 600;
}

.data-table tr:hover {
    background: var(--bg);
}

.data-table a {
    color: var(--primary);
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-active { background: #dbeafe; color: #1d4ed8; }
.status-completed { background: #dcfce7; color: #166534; }
.status-timeout { background: #fef3c7; color: #92400e; }
.status-pending { background: #e2e8f0; color: #475569; }
.status-done { background: #dcfce7; color: #166534; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-skipped { background: #e2e8f0; color: #475569; }

.filter-bar {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-bar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}

.back-link {
    margin-bottom: 20px;
}

.back-link a {
    color: var(--text-light);
    text-decoration: none;
}

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

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 30px;
}

.detail-item .label {
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
    color: var(--text-light);
}

.detail-item code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.summary-box,
.analysis-box {
    background: var(--bg-white);
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.summary-box pre,
.analysis-box pre {
    white-space: pre-wrap;
    font-family: inherit;
}

.transcript {
    background: var(--bg-white);
    border-radius: var(--radius);
    overflow: hidden;
}

.transcript-message {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
}

.transcript-message:last-child {
    border-bottom: none;
}

.transcript-message.user {
    background: #f0f9ff;
}

.transcript-message .message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.transcript-message .role {
    font-weight: 600;
}

.transcript-message .time {
    color: var(--text-light);
}

.transcript-message .message-content {
    white-space: pre-wrap;
    font-family: inherit;
    max-width: 100%;
    padding: 0;
    border-radius: 0;
    background: transparent;
}

.transcript-message .thinking-content {
    margin-bottom: 10px;
    padding: 10px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 4px;
}

.transcript-message .thinking-content summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: #92400e;
    font-weight: 500;
}

.transcript-message .thinking-content pre {
    margin-top: 10px;
    white-space: pre-wrap;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.8rem;
    color: #78350f;
    max-height: 400px;
    overflow-y: auto;
}

.edit-form {
    background: var(--bg-white);
    padding: 30px;
    border-radius: var(--radius);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.code-display {
    display: flex;
    align-items: center;
    gap: 15px;
}

.code-display code {
    background: var(--bg);
    padding: 10px 15px;
    border-radius: var(--radius);
    font-size: 1rem;
}

.help-text {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 8px;
}

.form-actions {
    display: flex;
    gap: 15px;
    margin-top: 30px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

.info {
    color: var(--text-light);
    margin-bottom: 20px;
}

.actions {
    margin-top: 20px;
}

/* Mobile responsive - Chat */
@media (max-width: 768px) {
    .chat-header {
        padding: 10px 15px;
    }

    .chat-header h1 {
        font-size: 0.95rem;
    }

    .chat-messages {
        padding: 12px;
    }

    .message-content {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 0.95rem;
    }

    .chat-form {
        padding: 10px 12px;
    }

    .input-group textarea {
        font-size: 16px; /* Prevents iOS zoom */
        rows: 1;
    }

    .pii-warning {
        font-size: 0.8rem;
        padding: 6px 12px;
    }

    .chat-actions {
        padding: 8px 12px;
    }

    .chat-actions button {
        padding: 8px 16px;
        font-size: 0.85rem;
    }

    .end-hint {
        font-size: 0.75rem;
        margin-top: 4px;
    }
}

@media (max-width: 480px) {
    /* Prevent iOS auto-zoom on all inputs */
    input, textarea, select {
        font-size: 16px !important;
    }

    .container {
        padding: 10px;
    }

    .chat-header {
        padding: 8px 12px;
    }

    .chat-header h1 {
        font-size: 0.9rem;
    }

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

    .input-group {
        flex-direction: row;
        gap: 8px;
    }

    .input-group button {
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .chat-actions {
        padding: 6px 12px;
    }

    .chat-actions button {
        padding: 6px 12px;
        font-size: 0.8rem;
    }

    .end-hint {
        display: none;
    }
}
