* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Dark mode (default) - GitHub-inspired */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-container: #161b22;
    --bg-input: #161b22;
    --bg-output: #161b22;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-label: #8b949e;
    --border-color: #30363d;
    --border-focus: #8f11eb;
    --accent-color: #8f11eb;
    --accent-hover: #a83eef;
    --success-color: #3fb950;
    --danger-color: #f85149;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --input-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.light-mode {
    /* Light mode */
    --bg-primary: #f6f8fa;
    --bg-secondary: #ffffff;
    --bg-container: #ffffff;
    --bg-input: #ffffff;
    --bg-output: #f6f8fa;
    --text-primary: #24292f;
    --text-secondary: #57606a;
    --text-label: #57606a;
    --border-color: #d0d7de;
    --border-focus: #8f11eb;
    --accent-color: #8f11eb;
    --accent-hover: #a83eef;
    --success-color: #1a7f37;
    --danger-color: #cf222e;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    --input-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-container);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.main-content {
    display: flex;
}

.form-section header {
    background: var(--accent-color);
    color: white;
    padding: 30px;
    text-align: center;
    position: relative;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.theme-toggle,
.logout-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    font-size: 20px;
}

.theme-toggle:hover,
.logout-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.theme-toggle:active,
.logout-btn:active {
    transform: scale(0.95);
}

.logout-btn:hover {
    background: rgba(248, 81, 73, 0.3);
    border-color: rgba(248, 81, 73, 0.5);
}

header h1 {
    font-size: 28px;
    margin-bottom: 10px;
    font-weight: 600;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
}

.form-section {
    flex: 1;
    padding: 0;
    background: var(--bg-container);
    transition: background-color 0.3s ease;
    border-right: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.form-section > form {
    flex: 1;
    padding: 30px;
    display: flex;
    flex-direction: column;
}

.form-section h2 {
    color: var(--accent-color);
    margin-bottom: 20px;
    font-size: 22px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 10px;
    transition: color 0.3s ease, border-color 0.3s ease;
}

.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-label);
    font-size: 14px;
    transition: color 0.3s ease;
}

.field-hint {
    display: block;
    margin-top: 5px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* A label with its button for hiding the field from the output */
.label-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.form-group .label-row label {
    margin-bottom: 0;
}

/* The eye only shows while hovering its form item, or when focused from the keyboard */
.eye-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.eye-btn svg {
    width: 14px;
    height: 14px;
}

.eye-btn:hover,
.eye-btn:focus-visible {
    color: var(--text-primary);
    background: rgba(143, 17, 235, 0.12);
}

.eye-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 1px;
}

.form-group:hover .eye-btn {
    opacity: 0.6;
}

/* Fields hidden from the output stay editable but look faded */
.is-output-hidden > :not(.label-row),
.is-output-hidden > .label-row > :not(.eye-btn) {
    opacity: 0.45;
}

.is-output-hidden .eye-btn {
    color: var(--accent-color);
}

.form-group.is-output-hidden:hover .eye-btn,
.form-group:hover .eye-btn:hover,
.form-group .eye-btn:focus-visible {
    opacity: 1;
}

.form-group:hover .eye-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: transparent;
}

/* Touch screens can't hover, so keep the eyes visible there */
@media (hover: none) {
    .eye-btn {
        opacity: 0.6;
    }

    .is-output-hidden .eye-btn {
        opacity: 1;
    }

    .eye-btn:disabled {
        opacity: 0.3;
    }
}

/* Fade the cohort button, not its dropdown menu */
.is-output-hidden > .cohort-controls {
    opacity: 1;
}

.is-output-hidden .cohort-dropdown-btn {
    opacity: 0.45;
}

/* Number input spin buttons - subtle styling */
.form-group input[type="number"]::-webkit-inner-spin-button,
.form-group input[type="number"]::-webkit-outer-spin-button {
    opacity: 0.7;
    cursor: pointer;
}

.form-group input[type="number"]::-webkit-inner-spin-button:hover,
.form-group input[type="number"]::-webkit-outer-spin-button:hover {
    opacity: 1;
}

.form-group input[type="number"]::-webkit-inner-spin-button {
    background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b949e' d='M6 4L2 8h8L6 4zm0 4L2 4h8L6 8z'/%3E%3C/svg%3E") no-repeat center;
    -webkit-appearance: none;
    appearance: none;
    height: 24px;
    width: 20px;
    margin: 0 2px;
    border-radius: 4px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
    box-shadow: var(--input-shadow);
}

.cohort-controls {
    position: relative;
}

.cohort-dropdown-btn {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    box-shadow: var(--input-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.cohort-dropdown-btn:hover {
    border-color: var(--border-focus);
}

.cohort-dropdown-btn:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(143, 17, 235, 0.2), var(--input-shadow);
}

.cohort-caret {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.cohort-dropdown-menu {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow);
    z-index: 20;
    display: none;
    max-height: 220px;
    overflow-y: auto;
    padding: 0.25rem;
}

.cohort-controls.is-open .cohort-dropdown-menu {
    display: block;
}

.cohort-dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.55rem;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary);
}

.cohort-dropdown-item:hover {
    background: rgba(143, 17, 235, 0.12);
}

.cohort-dropdown-item.is-active {
    background: rgba(143, 17, 235, 0.2);
}

