/* ========================================
   FORMS & MODALS - Input elements and modal dialogs
   ======================================== */

/* ========== FORM GROUPS ========== */
.form-group {
    margin-bottom: 18px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Sits between an uppercase .form-label and its input to say what the field
   is for — used where two adjacent fields could be confused. */
.form-hint {
    margin-top: -4px;
    margin-bottom: 8px;
    font-family: var(--font-sans);
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-tertiary);
}

/* ========== FORM INPUTS ========== */
.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary) 10%, transparent);
}

/* ========== CUSTOM SELECT DROPDOWN ========== */
.custom-select {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    width: 100%;
    padding: 10px 14px;
    padding-right: 36px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    user-select: none;
    position: relative;
}

.custom-select-trigger::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4.5px solid transparent;
    border-right: 4.5px solid transparent;
    border-top: 5px solid var(--text-tertiary);
    transition: transform 0.2s ease;
}

.custom-select.open .custom-select-trigger::after {
    transform: translateY(-50%) rotate(180deg);
}

.custom-select.open .custom-select-trigger {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary) 10%, transparent);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.custom-select-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-primary);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 20%);
    z-index: 50;
    max-height: 230px;
    overflow-y: auto;
}

.custom-select.open .custom-select-options {
    display: block;
    animation: select-slide-down 0.15s ease both;
}

@keyframes select-slide-down {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.custom-select-option {
    padding: 9px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.1s ease;
}

.custom-select-option:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.custom-select-option.selected {
    color: var(--accent-primary);
    font-weight: 500;
    background: color-mix(in srgb, var(--accent-primary) 8%, transparent);
}

.custom-select-option:last-child {
    border-radius: 0 0 10px 10px;
}

/* ========== TIME FIELD (input + time list) ========== */

.time-field {
    position: relative;
    width: 100%;
}

/* Start and end sit on one row, each keeping its own dropdown anchor.
   The fields hold five characters, so they size to content rather than
   splitting the row between them. */
.time-range {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
}

.time-range .time-field {
    width: auto;
    flex: 0 0 auto;
}

.time-range-dash {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

/* Reads as one input, but hours and minutes are edited separately. */
.time-segments {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: text;
}

.time-field.open .time-segments {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary) 10%, transparent);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.time-segment {
    width: 2ch;
    padding: 0;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    text-align: center;
}

.time-segment:focus {
    outline: none;
}

.time-segment::selection {
    background: color-mix(in srgb, var(--accent-primary) 25%, transparent);
}

.time-segment::placeholder {
    color: var(--text-tertiary);
}

.time-segments-colon {
    color: var(--text-secondary);
    font-size: 14px;
}

.time-field-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;

    /* The field is only as wide as "00:00"; the rows need room for the
       duration note beside the time. */
    min-width: max-content;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-primary);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 20%);
    z-index: 50;
    max-height: 230px;
    overflow-y: auto;
}

.time-field.open .time-field-options {
    display: block;
    animation: select-slide-down 0.15s ease both;
}

.time-field-option {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.1s ease;
}

.time-field-option:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.time-field-option.selected {
    color: var(--accent-primary);
    font-weight: 500;
    background: color-mix(in srgb, var(--accent-primary) 8%, transparent);
}

.time-field-option:last-child {
    border-radius: 0 0 10px 10px;
}

.time-field-note {
    margin-left: auto;
    padding-left: 16px;
    color: var(--text-tertiary);
    font-size: 13px;
}

.time-field-empty {
    padding: 9px 14px;
    font-size: 13px;
    color: var(--text-tertiary);
    font-style: italic;
}

.form-textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
    min-height: 200px;
}

.form-textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

/* ========== SEARCH & INPUT FIELDS ========== */
.search-input,
.tag-search-input,
.input-field {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
}

