/* Environmental Science Tutor — hub + lesson chat/widget UI. Adapted from
   History Tutor's layout (static/css/projects/history_tutor/history_tutor.css),
   trimmed to this feature's widget set (concept card, quiz, mastery panel --
   no map/timeline/figure). Uses the site's edu-theme design tokens. */

.est-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px 80px;
}

.est-header {
    position: relative;
    text-align: center;
    margin-bottom: 32px;
}

.est-back {
    position: absolute;
    left: 0;
    top: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.est-back:hover {
    color: var(--accent-blue);
}

@media (max-width: 640px) {
    .est-back {
        position: static;
        display: block;
        text-align: left;
        margin-bottom: 12px;
    }
}

.est-header h1 {
    font-size: 2.2rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.est-header p {
    color: var(--text-secondary);
    font-size: 1.05rem;
    max-width: 640px;
    margin: 0 auto;
}

/* ---------- Hub page: subfield cards ---------- */

.est-subfield-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.est-subfield-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    padding: 22px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

a.est-subfield-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--glass-shadow);
    border-color: var(--accent-blue);
}

.est-subfield-card h2 {
    font-size: 1.3rem;
    margin: 0;
    color: var(--text-primary);
}

.est-subfield-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    flex: 1;
}

.est-subfield-meta {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-green);
    font-weight: 600;
}

.est-subfield-cta {
    font-weight: 600;
    color: var(--accent-deep);
    font-size: 0.9rem;
}

/* ---------- Lesson chat page ---------- */

.est-starters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 24px;
}

.est-starter-chip {
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 999px;
    padding: 7px 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.est-starter-chip:hover {
    border-color: var(--accent-blue);
    color: var(--accent-deep);
}

.est-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    gap: 24px;
    align-items: start;
}

@media (max-width: 860px) {
    .est-layout {
        grid-template-columns: 1fr;
    }
}

.est-chat-col {
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    height: 70vh;
    min-height: 420px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.message-avatar {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    background: var(--tertiary-dark);
    color: var(--text-secondary);
}

.message.user .message-avatar {
    background: var(--accent-blue);
    color: #fff;
}

.message-content {
    background: var(--tertiary-dark);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
    max-width: 85%;
    white-space: pre-wrap;
}

.message.user .message-content {
    background: var(--accent-blue);
    color: #fff;
}

/* Source chips under an AI reply (links into the textbook PDF) */
.est-citations {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    white-space: normal;
    font-size: 0.8rem;
}

.est-citations-label {
    color: var(--text-muted);
}

.est-citation-chip {
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 999px;
    padding: 2px 10px;
    color: var(--accent-deep);
    text-decoration: none;
}

a.est-citation-chip:hover,
a.est-citation-chip:focus-visible {
    border-color: var(--accent-blue);
}

.typing-indicator {
    display: flex;
    gap: 4px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: est-typing 1.1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes est-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 14px;
    border-top: 1px solid var(--hairline);
}

.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--hairline);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--primary-dark);
    color: var(--text-primary);
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.send-btn {
    background: var(--accent-blue);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0 20px;
    font-weight: 600;
    cursor: pointer;
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.alert {
    background: #fbe6e6;
    color: #8a2a2a;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.9rem;
}

/* ---------- Widget stage ---------- */

.est-stage-col {
    min-height: 420px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.est-mastery-panel {
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    padding: 14px 16px;
}

.est-mastery-panel h3 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.est-mastery-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 4px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.est-mastery-badge {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.est-mastery-badge[data-state="not_started"] { background: var(--tertiary-dark); color: var(--text-muted); }
.est-mastery-badge[data-state="familiar"]    { background: rgba(217, 164, 65, 0.18); color: var(--accent-deep); }
.est-mastery-badge[data-state="proficient"]  { background: rgba(150, 48, 95, 0.12); color: var(--accent-deep); }
.est-mastery-badge[data-state="mastered"]    { background: rgba(47, 122, 107, 0.18); color: var(--accent-green); }

.est-stage {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 2px;
}

.est-stage-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
    border: 1px dashed var(--hairline);
    border-radius: 14px;
}

.est-widget {
    background: var(--secondary-dark);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    padding: 16px;
    animation: est-widget-in 0.25s ease;
}

@keyframes est-widget-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.est-widget h3 {
    margin: 0 0 10px;
    font-size: 1rem;
    color: var(--text-primary);
}

/* Concept card widget */

.est-concept-summary {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.est-concept-prereqs {
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Quiz widget */

.est-quiz-question {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.est-quiz-choices {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.est-quiz-choice {
    text-align: left;
    background: var(--primary-dark);
    border: 1px solid var(--hairline);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--text-primary);
}

.est-quiz-choice:hover:not(:disabled) {
    border-color: var(--accent-blue);
}

.est-quiz-choice:disabled {
    cursor: default;
}

.est-quiz-choice.est-correct {
    border-color: var(--accent-green);
    background: rgba(47, 122, 107, 0.12);
}

.est-quiz-choice.est-incorrect {
    border-color: #b23a3a;
    background: rgba(178, 58, 58, 0.1);
}

.est-quiz-feedback {
    margin-top: 12px;
    font-size: 0.88rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--hairline);
    padding-top: 10px;
}

/* Interactive labs on the hub page */
.est-labs { margin-top: 36px; }
.est-labs h2 { margin: 0 0 6px; font-size: 1.4rem; color: var(--text-primary); }
.est-labs-intro { margin: 0 0 16px; max-width: 640px; color: var(--text-secondary); }