.cohort-dropdown-item-delete {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0.1rem 0.25rem;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.12s, color 0.12s;
}

.cohort-dropdown-item:hover .cohort-dropdown-item-delete {
    opacity: 1;
}

.cohort-dropdown-item-delete:hover {
    color: var(--danger-color);
}

.cohort-dropdown-add {
    margin-top: 0.2rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.25rem;
}

.cohort-dropdown-add button {
    width: 100%;
    align-self: auto;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    text-align: left;
    padding: 0.4rem 0.55rem;
}

.cohort-dropdown-add button:hover {
    color: var(--text-primary);
    background: rgba(143, 17, 235, 0.12);
}

/* Student attendance picker */
.students-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
}

.students-action-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.15s;
}

.students-action-btn:hover:not(:disabled) {
    color: var(--text-primary);
}

/* Disabled while students are hidden from the output */
.students-action-btn:disabled {
    cursor: not-allowed;
}

/* Add and Select All only make sense while the student list is open */
.collapsible:not([open]) .students-actions {
    display: none;
}

.student-picker {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    padding: 8px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-input);
    font-size: 14px;
    font-family: inherit;
    box-shadow: var(--input-shadow);
    min-height: 120px;
    max-height: 160px;
    overflow-y: auto;
}

.student-picker-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.student-picker-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.student-picker-delete-btn {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0.1rem 0.25rem;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.12s, color 0.12s;
}

.student-picker-item:hover .student-picker-delete-btn {
    opacity: 1;
}

.student-picker-delete-btn:hover {
    color: var(--danger-color);
}

.student-picker-item:hover {
    background: rgba(143, 17, 235, 0.12);
}

.student-picker-item.is-selected {
    background: rgba(143, 17, 235, 0.25);
}

.student-picker:focus-within {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(143, 17, 235, 0.2), var(--input-shadow);
}

/* Collapsible sections (topics, tasks, students, footer) with a one-line preview when closed */
.collapsible > summary {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.collapsible > summary::-webkit-details-marker {
    display: none;
}

.collapsible:not([open]) > summary {
    margin-bottom: 0;
}

.collapsible > summary:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
    border-radius: 4px;
}

.collapsible-label {
    flex-shrink: 0;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-label);
}

.collapsible-caret {
    display: inline-block;
    flex-shrink: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    transform: rotate(-90deg);
    transition: transform 0.15s;
}

.collapsible[open] .collapsible-caret {
    transform: none;
}

.collapsible-preview {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-secondary);
}

.collapsible[open] .collapsible-preview {
    display: none;
}

/* Scrollbars */
*::-webkit-scrollbar {
    width: 8px;
}

*::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-primary);
}

.form-group input[type="text"]:focus,
.form-group input[type="number"]:focus,
.form-group input[type="date"]:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(143, 17, 235, 0.2), var(--input-shadow);
    background: var(--bg-input);
}

.form-group input[type="text"]:hover,
.form-group input[type="number"]:hover,
.form-group input[type="date"]:hover,
.form-group textarea:hover {
    border-color: var(--border-focus);
}

.form-group textarea {
    resize: vertical;
    overflow: hidden;
    min-height: 24px;
}

.form-group textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.generate-btn {
    flex: 1;
    padding: 14px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.generate-btn:hover {
    transform: translateY(-2px);
    background: var(--accent-hover);
    box-shadow: 0 5px 15px rgba(143, 17, 235, 0.4);
}

.generate-btn:active {
    transform: translateY(0);
}

.clear-btn {
    flex: 1;
    padding: 14px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.clear-btn:hover {
    background: #da3633;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(248, 81, 73, 0.4);
}

.clear-btn:active {
    transform: translateY(0);
}

.output-section {
    flex: 1;
    padding: 30px;
    background: var(--bg-output);
    transition: background-color 0.3s ease, border-color 0.3s ease;
    display: flex;
    flex-direction: column;
}

.output-section h2 {
    color: var(--accent-color);
    margin-bottom: 20px;
    font-size: 22px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 10px;
    transition: color 0.3s ease, border-color 0.3s ease;
}

.output-container {
    position: relative;
}

#outputContent {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 6px;
    border: 2px solid var(--border-color);
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    flex: 1;
    color: var(--text-primary);
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
    min-height: 200px;
}

.output-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.copy-btn,
.copy-markdown-btn {
    flex: 1;
    padding: 10px 20px;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease;
}

.copy-btn {
    background: var(--success-color);
}

.copy-btn:hover {
    background: #2ea043;
}

.copy-markdown-btn {
    background: var(--accent-color);
}

.copy-markdown-btn:hover {
    background: var(--accent-hover);
}

.copy-btn:active,
.copy-markdown-btn:active {
    transform: scale(0.98);
}

.copy-btn.copied {
    background: #2ea043;
}

.copy-markdown-btn.copied {
    background: var(--accent-hover);
}

@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .form-section {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        max-height: none;
    }

    .output-section {
        max-height: none;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        margin: 0;
        border-radius: 8px;
    }

    .form-section header {
        padding: 20px;
    }

    .header-content {
        flex-direction: column;
        align-items: center;
    }

    .header-buttons {
        margin-top: 10px;
    }

    .form-section header h1 {
        font-size: 22px;
    }

    .form-section,
    .output-section {
        padding: 20px;
    }
}
