/* style.css */

/* Make height calculations reliable for flex + scrolling */
html, body {
    height: 100%;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background-color: #333;
    color: white;
    text-align: center;
    box-shadow: 0 2px 4px #aaaaaa;
    z-index: 10;
    position: fixed;
    top: 0;
    width: 100%;
    white-space: nowrap;
    overflow-x: auto;
}

h1 {
    margin: 20px 0;
}

main {
    padding: 20px 15px;
    margin: 80px auto 0;
    background-color: white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    max-height: calc(100vh - 80px);
    width: 90%;
}

main > h2 {
    margin-top: 0;
}

#login-view {
    margin: 0;
    height: 100vh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f4f4f4;
}

.login-box {
    width: 100%;
    max-width: 520px;
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    box-sizing: border-box;
    text-align: center;
}

.login-box h2 {
    margin: 0 0 30px 0;
    color: #333;
    text-align: center !important;
}

.login-box form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.login-box label {
    width: 100%;
    text-align: center;
}

#matriculation-number,
#matriculation-number-confirm {
    width: 100%;
    max-width: 420px;
    text-align: center;
}

#login-button {
    width: 100%;
    max-width: 420px;
    background-color: #333;
}

#login-button:hover {
    background-color: #555;
}

form {
    display: flex;
    flex-direction: column;
}

label {
    margin-bottom: 0.5em;
    font-weight: bold;
}

input {
    padding: 0.5em;
    margin-bottom: 1em;
    border: 1px solid #ccc;
    border-radius: 4px;
    min-width: 50px;
}

button {
    padding: .5em .75em;
    background-color: #333;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background-color: #555;
}

/* Common utility / state classes (keep) */
.error {
    color: red;
    font-size: 1.05em;
    width: 75%;
    margin-left: 12.5%;
    margin-right: 12.5%;
    font-weight: bold;
    text-align: center;
    font-style: italic;
}

.bold {
    font-weight: bold;
}

.italic {
    font-style: italic;
}

.invalid {
    border: 2px solid red;
}

.warning {
    font-weight: bold;
    color: darkred;
    text-align: center;
    font-size: 1.05em;
}

.center {
    text-align: center;
}

*[hidden] {
    display: none !important;
}

/* Responsive header tweaks */
@media (max-width: 1024px) {
    header {
        font-size: 13px;
        padding: 7px 0;
    }
}

@media (max-width: 768px) {
    header {
        font-size: 10px;
        padding: 10px 0;
    }
}

@media (max-width: 460px) {
    header {
        font-size: 8px;
        padding: 10px 0;
    }
}

/* admin layout */

/* Overall "wide admin" layout: fixed header, left nav, right main */
body.wide {
    /* keep Open Sans if you still want it; otherwise remove to avoid CSP/font loading */
    font-family: "Open Sans", sans-serif;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100vh;
    font-size: 16px;
}

body.wide .content {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0; /* critical for proper shrinking/scrolling */
}

/* Left navigation */
body.wide nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 260px;
    min-width: 220px;

    margin: 80px 0 0;
    padding: 15px;

    height: calc(100vh - 80px);
    box-sizing: border-box;

    border-right: 1px solid #ccc;
    background-color: #f9f9f9;
    overflow: hidden;

    min-height: 0;
}

/* Headings in left nav */
body.wide nav h2,
body.wide nav h3 {
    margin: 0;
    font-size: 18px;
    text-align: center;
}

/* A scrollable task list area */
body.wide nav .nav-list {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

body.wide nav .tasks-accordion {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

body.wide nav .list {
    flex: 1;
    overflow: hidden;
    font-family: monospace;
    background-color: white;
    border: 1px solid #ccc;
    box-sizing: border-box;
    text-align: center;
    min-height: 0;
}

body.wide nav .selection {
    margin: 0;
    height: 100%;
    min-height: 100px;
    padding: 0;
    list-style-type: none;
    overflow: auto;
}

body.wide nav .selection li {
    padding: 7px 0;
    cursor: pointer;
    user-select: none;
}

body.wide nav .selection li.active {
    font-weight: bold;
    color: white;
    background-color: blue;
    cursor: default;
}

body.wide nav .selection li.finished {
    background-color: lightgreen;
}

/* ---- Tasks accordion: make task toggles look like headings, not buttons ---- */

body.wide nav .task-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

body.wide nav .task-heading {
    margin: 0;
    font-size: 18px;
    text-align: left; /* change to center if you want */
}

/* Override global button styling for task toggles */
body.wide nav .task-toggle.task-toggle--heading {
    padding: 0;
    background: transparent;
    color: inherit;
    border: 0;
    border-radius: 0;

    width: 100%;
    text-align: left;
    font: inherit;
    font-weight: 700;
    cursor: pointer;

    display: flex;
    align-items: center;
    gap: 8px;

    line-height: 1.2;
}

body.wide nav .task-toggle.task-toggle--heading:hover,
body.wide nav .task-toggle.task-toggle--heading:focus-visible {
    text-decoration: underline;
    outline: none;
}

/* Triangle/chevron placeholder */
body.wide nav .task-toggle-icon {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 6px solid currentColor;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    transform: rotate(0deg);
}

body.wide nav .task-toggle[aria-expanded="true"] .task-toggle-icon {
    transform: rotate(90deg);
}

/* Ensure logout stays at the bottom */
body.wide nav #logout-button {
    margin-top: auto;
}

/* Nav header with countdown */
body.wide nav .nav-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

body.wide nav .nav-title {
    margin: 0;
    font-size: 18px;
    text-align: center;
}

body.wide nav .countdown {
    width: 100%;
    text-align: center;
    padding: .5em .75em;
    background-color: #333;
    color: white;
    border-radius: 6px;
    font-family: monospace;
    font-weight: 700;
    letter-spacing: 0.5px;
    user-select: none;
}

body.wide nav .nav-header {
    display: flex;
    flex-direction: row;      /* force horizontal layout */
    align-items: center;
    justify-content: center;  /* center the whole line */
    gap: 10px;
    white-space: nowrap;      /* prevent wrapping */
}

body.wide nav .time-text {
    font-size: 0.95rem;
    color: #444;
    white-space: nowrap;
}

/* Right main content */
body.wide main {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;

    flex: 1;
    overflow-y: auto;   /* allow whole right side to scroll */

    margin: 80px 0 0;
    height: calc(100vh - 80px);

    padding: 20px 25px;
    box-sizing: border-box;

    background-color: white;

    min-height: 0;
}

/* Main headings */
body.wide main h2 {
    margin: 0 0 15px;
    font-size: 22px;
    text-align: left;
}

.instructions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0;
}

