/* General Math Trainer - Styles */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #2563eb;
    color: #333;
    line-height: 1.6;
    padding-top: 80px; /* Space for fixed navbar when present */
    position: relative;
    overflow-x: hidden;
}

/* When logged in, navbar has more items and can wrap—reserve extra top space so content isn't under it */
body.has-navbar.logged-in-nav {
    padding-top: 100px;
}

@media (max-width: 768px) {
    body {
        padding-top: 120px;
    }
    body.has-navbar.logged-in-nav {
        padding-top: 150px;
    }
}

@media (max-width: 480px) {
    body {
        padding-top: 140px;
    }
    body.has-navbar.logged-in-nav {
        padding-top: 180px;
    }
}

/* Navbar (for issues page and any standalone app pages with nav) */
.navbar {
    background: #f5f5f5;
    padding: 15px 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 30px;
}

.navbar-brand a {
    font-size: 24px;
    font-weight: 700;
    color: #667eea;
    text-decoration: none;
}

.navbar-brand a:hover {
    opacity: 0.8;
}

.navbar-links {
    display: flex;
    align-items: center;
    gap: 20px;
}

.navbar-links a {
    color: #555;
    text-decoration: none;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 5px;
    transition: all 0.3s;
    background: rgba(102, 126, 234, 0.1);
}

.navbar-links a:hover {
    background: rgba(102, 126, 234, 0.2);
    color: #667eea;
}

.app-container {
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
    overflow-x: hidden;
}

/* Login Reminder */
.login-reminder {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
}

.login-reminder p {
    color: #856404;
    margin: 0;
}

.login-reminder a {
    color: #667eea;
    font-weight: 600;
    text-decoration: none;
}

.login-reminder a:hover {
    text-decoration: underline;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
    color: #667eea;
    font-size: 36px;
    margin-bottom: 10px;
    font-weight: 700;
}

.subtitle {
    color: #666;
    font-size: 18px;
}

/* Main Content Layout - min-width: 0 on grid so 1fr column can shrink when content is wide */
.main-content {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 20px;
    min-width: 0;
}

/* When guided mode is active, adjust layout */
.main-content.guided-mode-active {
    grid-template-columns: 300px 1fr 400px;
}

/* Left Panel */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.panel-section h3 {
    color: #333;
    font-size: 18px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

/* Filters */
.filter-group {
    margin-bottom: 20px;
}

.filter-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

.filter-select {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: #667eea;
}

.year-range {
    display: flex;
    align-items: center;
    gap: 10px;
}

.year-range input {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
}

.year-range input:focus {
    outline: none;
    border-color: #667eea;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    font-size: 12px;
    font-weight: bold;
    cursor: help;
    line-height: 1;
    position: relative;
}

.info-icon:hover {
    background: #5568d3;
}

.info-icon[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 5px;
    padding: 8px 12px;
    background: #333;
    color: white;
    border-radius: 5px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
}

.info-icon[title]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: -5px;
    border: 5px solid transparent;
    border-top-color: #333;
    z-index: 1000;
    pointer-events: none;
}

.current-topic-display {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
}

.current-topic-display div {
    margin-bottom: 8px;
    font-size: 14px;
}

.notes-input {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
    background: white;
    font-family: inherit;
    resize: vertical;
}

.notes-input:focus {
    outline: none;
    border-color: #667eea;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    margin-bottom: 10px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-success {
    background: #10B981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.btn-warning {
    background: #F59E0B;
    color: white;
}

.btn-warning:hover {
    background: #D97706;
}

