/* CSS Variables for Premium Look */
:root {
    --bg-color: #f7f9fc;
    --text-color: #2b3044;
    --text-muted: #5a6482;
    --card-bg: #ffffff;
    --primary: #4F46E5;
    /* Indigo */
    --primary-hover: #4338ca;
    --success: #10B981;
    --success-hover: #059669;
    --danger: #EF4444;
    --warning: #F59E0B;
    --moodle-orange: #f98012;
    /* Official Moodle Orange */
    --moodle-orange-hover: #e06d0a;
    --border-color: #e5e7eb;
    --input-bg: #f3f4f6;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
    --transition: all 0.2s ease-in-out;
}

/* Reset & Scaffolding */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Typography & Headers */
h1 {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.025em;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-color);
}

p {
    color: var(--text-muted);
}

.app-header {
    text-align: center;
    margin-bottom: 3rem;
}

/* Utilities */
.hidden {
    display: none !important;
}

.flex-row {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.gap-l {
    padding-bottom: 4rem;
}

.full-width {
    width: 100%;
}

.sticky-card {
    position: sticky;
    top: 2rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.setup-controls {
    max-width: 600px;
    margin: 0 auto 2rem auto;
}

/* Forms & Inputs */
.input-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
}

.input-group.inline {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0;
}

label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-color);
}

input[type="number"],
input[type="text"],
textarea,
input[type="range"] {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--input-bg);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
    color: var(--text-color);
    width: 100%;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
    background-color: var(--card-bg);
}

textarea {
    resize: vertical;
    font-family: monospace;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
    font-family: inherit;
}

.btn.primary {
    background-color: var(--primary);
    color: white;
}

.btn.primary:hover {
    background-color: var(--primary-hover);
}

.btn.success {
    background-color: var(--success);
    color: white;
}

.btn.success:hover {
    background-color: var(--success-hover);
}

.btn.secondary {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn.secondary:hover {
    background-color: var(--border-color);
}

.btn.outline {
    background-color: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn.outline:hover {
    background-color: var(--primary);
    color: white;
}

.btn-danger-outline {
    background-color: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger-outline:hover {
    background-color: var(--danger);
    color: white;
}

.btn-secondary-outline {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--text-muted);
}

.btn-secondary-outline:hover {
    background-color: var(--text-muted);
    color: white;
}

.btn-warning-outline {
    background-color: transparent;
    color: #d97706;
    border: 1px solid #d97706;
}

.btn-warning-outline:hover {
    background-color: #d97706;
    color: white;
}

.top-corner-actions {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    z-index: 1000;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.top-corner-actions .btn:not(:hover) {
    background-color: var(--bg-color);
}

.btn.small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn.large {
    padding: 1rem 2rem;
    font-size: 1.125rem;
    font-weight: 600;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-full);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--danger);
    background-color: #fee2e2;
}

/* Setup Phase specific */
.exercise-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.item-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: center;
    background: #fafafa;
    padding: 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid #f0f0f0;
}

.code-col {
    flex: 1;
}

.desc-col {
    flex: 3;
}

.weight-col {
    flex: 1;
    position: relative;
}

.item-col input {
    margin-bottom: 0;
}

.pct-sign {
    position: absolute;
    right: 1.5rem;
    top: 10px;
    color: var(--text-muted);
    pointer-events: none;
}

.exercise-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.weight-status {
    font-size: 0.875rem;
    margin-left: 0.5rem;
    font-weight: 500;
}

.weight-status.warning {
    color: var(--danger);
}

.weight-status.ok {
    color: var(--success);
}

/* Floating Action Button Setup */
.floating-action {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    padding: 1rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    text-align: center;
    border: 1px solid var(--border-color);
    animation: slideUp 0.3s ease-out forwards;
}

@keyframes slideUp {
    from {
        bottom: -5rem;
        opacity: 0;
    }

    to {
        bottom: 2rem;
        opacity: 1;
    }
}

.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.error-msg {
    color: var(--danger);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    max-width: 300px;
}

.success-msg {
    color: var(--success);
    font-size: 0.875rem;
    margin-top: 0.5rem;
    text-align: center;
}

/* Phase 3: Grading & Multi-Student Layout */
.grading-layout-app {
    display: grid;
    grid-template-columns: 280px 2fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

/* Sidebar List Styling */
.styled-list {
    list-style: none;
    margin-top: 1rem;
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: #fafafa;
}

.styled-list li {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.styled-list li:last-child {
    border-bottom: none;
}

.styled-list li:hover {
    background: #f3f4f6;
}

.styled-list li.active {
    background: #e0e7ff;
    border-left: 4px solid var(--primary);
    font-weight: 500;
}

.student-name-list {
    font-size: 0.9rem;
}

.student-status {
    font-size: 1rem;
}

.header-with-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

/* Grading Item Rows */
.item-grade-row {
    padding: 0.35rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.item-grade-row:last-child {
    border-bottom: none;
}

.item-info {
    flex: 1;
    margin-bottom: 0;
}

.item-meta {
    display: inline-block;
    background: #e0e7ff;
    color: var(--primary-hover);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.item-statement {
    font-weight: 500;
    font-size: 1rem;
}

.achievement-slider {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 400px;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 5px;
}

.achv-val-display {
    min-width: 4.5rem;
}

.achv-num-input {
    width: 4.5rem;
    padding: 0.25rem;
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    text-align: center;
    background: var(--input-bg);
}

.achv-num-input:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.achv-num-input::-webkit-outer-spin-button,
.achv-num-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Range input styling for better UX */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    margin-top: -8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: #cbd5e1;
    border-radius: 3px;
}

input[type=range]:focus::-webkit-slider-runnable-track {
    background: #94a3b8;
}

/* Results panel */
.score-display {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 1.5rem;
    background: #f8fafc;
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid #e2e8f0;
}

.score-label {
    font-size: 1.25rem;
    font-weight: 600;
}

.score-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--success);
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5rem 0;
}

.excel-btn {
    background-color: transparent;
    color: var(--moodle-orange);
    border: 1px solid var(--moodle-orange);
    font-weight: 500;
}

.excel-btn:hover {
    background-color: var(--moodle-orange);
    color: white;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .grading-layout-app {
        grid-template-columns: 250px 1fr;
    }

    .results-column {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    .grading-layout-app {
        grid-template-columns: 1fr;
    }

    .results-column {
        grid-column: 1;
    }

    .item-grade-row {
        flex-direction: column;
        align-items: stretch;
        margin-bottom: 1rem;
    }

    .achievement-slider {
        max-width: 100%;
        padding-top: 1rem;
    }

    .pct-sign {
        top: 38px;
    }

    .weight-col {
        width: 100%;
    }
}

.form-btn {
    min-width: 120px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    animation: fadeInScale 0.2s ease-out forwards;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}