.input-field {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

.tag-search-input {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
}

.search-input:focus,
.tag-search-input:focus,
.input-field:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.input-field:focus {
    border-color: var(--accent);
}

/* ========== MODALS ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 15%);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

/* Motion: backdrop fades in, the dialog grows 97% → 100% while fading;
   closing is quicker than opening. No travel. */
.modal.active {
    display: flex;
    animation: modal-fade-in var(--dur-base) var(--ease-calm) both;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-slide-up {
    from {
        opacity: 0;
        transform: scale(0.97);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modal-fade-out {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@keyframes modal-slide-down {
    from {
        opacity: 1;
        transform: scale(1);
    }

    to {
        opacity: 0;
        transform: scale(0.97);
    }
}

.modal.is-closing {
    display: flex;
    animation: modal-fade-out var(--dur-fast) var(--ease-calm) both;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 28px;
    border-radius: 16px;
    width: 90%;
    max-width: 420px;
    border: 1px solid var(--border-color);
    box-shadow: 0 16px 48px rgb(0 0 0 / 30%), 0 2px 8px rgb(0 0 0 / 15%);
    animation: modal-slide-up var(--dur-slow) var(--ease-calm) both;
}

.modal.is-closing .modal-content {
    animation: modal-slide-down var(--dur-fast) var(--ease-calm) both;
}

.modal-content.small {
    max-width: 380px;
}

.modal-content.large {
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-header h3 {
    font-family: var(--font-sans);
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.modal-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Destructive actions in a dialog footer (Edit student). The ghost sits far left, away from Save. */
.modal-actions .btn-danger-ghost {
    margin-right: auto;
    padding: 9px 14px;
    border: 1px solid color-mix(in srgb, var(--accent-danger) 40%, var(--border-color));
    border-radius: 10px;
    background: transparent;
    color: var(--accent-danger);
    font-size: 14px;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-calm);
}

.modal-actions .btn-danger-ghost:hover {
    background: color-mix(in srgb, var(--accent-danger) 10%, transparent);
}

.modal-actions .btn-danger {
    padding: 9px 18px;
    border: none;
    border-radius: 10px;
    background: var(--accent-danger);
    color: var(--text-on-accent);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-calm);
}

.modal-actions .btn-danger:hover {
    background: color-mix(in srgb, var(--accent-danger) 85%, var(--text-primary));
}

.edit-student-confirm {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.edit-student-confirm .modal-actions {
    margin-top: 12px;
}

.edit-student-confirm-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
}

.modal-actions .btn-secondary {
    padding: 9px 18px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.modal-actions .btn-secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-actions .btn-primary,
.modal-actions .btn-add-topic {
    padding: 9px 20px;
    background: var(--accent-primary);
    border: none;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-on-accent);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--accent-primary) 30%, transparent);
    transition: all 0.15s ease;
}

/* ========== INPUT WRAPPERS ========== */
.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
}

.search-bar {
    flex: 1;
    max-width: 400px;
    min-width: 200px;
}

.tag-input-wrapper {
    position: relative;
}

/* ========== DROPDOWNS ========== */
.tag-dropdown,
.menu-dropdown {
    display: none;
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgb(0 0 0 / 30%);
    z-index: 10;
}

.tag-dropdown {
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
}

.tag-dropdown.active {
    display: block;
}

.menu-dropdown {
    top: 28px;
    right: 0;
    padding: 4px;
    min-width: 120px;
    z-index: 50;
}

.tag-dropdown-item,
.menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.2s;
}

.tag-dropdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.menu-item {
    font-size: 15px;
    border-radius: 4px;
}

.tag-dropdown-item:hover,
.menu-item:hover {
    background: var(--bg-tertiary);
}

.tag-dropdown-item.no-results {
    color: var(--text-tertiary);
    cursor: default;
    font-style: italic;
}

.tag-dropdown-item.no-results:hover {
    background: transparent;
}

.tag-dropdown-add {
    padding: 8px 12px;
    background: var(--accent-primary);
    color: white;
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
}

.tag-dropdown-add:hover {
    background: var(--accent-secondary);
}

.tag-count {
    font-size: 11px;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 3px;
}

.tag-dropdown-item:hover .tag-count {
    background: var(--bg-hover);
}

/* ========== RESPONSIVE ========== */
@media (width <= 1200px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .search-bar {
        max-width: 100%;
    }
}