.instructions-header h2 {
    margin: 0;
    font-size: 22px;
    text-align: left;
}

.instructions-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.score-text {
    font-size: 0.95rem;
    color: #444;
    white-space: nowrap;
}

.score-badge {
    min-width: 1.5em;
    text-align: center;
    padding: .5em .75em;
    background-color: #333;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 1em;
    line-height: 1;
    user-select: none;
    cursor: default;
    white-space: nowrap;
}

.instructions {
    flex: 0 0 auto;

    height: 15vh;                 /* smaller initial height */
    min-height: 200px;            /* smaller minimum */
    max-height: calc(80vh - 260px);

    overflow: auto;
    resize: vertical;             /* user can resize vertically */

    border: 1px solid #ccc;
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 4px;
    box-sizing: border-box;
}

.instructions p:first-child {
    margin-top: 0;
}

/* Code area shrinks/grows based on remaining space */
.code-area {
    flex: 1 1 auto;
    min-height: 0;

    margin-top: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Editor container (CodeMirror will render into this) */
#code-editor {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;

    border: 1px solid #ccc;
    background-color: #fcfcfc;
    border-radius: 4px;
    box-sizing: border-box;

    padding: 0;
}

/* Ensure CodeMirror fills the container */
#code-editor .CodeMirror {
    height: 100%;
}

.run-row {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 0 0 auto;
    background: white;
    padding: 10px 0;
}

h3 {
    margin: 5px 0 0;
    padding: 0;
}

.output {
    flex: 1;
    min-height: 3.25em;
    max-height: 40vh;        /* prevents it from growing infinitely */

    resize: vertical;        /* user can drag vertically */
    overflow-y: auto;        /* force vertical scrolling */
    overflow-x: auto;        /* allow horizontal scroll for long lines */

    border: 1px solid #ccc;
    background-color: #f9f9f9;
    padding: 10px;
    border-radius: 4px;
    box-sizing: border-box;

    font-family: monospace;
    white-space: pre;        /* better for code-style output */
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    margin-bottom: 0;
}

.code-header h2 {
    margin: 0;
}

.code-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Regular text, not heading-style */
.run-status {
    font-size: 0.95rem;
    color: #444;
    white-space: nowrap;
}

.code-header button {
    margin: 0;
    line-height: 1;
    font-size: 1em;
}

.code-area .output {
    flex: 0 0 auto;
    width: 100%;
}

/* Small screens: stack nav above main */
@media (max-width: 900px) {
    body.wide .content {
        flex-direction: column;
    }

    body.wide nav {
        width: 100%;
        min-width: 0;
        height: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid #ccc;
    }

    body.wide main {
        height: auto;
        min-height: calc(60vh - 80px);
    }

    .instructions {
        height: auto;
        max-height: none;
        resize: vertical;
    }

    .run-row {
        flex-direction: column;
        align-items: stretch;
    }

    .run-row button {
        width: 100%;
    }
}

.code-header {
    position: relative;
}

.code-header-right {
    position: relative;
    z-index: 2;
}

.code-header-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1;
}

.code-header-center button {
    margin: 0;
    line-height: 1;
    font-size: 1em;
}

#reset-button, #submit-early-button {
    padding: 0.35em 0.55em;
    font-size: 0.9em;
}

.instructions ul:has(> li:only-child) {
    list-style: none;
    margin: 0 0 10px 22px;
    padding: 0;
}

.instructions ul:has(> li:only-child) > li {
    margin: 4px 0;
}

.inactive-task-number {
  display: block;
  margin-top: 16px;
  font-size: 96px;
  font-weight: 700;
  text-align: center;
  line-height: 1;
}