/* ========================================
   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;
}

/* ========== 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 rgba(0, 0, 0, 0.2);
    z-index: 50;
    max-height: 230px;
    overflow-y: auto;
}

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

@keyframes selectSlideDown {
    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;
}

.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;
}

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

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

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

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

/* ========== TEXTAREA SPECIFIC ========== */
.notes-textarea {
    width: 100%;
    height: 40dvh;
    max-height: 50dvh;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
}

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

/* ========== MODALS ========== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal.active {
    display: flex;
    animation: modalFadeIn 0.2s ease both;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes modalFadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@keyframes modalSlideDown {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to   { opacity: 0; transform: translateY(12px) scale(0.97); }
}

.modal.is-closing {
    display: flex;
    animation: modalFadeOut 0.18s ease both;
    pointer-events: none;
}

.modal.is-closing .modal-content {
    animation: modalSlideDown 0.18s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.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 rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.15);
    animation: modalSlideUp 0.25s cubic-bezier(0.22, 1, 0.36, 1) 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;
}

.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: #FFF;
    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 rgba(0, 0, 0, 0.3);
    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 (max-width: 1200px) {
    .form-row {
        grid-template-columns: 1fr;
    }

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