/* ── Design tokens ───────────────────────────────────────────────────────────*/
/* §3.2: per-project accent colour will override --clr-primary at runtime     */
:root {
    --clr-primary:      #007bff;
    --clr-primary-dark: #0056b3;
    --clr-success:      #28a745;
    --clr-success-dark: #218838;
    --clr-danger:       #dc3545;
    --clr-danger-dark:  #c82333;
    --clr-muted:        #6c757d;
    --clr-dark:         #495057;
    --clr-border:       #dee2e6;
    --clr-surface:      #f8f9fa;
    --clr-text:         #2c3e50;
}

/* ── Base layout ─────────────────────────────────────────────────────────────*/
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    background-color: var(--clr-surface); /* overridden inline by applyProjectBackground() */
    line-height: 1.4;
    transition: background-color 0.4s ease;
}

/* §4 — max-width lives on the wrapper so the fixed sidebar doesn't fight it */
.main-wrapper {
    max-width: 1000px;
    margin: 0 auto;
    padding: 15px;
}

.container {
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

h1 {
    color: var(--clr-text);
    text-align: center;
    margin-bottom: 25px;
    font-size: 28px;
    font-weight: 600;
}

/* ── §4.1  Sidebar toggle — fixed top-left of viewport ──────────────────────*/
#sidebarToggle {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 500;
    background: white;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    cursor: pointer;
    box-shadow: 0 1px 6px rgba(0,0,0,0.1);
}

#sidebarToggle:hover { background: #f5f5f5; }

/* ── Sidebar overlay ─────────────────────────────────────────────────────────*/
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.22);
    z-index: 600;
}

#sidebarOverlay.open { display: block; }

/* ── §4  Sidebar panel ───────────────────────────────────────────────────────*/
#sidebar {
    position: fixed;
    top: 0;
    left: -290px;
    width: 278px;
    height: 100vh;
    background: white;
    border-right: 1px solid #e9ecef;
    box-shadow: 3px 0 18px rgba(0,0,0,0.13);
    z-index: 700;
    display: flex;
    flex-direction: column;
    transition: left 0.22s ease;
    overflow: hidden;
}

#sidebar.open { left: 0; }

.sb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px;
    border-bottom: 1px solid #e9ecef;
}

.sb-heading {
    font-size: 15px;
    font-weight: 700;
    color: var(--clr-text);
}

.sb-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--clr-muted);
    padding: 0;
    line-height: 1;
}

.sb-close:hover { color: #333; }

/* ── §4.2  Project rows ──────────────────────────────────────────────────────*/
#projectList {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.proj-row {
    border-left: 3px solid transparent;
    padding: 8px 10px 6px;
    transition: background 0.12s;
}

.proj-row:hover { background: var(--clr-surface); }

.proj-row.active {
    background: #edf2ff;
    border-left-color: var(--proj-color, var(--clr-primary));
}

.proj-top {
    display: flex;
    align-items: center;
    gap: 7px;
}

.color-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.12);
    cursor: pointer;
    position: relative;
}

.color-swatch input[type=color] {
    opacity: 0;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    border: none;
    padding: 0;
}

