/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --accent:    #3B82F6;
    --accent-dk: #1D4ED8;
    --accent-bg: #EFF6FF;
    --success:   #16a34a;
    --danger:    #dc2626;
    --border:    #e2e8f0;
    --text:      #1e293b;
    --muted:     #64748b;
    --bg:        #f8fafc;
    --white:     #ffffff;
    --radius:    12px;
    --shadow:    0 2px 12px rgba(0,0,0,.06);
}

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

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 80px 1.25rem 4rem; }
.page-wrap-narrow { max-width: 800px; margin: 0 auto; padding: 80px 1.25rem 4rem; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
}
.card-header {
    padding: 1rem 1.25rem .75rem;
    border-bottom: 1px solid var(--border);
    font-size: 1rem; font-weight: 700; color: var(--text);
    display: flex; align-items: center; gap: .5rem;
}
.card-body { padding: 1.25rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    border: none; border-radius: 8px; cursor: pointer;
    font-size: .875rem; font-weight: 600; padding: .55rem 1.1rem;
    text-decoration: none; transition: all .15s;
}
.btn-primary   { background: var(--accent); color: var(--white); }
.btn-primary:hover { background: var(--accent-dk); }
.btn-success   { background: var(--success); color: var(--white); }
.btn-success:hover { opacity: .88; }
.btn-danger    { background: var(--danger); color: var(--white); }
.btn-danger:hover { opacity: .88; }
.btn-outline   { background: transparent; border: 1.5px solid var(--accent); color: var(--accent); }
.btn-outline:hover { background: var(--accent-bg); }
.btn-secondary { background: #f1f5f9; color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-sm { font-size: .8rem; padding: .35rem .7rem; }
.btn:disabled  { opacity: .5; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .35rem; color: var(--text); }
.form-control {
    width: 100%; padding: .55rem .75rem;
    border: 1.5px solid var(--border); border-radius: 8px;
    font: inherit; font-size: .9rem; color: var(--text);
    transition: border-color .2s, box-shadow .2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
textarea.form-control { min-height: 100px; resize: vertical; }
select.form-control { appearance: auto; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th {
    text-align: left; padding: .6rem .75rem;
    background: #f8fafc; color: var(--muted);
    font-weight: 700; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .03em;
    border-bottom: 2px solid var(--border);
}
.data-table td {
    padding: .6rem .75rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.data-table tr:hover { background: #fafbfd; }

/* ── Status dots ─────────────────────────────────────────────────────────── */
.status-dot {
    display: inline-block; width: 10px; height: 10px;
    border-radius: 50%; border: 1.5px solid transparent;
}
.status-dot.not_started { background: #e2e8f0; border-color: #cbd5e1; }
.status-dot.opened { background: #fbbf24; border-color: #f59e0b; }
.status-dot.editing { background: #3b82f6; border-color: #2563eb; }
.status-dot.completed { background: #22c55e; border-color: #16a34a; }

/* ── Save indicator ──────────────────────────────────────────────────────── */
.save-indicator { font-size: .8rem; color: var(--muted); margin-top: .5rem; min-height: 1.2em; }
.save-indicator.saved { color: var(--success); }
.save-indicator.error { color: var(--danger); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
    display: inline-block; width: 1.1em; height: 1.1em;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Phase card (student view) ───────────────────────────────────────────── */
.phase-card {
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--white);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: box-shadow .3s;
}
.phase-card.active { box-shadow: 0 4px 24px rgba(59,130,246,.12); }
.phase-card.locked { opacity: .5; pointer-events: none; }

.phase-header {
    padding: 1rem 1.25rem;
    display: flex; align-items: center; gap: .75rem;
    cursor: pointer; user-select: none;
    transition: background .2s;
}
.phase-header:hover { background: #fafbfd; }
.phase-num {
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: .85rem; color: #fff; flex-shrink: 0;
}
.phase-title { font-weight: 700; font-size: 1rem; flex: 1; }
.phase-status { font-size: .75rem; font-weight: 600; padding: .2rem .6rem; border-radius: 99px; }
.phase-arrow { font-size: .7rem; color: var(--muted); transition: transform .3s; }
.phase-arrow.open { transform: rotate(180deg); }

.phase-body {
    overflow: hidden; transition: max-height .4s ease;
    border-top: 1px solid var(--border);
}
.phase-body.collapsed { max-height: 0 !important; border-top: none; }
.phase-body-inner { padding: 1.25rem; }

/* ── Material section ────────────────────────────────────────────────────── */
.material-section {
    margin-bottom: 1.5rem;
    border-radius: 10px;
    overflow: hidden;
    background: #f8fafc;
    border: 1px solid #f1f5f9;
}

/* ── Activity card ───────────────────────────────────────────────────────── */
.activity-card {
    background: linear-gradient(135deg, #fafbfd 0%, #fff 60%);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: border-color .3s, box-shadow .3s;
}
.activity-card:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,.08);
}
.activity-prompt {
    font-weight: 700; font-size: .9rem; color: var(--text);
    margin-bottom: .75rem; line-height: 1.5;
}
.activity-actions {
    display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
    margin-top: .75rem;
}

/* ── Version timeline ────────────────────────────────────────────────────── */
.version-timeline { margin-top: 1rem; }
.version-entry {
    margin-bottom: .75rem;
    border-radius: 8px;
    overflow: hidden;
}
.version-header {
    padding: .4rem .75rem;
    font-size: .75rem; font-weight: 700;
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; user-select: none;
}
.version-header.student-version {
    background: #f1f5f9; color: #475569;
}
.version-header.ai-feedback {
    background: #eff6ff; color: #1d4ed8;
    border-left: 3px solid #3b82f6;
}
.version-content {
    padding: .75rem;
    font-size: .88rem;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}
.version-content.collapsed { display: none; }

/* ── AI Feedback card ────────────────────────────────────────────────────── */
.ai-feedback-card {
    background: #eff6ff;
    border-left: 3px solid #3b82f6;
    border-radius: 0 8px 8px 0;
    padding: .75rem 1rem;
    margin-bottom: .75rem;
    font-size: .88rem;
    line-height: 1.6;
}
.ai-feedback-card p { margin-bottom: .5rem; }
.ai-feedback-card p:last-child { margin-bottom: 0; }

/* ── Previous phase read-only ────────────────────────────────────────────── */
.readonly-text {
    background: #f8fafc;
    border: 1px solid #f1f5f9;
    border-radius: 8px;
    padding: .75rem 1rem;
    font-size: .88rem;
    line-height: 1.6;
    color: #475569;
    max-height: 300px;
    overflow-y: auto;
}

/* ── Admin ────────────────────────────────────────────────────────────────── */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}
.stat-card .stat-num { font-size: 2rem; font-weight: 800; color: var(--accent); }
.stat-card .stat-label { font-size: .82rem; color: var(--muted); margin-top: .25rem; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); backdrop-filter: blur(4px);
    z-index: 300; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-box {
    background: #fff; border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
    padding: 2rem; max-width: 500px; width: 90%;
    max-height: 80vh; overflow-y: auto;
}
.modal-box h3 { margin-bottom: 1rem; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .page-wrap { padding-top: 70px; }
    .card-body { padding: .9rem; }
    .admin-grid { grid-template-columns: 1fr; }
}