.btn-outline {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-outline:hover {
    background: #667eea;
    color: white;
}

.btn-info {
    background: #17a2b8;
    color: white;
}

.btn-info:hover {
    background: #138496;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(23, 162, 184, 0.4);
}

.btn-small {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 5px;
    flex-shrink: 0;
    width: auto;
    min-width: auto;
}

.btn-small.btn-outline {
    border: 1px solid #667eea;
    background: transparent;
    color: #667eea;
}

.btn-small.btn-outline:hover {
    background: #667eea;
    color: white;
}

.btn-small:not(.btn-outline) {
    background: #667eea;
    color: white;
    border: none;
}

.btn-small:not(.btn-outline):hover {
    background: #5568d3;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Right Panel - min-width: 0 so grid item can shrink; contain width so content doesn't stretch layout */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
    overflow-x: hidden;
}

/* Problem Info */
.problem-info {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-width: 0;
}

.problem-header {
    margin-bottom: 10px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

.problem-meta {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.user-rating-display {
    max-width: 100%;
    display: block;
    line-height: 1.4;
}

/* When showing type ratings grid: 3 topics per row, next 3 on following row */
.user-rating-display .type-ratings-grid {
    display: block;
    white-space: normal;
}

.user-rating-display .type-rating-row {
    display: block;
    margin-bottom: 4px;
    white-space: nowrap;
}

.user-rating-display .type-rating-row:last-child {
    margin-bottom: 0;
}

.user-rating-display .type-rating-item {
    display: inline;
    white-space: nowrap;
}

.user-rating-display span:not(.type-rating-item) {
    display: inline;
}

.problem-rating {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: #667eea;
    color: white;
}

.problem-type-info {
    color: #666;
    font-size: 14px;
    margin-bottom: 10px;
}

/* Problem Content - constrain width so problem load doesn't stretch beyond bounds */
.problem-content {
    background: white;
    border-radius: 10px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    min-height: 200px;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    text-align: center;
}

.problem-text {
    font-size: 18px;
    line-height: 1.8;
    color: #333;
    text-align: center;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* LaTeX/MathJax styling - same as AMC 8 */
.problem-text .MathJax {
    font-size: 1.1em;
}

/* TikZ diagrams (TikZJax replaces script type="text/tikz" with SVG) - centered */
.problem-text svg,
.solution-text svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0.75em auto;
    vertical-align: middle;
}
.problem-text .tikz-placeholder,
.solution-text .tikz-placeholder {
    font-style: italic;
    color: #666;
}

.problem-text .tikzjax-placeholder,
.solution-text .tikzjax-placeholder {
    display: inline-block;
    min-width: 1px;
    vertical-align: middle;
}
.problem-text .tikz-error,
.solution-text .tikz-error {
    color: #c00;
    font-size: 0.9em;
}

.problem-text mjx-container {
    display: inline !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    vertical-align: baseline !important;
    text-align: center !important;
}

.problem-text mjx-container[display="true"],
.problem-text mjx-container[display="true"] {
    display: inline !important;
    text-align: center !important;
    margin: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    vertical-align: baseline !important;
}

/* Answer Section */
.answer-section {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.answer-options {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
}

/* Hide empty answer options until MC problem loads */
#answerOptions:empty {
    display: none;
}

.answer-option {
    padding: 15px 20px;
    background: #f8f9fa;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 18px;
    font-weight: 400;
    text-align: center;
}

.answer-option:hover {
    border-color: #667eea;
    background: #f0f4ff;
}

.answer-option.selected {
    border-color: #667eea;
    background: #e6f2ff;
    color: #667eea;
}

.answer-option.correct {
    border-color: #28a745;
    background: #d4edda;
    color: #155724;
}

.answer-option.incorrect {
    border-color: #dc3545;
    background: #f8d7da;
    color: #721c24;
}

/* MathJax styling for answer options - match AMC trainer */
.answer-options mjx-container[display="true"],
.answer-options .MathJax-Display {
    display: inline-block !important;
    margin: 0 !important;
    text-align: center;
}

.answer-options mjx-container:not([display="true"]),
.answer-options .MathJax:not(.MathJax-Display) {
    display: inline !important;
    margin: 0 !important;
}

.answer-choice-text {
    display: inline-block;
}

.answer-input-container {
    margin-bottom: 20px;
}

.answer-input-container label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
    font-size: 14px;
}

.answer-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 16px;
    font-family: inherit;
}

.answer-input:focus {
    outline: none;
    border-color: #667eea;
}

.answer-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.answer-actions .btn {
    width: auto;
    flex: 1;
    min-width: 120px;
}

/* Feedback */
.feedback {
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    font-weight: 500;
}

.feedback.correct {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Below incorrect feedback: self-report (typed answers only) */
.did-it-right-wrap {
    margin-top: 12px;
    padding: 14px 16px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    text-align: center;
}

.did-it-right-btn {
    margin-bottom: 8px;
}

.did-it-right-hint {
    margin: 0;
    font-size: 13px;
    color: #666;
}

/* Overall Stats */
.overall-stats {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.overall-stats h3 {
    color: #333;
    font-size: 18px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}

.stat-card {
    background: #667eea;
    color: white;
    padding: 16px 6px;
    border-radius: 6px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
    min-height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    color: white !important;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 30px;
    border-radius: 10px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-content.large {
    max-width: 1200px;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

.modal h2 {
    color: #667eea;
    margin-bottom: 20px;
}

/* Statistics Tables */
.stats-overview {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.stats-overview h3 {
    color: #333;
    margin-bottom: 15px;
}

.stats-overview p {
    margin: 8px 0;
    font-size: 16px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.stats-table th,
.stats-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.stats-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
}

.stats-table tr:hover {
    background: #f8f9fa;
}

.mistakes-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.mistakes-table th,
.mistakes-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.mistakes-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
}

.mistakes-table tr:hover {
    background: #f8f9fa;
}

.mistakes-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.solution-text {
    font-size: 16px;
    line-height: 1.8;
    color: #333;
    margin-top: 15px;
    text-align: center;
}

/* Guided AI Mode Panel */
.guided-mode-panel {
    display: none;
    position: sticky;
    top: 100px;
    height: calc(100vh - 120px);
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex-direction: column;
    overflow: hidden;
}

.guided-mode-panel.active {
    display: flex;
}

.guided-mode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 2px solid #e0e0e0;
    background: #f8f9fa;
}

.guided-mode-header h3 {
    margin: 0;
    color: #667eea;
    font-size: 18px;
}

.guided-mode-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #aaa;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s;
}

.guided-mode-close:hover {
    color: #000;
    background: rgba(0, 0, 0, 0.05);
}

.guided-mode-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 15px;
}

.guided-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0;
}

.guided-chat-input-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

.guided-chat-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.guided-chat-input:focus {
    outline: none;
    border-color: #667eea;
}

.guided-chat-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 250px 1fr;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Responsive: Hide guided mode panel on smaller screens or stack it */
@media (max-width: 1400px) {
    .main-content.guided-mode-active {
        grid-template-columns: 300px 1fr;
    }
    
    .guided-mode-panel {
        position: fixed;
        right: 0;
        top: 80px;
        width: 400px;
        z-index: 999;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
    }
    
    .main-content.guided-mode-active .right-panel {
        margin-right: 420px;
    }
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }
    
    .left-panel {
        order: 2;
    }
    
    .right-panel {
        order: 1;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .answer-actions {
        flex-direction: column;
    }
    
    .answer-actions .btn {
        width: 100%;
    }
    
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 20px;
    }
    
    .mistakes-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
    
    .mistakes-table {
        min-width: 600px;
    }
    
    .mistakes-table th,
    .mistakes-table td {
        padding: 8px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .guided-mode-panel {
        width: 100%;
        right: 0;
        left: 0;
        height: 50vh;
        top: auto;
        bottom: 0;
        border-radius: 10px 10px 0 0;
    }
    
    .main-content.guided-mode-active .right-panel {
        margin-right: 0;
        margin-bottom: 50vh;
    }
}