.proj-name {
    flex: 1;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--clr-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.proj-name:hover { color: var(--clr-primary); }

.proj-name-input {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid #80bdff;
    border-radius: 4px;
    padding: 2px 6px;
    outline: none;
    font-family: inherit;
    box-shadow: 0 0 0 2px rgba(0,123,255,0.12);
}

.proj-badge {
    background: #adb5bd;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    flex-shrink: 0;
}

.proj-row.active .proj-badge { background: var(--proj-color, var(--clr-primary)); }

.proj-menu-wrap {
    position: relative;
}

.proj-menu-btn {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--clr-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    font-family: inherit;
}

.proj-menu-btn:hover { color: #333; }

.proj-slug-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 19px;
    margin-top: 3px;
}

.proj-slug {
    font-size: 10.5px;
    color: #b0b8cc;
    font-family: Consolas, monospace;
    user-select: all;
}

.proj-slug-link {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ── Sidebar footer ──────────────────────────────────────────────────────────*/
.sb-footer {
    border-top: 1px solid #e9ecef;
    padding: 9px 11px;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.sb-foot-btn {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid var(--clr-border);
    background: white;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.sb-foot-btn:hover { background: #f0f0f0; }

/* ── Dropdowns ───────────────────────────────────────────────────────────────*/
.dropdown {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: white;
    border: 1px solid var(--clr-border);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.12);
    min-width: 185px;
    z-index: 800;
    display: none;
}

.proj-dropdown {
    bottom: auto;
    top: calc(100% + 4px);
    right: 0;
}

.dropdown.open { display: block; }

.dd-item {
    padding: 9px 14px;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    white-space: nowrap;
    text-align: left;
    display: block;
    text-decoration: none;   /* reset <a> default underline */
}

.dd-item:first-child { border-radius: 8px 8px 0 0; }
.dd-item:last-child  { border-radius: 0 0 8px 8px; }
.dd-item:hover       { background: var(--clr-surface); }
.dd-item.dd-danger:hover { background: #fff5f5; color: var(--clr-danger); }

/* ── Student info area ───────────────────────────────────────────────────────*/
.student-info {
    background: var(--clr-surface);
    color: #333;
    padding: 18px;
    border-radius: 10px;
    margin-bottom: 25px;
    border: 2px solid var(--clr-border);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.student-info label {
    color: #333;
    font-weight: 500;
}

.student-name-input {
    width: 280px;
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s;
}

.student-name-input:focus {
    outline: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ── Rubric / data management buttons ────────────────────────────────────────*/
.clear-storage-button {
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s;
    margin-left: 10px;
    background: var(--clr-danger);
}

.clear-storage-button:hover { background: var(--clr-danger-dark); }

/* ── Criteria ────────────────────────────────────────────────────────────────*/
.criterion {
    margin-bottom: 18px;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: transform 0.2s, box-shadow 0.2s;
}

.criterion:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.criterion-header {
    background: var(--clr-dark);
    color: white;
    padding: 12px 18px;
    font-weight: 600;
    font-size: 15px;
    transition: background-color 0.3s ease;
}

/* "**Head**: description" format — head inherits bold, description is lighter */
.criterion-head { font-weight: 600; }

.criterion-desc {
    font-weight: 400;
    opacity: 0.82;
    margin-left: 6px;
}

.criterion-header.missing {
    background: var(--clr-danger);
    animation: pulse-red 2s ease-in-out;
}

@keyframes pulse-red {
    0%, 100% { background: var(--clr-danger); }
    50%       { background: var(--clr-danger-dark); }
}

.criterion-options {
    padding: 12px;
    background: #fafbfc;
}

.option {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    background: white;
    cursor: pointer;
    min-height: 44px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.option:hover {
    background-color: #f8f9ff;
    border-color: #e3f2fd;
    transform: translateX(3px);
}

.option:active {
    transform: translateX(1px) scale(0.98);
}

.option.selected {
    background: var(--clr-primary);
    color: white;
    border-color: var(--clr-primary);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.option input[type="radio"] {
    margin-right: 15px;
    transform: scale(1.4);
    accent-color: var(--clr-primary);
}

.option.selected input[type="radio"] {
    accent-color: white;
}

.option label {
    cursor: pointer;
    flex: 1;
    line-height: 1.4;
    font-size: 14px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.option.selected label {
    color: white;
    font-weight: 500;
}

.score-badge {
    background: var(--clr-success);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-right: 8px;
    min-width: 32px;
    text-align: center;
}

.option.selected .score-badge {
    background: rgba(255,255,255,0.9);
    color: var(--clr-primary);
}

/* ── Score display ───────────────────────────────────────────────────────────*/
.score-display {
    background: var(--clr-success);
    color: white;
    padding: 16px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    margin: 20px 0;
    border-radius: 10px;
    min-height: 24px;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.score-display.incomplete {
    background: #ffc107;
    color: #212529;
}

/* ── Validation warnings ─────────────────────────────────────────────────────*/
.validation-warning {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
    font-weight: 500;
}

.warning {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
    padding: 15px;
    border-radius: 8px;
    margin: 20px 0;
}

/* ── Navigation ──────────────────────────────────────────────────────────────*/
.navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 25px 0;
    padding: 18px;
    background: var(--clr-surface);
    border-radius: 10px;
    border: 1px solid var(--clr-border);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.nav-button {
    background: var(--clr-primary);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s;
    min-height: 44px;
    min-width: 120px;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.nav-button:hover {
    background: var(--clr-primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
}

.nav-button:active {
    transform: translateY(0);
}

.nav-button:disabled {
    background: var(--clr-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.student-counter {
    font-size: 18px;
    font-weight: 600;
    color: var(--clr-dark);
    background: white;
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ── Notes field ─────────────────────────────────────────────────────────────*/
.notes-section {
    margin: 0 0 16px;
}

.notes-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--clr-dark);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.notes-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px 14px;
    border: 1px solid var(--clr-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--clr-dark);
    background: white;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.5;
}

.notes-textarea::placeholder {
    color: #adb5bd;
}

/* ── Layout toggle ───────────────────────────────────────────────────────────*/
.layout-toggle-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.layout-toggle-btn {
    background: #f1f3f5;
    color: var(--clr-dark);
    border: 1px solid #ced4da;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.layout-toggle-btn:hover {
    background: #e2e6ea;
    border-color: #adb5bd;
}

.layout-toggle-btn.active {
    background: var(--clr-dark);
    color: white;
    border-color: var(--clr-dark);
}

/* Column layout overrides */
.column-layout .criterion-options {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: stretch;
}

.column-layout .option {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    min-height: 90px;
    margin-bottom: 0;
    padding: 12px 8px;
}

.column-layout .option:hover {
    transform: translateY(-3px);
}

.column-layout .option input[type="radio"] {
    margin-right: 0;
    margin-bottom: 8px;
}

.column-layout .score-badge {
    margin-right: 0;
    margin-bottom: 8px;
}

.column-layout .option label {
    text-align: center;
    font-size: 13px;
}

/* ── Download section ────────────────────────────────────────────────────────*/
.download-section {
    border-top: 2px solid #e9ecef;
    padding-top: 25px;
    margin-top: 25px;
}

.download-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.download-button {
    background: var(--clr-success);
    color: white;
    border: none;
    padding: 12px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    min-height: 44px;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.download-button:hover {
    background: var(--clr-success-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.4);
}

.download-button:active {
    transform: translateY(0);
}

/* ── PDF header meta fields ──────────────────────────────────────────────────*/
.pdf-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.pdf-meta-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--clr-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.pdf-meta-input {
    padding: 7px 11px;
    border: 1px solid var(--clr-border);
    border-radius: 6px;
    font-size: 14px;
    width: 190px;
    color: var(--clr-dark);
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.pdf-meta-input::placeholder {
    color: #adb5bd;
}

/* ── Focus ring (shared) ─────────────────────────────────────────────────────*/
.notes-textarea:focus,
.pdf-meta-input:focus {
    outline: none;
    border-color: #80bdff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

/* ── §5.3  Read-only banner ──────────────────────────────────────────────────*/
#readonlyBanner {
    display: none;
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

#readonlyBanner.visible { display: flex; }

.ro-text {
    font-size: 14px;
    font-weight: 500;
}

.takeover-btn {
    background: #ffc107;
    color: #5d4a00;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    flex-shrink: 0;
}

.takeover-btn:hover { background: #e0a800; }

/* ── §7  Modals ──────────────────────────────────────────────────────────────*/
.modal-bg {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 900;
    align-items: center;
    justify-content: center;
}

.modal-bg.open { display: flex; }

.modal {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    width: 480px;
    max-width: 95vw;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-head {
    padding: 18px 22px 14px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--clr-text);
}

.modal-x {
    background: none;
    border: none;
    font-size: 21px;
    cursor: pointer;
    color: var(--clr-muted);
    line-height: 1;
    font-family: inherit;
}

.modal-x:hover { color: #333; }

.modal-body {
    padding: 14px 22px;
    flex: 1;
    overflow-y: auto;
}

.modal-foot {
    padding: 13px 22px;
    border-top: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Edit-project form fields */
.modal-field {
    margin-bottom: 16px;
}

.modal-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--clr-dark);
    margin-bottom: 5px;
}

.modal-hint {
    font-weight: 400;
    color: var(--clr-muted);
    font-size: 11px;
}

.modal-input {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--clr-border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    color: var(--clr-dark);
    box-sizing: border-box;
}

.modal-input:focus {
    outline: none;
    border-color: #80bdff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

/* Select all / Deselect all toggle */
.sel-all-btn {
    background: none;
    border: none;
    color: var(--clr-primary);
    font-size: 13px;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
}

.sel-all-btn:hover { text-decoration: underline; }

/* Action buttons */
.modal-act-btn {
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: white;
    font-family: inherit;
}

.modal-act-primary             { background: var(--clr-primary); }
.modal-act-primary:hover       { background: var(--clr-primary-dark); }

/* Project checklist rows (export/import) */
.check-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

.check-row:last-child { border-bottom: none; }

.chk-swatch {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chk-info   { flex: 1; }
.chk-name   { font-size: 14px; font-weight: 500; color: var(--clr-text); }
.chk-meta   { font-size: 11px; color: var(--clr-muted); margin-top: 1px; }

.import-conflict-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.import-radio-label {
    font-size: 12px;
    color: #495057;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.conflict-tag {
    font-size: 11px;
    color: #856404;
    background: #fff3cd;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #ffc107;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Toasts ──────────────────────────────────────────────────────────────────*/
#toastArea {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--clr-text);
    color: white;
    padding: 11px 17px;
    border-radius: 8px;
    font-size: 13px;
    max-width: 310px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    pointer-events: all;
    cursor: pointer;
    animation: toastIn 0.22s ease;
}

.toast.warn { background: #7a5c00; }

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

/* ── Mobile responsiveness ───────────────────────────────────────────────────*/
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 15px;
    }

    h1 {
        font-size: 24px;
    }

    .student-name-input {
        width: 100%;
        max-width: 280px;
    }

    .criterion-header {
        padding: 10px 15px;
        font-size: 14px;
    }

    .criterion-options {
        padding: 8px;
    }

    .option {
        padding: 10px 8px;
        margin-bottom: 6px;
    }

    .navigation {
        flex-direction: column;
        gap: 15px;
    }

    .nav-button {
        width: 100%;
        max-width: 200px;
    }

    .download-buttons {
        flex-direction: column;
        align-items: center;
    }

    .download-button {
        width: 100%;
        max-width: 200px;
    }
}
